cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1804
Views
0
Helpful
2
Replies

HELP Using EEM

jaydiemoore
Level 1
Level 1

Im trying to use EEM to check the output of "show interface description | include TEST" to shutdown all ports with the description TEST. Was wondering if anyone had any ideas

2 Replies 2

Jason Pfeifer
Cisco Employee
Cisco Employee

Here is a .tcl EEM policy which should help.  It does some extra checking to narrow by interface type.  You can

remove that if needed.

Thanks.

::cisco::eem::event_register_none maxrun 120 default 120

namespace import ::cisco::eem::*

namespace import ::cisco::lib::*

# 1. execute cli commands to gather data

if [catch {cli_open} result] {

    error $result $errorInfo

} else {

    array set cli1 $result

}

if [catch {cli_exec $cli1(fd) "enable"} result] {

    error $result $errorInfo

}

if [catch {cli_exec $cli1(fd) "show int desc | in TEST"} cli_show_int] {

    error $cli_show_int $errorInfo

}

foreach line [split $cli_show_int \n] {

    set match1 [regexp {^[F|G|T][a|i|e][0-9|/]+} $line match]

    if {$match1 == 1} {

        if [catch {cli_exec $cli1(fd) "conf t"} result] {

            error $result $errorInfo

        }

        if [catch {cli_exec $cli1(fd) "interface $match"} result] {

            error $result $errorInfo

        }

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

            error $result $errorInfo

        }

        if [catch {cli_exec $cli1(fd) "end"} result] {

            error $result $errorInfo

        }

        puts "shutting interface $match"

    } else {

        puts "skipping interface $line"

    }

}

Here is a sample EEM applet which does this as well:

event manager applet desctest

event none

action 100 cli command "enable"

action 101 cli command "show int descr | inc TEST"

action 102 foreach line "$_cli_result" "\n"

action 103 regexp "([^\s]*).*TEST.*" $line match _int

action 104 puts "line is --$line--"

action 105  if $_regexp_result eq "0"

action 106   puts "Interface is $_int"

action 107   cli command "conf t"

action 108   cli command "interface $_int"

action 109   cli command "shutdown"

action 110  end

action 111 end