Cisco Support Community
cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Community Member

EEM - IP Routing

We have some windows based scripts that run and check to make sure that certain servers (web monitors) are up and running. If they are not up, then it will log into the routers and change the routing tables on the router. I do not have access to these scripts or get emailed on their results, so I would like to set up a EEM applet to let me know on this.

These are the two possibilities:

Normal Routing

ip route 0.0.0.0 0.0.0.0 fa0/1 10

ip route 0.0.0.0 0.0.0.0 172.20.240.1 20

After routing has been changed

ip route 0.0.0.0 0.0.0.0 172.20.240.1

ip route 0.0.0.0 0.0.0.0 fa0/1 10

So I need to trigger off of 172.20.240.1 20.

Also if possible, I would like this to run and check every 10 minutes, but I only want emailed every 60 minutes? Is this option possible?

This is what I have come up with so far, but this is my first adventure into EEM. Can anyone provide some assistance? Thanks.

 
event manager applet iprouting-check
event timer watchdog time 600
action 001 cli command "enable"
action 002 cli command "show run | inc ip route"
action 003 regexp "(172\.20\.240\.1\_\20\")" $_cli_result ignore match
action 004 if $_regexp_result eq 1
action 005 mail subject "Branch Routing Is Not Local" body "Found $match in IP Routing" to user@company.com from user@company.com server y.y.y.y
action 006 end

Everyone's tags (6)
1 ACCEPTED SOLUTION

Accepted Solutions
Cisco Employee

Re: EEM - IP Routing

The Cc: field got dropped.  Try this version.

24 REPLIES
Cisco Employee

Re: EEM - IP Routing

This should do what you want.

event manager applet iprouting-check

event timer watchdog 600

action 001 cli command "enable"

action 002 cli command "show run | inc ip route"

action 003 regexp "(172\.20\.240\.1 20)" $_cli_result ignore match

action 004 if $_regexp_result eq 1

action 005  handle-error type ignore

action 006  context retrieve key IPROUTECTXT variable counter

action 007  if $_error ne FH_EOK

action 008   set counter 1

action 009  end

action 010  handle-error type exit

action 011  if $counter eq 6

action 012   set counter 1

action 013  else

action 014   increment counter

action 015   mail subject "Branch Routing Is Not Local" body "Found $match in IP Routing" to user@company.com from user@company.com server y.y.y.y

action 016  end

action 017  context save key IPROUTECTXT variable counter

action 018 end

Community Member

Re: EEM - IP Routing

I get the following when trying to put this in

NEWI-2801-001(config-applet)#action 003 regexp "(172\.20\.240\.1 20)" $_cli_result ignore match
                                                                ^
% Invalid input detected at '^' marker.

NEWI-2801-001(config-applet)#ac
NEWI-2801-001(config-applet)#action 003 ?
  cli               Execute a CLI command
  cns-event         Send a CNS event
  counter           Modify a counter value
  force-switchover  Force a software switchover
  info              Obtain system specific information
  mail              Send an e-mail
  policy            Run a pre-registered policy
  publish-event     Publish an application specific event
  reload            Reload system
  snmp-trap         Send an SNMP trap
  syslog            Log a syslog message

Any ideas?

Cisco Employee

Re: EEM - IP Routing

You need EEM 3.0 to do what you want to do in applets.  This means you'll need 12.4(22)T or higher.  It looks like you may have 12.4 mainline.  In that case, you'll need to use Tcl for this.

Community Member

Re: EEM - IP Routing

Is there a convertor tool to use to convert this to tcl?

Cisco Employee

Re: EEM - IP Routing

Here is the Tcl version.  There is no externally available converter tool.

::cisco::eem::event_register_timer watchdog 600 

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


if [catch {cli_open} result] {
    error $result $errorInfo
} else {
    array set cli1 $result
}

if [catch {cli_exec $cli1(fd) "enable"} _cli_result] {
    error $_cli_result $errorInfo
}

if [catch {cli_exec $cli1(fd) "show run | inc ip route"} _cli_result] {
    error $_cli_result $errorInfo
}

set _regexp_result [regexp {(172\.20\.240\.1 20)} $_cli_result ignore match]
if {$_regexp_result == 1} {
    if {[catch {

        if {[catch {set counter [context_retrieve IPROUTECTXT counter]} errmsg]} {
            puts "context_retrieve failed: "
        }
        if {$_error != FH_EOK} {
            set counter 1
        }
    } _catch_result]} {
        # Errors have been ignored.
    }
    if {$counter == 6} {
        set counter 1
    } else {
        incr counter

        set mail_pre y.y.y.y
        append mail_pre user@company.com
        append mail_pre user@company.com
        append mail_pre
        append mail_pre "Subject: Branch Routing Is Not Local\n\n"
        append mail_pre "Found $match in IP Routing\n\n"
        set mail_msg [uplevel #0 [list subst -nobackslashes -nocommands $mail_pre]]
        if [catch {smtp_send_email $mail_msg} result] {
            error $result $errorInfo
        }

    }

    if {[catch {context_save IPROUTECTXT counter} errmsg]} {
        puts "context_save failed: "
    }
}

# Close open cli before exit.
if [catch {cli_close $cli1(fd) $cli1(tty_id)} result] {
    error $result $errorInfo
}
Community Member

Re: EEM - IP Routing

Ok one last question. Maybe I described what I am looking for wrong, maybe this does this already. Will this script email the 1st time it detects the issue? Or will it wait until 60 min? I want it to email me the 1st time it detects the problem, but then only renotify me every 60 minutes of the ongoing problem. Thanks.

Cisco Employee

Re: EEM - IP Routing

Try this version instead:

::cisco::eem::event_register_timer watchdog 600 

#
# This EEM tcl policy was generated by the EEM applet conversion
# utility at http://wwwin-swpkg.cisco.com/fm/convert_applet/
# using the following applet:
#
# event manager applet iprouting-check
#  event timer watchdog 600
#  action 001 cli command "enable"
#  action 002 cli command "show run | inc ip route"
#  action 003 regexp "(172\.20\.240\.1 20)" $_cli_result ignore match
#  action 004 if $_regexp_result eq 1
#  action 005  handle-error type ignore
#  action 006  context retrieve key IPROUTECTXT variable counter
#  action 007  if $_error ne FH_EOK
#  action 008   set counter 1
#  action 009  end
#  action 010  handle-error type exit
#  action 011  if $counter lt 6
#  action 012   increment counter
#  action 013  else
#  action 014   set counter 1
#  action 015   mail subject "Branch Routing Is Not Local" body "Found $match in IP Routing" to user@company.com from user@company.com server y.y.y.y
#  action 016  end
#  action 017  context save key IPROUTECTXT variable counter
#  action 018 end
#

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


if [catch {cli_open} result] {
    error $result $errorInfo
} else {
    array set cli1 $result
}

if [catch {cli_exec $cli1(fd) "enable"} _cli_result] {
    error $_cli_result $errorInfo
}

if [catch {cli_exec $cli1(fd) "show run | inc ip route"} _cli_result] {
    error $_cli_result $errorInfo
}

set _regexp_result [regexp {(172\.20\.240\.1 20)} $_cli_result ignore match]
if {$_regexp_result == 1} {
    if {[catch {

        if {[catch {set counter [context_retrieve IPROUTECTXT counter]} errmsg]} {
            set counter 0
        }
    } _catch_result]} {
        # Errors have been ignored.
    }
    if {$counter < 6 && $counter > 0} {
        incr counter
    } else {
        set counter 1

        set mail_pre y.y.y.y
        append mail_pre user@company.com
        append mail_pre user@company.com
        append mail_pre
        append mail_pre "Subject: Branch Routing Is Not Local\n\n"
        append mail_pre "Found $match in IP Routing\n\n"
        set mail_msg [uplevel #0 [list subst -nobackslashes -nocommands $mail_pre]]
        if [catch {smtp_send_email $mail_msg} result] {
            error $result $errorInfo
        }

    }

    if {[catch {context_save IPROUTECTXT counter} errmsg]} {
        puts "context_save failed: "
    }
}

# Close open cli before exit.
if [catch {cli_close $cli1(fd) $cli1(tty_id)} result] {
    error $result $errorInfo
}
Community Member

Re: EEM - IP Routing

When I go to register it, I get the following:

1841-001(config)#event manager directory user policy flash:/eempolicy

1841-001(config)#event manager policy routingcheck-new.tcl
Compile check and registration failed:Wrong # args, usage is "::cisco::eem::event_register_timer watchdog|countdown|absolute|cron name ? cron_entry ? time ? queue_priority normal|low|high maxrun ? nice ?"
    while executing
"::cisco::eem::event_register_timer watchdog 600
"
Tcl policy execute failed: Wrong # args, usage is "::cisco::eem::event_register_timer watchdog|countdown|absolute|cron name ? cron_entry ? time ? queue_priority normal|low|high maxrun ? nice ?"

Embedded Event Manager configuration: failed to retrieve intermediate registration result for policy routingcheck-new.tcl: Unknown error 0

I have attached the script that I loaded.

Cisco Employee

Re: EEM - IP Routing

Add the following on to the end of the first line:

name route_timer

So the line will look like:

::cisco::eem::event_register_timer watchdog 600 name route_timer
Community Member

Re: EEM - IP Routing

I still get the same type of error.

1841-001(config)#event manager policy routingcheck-new.tcl
Compile check and registration failed:Wrong # args, usage is "::cisco::eem::event_register_timer watchdog|countdown|absolute|cron name ? cron_entry ? time ? queue_priority normal|low|high maxrun ? nice ?"
    while executing
"::cisco::eem::event_register_timer watchdog 600 name route_timer
"
Tcl policy execute failed: Wrong # args, usage is "::cisco::eem::event_register_timer watchdog|countdown|absolute|cron name ? cron_entry ? time ? queue_priority normal|low|high maxrun ? nice ?"

Embedded Event Manager configuration: failed to retrieve intermediate registration result for policy routingcheck-new.tcl: Unknown error 0

Cisco Employee

Re: EEM - IP Routing

Sorry, I forgot an argument last time:

::cisco::eem::event_register_timer watchdog time 600 name route_timer
Community Member

Re: EEM - IP Routing

It registerd and is running

1841-001#show event manager history events
No.  Time of Event             Event Type          Name
1    Fri Nov19  06:21:12 2010  timer watchdog      script: routing_check.tcl
2    Fri Nov19  06:31:12 2010  timer watchdog      script: routing_check.tcl
3    Fri Nov19  06:41:12 2010  timer watchdog      script: routing_check.tcl

However I do not get the emails, and I had our administrator check the logs and the email's are not getting to the server.

This is what I have for the email portion of the script

set counter 1       
set mail_pre 172.20.61.7       
append mail_pre network_admin@companysupport.com    
append mail_pre Branch.Router@company.com
append mail_pre        
append mail_pre "Subject: Branch Routing Is Not Local\n\n"       
append mail_pre "Found $match in IP Routing\n\n"       
set mail_msg [uplevel #0 [list subst -nobackslashes -nocommands $mail_pre]] 

I would like the email to go to network_admin@companysupport.com and come from Branch.Router@company.com Do I have this correct?

Cisco Employee

Re: EEM - IP Routing

There wasa conversion problem.  Try this version instead:

::cisco::eem::event_register_timer watchdog time 600 name route_timer

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

if [catch {cli_open} result] {
    error $result $errorInfo
} else {
    array set cli1 $result
}

if [catch {cli_exec $cli1(fd) "enable"} _cli_result] {
    error $_cli_result $errorInfo
}

if [catch {cli_exec $cli1(fd) "show run | inc ip route"} _cli_result] {
    error $_cli_result $errorInfo
}

set _regexp_result [regexp {(172\.20\.240\.1 20)} $_cli_result ignore match]
if {$_regexp_result == 1} {
    if {[catch {

        if {[catch {set counter [context_retrieve IPROUTECTXT counter]} errmsg]} {
            set counter 0
        }
    } _catch_result]} {
        # Errors have been ignored.
    }
    if {$counter < 6 && $counter > 0} {
        incr counter
    } else {
        set counter 1

        set mail_pre "Mailservername: y.y.y.y\n"
        append mail_pre "From: user@company.com\n"
        append mail_pre "To: user@company.com\n"
        append mail_pre
        append mail_pre "Subject: Branch Routing Is Not Local\n\n"
        append mail_pre "Found $match in IP Routing\n\n"
        set mail_msg [uplevel #0 [list subst -nobackslashes -nocommands $mail_pre]]
        if [catch {smtp_send_email $mail_msg} result] {
            error $result $errorInfo
        }

    }

    if {[catch {context_save IPROUTECTXT counter} errmsg]} {
        puts "context_save failed: "
    }
}

# Close open cli before exit.
if [catch {cli_close $cli1(fd) $cli1(tty_id)} result] {
    error $result $errorInfo
}

Community Member

Re: EEM - IP Routing

Still not getting anything to come from this. This is what I have entered, it is registered and it is running.

::cisco::eem::event_register_timer watchdog time 600 name route_timer

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

if [catch {cli_open} result] {
    error $result $errorInfo
} else {
    array set cli1 $result
}

if [catch {cli_exec $cli1(fd) "enable"} _cli_result] {
    error $_cli_result $errorInfo
}

if [catch {cli_exec $cli1(fd) "show run | inc ip route"} _cli_result] {
    error $_cli_result $errorInfo
}

set _regexp_result [regexp {(172\.20\.240\.1 20)} $_cli_result ignore match]
if {$_regexp_result == 1} {
    if {[catch {

        if {[catch {set counter [context_retrieve IPROUTECTXT counter]} errmsg]} {
            set counter 0
        }
    } _catch_result]} {
        # Errors have been ignored.
    }
    if {$counter < 6 && $counter > 0} {
        incr counter
    } else {
        set counter 1

        set mail_pre "Mailservername: 172.20.41.152\n"
        append mail_pre "From: Boise.Router@company.com\n"
        append mail_pre "To: network_admin@companysupport.com\n"
        append mail_pre
        append mail_pre "Subject: Branch Routing Is Not Local\n\n"
        append mail_pre "Found $match in IP Routing\n\n"
        set mail_msg [uplevel #0 [list subst -nobackslashes -nocommands $mail_pre]]
        if [catch {smtp_send_email $mail_msg} result] {
            error $result $errorInfo
        }

    }

    if {[catch {context_save IPROUTECTXT counter} errmsg]} {
        puts "context_save failed: "         
    }
}

# Close open cli before exit.
if [catch {cli_close $cli1(fd) $cli1(tty_id)} result] {
    error $result $errorInfo
}

1841-001#show event manager history events          
No.  Time of Event             Event Type          Name
1    Tue Nov30  05:23:15 2010  timer watchdog      script: routing_check_test.tcl
2    Tue Nov30  05:33:15 2010  timer watchdog      script: routing_check_test.tcl
3    Tue Nov30  05:43:15 2010  timer watchdog      script: routing_check_test.tcl
4    Tue Nov30  05:53:15 2010  timer watchdog      script: routing_check_test.tcl
5    Tue Nov30  06:03:15 2010  timer watchdog      script: routing_check_test.tcl
6    Tue Nov30  06:13:15 2010  timer watchdog      script: routing_check_test.tcl
7    Tue Nov30  06:23:15 2010  timer watchdog      script: routing_check_test.tcl
8    Tue Nov30  06:33:15 2010  timer watchdog      script: routing_check_test.tcl
9    Tue Nov30  06:43:15 2010  timer watchdog      script: routing_check_test.tcl
10   Tue Nov30  06:53:15 2010  timer watchdog      script: routing_check_test.tcl

Any other ideas?

2502
Views
0
Helpful
24
Replies
CreatePlease to create content