cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
7098
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

1 Accepted Solution

Accepted Solutions

Try this one.

 

event manager applet test
 event none
 action 010 cli command "enable"
 action 020 cli command "show run | inc hostname"
 action 030 regexp "hostname ([\_A-Za-z0-9]+)" "$_cli_result" match name
 action 040 puts "$name"

View solution in original post

19 Replies 19

balaji.bandi
Hall of Fame
Hall of Fame

How about doing as below : for the 1 question :

 

cli command "show run | exclude hostname|router"
action  puts $_cli_result

 

2. not sure what delay you want to make - the track is required since it has action to take when the track up ?

show us some example or explain more ?

 

BB

***** Rate All Helpful Responses *****

How to Ask The Cisco Community for Help

I want to achieve such a scenario, the track crashes, eem logs it, but it starts working only if the track does not rise within three minutes, apparently the condition is necessary, but can eem do this? let's say, if track down is more than three minutes, then send a letter, if track went up in three minutes, then we don't send the letter

Dan Frey
Cisco Employee
Cisco Employee

Use subvariable to get the name "test" from the hostname statement.

 

 

event manager applet test
 event none
 action 010 cli command "enable"
 action 020 cli command "show run | inc hostname"
 action 030 regexp "hostname (test)-router" "$_cli_result" match name
 action 040 puts "$name"
!
     
test-router#event manager run test
test

test-router#

 

Hi, I wanted to exclude "hostname" and "-router" because there may be other values ​​instead of "test"

Try this one.

 

event manager applet test
 event none
 action 010 cli command "enable"
 action 020 cli command "show run | inc hostname"
 action 030 regexp "hostname ([\_A-Za-z0-9]+)" "$_cli_result" match name
 action 040 puts "$name"

hmm, yes, it works for all values ​​of this kind "hostname border-router" "hostname test-router" and so on, can you give a little explanation?

[\ _A-Za-z0-9] +)

"\ _" - match the character "_" or a space?
"A-Z" "a-z" "0-9" all lowercase, uppercase and all numbers?

 

I want to figure it out so that I can then try to transfer for such hostname test-gw-router, so that only test-gw is left

Hi there,

You description is correct. Crucially the '+' quantifier will keep matching until it hits the first hyphen, which is what you wanted for the first use case.

To match  a host name with two hyphens present you could try this:

hostname ([\_A-Za-z0-9]+(\-[\_A-Za-z0-9]+)?)-router

...which becomes:

 action 030 regexp "hostname ([\_A-Za-z0-9]+(\-[\_A-Za-z0-9]+)?)-router" "$_cli_result" match name

...this creates a second group within the first match and by using the '?' quantifier we are matching the second group zero or more times up until it hits the string '-router' .  (I should point out I have only run this through an online PCRE checker)

 

cheers,

Seb.

 

 

I'll try later, but I'm thinking of the "?" will swear again

 

this is how it works, but if a hostname of this kind comes across, then "test-router" will not work, it will work only for two "-"

I did it by pushing the whistle off your

event manager applet test
 event none
 action 010 cli command "enable"
 action 020 cli command "show run | inc hostname"
 action 030 regexp "hostname (([\_A-Za-z0-9]+)|[\_A-Za-z0-9]+(\-[\_A-Za-z0-9]+)?)-router" "$_cli_result" match name
 action 040 puts "$name"

 

hmmm I suppose if the '?' quantifier doesn't work in EEM, try this:

hostname ([\-A-Za-z0-9]+)-router

This will endlessly match multi-hyphenated hostnames.

 

cheers,

Seb.

? is a valid character in IOS when users do "control v" then ?.    Inside EEM you can pass the ascii number  \022 for control v to use it.  Make sure to actually type in control v before ? or you will get the help menu when building the applet.

 

action 030 regexp "hostname (([\_A-Za-z0-9]+)|[\_A-Za-z0-9]+(\-[\_A-Za-z0-9]+)\022?)-router" "$_cli_result" match name
test-gw-router# event manager run test
test-gw

test-gw-router#

hmm, error

action 030 regexp "hostname (([\_A-Za-z0-9]+)|[\_A-Za-z0-9]+(\-[\_A-Za-z0-9]+)\022?
Warning: Assumed end-quote for quoted string
WORD

  Did you type "control v" before the question mark?

I added to eem like this, including the "control v" character

 

action 030 regexp "hostname (([\_A-Za-z0-9]+)|[\_A-Za-z0-9]+(\-[\_A-Za-z0-9]+)\022?)-router" "$_cli_result" match name

in this form it looks on the router

event manager applet test
 event none
 action 010 cli command "enable"
 action 020 cli command "show run | inc hostname"
 action 030 regexp "hostname (([\_A-Za-z0-9]+)|[\_A-Za-z0-9]+(\-[\_A-Za-z0-9]+)^R?)-router" "$_cli_resul"
 action 040 puts "$name"

 

Hi Dan..  I have a similiar regexp I'm working on, that I would think should be easy.

I am able to extract the IP I want, but I just want the last two octets of that IP..

ie.. 107.84.30.1, I just want the 30.1  portion, octets 3 & 4 

Any chance this can be done easily using cisco eem regex expression. It's my line 0040 that I'm failing to parse out the two octets.


event manager applet DMVPNIP
event none sync yes
action 0010 cli command "enable"
action 0020 cli command "show ip int brief | include Cellular0/2/0"
action 0030 regexp "[0-9.]+[0-9.]+[0-9.]+[0-9.]" "$_cli_result" WANIP
action 0040 regexp "{\A([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})[0-9]+\.[0-9]\z}" "$_cli_result" DMVPNIP

 

 

Review Cisco Networking for a $25 gift card