cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
7343
Views
20
Helpful
19
Replies

EEM regexp exclude word

fractal90
Level 3
Level 3

hi, please tell me two points:

1. I want to exclude a word in eem via regexp, for example there is a line:

sh run | i hostname
hostname test-router

i need to select everything except "hostname" and "router"

doing so:

action 112 regexp "(!?hostname|-router)" "$_cli_result" name

but it doesn't work because eem swears at the "?" and it is removed

2. how to make a delay in EEM, let's say it should trigger on "event track 10 state down" I just want him to wait 3 minutes after he fixes it and then run all the necessary commands

19 Replies 19

Change action 0030 to this line and variable $octet3and4 will contain the value of the last two octets.  action 0040 is not needed.  

action 0030 regexp "([0-9]+\.[0-9]+\.([0-9]+\.[0-9]+))" $_cli_result match WANIP octet3and4

 

 

I have seemingly the same problem, I am getting error with regular expression from the logs

event manager applet unshutdownBgpPeerCoreSwitch authorization bypass
event timer watchdog time 60
action 010 cli command "enable"
action 020 cli command "show ip bgp nei 39.38.90.233 | include BGP.state"
action 030 regexp "BGP state = Established, up for (00) 00)\\:(3[0 9]+)9]+)\\:([0 9]+)" "$_cli_result"
action 040 if $_regexp_result eq "1"
action 050 syslog msg "Remove Administratively shutdown of eBGP and iBGP neighbors 10.241.62.65 and 10.0.240.87 respectively"
action 060 cli command "config t"
action 070 cli command "router bgp 64722"
action 080 cli command "no neighbor 10.241.62.65 shutdown"
action 090 cli command "no neighbor 10.0.240.87 shutdown"
action 100 cli command "end"
action 110 cli command "clear ip bgp * all soft"
action 120 else
action 130 end

 

xxx here is the error I get

 

Aug 2 04:09:21.819: %HA_EM-6-FMPD_REGCOMP: Error compiling regular expression: *** unknown regexp error code ***
Aug 2 04:09:21.819: %HA_EM-3-FMPD_ERROR: Error executing applet unshutdownBgpPeerCoreSwitch statement 030
Aug 2 04:10:21.820: %HA_EM-6-FMPD_REGCOMP: Error compiling regular expression: *** unknown regexp error code ***
Aug 2 04:10:21.820: %HA_EM-3-FMPD_ERROR: Error executing applet unshutdownBgpPeerCoreSwitch statement 030
Aug 2 04:11:21.921: %HA_EM-6-FMPD_REGCOMP: Error compiling regular expression: *** unknown regexp error code ***
Aug 2 04:11:21.921: %HA_EM-3-FMPD_ERROR: Error executing applet unshutdownBgpPeerCoreSwitch statement 030

 

xxxx

basically all I want is if the output of the CLI command returns an output where BGP is established for at least 30 minutes, it would execute the scripts in my EEM config

show ip bgp nei 39.38.90.233 | include BGP.state

xxxx

Am I missing something ? Thanks in advance for the valuable inputs.

 

 

It is going to be a struggle to find regexp that will capture greater than 30 minute uptime without a common unit of measure like seconds.   The result of the BGP uptime can be displayed differently depending on the elapsed time and regexp needs to account for both.

 

  BGP state = Established, up for 03:55:20
or it can look like
  BGP state = Established, up for 5d06h

 

   Here is an example and you need to fill in the actions depending if the threshold is crossed or not.

 

event manager applet unshutdownBgpPeerCoreSwitch authorization bypass
 event none
 action 010 cli command "enable"
 action 015 set gt30min "false"
 action 020 cli command "show ip bgp vpnv4 vrf 1 neighbors 10.32.200.2 | inc BGP state"
 action 030 regexp "BGP state = Established, up for ([0-9]+):([0-9]+):([0-9]+)" "$_cli_result" match hour min sec
 action 040 if $_regexp_result eq "1"
 action 050  multiply $hour 3600
 action 055  set hour "$_result"
 action 060  multiply $min 60
 action 065  set min "$_result"
 action 070  add $hour $min
 action 080  add $_result $sec
 action 085  set seconds "$_result"
 action 087  puts "seconds = $seconds"
 action 090 if $seconds gt 1800
 action 100 set gt30min "true"
 action 110 end
 action 189 end
 action 190 regexp "BGP state = Established, up for ([0-9]+[a-z]+[0-9]+[a-z])" "$_cli_result" match uptime
 action 200 if $_regexp_result eq "1"
 action 205  puts "uptime = $uptime"
 action 210  set gt30min "true"
 action 220 end
 action 300 if $gt30min eq "true"
 action 310  syslog msg "Remove Administratively shutdown of eBGP and iBGP neighbors 10.241.62.65 and 10.0.240.87 respectively"
 action 320  cli command "conf t"
***Do Actions Here*** when uptime greater than 30 minutes
 action 400 else
 action 410  puts "less than 30 minute up time"
***Do Actions Here*** when uptime 30 minutes or less
 action 500 end
 action 510 puts "value = $gt30min"

 

Hello,

 

not sure if the second part of your question has already been answered:

 

--> 2. how to make a delay in EEM, let's say it should trigger on "event track 10 state down" I just want him to wait 3 minutes after he fixes it and then run all the necessary commands

 

The line:

 

action x wait 180

 

would delay the execution of the script, depending on where that line is placed in the script.

thought about the proposed a little, apparently the best option would be the following

if the line "% TRACK-6-STATE: 10 ip sla 10 reachability Up -> Down" appears in syslog, then turn on the countdown, if the line "% TRACK-6-STATE: 10 ip sla 10 reachability does not appear in syslog in 5 minutes Down-> Up "then further check the mac address on the port and send the letter

 

though I'm still thinking how to portray it

Review Cisco Networking for a $25 gift card