Event Manager Applet [ EEM ]
이와 같은 토폴로지에서…
· Condition 1
· FastEthernet0/0 , FastEthernet0/1 두 개의 인터페이스 중 하나라도 Down되면 Serial Interface 를 shutdown
· Condition 2
· FastEthernet0/0 , FastEthernet0/1 두 개의 인터페이스가 모두 Up 상태이면 Serial Interface 를 no shutdown
각 인터페이스를 위한 tracking 설정
Track 100 interface fa0/0 line-protocol // interface fa0/0 의 포트 상태 모니터링
Track 101 interface fa0/1 line-protocol // interface fa0/1 의 포트 상태 모니터링
Condition 1 ( Down ) 에 대한 EEM
event manager applet EEM_DOWN
event tag 200 track 100 state down // track 100이 down될 경우를 부분을 tag 200으로 설정
event tag 201 track 101 state down // track 101에 down될 경우를 tag 201로 설정
trigger // 발동 조건
correlate event 200 or event 201 // 둘중 하나가 일어나게 되면 ( OR )
attribute tag 200 occurs 1 // tag에 대한 발생 횟수 설정
attribute tag 201 occurs 1 // tag에 대한 발생 횟수 설정
action 050 puts "oooooooooooooooo" // 실행될 부분
action 051 puts "o DOWN o"
action 052 puts "oooooooooooooooo"
* 인터넷을 찾아보면 syslog를 읽어서 발동시키는 부분이 많은데, 이는 좀 불안해서 tracking 상태를 읽는 방법으로 사용했습니다. 아래의 예시가 인터페이스가 down 되었을 경우를 읽는 것입니다.
event manager applet WatchLo0
event syslog pattern "Interface Loopback0.* down" period 1
action 2.0 cli command "enable"
action 2.1 cli command "config t"
<생략>
Condition 2 ( Up ) 에 대한 EEM
event manager applet EEM_UP
event tag 200 track 100 state up // track 100이 up될 경우를 tag 200으로 설정
event tag 201 track 101 state up // track 101이 up될 경우를 tag 201로 설정
trigger // 발동 조건
correlate event 200 or event 201 // 위와 동일한 부분...
attribute tag 200 occurs 1
attribute tag 201 occurs 1
action 010 track read 100 // track 100의 상태를 읽어서
action 019 puts "track 100 is $_track_state" // track 100의 상태를 출력하고 ( debug )
action 020 if $_track_state eq down goto 060 // down 이면 맨 끝 줄로 jump
action 030 track read 101 // track 101의 상태를 읽어서
action 039 puts "track 101 is $_track_state" // track 101의 상태를 출력하고 ( debug )
action 040 if $_track_state eq down goto 060 // down 이면 맨 끝 줄로 jump
action 050 puts "oooooooooooooooo" // 실행될 부분
action 051 puts "o UP o"
action 052 puts "oooooooooooooooo"
action 060 puts "end point"
!
end
* UP 에 대한 부분은 "AND" 연산이 필요하기 때문에 프로그래밍 언어적인 부분이 사용되었는데요, EEM 하나에 구현하려면 어쩔 수가 없었던 것 같습니다.
Correlate 를 사용해서 "and"가 적용이 가능하지만 occurs 를 통해 횟수를 지정해 줘야 하는데 최소값이 1이기 때문에 포트 하나만 down->up 되었을 경우에는 하나의 태그에 대해서만 이벤트가 발생되었기 때문에 trigger 가 발동하지 못합니다.
그래서 위와 같은 방식으로 짜게 되었는데요. 그 외에도 여러 시도를 해봤었습니다.
아래와 같이 while loop 를 사용해서 짜보기도 했었는데요 5초에 한번씩 링크 상태를 체크했었습니다. ( 초기에 작업한 거라 좀 잡다한 부분이 많이 들어가 있습니다) 아무튼 아래와 같이 돌리게 되면 디버그를 돌려보면 몇 번 돌아가다 보면 EEM 자체에서 Loop를 감지해서 eem을 close 시켜버립니다. 그래서 loop를 이용해서는 불가능 하다고 생각했죠. 그래서 위와 같은 방법을 통해서 완성한 것입니다.
event manager applet LOOP
event tag 200 track 100 state down
event tag 201 track 101 state down
trigger
correlate event 200 or event 201
action 001 cli command "enable"
action 002 cli command "conf t"
action 003 cli command "interface s0/0/0"
action 004 cli command "shutdown"
action 005 cli command "end"
action 006 while 1 eq 1
action 010 wait 5
action 011 cli command "show int fa0/0 | inc FastEthernet0/0"
action 012 regexp "up, line protocol is up" "$_cli_result"
action 013 if $_regexp_result eq 1
action 014 puts "break 3"
action 015 cli command "show int fa0/1 | inc FastEthernet0/1"
action 016 regexp "up, line protocol is up" "$_cli_result"
action 017 if $_regexp_result eq 1
action 018 puts "break 4"
action 019 cli command "conf t"
action 020 cli command "int s0/0/0"
action 021 cli command "no shutdown"
action 022 cli command "end"
action 023 break
action 024 end
action 025 end
action 026 end
아래는 저 위의 실제 적용한 컨피그에 대한 로그 부분입니다.
Router#
*Nov 26 06:27:56.702: %TRACKING-5-STATE: 100 interface Fa0/0 line-protocol Up->Down
*Nov 26 06:27:56.702: %TRACKING-5-STATE: 101 interface Fa0/1 line-protocol Up->Down
*Nov 26 06:27:56.710: %HA_EM-6-LOG: EEM_DOWN: oooooooooooooooo
*Nov 26 06:27:56.710: %HA_EM-6-LOG: EEM_DOWN: o DOWN o
*Nov 26 06:27:56.710: %HA_EM-6-LOG: EEM_DOWN: oooooooooooooooo
*Nov 26 06:27:56.714: %HA_EM-6-LOG: EEM_DOWN: oooooooooooooooo
*Nov 26 06:27:56.714: %HA_EM-6-LOG: EEM_DOWN: o DOWN o
*Nov 26 06:27:56.718: %HA_EM-6-LOG: EEM_DOWN: oooooooooooooooo
*Nov 26 06:27:56.834: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to down
*Nov 26 06:27:57.202: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to down
*Nov 26 06:27:59.702: %TRACKING-5-STATE: 100 interface Fa0/0 line-protocol Down->Up
*Nov 26 06:27:59.710: %HA_EM-6-LOG: EEM_UP: track 100 is up
*Nov 26 06:27:59.710: %HA_EM-6-LOG: EEM_UP: track 101 is down
*Nov 26 06:27:59.710: %HA_EM-6-LOG: EEM_UP: end point
*Nov 26 06:28:00.702: %TRACKING-5-STATE: 100 interface Fa0/0 line-protocol Up->Down
*Nov 26 06:28:00.702: %TRACKING-5-STATE: 101 interface Fa0/1 line-protocol Down->Up
*Nov 26 06:28:00.710: %HA_EM-6-LOG: EEM_DOWN: oooooooooooooooo
*Nov 26 06:28:00.710: %HA_EM-6-LOG: EEM_DOWN: o DOWN o
*Nov 26 06:28:00.710: %HA_EM-6-LOG: EEM_DOWN: oooooooooooooooo
*Nov 26 06:28:00.718: %HA_EM-6-LOG: EEM_UP: track 100 is down
*Nov 26 06:28:00.718: %HA_EM-6-LOG: EEM_UP: end point
*Nov 26 06:28:01.702: %TRACKING-5-STATE: 101 interface Fa0/1 line-protocol Up->Down
*Nov 26 06:28:01.706: %HA_EM-6-LOG: EEM_DOWN: oooooooooooooooo
*Nov 26 06:28:01.706: %HA_EM-6-LOG: EEM_DOWN: o DOWN o
*Nov 26 06:28:01.710: %HA_EM-6-LOG: EEM_DOWN: oooooooooooooooo
*Nov 26 06:28:02.702: %TRACKING-5-STATE: 100 interface Fa0/0 line-protocol Down->Up
*Nov 26 06:28:02.702: %TRACKING-5-STATE: 101 interface Fa0/1 line-protocol Down->Up
*Nov 26 06:28:02.710: %HA_EM-6-LOG: EEM_UP: track 100 is up
*Nov 26 06:28:02.714: %HA_EM-6-LOG: EEM_UP: track 101 is up
*Nov 26 06:28:02.714: %HA_EM-6-LOG: EEM_UP: oooooooooooooooo
*Nov 26 06:28:02.714: %HA_EM-6-LOG: EEM_UP: o UP o
*Nov 26 06:28:02.714: %HA_EM-6-LOG: EEM_UP: oooooooooooooooo
*Nov 26 06:28:02.714: %HA_EM-6-LOG: EEM_UP: end point
*Nov 26 06:28:02.718: %HA_EM-6-LOG: EEM_UP: track 100 is up
*Nov 26 06:28:02.718: %HA_EM-6-LOG: EEM_UP: track 101 is up
*Nov 26 06:28:02.722: %HA_EM-6-LOG: EEM_UP: oooooooooooooooo
*Nov 26 06:28:02.722: %HA_EM-6-LOG: EEM_UP: o UP o
*Nov 26 06:28:02.722: %HA_EM-6-LOG: EEM_UP: oooooooooooooooo
*Nov 26 06:28:02.722: %HA_EM-6-LOG: EEM_UP: end point
*Nov 26 06:28:02.726: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
*Nov 26 06:28:03.406: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up
Router#
*Nov 26 06:28:25.702: %TRACKING-5-STATE: 100 interface Fa0/0 line-protocol Up->Down
*Nov 26 06:28:25.706: %HA_EM-6-LOG: EEM_DOWN: oooooooooooooooo
*Nov 26 06:28:25.706: %HA_EM-6-LOG: EEM_DOWN: o DOWN o
*Nov 26 06:28:25.706: %HA_EM-6-LOG: EEM_DOWN: oooooooooooooooo
*Nov 26 06:28:25.962: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to down
*Nov 26 06:28:26.702: %TRACKING-5-STATE: 101 interface Fa0/1 line-protocol Up->Down
*Nov 26 06:28:26.706: %HA_EM-6-LOG: EEM_DOWN: oooooooooooooooo
*Nov 26 06:28:26.706: %HA_EM-6-LOG: EEM_DOWN: o DOWN o
*Nov 26 06:28:26.710: %HA_EM-6-LOG: EEM_DOWN: oooooooooooooooo
*Nov 26 06:28:26.926: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to down
*Nov 26 06:28:27.702: %TRACKING-5-STATE: 101 interface Fa0/1 line-protocol Down->Up
*Nov 26 06:28:27.710: %HA_EM-6-LOG: EEM_UP: track 100 is down
*Nov 26 06:28:27.710: %HA_EM-6-LOG: EEM_UP: end point
*Nov 26 06:28:28.702: %TRACKING-5-STATE: 101 interface Fa0/1 line-protocol Up->Down
*Nov 26 06:28:28.706: %HA_EM-6-LOG: EEM_DOWN: oooooooooooooooo
*Nov 26 06:28:28.706: %HA_EM-6-LOG: EEM_DOWN: o DOWN o
*Nov 26 06:28:28.710: %HA_EM-6-LOG: EEM_DOWN: oooooooooooooooo
*Nov 26 06:28:29.702: %TRACKING-5-STATE: 101 interface Fa0/1 line-protocol Down->Up
*Nov 26 06:28:29.710: %HA_EM-6-LOG: EEM_UP: track 100 is down
*Nov 26 06:28:29.710: %HA_EM-6-LOG: EEM_UP: end point
*Nov 26 06:28:30.502: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up
*Nov 26 06:28:30.702: %TRACKING-5-STATE: 100 interface Fa0/0 line-protocol Down->Up
*Nov 26 06:28:30.710: %HA_EM-6-LOG: EEM_UP: track 100 is up
*Nov 26 06:28:30.710: %HA_EM-6-LOG: EEM_UP: track 101 is up
*Nov 26 06:28:30.710: %HA_EM-6-LOG: EEM_UP: oooooooooooooooo
*Nov 26 06:28:30.710: %HA_EM-6-LOG: EEM_UP: o UP o
*Nov 26 06:28:30.710: %HA_EM-6-LOG: EEM_UP: oooooooooooooooo
*Nov 26 06:28:30.710: %HA_EM-6-LOG: EEM_UP: end point
*Nov 26 06:28:31.238: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
*Nov 26 06:29:19.702: %TRACKING-5-STATE: 100 interface Fa0/0 line-protocol Up->Down
*Nov 26 06:29:19.706: %HA_EM-6-LOG: EEM_DOWN: oooooooooooooooo
*Nov 26 06:29:19.706: %HA_EM-6-LOG: EEM_DOWN: o DOWN o
*Nov 26 06:29:19.706: %HA_EM-6-LOG: EEM_DOWN: oooooooooooooooo
*Nov 26 06:29:20.674: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to down
Router#