04-14-2016 10:57 AM
Hi, hope you can help me here since I am new to EEM.
I wrote a script to monitor SIP trunk status every 5 minutes and if it goes down send me an email. It works good, but if the SIP trunk is down, script will continue to run and I will keep getting alerts every 5 minutes until the issue is resolved.
I was wondering if there is any way to stop the script from running until trunk comes back up. I am assuming I will need to create another script to monitor if SIP registration is up and somehow tie two scripts together so that one disables another. Hope there is a more elegant solution.
Here is my script:
event manager applet SIP_Trunk_Monitor
event timer cron cron-entry "*/5 * * * *"
action 100 cli command "en"
action 200 cli command "show sip-ua register status"
action 250 foreach line "$_cli_result" "\n"
action 300 regexp "4262456285(.*) no " "$line"
action 400 if $_regexp_result eq "1"
action 600 mail server "10.10.10.10" to "email@company.com" from "monitoring@company.com" subject "SIP trunk is DOWN" body "SIP trunk is DOWN on RouterA"
action 700 end
action 800 end
Thanks for your help
Solved! Go to Solution.
04-18-2016 08:13 AM
No, this won't work. You need to configure (config t) the environment variable that you wish to use to track the trunk status.
04-17-2016 08:18 AM
What you could do is when the event is triggered, drop into config mode and set the event for this applet to be "none". Then, within the same applet, configure a second countdown timer applet that times your hold down period. When it fires, it drops into config mode, sets the event for SIP_Trunk_Monitor back to a cron timer, and then removes itself.
This is similar to the hold down strategy I discuss in https://supportforums.cisco.com/document/12723951/how-introduce-large-delays-eem-policies .
04-18-2016 07:41 AM
Thanks
Another solution I was thinking about - is there any way to define a global variable "i" (kind of like you did event manager environment q "). Variable will either be i=1 (trunk is up) or i=0 (trunk is down).
Then have two conditions:
1. if trunk is down and variable equals 1 (trunk was UP before) - send alert email that trunk is down and change variable to 0
2. if trunk is up and variable equals 0 (trunk was DOWN before) - send another email that trunk came back up and change var to 1
I think this will be much easier, but I am not sure if we can have such variables in EEM and if we can compare it's value to regex results like this:
action 400 if $_regexp_result eq i
04-18-2016 07:47 AM
You can do this with EEM contexts or by configuring an environment variable within your policy.
04-18-2016 08:08 AM
Please take a look at this. Since I don't have a test router and my sip trunk rarely goes down, I don't have a way to test this script. Does it make sense to you?
As I said before, I am new to EEM so you help is really appreciated.
event manager applet SIP_Trunk_Monitor
event timer cron cron-entry "*/5 * * * *"
action 50 set i 1
action 100 cli command "en"
action 200 cli command "show sip-ua register status"
action 250 foreach line "$_cli_result" "\n"
action 300 regexp "4262456285(.*) no " "$line"
action 400 if $_regexp_result eq "1"
action 450 if $i eq "1"
action 600 mail server "10.10.50.223" to "email@company.com" from "email@company.com" subject "RouterA: SIP trunk is DOWN" body "SIP trunk is DOWN on RouterA"
action 601 set i 0
action 602 end
action 603 else
action 650 if $i eq "0"
action 651 mail server "10.10.50.223" to "email@company.com" from "email@company.com" subject "RouterA: SIP trunk is back UP" body "SIP trunk is back UP on RouterA"
action 652 set i 1
action 700 end
action 800 end
action 900 end
04-18-2016 08:13 AM
No, this won't work. You need to configure (config t) the environment variable that you wish to use to track the trunk status.
04-18-2016 08:50 AM
so are you saying I should use "event manager environment command" and not "action set i 1"? Something like this?
event manager environment i 1
event manager applet SIP_Trunk_Monitor
event timer cron cron-entry "*/5 * * * *"
action 100 cli command "en"
action 200 cli command "show sip-ua register status"
action 250 foreach line "$_cli_result" "\n"
action 300 regexp "4262456285(.*) no " "$line"
action 400 if $_regexp_result eq "1"
action 450 if $i eq "1"
action 500 mail server "10.10.50.223" to "email@company.com" from "email@company.com" subject "RouterA: SIP trunk is DOWN" body "SIP trunk is DOWN on RouterA"
action 600 cli command "conf t"
action 601 cli command "event manager environment i 0"
action 602 cli command "exit"
action 603 end
action 604 else
action 650 if $i eq "0"
action 651 mail server "10.10.50.223" to "email@company.com" from "email@company.com" subject "RouterA: SIP trunk is back UP" body "SIP trunk is back UP on RouterA"
action 652 cli command "conf t"
action 653 cli command "event manager environment i 1"
action 654 cli command "exit"
action 700 end
action 800 end
action 900 end
04-18-2016 08:54 AM
Yes, this is correct. While I would have chosen a variable name that was more descriptive, it should do what you want.
04-18-2016 09:10 AM
I just tested the script and did not get any emails at all (I brought our sip trunk down to test). Have a feeling it's not taking this command:
action 450 if $i eq "1"
what's the best way I can debug this script? I am assuming there is no way to run it line by line and see the output or changes each line makes?
04-18-2016 09:44 AM
You can enable "debug event manager action cli" to see the CLI commands being run.
04-18-2016 09:46 AM
Thanks for your help. Looks like the script is working as it should now. I forgot to add one more "end" before:)
09-05-2016 05:33 AM
Hi team! this post is awesome!
But i need your help...
I am newbie to EMM
How change above script ,to send the router to reboot if 1 SIP account is missing in "sh sip-ua register status"
09-05-2016 10:34 AM
You should start a new thread for your issue.
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