12-19-2023 07:48 AM
Hello,
I am currently working on a eem script and I am struggling to display a script output line by line on a syslog.
The command is show mab all sum and the result is usually like this :
Interface Client Mac Authen Status
Gi1/0/1 aaaa.bbbb.cccc SUCCESS
Tw2/0/2 cccc.dddd.eeee FAILED
Tw3/0/3 rrrr.dddd.aaaa SUCCESS
etc etc ...
Here is my current script :
event manager applet timer-display-mab-int
event timer watchdog time 10
action 1.1 cli command "enable"
action 1.2 cli command "show mab all sum"
action 1.3 foreach loop $_cli_result "\n"
action 1.4 regexp "(Gi([0-9/]+)|Tw([0-9/]+)) "$_cli_result" match ifname
action 1.5 syslog msg "Interface name is $ifname"
action 1.6 end
The goal is to display a syslog with each interface number (and more later on)
For example syslog would display :
Interface name is Gi1/0/1
Interface name is Tw2/0/2
Interface name is Tw3/0/3
Can anyone help me in any way ?
Let me know if I wasn't clear enough !
Thanks in advance,
Solved! Go to Solution.
12-19-2023 10:14 AM - edited 12-19-2023 10:15 AM
I do not have mab running so here is an example with another command to filter out only GigabitEthernet and Loopback interfaces. I believe your regexp statement needs to be updated and also add in the $_regexp_result eq 1 command so it does not throw an error when iterating over lines that do not match.
event manager applet test
event none
action 010 cli command "enable"
action 020 cli command "show ip int brief"
action 040 foreach loop "$_cli_result" "\n"
action 050 regexp "(^[GL][a-zE0-9\/\.]+)" "$loop" match ifname
action 055 if $_regexp_result eq "1"
action 060 syslog msg "Interface name is $ifname"
action 100 end
action 110 end
INET#event manager run test
INET#
*Dec 19 18:13:05.589: %HA_EM-6-LOG: test: Interface name is GigabitEthernet1
*Dec 19 18:13:05.589: %HA_EM-6-LOG: test: Interface name is GigabitEthernet2
*Dec 19 18:13:05.589: %HA_EM-6-LOG: test: Interface name is GigabitEthernet3
*Dec 19 18:13:05.589: %HA_EM-6-LOG: test: Interface name is GigabitEthernet4
*Dec 19 18:13:05.589: %HA_EM-6-LOG: test: Interface name is GigabitEthernet4.2
*Dec 19 18:13:05.590: %HA_EM-6-LOG: test: Interface name is GigabitEthernet5
*Dec 19 18:13:05.590: %HA_EM-6-LOG: test: Interface name is GigabitEthernet6
*Dec 19 18:13:05.590: %HA_EM-6-LOG: test: Interface name is GigabitEthernet7
*Dec 19 18:13:05.590: %HA_EM-6-LOG: test: Interface name is GigabitEthernet8
*Dec 19 18:13:05.590: %HA_EM-6-LOG: test: Interface name is GigabitEthernet9
*Dec 19 18:13:05.590: %HA_EM-6-LOG: test: Interface name is GigabitEthernet10
*Dec 19 18:13:05.590: %HA_EM-6-LOG: test: Interface name is Loopback1
*Dec 19 18:13:05.590: %HA_EM-6-LOG: test: Interface name is Loopback2
12-19-2023 08:00 AM
Hi friend'
I think you can use aaa account and send syslog to server
I will check this point
MHM
12-19-2023 10:07 AM
Hey, thank you for answering !
However I am trying to do that so I can later replace the syslog message results with commands, such as clear authentifications sessions etc ...
So sending the results into a syslog server or else is not gonna help :(.
12-19-2023 10:14 AM - edited 12-19-2023 10:15 AM
I do not have mab running so here is an example with another command to filter out only GigabitEthernet and Loopback interfaces. I believe your regexp statement needs to be updated and also add in the $_regexp_result eq 1 command so it does not throw an error when iterating over lines that do not match.
event manager applet test
event none
action 010 cli command "enable"
action 020 cli command "show ip int brief"
action 040 foreach loop "$_cli_result" "\n"
action 050 regexp "(^[GL][a-zE0-9\/\.]+)" "$loop" match ifname
action 055 if $_regexp_result eq "1"
action 060 syslog msg "Interface name is $ifname"
action 100 end
action 110 end
INET#event manager run test
INET#
*Dec 19 18:13:05.589: %HA_EM-6-LOG: test: Interface name is GigabitEthernet1
*Dec 19 18:13:05.589: %HA_EM-6-LOG: test: Interface name is GigabitEthernet2
*Dec 19 18:13:05.589: %HA_EM-6-LOG: test: Interface name is GigabitEthernet3
*Dec 19 18:13:05.589: %HA_EM-6-LOG: test: Interface name is GigabitEthernet4
*Dec 19 18:13:05.589: %HA_EM-6-LOG: test: Interface name is GigabitEthernet4.2
*Dec 19 18:13:05.590: %HA_EM-6-LOG: test: Interface name is GigabitEthernet5
*Dec 19 18:13:05.590: %HA_EM-6-LOG: test: Interface name is GigabitEthernet6
*Dec 19 18:13:05.590: %HA_EM-6-LOG: test: Interface name is GigabitEthernet7
*Dec 19 18:13:05.590: %HA_EM-6-LOG: test: Interface name is GigabitEthernet8
*Dec 19 18:13:05.590: %HA_EM-6-LOG: test: Interface name is GigabitEthernet9
*Dec 19 18:13:05.590: %HA_EM-6-LOG: test: Interface name is GigabitEthernet10
*Dec 19 18:13:05.590: %HA_EM-6-LOG: test: Interface name is Loopback1
*Dec 19 18:13:05.590: %HA_EM-6-LOG: test: Interface name is Loopback2
12-21-2023 02:02 AM
Thank you very much for your help ! I tweaked it a bit to match my needs , but adding the second loop (if statement + rege result variable) did the job !
You are the GOAT, please keep that in mind.
Have a great day !
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