05-09-2024 04:02 AM
I am working on a eem script and struggling to display a script output line by line on a syslog. It 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 ?
05-09-2024 05:54 AM
Try using more descriptive variable names, so for exmaple, instead of the $_cli_result, try c$mab_output. You can also streamline your regular expression to (\w+[0-9/]+) for a simpler pattern that matches word characters followed by digits and slashes. Often when i am logging messages, i leverage syslog with a specified severity level for clarity and organization, rather than a basic syslog msg, opt for syslog priority info msg to denote the importance of the log message.
Try this verison, that I've also added a foreach loop to iterate over each line in the mab_output variable, and used the line variable to access each line individually. This should make the script more efficient and easier to read too.
Hope this helps.
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 line in $_cli_result "\n" {
action 1.4 regexp "(\w+[0-9/]+)" $line match ifname
action 1.5 syslog priority info msg "Interface name is $ifname"
}
action 1.6 end
05-22-2024 05:40 AM
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.
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