03-12-2021 02:47 AM
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
Solved! Go to Solution.
03-12-2021 06:23 PM - edited 03-12-2021 06:25 PM
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"
03-12-2021 03:51 AM
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 ?
03-13-2021 03:19 AM
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
03-12-2021 10:06 AM
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#
03-12-2021 06:12 PM
Hi, I wanted to exclude "hostname" and "-router" because there may be other values instead of "test"
03-12-2021 06:23 PM - edited 03-12-2021 06:25 PM
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"
03-13-2021 03:30 AM - edited 03-13-2021 03:44 AM
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
03-15-2021 03:09 AM
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.
03-15-2021 03:17 AM - edited 03-15-2021 03:28 AM
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"
03-15-2021 04:50 AM
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.
03-15-2021 05:26 AM
? 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#
03-15-2021 08:27 AM
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
03-15-2021 10:04 AM
Did you type "control v" before the question mark?
03-15-2021 07:17 PM - edited 03-15-2021 07:32 PM
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"
11-23-2022 06:46 AM
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
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide