RE: EEM Applet

From: Tyson Scott <tscott_at_ipexpert.com>
Date: Tue, 8 Feb 2011 16:58:02 -0500

OK I haven't actually tested this script yet but I think this will do it.
If anyone else that is strong with TCL wants to comment as well that would
be great.

 

After creating the file below put the following two command in global
configuration

event manager environment EEM_L2VPN_SCRIPT_INTERVAL 10

event manager policy EEM_L2VPN_SCRIPT.tcl

 

Create the file EEM_L2VPN_SCRIPT.tcl with the following content and put on
the flash drive of the router

 

# Beginning of File

#

::cisco:eem:event_register_timer watchdog name timer time
$EEM_L2VPN_SCRIPT_INTERVAL

namespace import ::cisco::eem::*

if {![info exists EEM_L2VPN_SCRIPT_INTERVAL]} {

set result "Policy cannot be run: variable EEM_L2VPN_SCRIPT_INTERVAL has not
been set"

error $result $errorInfo

}

#

#

if [catch {context_retrieve "EEM_RECEIVE_COUNTER" "count"} result] {

set receivecounter 0

} else {

set receivecounter $result

}

#

# Open the CLI; the cli_* functions are part of the

# ::cisco::eem namespace.

#

if [catch {cli_open} result] {

error $result $errorInfo

} else {

array set cli $result

}

#

# Execute the 'show mpls l2transport vc 10 detail' command

#

if [catch {cli_exec $cli(fd) "show mpls l2transport vc 10 detail | incl byte
total"} result] {

error $result $errorInfo

} else {

set cmd_output $result

}

#

#

set count ""

catch [regexp -all -inline {receive (\d+),} $cmd_output} count

set diff [expr $count - $receivecounter]

#

#puts "New count = $count, Old Count = $receivecounter, difference = $diff"

#

if {$diff == 0} {

action_syslog priority error msg "Receive Counter for L2VPN VC 10\

                              has not Incremented. Shutting down
Interface."

if [catch {cli_exec $cli(fd) "configure terminal"} result] {

  error $result $errorInfo

}

if [catch {cli_exec $cli(fd) "interface FastEthernet0/0.10"} result] {

  error $result $errorInfo

}

if [catch {cli_exec $cli(fd) "shutdown"} result] {

  error $result $errorInfo

}

}

#

# Close the CLI.

#

if [catch {cli_close $cli(fd) $cli(tty_id)} result] {

error $result $errorInfo

}

#

# Save the Last Receive Counter for Next time the script Runs

#

context_save EEM_RECEIVE_COUNTER count

#

#

# End of File

 

Regards,

 

Tyson Scott - CCIE #13513 R&S, Security, and SP
Managing Partner / Sr. Instructor - IPexpert, Inc.
Mailto: <mailto:tscott_at_ipexpert.com> tscott_at_ipexpert.com
Telephone: +1.810.326.1444, ext. 208
Live Assistance, Please visit: <http://www.ipexpert.com/chat>
www.ipexpert.com/chat
eFax: +1.810.454.0130

 

IPexpert is a premier provider of Self-Study Workbooks, Video on Demand,
Audio Tools, Online Hardware Rental and Classroom Training for the Cisco
CCIE (R&S, Voice, Security & Service Provider) certification(s) with
training locations throughout the United States, Europe, South Asia and
Australia. Be sure to visit our online communities at
<http://www.ipexpert.com/communities> www.ipexpert.com/communities and our
public website at <http://www.ipexpert.com/> www.ipexpert.com

 

From: Mohamed Osama [mailto:tetoo_me_at_hotmail.com]
Sent: Tuesday, February 08, 2011 2:06 PM
To: tscott_at_ipexpert.com; Cisco certification; markom_at_ipexpert.com
Subject: RE: EEM Applet

 

Dear Tyson,

 

Thanks for sharing your Idea and I'm here Waiting for your Test
Results,because that scenario really makes me crazy and i need to solve it
as soon as possible :( due to the lack of keepalives end - to - end.

 

Thanks,

 

  _____

From: tscott_at_ipexpert.com
To: tetoo_me_at_hotmail.com; ccielab_at_groupstudy.com; markom_at_ipexpert.com
Subject: RE: EEM Applet
Date: Tue, 8 Feb 2011 13:43:07 -0500

I will test to see if I can find a way to do this, this is interesting to
me. I am not sure without testing, I will get back when/if I figure it out.

 

To give some ideas this is how you could do it with expect.

 

set down_count 0

set receive_count 0

while { $down_count == 0 } {

               send "show mpls l2transport vc 10 detail\r"

               expect "show mpls l2transport vc 10 detail"

               expect {

                              -re "receive \(\[0-9]+\)," {

                                             set string1
$expect_out(1,string)

                                             if { [ string match "$string1"
"$receive_count" ] } { set down_count 1 } else { set receive_count
"$string1"; sleep 5 }

                                             }

                              }

               }

send "configure terminal\r"

expect "configure terminal"

send "interface FastEthernet0/0.10\r"

expect "interface FastEthernet0/0.10"

send "shutdown\r"

expect "shutdown"

exec echo "SCRIPT Shutdown FastEthernet0/0.10 on RouterX. Please solve the
problem and restart the script" | /bin/mail -s "FAILURE DETECTED"
tetoo_me_at_hotmail.com

exit 1

 

Expect is built on TCL which is what we use in IOS. If it is possible to do
this same thing with EEM, which I am just not sure about, you would need to
combine a TCL script with EEM to perform your function. But I would be
nervous doing EEM like this in production. I would be nervous about it
being caught in a loop and hogging resources.

 

Regards,

 

Tyson Scott - CCIE #13513 R&S, Security, and SP
Managing Partner / Sr. Instructor - IPexpert, Inc.
Mailto: tscott_at_ipexpert.com

 

 

From: Mohamed Osama [mailto:tetoo_me_at_hotmail.com]
Sent: Tuesday, February 08, 2011 11:31 AM
To: Cisco certification; markom_at_ipexpert.com; tscott_at_ipexpert.com
Subject: OT : EEM Applet

 

Dear all,

 

Sorry for this,but I need to Configure a Complicate Embedded Event Manager
Script that doing the Following :

 

First issue the below Command :

 

NewYork#show mpls l2transport vc 10 detail

 

Local interface: FastEternet0/0.10 up, line protocol up, Eth VLAN 10 up

  Destination address: 192.168.1.102, VC ID: 10, VC status:up

    Tunnel label: not ready

  Create time: 22:31:53, last status change time: 04:02:56

  Signaling protocol: LDP, peer 192.168.1.102:0 up

  VC statistics:

    packet totals: receive 1650, send 1743

    byte totals: receive 552557, send 550044

    packet drops: receive 0, send 7

 

Then Look at Packet totals : receive 1650 , and checks it Value using Logic
loop or something,

 

If EEM find receive value is the same which means we didn't recive any
Packets which mean for me the Link is broken

 

Then do the Following Action : shutdown int fa0/2.3 as Example ,so we
terminate the Link and the other end of the tunnel

can know that we are not connected anymore to the Customer Device.

 

Can anyone help me with this please?I need to the Logical Sequence to do it
and Logical Mathematical sentence

for checking Receive parameter?

Blogs and organic groups at http://www.ccie.net
Received on Tue Feb 08 2011 - 16:58:02 ART

This archive was generated by hypermail 2.2.0 : Tue Mar 01 2011 - 07:01:50 ART