cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1586
Views
0
Helpful
11
Replies

How to access an url when interface has down for 5 minutes and will send an email if it has up before 5 mins (will not access url)

sunning_pro
Level 1
Level 1

I've tried this one before and it works, but the problem is, I would like to use full tcl, do I need 3 tcl script to do that? And is there another way to implement that 5 minutes problem? Because it looks a bit brute force to cancel the trigger occurs...

 

#event manager directory user policy "flash:/Test"
#event manager policy test.tcl

#test.tcl already contain the http::get

 

event manager environment _email_from yyy@yyy.com

event manager environment _email_to yyy@yyy.com

event manager environment _email_server yyy@yyy.com

event manager environment _email_cc yyy@yyy.com

 

event manager applet one

event syslog pattern "Line protocol on Interface GigabitEthernet0/0, changed state to down"

action 1.0 cli command "enable"

action 1.1 cli command "show clock"

action 2.0 mail server "$_email_server" to "$_email_to" from "$_email_from" cc "$_email_cc" subject "Test" body "$_cli_result"

 

event manager applet two

event tag e1 syslog pattern "Line protocol on Interface GigabitEthernet0/0, changed state to down"

trigger occurs 1 delay 60

 correlate event e1

action 1.0 cli command "enable"

action 1.6 cli command "tclsh flash:/Test/test.tcl"

 

event manager applet three

event syslog pattern "Line protocol on Interface GigabitEthernet0/0, changed state to up"

action 1.0 cli command "enable"

action 1.1 cli command "configure term"

action 1.2 cli command "event manager applet two"

action 1.3 cli command "no trigger occurs 1 delay 60"

action 1.4 cli command "trigger occurs 1 delay 60"

action 1.5 cli command "correlate event e1"

action 2.0 mail server "$_email_server" to "$_email_to" from "$_email_from" cc "$_email_cc" subject "Test" body "$_cli_result"

11 Replies 11

toonz_vpec17
Level 1
Level 1

TCL Script is difficult then EEM

Joe Clarke
Cisco Employee
Cisco Employee

I don't understand your questions because you didn't share the whole solution.  I have no idea what the test.tcl thing does.  However, what is here could certainly be combined into one EEM policy using some programmatic logic.

Below is the test.tcl which only access the url:

source "tmpsys:lib/tcl/http.tcl"
set Token [::http::geturl "http://172.16.213.18/o"]

One EEM policy means that only one tcl script could solve it?

I am new to EEM, please show how to do the EEM policy?

Any help would be really appreciated.

Thanks

 

Sure, one script could do it.  The HTTP library you source is natively part of EEM Tcl.  So your applet two could be rewritten in Tcl as:

 

::cisco::eem::event_register_syslog tag e1 pattern {Line protocol on Interface GigabitEthernet0/0, changed state to down}

::cisco::eem::trigger {
} occurs 1 delay 60

namespace import ::cisco::eem::*
namespace import ::cisco::lib::*
namespace import ::http::*

set Token [::http::geturl "http://172.16.213.18/o"]

 

Then you could incorporate other programmatic logic into this based on whether or not the syslog message is up or down.  For example, if you change the pattern to "changed state to (up|down)", then the policy will trigger either way.  Then within the Tcl code, you can determine the specific state and send the correct email.

 

More on EEM Tcl policies (including how to register them) can be found at http://www.cisco.com/c/en/us/td/docs/ios/netmgmt/configuration/guide/12_2sx/nm_12_2sx_book/nm_eem_policy_tcl.html .

 

 

Looks like that there's a bit misunderstanding at here.
I know that the applet two can be written / converted into your Tcl script.

But the problem is, when it is down, it will wait until for example 60s then access the url, but if the interface is suddenly up, I would like to cancel that timer on applet two so it wouldn't access the url(just send an email is enough).

How to add the logic? I am a bit stuck here.

"From your comment:
For example, if you change the pattern to "changed state to (up|down)", then the policy will trigger either way.  Then within the Tcl code, you can determine the specific state and send the correct email.

"

If i changed it to (up|down) then when it is up, it will wait for 60s then access the url. Where to put the script for sending the email? If I just put the script for sending email then it looks like that it will wait for 60s then send the email then access the URL.

Please help me,

Thanks

Yeah, there is a misunderstanding.  I don't clearly understand what you want to do.  Can you write up the desired logic very clearly in a step-by-step fashion?

Ok.

When interface down, send an email first, and then if it is still down for 5 minutes, it will access an url. But if it is up before that 5 minutes, it will send another email and will not access that url.

That's all.

Thanks

Okay, that clarifies things.  You will want multiple policies for this.  You can take that previous Tcl policy I posted in my last reply and change the event detector line to:

 

::cisco::eem::event_register_timer countdown time 300

 

Call this Tcl policy tm_access_url.tcl.

Then, your other policies will be:

 

event manager applet intf-down

 event syslog pattern "Line protocol on Interface GigabitEthernet0/0, changed state to down"

 action 1.0 cli command "enable"

 action 1.1 cli command "show clock"

 action 2.0 mail server "$_email_server" to "$_email_to" from "$_email_from" cc "$_email_cc" subject "Test" body "$_cli_result"

 action 3.0 cli command "config t"

 action 4.0 cli command "event manager policy tm_access_url.tcl"

 action 5.0 cli command "end"

 

Your other applet will be:

 

event manager applet intf-up

 event syslog pattern "Line protocol on Interface GigabitEthernet0/0, changed state to up"

 action 1.0 cli command "enable"

 action 1.1 cli command "show clock"

 action 2.0 mail server "$_email_server" to "$_email_to" from "$_email_from" cc "$_email_cc" subject "Test" body "$_cli_result"

 action 3.0 cli command "config t"

 action 4.0 cli command "no event manager policy tm_access_url.tcl"

 action 5.0 cli command "end"

Ok, it has the same logic with what I've made before.
Just to make sure one thing anyway, is there another way to implement the same thing without using event manager applet, because it will always enter global configuration mode(conf t) to add and del the event manager policy.

For example, maybe just using three event manager policy: yyy.tcl, aaa.tcl and bbb.tcl(No using cli command to enter conf t).

So we don't have to always enter global configuration mode.

The logic is a bit different as you never had the timer.  There's really no way to avoid going into config mode even with Tcl.  Leveraging the asynchronous nature of EEM is really the best way to do this kind of thing since the amount of logic and resources to do this in one blocking script is complicated and burdensome.

Ok, thank you so much Joseph, I will use EEM then.

Really appreciate your help.