cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1503
Views
0
Helpful
1
Replies

Conditional registration?

dean holroyd
Beginner
Beginner

Hello

I am testing a script where I want a conditional registration line based upon the existance of an environment variable. The script below measures txload on one interface, but is supposed to measure txload on a second interface IF the environment variable 'if1' is added to the CLI. I have attempted to do this by adding [info exists if1] to the event register line for the second interface. When 'event manager environment if1 FastEthernet1/0/1'  is added to the cli, the script does not monitor that interface.

What am I doing wrong?

Thanks

::cisco::eem::event_register_interface tag e2 name FastEthernet1/0/2 parameter txload entry_op ge entry_val 51 entry_type value exit_time 60 poll_interval 30

::cisco::eem::event_register_interface tag e1 name [info exists if1] parameter txload entry_op ge entry_val 51 entry_type value exit_time 60 poll_interval 30

::cisco::eem::trigger {

    ::cisco::eem::correlate event e1 or event e2

}

namespace import ::cisco::eem::*

namespace import ::cisco::lib::*

array set arr_einfo [event_reqinfo]

set interface $arr_einfo(name)

set parameter $arr_einfo(parameter)

set value $arr_einfo(value)

puts $interface

puts $parameter

puts $value

MPLS-ME3750#

*Mar  4 00:37:55.730: %HA_EM-6-LOG: ifevents.tcl: FastEthernet1/0/2

*Mar  4 00:37:55.730: %HA_EM-6-LOG: ifevents.tcl: txload

*Mar  4 00:37:55.730: %HA_EM-6-LOG: ifevents.tcl: 81

MPLS-ME3750#conf t

Enter configuration commands, one per line.  End with CNTL/Z.

MPLS-ME3750(config)#event manager environment if1 FastEthernet1/0/1  

*Mar  4 00:38:55.935: %HA_EM-6-LOG: ifevents.tcl: FastEthernet1/0/2

*Mar  4 00:38:55.935: %HA_EM-6-LOG: ifevents.tcl: txload

*Mar  4 00:38:55.935: %HA_EM-6-LOG: ifevents.tcl: 86

*Mar  4 00:39:56.031: %HA_EM-6-LOG: ifevents.tcl: FastEthernet1/0/2

*Mar  4 00:39:56.031: %HA_EM-6-LOG: ifevents.tcl: txload

*Mar  4 00:39:56.031: %HA_EM-6-LOG: ifevents.tcl: 91

*Mar  4 00:40:55.884: %HA_EM-6-LOG: ifevents.tcl: FastEthernet1/0/2

*Mar  4 00:40:55.884: %HA_EM-6-LOG: ifevents.tcl: txload

*Mar  4 00:40:55.884: %HA_EM-6-LOG: ifevents.tcl: 94

MPLS-ME3750#show event manager environment

No.  Name                          Value                        

1    if2                           FastEthernet1/0/2            

2    if1                           FastEthernet1/0/1   

1 Reply 1

dean holroyd
Beginner
Beginner

I have resolved this myself. I was only testing to see if the variable existed, but not doing anything with it, which you can do with an expression. Of course, the script needs to be de registered and then registered again

::cisco::eem::event_register_interface tag e2 name FastEthernet1/0/2 parameter txload entry_op ge entry_val 51 entry_type value exit_time 30 poll_interval 15

::cisco::eem::event_register_interface tag e1 name [expr {[info exists if1] ? $if1 : 0}] parameter txload entry_op ge entry_val 51 entry_type value exit_time 30 poll_interval 15

::cisco::eem::trigger {

    ::cisco::eem::correlate event e1 or event e2

}

namespace import ::cisco::eem::*

namespace import ::cisco::lib::*

array set arr_einfo [event_reqinfo]

set interface $arr_einfo(name)

set parameter $arr_einfo(parameter)

set value $arr_einfo(value)

puts $interface

puts $parameter

puts $value


MPLS-ME3750(config)#      

MPLS-ME3750(config)# event manager policy ifevents.tcl               

MPLS-ME3750(config)#

*Mar  4 02:41:21.965: %HA_EM-6-LOG: ifevents.tcl: FastEthernet1/0/2

*Mar  4 02:41:21.965: %HA_EM-6-LOG: ifevents.tcl: txload

*Mar  4 02:41:21.965: %HA_EM-6-LOG: ifevents.tcl: 72

MPLS-ME3750(config)#event manager environment if1 FastEthernet1/0/1  

MPLS-ME3750(config)#

*Mar  4 02:42:22.388: %HA_EM-6-LOG: ifevents.tcl: FastEthernet1/0/2

*Mar  4 02:42:22.388: %HA_EM-6-LOG: ifevents.tcl: txload

*Mar  4 02:42:22.388: %HA_EM-6-LOG: ifevents.tcl: 79

MPLS-ME3750(config)#no  event manager policy ifevents.tcl         

MPLS-ME3750(config)# event manager policy ifevents.tcl            

MPLS-ME3750(config)#

*Mar  4 02:43:10.111: %HA_EM-6-LOG: ifevents.tcl: FastEthernet1/0/1

*Mar  4 02:43:10.111: %HA_EM-6-LOG: ifevents.tcl: txload

*Mar  4 02:43:10.111: %HA_EM-6-LOG: ifevents.tcl: 83

*Mar  4 02:43:14.666: %HA_EM-6-LOG: ifevents.tcl: FastEthernet1/0/2

*Mar  4 02:43:14.666: %HA_EM-6-LOG: ifevents.tcl: txload

*Mar  4 02:43:14.666: %HA_EM-6-LOG: ifevents.tcl: 83

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community:

Recognize Your Peers