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

check_dial_peer_status.tcl

leagle
Level 1
Level 1

I tried e-mailing this to askabouteem.cisco.com but received an smtp error for this address.

 

I’m using the check_dial_peer_status.tcl to provide notification of when a SIP dial-peer is down.  Can this .tcl and the event manager commands be modified to monitor more than one SIP dial-peer?  Below are the dial-peers, Event Manager commands and the .tcl script.  I would like to monitor dial-peers 200 and 300.  I’m currently monitoring dial-peer 200.

 

US-HAL-NP1-CUBE2-I6#sh dial-peer voice sum

dial-peer hunt 0

             AD                                    PRE PASS                OUT

TAG    TYPE  MIN  OPER PREFIX    DEST-PATTERN      FER THRU SESS-TARGET    STAT PORT    KEEPALIVE

1000   voip  up   up             [2-9].........     1  syst                               active

200    voip  up   up             .T                 0  syst                               active

2000   voip  up   up             [2-9].........     2  syst                               active

300    voip  down down           map:400            0  syst

600    voip  up   up             map:300            0  syst                               active

 

 

track 200 stub-object

 

event manager environment dial_peer_number 200

event manager environment check_interval 30

event manager directory user policy "flash:/"

event manager applet siptrunk_down

event track 200 state down

action 10 snmp-trap strdata "siptrunk DOWN"

action 20 syslog msg "siptrunk down"

event manager applet siptrunk_up

event track 200 state up

action 15 snmp-trap strdata "siptrunk UP"

action 25 syslog msg "siptrunk up"

event manager policy check_dial_peer_status.tcl

 

 

check_dial_peer_status.tcl

::cisco::eem::event_register_timer watchdog time $check_interval nice 1

#

# Namespace imports

#

namespace import ::cisco::eem::*

namespace import ::cisco::lib::*

#--- Check required environment variable(s) has been defined

if {![info exists dial_peer_number]} {

   set result "EEM Policy Error: variable dial_peer_number has not been set"

   error $result $errorInfo

}

#------------------- " cli open" -------------------

if [catch {cli_open} result] {

   error $result $errorInfo

} else {

   array set cli $result

}

#----------------------- "enable" ----------------------

if [catch {cli_exec $cli(fd) "enable"} result] { error $result $errorInfo }

#-------------- grab sip ood options-ping and track status --------------

if [catch {cli_exec $cli(fd) "show dial-peer voice sum | inc $dial_peer_number "} result] {

   error $result $errorInfo

}

set cmd_output $result

 

array set track_result [action_track_read $dial_peer_number]

set track_state $track_result(state)

#-------------- set stub status --------------

if [string match "*busyout*" $cmd_output] {

   if { $track_state == "up" } {

       action_track_set $dial_peer_number state "down"

   }

}

if [string match "*active*" $cmd_output] {

   if { $track_state == "down" } {

      action_track_set $dial_peer_number state "up"

   }

}

#--------------------- cli close ------------------------

catch {cli_close $cli(fd) $cli(tty_id)} result

2 Replies 2

Joe Clarke
Cisco Employee
Cisco Employee

This should work.  Change your dial_peer_number value to 200,300:

 

::cisco::eem::event_register_timer watchdog time $check_interval nice 1

#

# Namespace imports

#

namespace import ::cisco::eem::*

namespace import ::cisco::lib::*

#--- Check required environment variable(s) has been defined

if {![info exists dial_peer_number]} {

   set result "EEM Policy Error: variable dial_peer_number has not been set"

   error $result $errorInfo

}

#------------------- " cli open" -------------------

if [catch {cli_open} result] {

   error $result $errorInfo

} else {

   array set cli $result

}

#----------------------- "enable" ----------------------

if [catch {cli_exec $cli(fd) "enable"} result] { error $result $errorInfo }

#-------------- grab sip ood options-ping and track status --------------

foreach dp [split $dial_peer_number ","] {

if [catch {cli_exec $cli(fd) "show dial-peer voice sum | inc \"^$dp \""} result] {

   error $result $errorInfo

}

set cmd_output $result

 

array set track_result [action_track_read $dp]

set track_state $track_result(state)

#-------------- set stub status --------------

if [string match "*busyout*" $cmd_output] {

   if { $track_state == "up" } {

       action_track_set $dp state "down"

   }

}

if [string match "*active*" $cmd_output] {

   if { $track_state == "down" } {

      action_track_set $dp state "up"

   }

}

}

#--------------------- cli close ------------------------

catch {cli_close $cli(fd) $cli(tty_id)} result

I got an error with the foreach command.  I was able to get it working by creating two .tcl scripts with a unique dial_peer_number variable for each script.