08-14-2012 11:07 AM
I am trying to sample and add a number of oid's in the isdn mib on 2431 & 2921 boxes. The number of T1s on the boxes can vary with the model and config of the box. I have researched the oids that I want to loop through and am confident which ones I need to sample, but I am having trouble constructing the numerical oid's using the 'append' command and getting the snmp get command to use the result. Below is my test applet:
config t
no event manager applet test
event manager applet test
event none
action 200 info type snmp oid 1.3.6.1.2.1.10.20.1.3.1.0 get-type exact ! isdnSignalingGetIndex
action 202 set j "$_info_snmp_value"
action 203 set i "1"
action 204 set k "2"
action 206 set Calls "0"
action 210 while $i lt $j ! loop through isdn interfaces
action 215 while $k le 4 ! loop through calls in & out connected stats .2 & .4
action 220 set myoid "1.3.6.1.2.1.10.20.1.3.3.1."
action 222 append $myoid "$k.$i"
action 223 info type snmp oid $myoid get-type exact
action 224 puts "myoid = $myoid, i = $i, j = $j, k = $k, snmp oid value= $_info_snmp_value "
action 225 regexp "[0-9]+" "$_info_snmp_value"
action 226 if $_regexp_result eq 1
action 227 add $Calls $_info_snmp_value
action 228 set $Calls "$_result"
action 229 puts "Calls = $Calls"
action 230 end
action 232 increment k 2
action 234 end
action 240 increment i
action 250 end
end
event manager sched clear all
event manager run test
Below is the result when I run the applet:
bctrunks-2431-2#event man run test
myoid = 1.3.6.1.2.1.10.20.1.3.3.1., i = 1, j = 2, k = 2, snmp oid value= 2
Calls = 0
myoid = 1.3.6.1.2.1.10.20.1.3.3.1., i = 1, j = 2, k = 4, snmp oid value= 2
Calls = 0
Below is an snmpwalk from a Solaris 10 server polling the oids I am trying to sample and add
-bash-3.00$ snmpwalk -v1 -c TWC-default 10.40.209.2 1.3.6.1.2.1.10.20.1.3.1.0
SNMPv2-SMI::transmission.20.1.3.1.0 = INTEGER: 2 <---- this is isdnSignallingGetIndex which is 1 + last isdn port config'd
-bash-3.00$ snmpwalk -v1 -c TWC-default 10.40.209.2 1.3.6.1.2.1.10.20.1.3.3.1
SNMPv2-SMI::transmission.20.1.3.3.1.1.1 = Counter32: 10
SNMPv2-SMI::transmission.20.1.3.3.1.2.1 = Counter32: 10 <----- this is the number of ISDN outbound calls connected
SNMPv2-SMI::transmission.20.1.3.3.1.3.1 = Counter32: 2
SNMPv2-SMI::transmission.20.1.3.3.1.4.1 = Counter32: 2 <------ this is the number of ISDN inbound calls connected
SNMPv2-SMI::transmission.20.1.3.3.1.5.1 = Counter32: 0
-bash-3.00$
In this case, the applet should get the values of oids 1.3.6.1.2.1.10.20.1.3.3.1.2.1 & 1.3.6.1.2.1.10.20.1.3.3.1.4.1 and add them.
The 'append' comand does not seem to be working right, as shown by the value of myoid. The IOS command lookup tool result for the 'action append'
command does not say explicitly where the result of the append is placed, so I am assuming the result is placed back in the 'myoid' variable in my test applet.
I have successfully used the 'action info type snmp oid <literal_oid> get-type exact' syntax in the past, but I am not sure if it works using a constructed string variable.
Let me know if you can help me out. Thanks in advance.
Solved! Go to Solution.
08-14-2012 02:30 PM
Append uses the variable name not its value. Try this instead:
action 222 append myoid "$k.$i"
08-14-2012 02:30 PM
Append uses the variable name not its value. Try this instead:
action 222 append myoid "$k.$i"
08-15-2012 11:14 AM
The correction you made to action 222 solved one problem. Thanks a lot.
But now I am seeing a different problem, with the 'action info type snmp oid' command using a variable as the oid_value, as shown below. It appears that only the first snmp get is actually performed by the 'action 200 info type snmp oid 1.3.6.1.2.1.10.20.1.3.1.0 get-type exact' action. The subsequent command 'action 218 info type snmp oid $myoid get-type exact' does not seem to actually do an actual get. I conclude this from the output of 'action 222 puts " shown below the listing of the applet after the snmp and eem debug. In each iteration, both the 'info_snmp_oid = 1.3.6.1.2.1.10.20.1.3.1.0' and the 'info_snmp_value = 3' never change and do not match what I get from an snmpwalk run on an Solaris server querying the same 2431 box.
Will the 'action info type snmp oid' command work with a string variable as the oid value, instead of as a literal string? I'd realy appreciate any help you can offer.
bctrunks-2431-1#
bctrunks-2431-1#srs let test
event manager applet test
event none
action 200 info type snmp oid 1.3.6.1.2.1.10.20.1.3.1.0 get-type exact
action 202 set j "$_info_snmp_value"
action 204 set i "1"
action 206 set Calls "0"
action 208 while $i lt $j
action 210 set k "2"
action 212 while $k le 4
action 214 set myoid "1.3.6.1.2.1.10.20.1.3.3.1."
action 216 append myoid "$k.$i"
action 218 info type snmp oid $myoid get-type exact
action 220 regexp "[0-9]+" "$_info_snmp_value"
action 222 puts "act 224: myoid = $myoid, info_snmp_oid = $_info_snmp_oid, i = $i, j = $j, k = $k, info_snmp_value = $_info_snmp_value, reg_exp_result = $_regexp_result"
action 224 if $_regexp_result eq 1
action 226 add $Calls $_info_snmp_value
action 228 set Calls "$_result"
action 230 puts "act 229: Calls = $Calls"
action 232 end
action 234 increment k 2
action 236 end
action 240 increment i 1
action 250 end
bctrunks-2431-1#event manager sched clear all
bctrunks-2431-1#debug ev man all
All possible Embedded Event Manager debugging has been turned on
bctrunks-2431-1#term mon
bctrunks-2431-1#event manager run test
SrCheckNotificationFilter: OID is included.
SrCheckNotificationFilter: OID is included.
SrCheckNotificationFilter: OID is included.
SrCheckNotificationFilter: OID is included.
Sr_send_trap: trap sent to 24.30.210.15:162
SrV2GenerateNotification:Function has reached clean up routine.
Aug 15 11:38:28.780 CDT: cli_history_entry_add: free_hist_list size=0, hist_list size=7
Aug 15 11:38:28.780 CDT: check_eem_cli_policy_handler: command_string=terminal monitor
Aug 15 11:38:28.780 CDT: check_eem_cli_policy_handler: num_matches = 0, response_code = 1
Aug 15 11:38:28.816 CDT: cli_history_entry_add: free_hist_list size=0, hist_list size=7
Aug 15 11:38:28.816 CDT: check_eem_cli_policy_handler: command_string=event manager run test
Aug 15 11:38:28.816 CDT: check_eem_cli_policy_handler: num_matches = 0, response_code = 1
Aug 15 11:38:28.816 CDT: fh_fd_none_event_match: parameters = , sync = 1, get_tty = 1, tty_buf = 98
Aug 15 11:38:28.816 CDT: none_conn_tm_alloc: ptp=0x689C8900
Aug 15 11:38:28.816 CDT: fh_fd_none_event_match: publish_timer=0x689C8740, ptp=0x689C8900, max_delay=30000
Aug 15 11:38:28.816 CDT: none_conn_tm_add: re=0x689C8540, ptp=0x689C8900
Aug 15 11:38:28.816 CDT: fh_fd_none_event_match: re = 0x689C8540, num_matches = 1
Aug 15 11:38:28.816 CDT: fh_send_server_sig_hndlr: received a pulse from none on node0/0 with fdid: 10
Aug 15 11:38:28.816 CDT: fh_send_none_fd_msg: msg_type=64
Aug 15 11:38:28.816 CDT: fh_send_none_fd_msg: sval=0
Aug 15 11:38:28.820 CDT: fh_send_server_sig_hndlr: received FH_MSG_EVENT_PUBLISH_SYNC
Aug 15 11:38:28.820 CDT: EEM: server processes multi events: timewin=1, sync_flag=1, ec_index=0, cmp_occ=1
Aug 15 11:38:28.820 CDT: EEM: ctx=13:(18,1,1)
Aug 15 11:38:28.820 CDT: EEM: server processes multi events: corr_res=1, cur_tcnt=1, cmp_tcnt=1
Aug 15 11:38:28.820 CDT: fh_schedule_callback: fh_schedule_callback: cc=67C54FF8 prev_epc=0; epc=688CC518
act 224: myoid = 1.3.6.1.2.1.10.20.1.3.3.1.2.1, info_snmp_oid = 1.3.6.1.2.1.10.20.1.3.1.0, i = 1, j = 3, k = 2, info_snmp_value = 3, reg_exp_result = 1
act 229: Calls = 3
act 224: myoid = 1.3.6.1.2.1.10.20.1.3.3.1.4.1, info_snmp_oid = 1.3.6.1.2.1.10.20.1.3.1.0, i = 1, j = 3, k = 4, info_snmp_value = 3, reg_exp_result = 1
act 229: Calls = 6
act 224: myoid = 1.3.6.1.2.1.10.20.1.3.3.1.2.2, info_snmp_oid = 1.3.6.1.2.1.10.20.1.3.1.0, i = 2, j = 3, k = 2, info_snmp_value = 3, reg_exp_result = 1
act 229: Calls = 9
act 224: myoid = 1.3.6.1.2.1.10.20.1.3.3.1.4.2, info_snmp_oid = 1.3.6.1.2.1.10.20.1.3.1.0, i = 2, j = 3, k = 4, info_snmp_value = 3, reg_exp_result = 1
act 229: Calls = 12
bctrunks-2431-1#term no mon
bctrunks-2431-1#undebug all
All possible debugging has been turned off
bctrunks-2431-1#
-bash-3.00$ snmpwalk -v1 -c TWC-default 24.30.210.142 1.3.6.1.2.1.10.20.1.3
SNMPv2-SMI::transmission.20.1.3.1.0 = INTEGER: 3 <--- Index of last PRI + 1
SNMPv2-SMI::transmission.20.1.3.2.1.2.1 = INTEGER: 32
SNMPv2-SMI::transmission.20.1.3.2.1.2.2 = INTEGER: 81
SNMPv2-SMI::transmission.20.1.3.2.1.3.1 = INTEGER: 10
SNMPv2-SMI::transmission.20.1.3.2.1.3.2 = INTEGER: 10
SNMPv2-SMI::transmission.20.1.3.2.1.4.1 = ""
SNMPv2-SMI::transmission.20.1.3.2.1.4.2 = ""
SNMPv2-SMI::transmission.20.1.3.2.1.5.1 = ""
SNMPv2-SMI::transmission.20.1.3.2.1.5.2 = ""
SNMPv2-SMI::transmission.20.1.3.2.1.6.1 = INTEGER: 23
SNMPv2-SMI::transmission.20.1.3.2.1.6.2 = INTEGER: 23
SNMPv2-SMI::transmission.20.1.3.2.1.7.1 = INTEGER: 2
SNMPv2-SMI::transmission.20.1.3.2.1.7.2 = INTEGER: 2
SNMPv2-SMI::transmission.20.1.3.2.1.8.1 = INTEGER: 1
SNMPv2-SMI::transmission.20.1.3.2.1.8.2 = INTEGER: 1
SNMPv2-SMI::transmission.20.1.3.3.1.1.1 = Counter32: 0
SNMPv2-SMI::transmission.20.1.3.3.1.1.2 = Counter32: 0
SNMPv2-SMI::transmission.20.1.3.3.1.2.1 = Counter32: 0 <------ Calls Connected Inbound for 1st PRI
SNMPv2-SMI::transmission.20.1.3.3.1.2.2 = Counter32: 0 <------ Calls Connected Inbound for 2nd PRI
SNMPv2-SMI::transmission.20.1.3.3.1.3.1 = Counter32: 0
SNMPv2-SMI::transmission.20.1.3.3.1.3.2 = Counter32: 0
SNMPv2-SMI::transmission.20.1.3.3.1.4.1 = Counter32: 0 <----- Calls Connected Inbound for 1st PRI
SNMPv2-SMI::transmission.20.1.3.3.1.4.2 = Counter32: 0 <----- Calls Connected Inbound for 2nd PRI
SNMPv2-SMI::transmission.20.1.3.3.1.5.1 = Counter32: 0
SNMPv2-SMI::transmission.20.1.3.3.1.5.2 = Counter32: 0
SNMPv2-SMI::transmission.20.1.3.4.1.1.31 = INTEGER: 1
SNMPv2-SMI::transmission.20.1.3.4.1.1.80 = INTEGER: 1
SNMPv2-SMI::transmission.20.1.3.4.1.2.31 = INTEGER: 3
SNMPv2-SMI::transmission.20.1.3.4.1.2.80 = INTEGER: 1
SNMPv2-SMI::transmission.20.1.3.4.1.3.31 = Counter32: 1
SNMPv2-SMI::transmission.20.1.3.4.1.3.80 = Counter32: 0
SNMPv2-SMI::transmission.20.1.3.4.1.4.31 = Counter32: 0
SNMPv2-SMI::transmission.20.1.3.4.1.4.80 = Counter32: 0
-bash-3.00$
08-15-2012 11:18 AM
No, that's not one of the arguments that was variablized. To do what you want, you'll need to switch to Tcl. You can use the converter at http://www.marcuscom.com/convert_applet to get you started.
08-16-2012 07:34 AM
Joe,
I tried converting my applet to a tcl script using the marcuscom.com converter, and then pasting the result into the IOS tclsh prompt, but it looks like I am missing something in the environment, as shown below. I am running c2430-ik9o3s-mz.151-2.T.bin on an iad2431. It appears to provide a built-in tclsh interpreter, but seems to be missing some basic cisco eem initialization and run-time scripts and namespaces. The TclPro interpreter in is also mentioned in the Cisco Doc on writing EEM scripts in tcl, but I have not found a Cisco document with a concise description of what is required to get a tclsh environment set up to run cisco eem tcl scripts on either the IOS 15.1 CLI or on a Windows XP PC. Can you point me in the right direction here?
bctrunks-2431-1#show ev man policy av
No. Type Time Created Name
1 system Thu Feb 7 00:28:15 2036 ap_perf_test_base_cpu.tcl
2 system Thu Feb 7 00:28:15 2036 cl_show_eem_tech.tcl
3 system Thu Feb 7 00:28:15 2036 no_perf_test_init.tcl
4 system Thu Feb 7 00:28:15 2036 sl_intf_down.tcl
5 system Thu Feb 7 00:28:15 2036 tm_cli_cmd.tcl
6 system Thu Feb 7 00:28:15 2036 tm_crash_reporter.tcl
7 system Thu Feb 7 00:28:15 2036 tm_fsys_usage.tcl
bctrunks-2431-1#tclsh
bctrunks-2431-1(tcl)#::cisco::eem::event_register_none
invalid command name "::cisco::eem::event_register_none" ^
% Invalid input detected at '^' marker.
bctrunks-2431-1(tcl)#
bctrunks-2431-1(tcl)##
bctrunks-2431-1(tcl)#$tcl policy was generated by the EEM applet conversion # utility at http://www.marcuscom.com/convert_applet/
bctrunks-2431-1(tcl)## using the following applet:
bctrunks-2431-1(tcl)##
bctrunks-2431-1(tcl)## event manager applet test
bctrunks-2431-1(tcl)## event none
bctrunks-2431-1(tcl)#$d 1.3.6.1.2.1.10.20.1.3.1.0 get-type exact ! isdnSignalingGetIndex # action 202 set j "$_info_snmp_value"
bctrunks-2431-1(tcl)## action 204 set i "1"
bctrunks-2431-1(tcl)## action 206 set Calls "0"
bctrunks-2431-1(tcl)## action 208 while $i lt "$j" ! loop through isdn interfaces
bctrunks-2431-1(tcl)## action 210 set k "2"
bctrunks-2431-1(tcl)## action 212 while $k le 4 ! loop through calls in & out connected stats .2 & .4
bctrunks-2431-1(tcl)## action 214 set myoid "1.3.6.1.2.1.10.20.1.3.3.1."
bctrunks-2431-1(tcl)## action 216 append myoid "$k.$i"
bctrunks-2431-1(tcl)## action 218 info type snmp oid $myoid get-type exact
bctrunks-2431-1(tcl)## action 220 regexp "[0-9]+" "$_info_snmp_value"
bctrunks-2431-1(tcl)#$_snmp_oid, i = $i, j = $j, k = $k, info_snmp_value = $_info_snmp_value, reg_exp_result = $_regexp_result"
bctrunks-2431-1(tcl)## action 224 if $_regexp_result eq 1
bctrunks-2431-1(tcl)## action 226 add $Calls $_info_snmp_value
bctrunks-2431-1(tcl)## action 228 set Calls "$_result"
bctrunks-2431-1(tcl)## action 230 puts "act 229: Calls = $Calls"
bctrunks-2431-1(tcl)## action 232 end
bctrunks-2431-1(tcl)## action 234 increment k 2
bctrunks-2431-1(tcl)## action 236 end
bctrunks-2431-1(tcl)## action 240 increment i 1
bctrunks-2431-1(tcl)## action 250 end
bctrunks-2431-1(tcl)## end
bctrunks-2431-1(tcl)##
bctrunks-2431-1(tcl)#
bctrunks-2431-1(tcl)#namespace import ::cisco::eem::*
unknown namespace in import pattern "::cisco::eem::*"
bctrunks-2431-1(tcl)#namespace import ::cisco::lib::*
unknown namespace in import pattern "::cisco::lib::*"
bctrunks-2431-1(tcl)#
bctrunks-2431-1(tcl)#array set arr_einfo [event_reqinfo]
invalid command name "event_reqinfo" ^
% Invalid input detected at '^' marker.
bctrunks-2431-1(tcl)#
bctrunks-2431-1(tcl)#$fo_snmp oid 1.3.6.1.2.1.10.20.1.3.1.0 get_type exact] # The array _info_snmp can now be accessed # Example:
invalid command name "sys_reqinfo_snmp" ^
% Invalid input detected at '^' marker.
bctrunks-2431-1(tcl)## puts "OID: $_info_snmp(oid)"
bctrunks-2431-1(tcl)## puts "Value: $_info_snmp(value)"
bctrunks-2431-1(tcl)#
bctrunks-2431-1(tcl)#set j "$_info_snmp_value"
can't read "_info_snmp_value": no such variable
bctrunks-2431-1(tcl)#set i "1"
1
bctrunks-2431-1(tcl)#set Calls "0"
0
bctrunks-2431-1(tcl)#while {$i < "$j"} {
+> set k "2"
+> while {$k <= 4} {
+> set myoid "1.3.6.1.2.1.10.20.1.3.3.1."
+> append myoid "$k.$i"
+> array set _info_snmp [sys_reqinfo_snmp oid $myoid get_type exact]
+> # The array _info_snmp can now be accessed
+> # Example:
+> # puts "OID: $_info_snmp(oid)"
+> # puts "Value: $_info_snmp(value)"
+>
+> set _regexp_result [regexp {[0-9]+} "$_info_snmp_value"]
+>$fo_snmp_oid = $_info_snmp_oid, i = $i, j = $j, k = $k, info_snmp_value = $_info_snmp_value, reg_exp_result = $_regexp_result"
+> if {$_regexp_result == 1} {
+> set _result [expr $Calls + $_info_snmp_value]
+> set Calls "$_result"
+> puts "act 229: Calls = $Calls"
+> }
+> incr k 2
+> }
+> incr i 1
+>}
can't read "j": no such variable
bctrunks-2431-1(tcl)#
08-16-2012 10:28 AM
You can't use EEM Tcl with tclsh. Instead, copy this file to, say, flash:policies, then configure:
event manager directory user policy flash:policies
event manager policy test.tcl
08-16-2012 11:54 AM
I saved my script, test.tcl to a flash:tcl/user, set up tcl/user as the user policy path, registered the policy, and ran it but I still get the error EEM policy test not registered with event none Event Detector, as shown below.
It does not seem to recognize the “::cisco::eem: syntax.
Is there something I need to define to link this to the Cisco EEM namespace?
Am I supposed to know to replace the ::cisco::*:: with something appropriate to my environment?
bctrunks-2431-1#config t
Enter configuration commands, one per line. End with CNTL/Z.
bctrunks-2431-1(config)#event man dir user policy flash:tcl/user
bctrunks-2431-1(config)#event man policy test.tcl
bctrunks-2431-1(config)#end
bctrunks-2431-1#event man run test
EEM policy test not registered with event none Event Detector
bctrunks-2431-1#cd tcl
%Error in getting status for flash:/tcl/user/tcl (File not found)
bctrunks-2431-1#pwd
flash:/tcl/user/
bctrunks-2431-1#dir
Directory of flash:/tcl/user/
52 -rw- 1243 Aug 16 2012 13:21:14 -05:00 test.tcl
64057344 bytes total (17895424 bytes free)
bctrunks-2431-1#more flash:/tcl/user/test.tcl
::cisco::eem::event_register_none
namespace import ::cisco::eem::*
namespace import ::cisco::lib::*
array set arr_einfo [event_reqinfo]
array set _info_snmp [sys_reqinfo_snmp oid 1.3.6.1.2.1.10.20.1.3.1.0 get_type exact]
set j "$_info_snmp_value"
set i "1"
set Calls "0"
while {$i < "$j"} {
set k "2"
while {$k <= 4} {
set myoid "1.3.6.1.2.1.10.20.1.3.3.1."
append myoid "$k.$i"
array set _info_snmp [sys_reqinfo_snmp oid $myoid get_type exact]
set _regexp_result [regexp {[0-9]+} "$_info_snmp_value"]
puts "act 224: myoid = $myoid, info_snmp_oid = $_info_snmp_oid, i = $i, j = $j, k = $k, info_snmp_value = $_info_snmp_value, reg_exp_result = $_regexp_result"
if {$_regexp_result == 1} {
set _result [expr $Calls + $_info_snmp_value]
set Calls "$_result"
puts "act 229: Calls = $Calls"
}
incr k 2
}
incr i 1
}
bctrunks-2431-1#
08-16-2012 11:58 AM
You need to run the script as:
event manager run test.tcl
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide