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

EEM nested applet regex issue

vv0bbLeS
Level 1
Level 1

Hello all,

I'm new to EEM, and I seem to be having trouble with a regex in a nested applet. Here is some sample code:

 

event manager environment q "
event manager environment t $timestamp

event man app parent
event none
action 1.0 cli command "enable"
action 2.0 cli command "conf t"
action 3.0 cli command "ev man app child"
action 4.0 cli command "event none"
action 5.0 cli command "action 0.1 cli command $q enable$q"
action 6.0 cli command "action 0.2 cli command $q show clock$q"
!
!This next statement is where the issue is action 7.0 cli command "action 0.3 regexp [0-9]+:[[:print:]]+ $_cli_result timestamp"
! action 8.0 cli command "action 0.4 puts $q current time is $t $q" action 9.0 cli command "action 0.5 syslog msg $q current time is $t $q"

After turning on debugging for EEM and looking at the Action 7.0 statement, when IOS tries to run the nested Action 0.3 statement, there is a carriage return that is being passed after the regular expression (right before the $timestamp variable, with the $_cli_result variable disappearing).

 

I'm wondering if this is because the $_cli_result variable itself starts with a carriage return and somehow the actual value of $_cli_result is being passed into the Action 0.3 statement, instead of just the reference to the variable? Any thoughts?

 

Finally, here is some quick debug output, starting with the Action 0.2 statement for "show clock" and ending with the Action 0.4 statement. You can see when the Action 0.3 statement is being passed, the $_cli_result variable disappears, almost as if it becomes the carriage return:

 

*Aug  6 16:20:15.379: %HA_EM-6-LOG: parent : DEBUG(cli_lib) : : OUT : R1(config-applet)#
*Aug  6 16:20:15.379: %HA_EM-6-LOG: parent : DEBUG(cli_lib) : : IN  : R1(config-applet)#action 0.2 cli command " show clock"
*Aug  6 16:20:15.383: cli_history_entry_add: free_hist_list size=0, hist_list size=7
*Aug  6 16:20:15.383: eem_no_scan flag set, skipping scan of command_string=action 0.2 cli command " show clock"
*Aug  6 16:20:15.383: fh_server: fh_io_ipc_msg: received msg FH_MSG_EVENT_NVGEN from client 1 pclient 1
*Aug  6 16:20:15.383: fh_reg_send_msg_to_fd server sending FH_MSG_EVENT_NVGEN message to FD:none xos_ipc_sync_send to fdc->eph = 1114128)
*Aug  6 16:20:15.383: fh_reg_send_msg_to_fd server sent FH_MSG_EVENT_NVGEN message to FD:none event passed to fdc->eph = 1114128 status 0
*Aug  6 16:20:15.383: fh_server: fh_io_ipc_msg: received msg FH_MSG_EVENT_NVGEN from client 1 pclient 1
*Aug  6 16:20:15.383: fh_reg_send_msg_to_fd server sending FH_MSG_EVENT_NVGEN message to FD:none xos_ipc_sync_send to fdc->eph = 1114128)
*Aug  6 16:20:15.383: fh_reg_send_msg_to_fd server sent FH_MSG_EVENT_NVGEN message to FD:none event passed to fdc->eph = 1114128 status 0
*Aug  6 16:20:15.391: %HA_EM-6-LOG: parent : DEBUG(cli_lib) : : OUT : R1(config-applet)#
*Aug  6 16:20:15.391: %HA_EM-6-LOG: parent : DEBUG(cli_lib) : : IN  : R1(config-applet)#action 0.3 regexp [0-9]+:[[:print:]]+ 
*Aug  6 16:20:15.391: %HA_EM-6-LOG: parent : DEBUG(cli_lib) : : IN  : R1(config-applet)# timestamp
*Aug  6 16:20:15.403: %HA_EM-6-LOG: parent : DEBUG(cli_lib) : : OUT : % Incomplete command.
*Aug  6 16:20:15.403: %HA_EM-6-LOG: parent : DEBUG(cli_lib) : : OUT : 
*Aug  6 16:20:15.403: %HA_EM-6-LOG: parent : DEBUG(cli_lib) : : OUT : R1(config-applet)#
*Aug  6 16:20:15.403: %HA_EM-6-LOG: parent : DEBUG(cli_lib) : : OUT : R1(config-applet)#                  ^
*Aug  6 16:20:15.403: %HA_EM-6-LOG: parent : DEBUG(cli_lib) : : OUT : % Invalid input detected at '^' marker.
*Aug  6 16:20:15.403: %HA_EM-6-LOG: parent : DEBUG(cli_lib) : : OUT : 
*Aug  6 16:20:15.403: %HA_EM-6-LOG: parent : DEBUG(cli_lib) : : OUT : R1(config-applet)#
*Aug  6 16:20:15.407: %HA_EM-6-LOG: parent : DEBUG(cli_lib) : : IN  : R1(config-applet)#action 0.4 puts " current time is $timestamp "
*Aug  6 16:20:15.407: cli_history_entry_add: free_hist_list size=0, hist_list size=7
*Aug  6 16:20:15.407: eem_no_scan flag set, skipping scan of command_string=action 0.4 puts " current time is $timestamp "
*Aug  6 16:20:15.407: fh_server: fh_io_ipc_msg: received msg FH_MSG_EVENT_NVGEN from client 1 pclient 1
*Aug  6 16:20:15.407: fh_reg_send_msg_to_fd server sending FH_MSG_EVENT_NVGEN message to FD:none xos_ipc_sync_send to fdc->eph = 1114128)
*Aug  6 16:20:15.407: fh_reg_send_msg_to_fd server sent FH_MSG_EVENT_NVGEN message to FD:none event passed to fdc->eph = 1114128 status 0
*Aug  6 16:20:15.407: fh_server: fh_io_ipc_msg: received msg FH_MSG_EVENT_NVGEN from client 1 pclient 1
*Aug  6 16:20:15.407: fh_reg_send_msg_to_fd server sending FH_MSG_EVENT_NVGEN message to FD:none xos_ipc_sync_send to fdc->eph = 1114128)
*Aug  6 16:20:15.407: fh_reg_send_msg_to_fd server sent FH_MSG_EVENT_NVGEN message to FD:none event passed to fdc->eph = 1114128 status 0
*Aug  6 16:20:15.419: %HA_EM-6-LOG: parent : DEBUG(cli_lib) : : OUT : R1(config-applet)#

 

 

0xD2A6762E
1 Accepted Solution

Accepted Solutions

vv0bbLeS
Level 1
Level 1

Nevermind, I figured it out. Since $_cli_result is overwritten with each "Action cli" command, and I'm nesting "action cli" commands inside "action cli" commands, things can get a little jumbled when trying to call the $_cli_result variable directly inside a statement that's already nested in another "Action cli" statement.

 

The solution is to not call the $_cli_result variable directly, but to instead define an environment variable for it at the start of your script, so that when you pass it to a nested "Action" statement, IOS will pass a reference to $_cli_result, instead of its actual value (which would be either blank or a carriage return, the latter was my issue above I believe).

 

Here is the corrected script:

event manager environment q "
event manager environment t $timestamp
!
!This is the variable that was needed:
event manager environment cliresult $_cli_result


event man app parent
event none
action 1.0 cli command "enable"
action 2.0 cli command "conf t"
action 3.0 cli command "ev man app child"
action 4.0 cli command "event none"
action 5.0 cli command "action 0.1 cli command $q enable$q"
action 6.0 cli command "action 0.2 cli command $q show clock$q"
action 7.0 cli command "action 0.3 regexp [0-9]+:[[:print:]]+ $cliresult timestamp"
action 8.0 cli command "action 0.4 puts $q current time is $t $q"
action 9.0 cli command "action 0.5 syslog msg $q current time is $t $q"

 

0xD2A6762E

View solution in original post

1 Reply 1

vv0bbLeS
Level 1
Level 1

Nevermind, I figured it out. Since $_cli_result is overwritten with each "Action cli" command, and I'm nesting "action cli" commands inside "action cli" commands, things can get a little jumbled when trying to call the $_cli_result variable directly inside a statement that's already nested in another "Action cli" statement.

 

The solution is to not call the $_cli_result variable directly, but to instead define an environment variable for it at the start of your script, so that when you pass it to a nested "Action" statement, IOS will pass a reference to $_cli_result, instead of its actual value (which would be either blank or a carriage return, the latter was my issue above I believe).

 

Here is the corrected script:

event manager environment q "
event manager environment t $timestamp
!
!This is the variable that was needed:
event manager environment cliresult $_cli_result


event man app parent
event none
action 1.0 cli command "enable"
action 2.0 cli command "conf t"
action 3.0 cli command "ev man app child"
action 4.0 cli command "event none"
action 5.0 cli command "action 0.1 cli command $q enable$q"
action 6.0 cli command "action 0.2 cli command $q show clock$q"
action 7.0 cli command "action 0.3 regexp [0-9]+:[[:print:]]+ $cliresult timestamp"
action 8.0 cli command "action 0.4 puts $q current time is $t $q"
action 9.0 cli command "action 0.5 syslog msg $q current time is $t $q"

 

0xD2A6762E

Review Cisco Networking for a $25 gift card