cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
3356
Views
0
Helpful
7
Replies

EEM registration failed for python script

Alex Willoughby
Level 1
Level 1

Hello all,

 

I'm trying to register a python script in EEM but it keeps failing, I have dumbed down the script do do nothing but print and im still getting nowhere, from articles I've read I should be all good (https://blogs.cisco.com/developer/on-box-python-for-devices)

 

ive seen that in bash patterns start with ## so I tried to also no no avail

 

test2.py

::cisco::eem::event_register_syslog pattern ".*%BGP-5-ADJCHANGE:.*Down.*" maxrun 60
print("BGP DOWN")

IOS

POC-RTR-01(config)#event manager directory user policy flash:scripts
POC-RTR-01(config)#event manager policy test2.py authorization bypass type user
EEM configuration: failed to retrieve intermediate registration result for policy test2.py
POC-RTR-01(config)#do dir flash:scripts
Directory of bootflash:/scripts/

186210  -rw-              420  Apr 12 2019 13:29:42 +00:00  test.py
186211  -rw-              104  Apr 17 2019 15:51:30 +00:00  test2.py

6703677440 bytes total (4593250304 bytes free)
POC-RTR-01#show event manager detector all
No.  Name                Version   Node        Type
1    application         01.00     node0/0     RP
2    rf                  01.00     node0/0     RP
3    syslog              01.00     node0/0     RP
4    mat                 01.00     node0/0     RP
5    neighbor-discovery  01.00     node0/0     RP
6    generic             01.00     node0/0     RP
7    track               01.00     node0/0     RP
8    routing             03.00     node0/0     RP
9    resource            01.00     node0/0     RP
10   cli                 01.00     node0/0     RP
11   counter             01.00     node0/0     RP
12   interface           01.00     node0/0     RP
13   ioswdsysmon         01.00     node0/0     RP
14   none                01.00     node0/0     RP
15   oir                 01.00     node0/0     RP
16   snmp                01.00     node0/0     RP
17   snmp-object         01.00     node0/0     RP
18   snmp-notification   01.00     node0/0     RP
19   timer               01.00     node0/0     RP
20   test                01.00     node0/0     RP
21   config              01.00     node0/0     RP
22   env                 01.00     node0/0     RP
23   ds                  01.00     node0/0     RP
24   crash               01.00     node0/0     RP
25   gold                01.00     node0/0     RP
26   rpc                 01.00     node0/0     RP
27   ipsla               01.00     node0/0     RP

 

 

has anyone come across this and know the fix?

 

 

1 Accepted Solution

Accepted Solutions

This was solved with TACs assistance, currently cannot run EEM python scripts from a sub directory, they have to be run from the root

View solution in original post

7 Replies 7

Alex Willoughby
Level 1
Level 1

I have some debug output from attempting to register the script as per the below, I have highlighted a possible issue, it seems as if eem cannot open the file.

 

I went into guesthell and gave the file 777 permissions and still the same issue occurred

 

[guestshell@guestshell scripts]$ chmod 777 eem_test.py
[guestshell@guestshell scripts]$ ls -lah eem_test.py
-rwxrwxrwx 1 guestshell guestshell 162 Apr 23 09:08 eem_test.py
[guestshell@guestshell scripts]$ exit

 

Also from what ive read eem should detect the .py extension and register it as python, in the logs below it looks like its attempting to register a tcl script only?

 

POC-RTR-01(config)#event manager policy flash:/scripts/eem_test.py
Apr 23 09:13:36.525: cli_history_entry_add: free_hist_list size=0, hist_list size=7
Apr 23 09:13:36.525: fh_fd_cli_event_match: fd_reg->cli_match_type = 1, match_info->match_type = 1
Apr 23 09:13:36.525: fh_fd_cli_event_match: fd_reg->cli_match_type = 1, match_info->match_type = 1
Apr 23 09:13:36.525: check_eem_cli_policy_handler: command_string=configure terminal
Apr 23 09:13:36.526: check_eem_cli_policy_handler: num_matches = 0, response_code = 1
POC-RTR-01(config)#event manager policy eem_test.py
EEM configuration: failed to retrieve intermediate registration result for policy eem_test.py
POC-RTR-01(config)#
Apr 23 09:13:40.022: cli_history_entry_add: free_hist_list size=0, hist_list size=7
Apr 23 09:13:40.022: fh_fd_cli_event_match: fd_reg->cli_match_type = 1, match_info->match_type = 1
Apr 23 09:13:40.022: fh_fd_cli_event_match: fd_reg->cli_match_type = 1, match_info->match_type = 1
Apr 23 09:13:40.022: check_eem_cli_policy_handler: command_string=event manager policy eem_test.py
Apr 23 09:13:40.022: check_eem_cli_policy_handler: num_matches = 0, response_code = 1
Apr 23 09:13:40.022: EEM Inside fh_set_policy()

Apr 23 09:13:40.022: fh_policyname = eem_test.py
Apr 23 09:13:40.022: type = 2
Apr 23 09:13:40.022: checksum type = FH_POLICY_CHECKSUM_UNKNOWN
Apr 23 09:13:40.023: found user policy absolute path flash:/scripts/eem_test.py
Apr 23 09:13:40.023: found type = 1
Apr 23 09:13:40.023: register eem policy flash:/scripts/eem_test.py
Apr 23 09:13:40.023: check 1: not duplicate registration
Apr 23 09:13:40.023: Checking security level: ECDSA 192
Apr 23 09:13:40.023: TCL secure mode OFF
Apr 23 09:13:40.023: No valid digital signature found or Tcl digital signatures are not supported in this image, registering as a user script.
Apr 23 09:13:40.024: waiting for mlang proc
Apr 23 09:13:40.025: fh_io_ipc_msg: received FH_MSG_API_INIT; jobid=19, processid=677, client=9, job name=EEM MLANG Proc
Apr 23 09:13:40.026: Could not open the file : eem_test.py
POC-RTR-01(config)#
Apr 23 09:13:40.026: fh_server: fh_io_ipc_msg: received msg FH_MSG_API_CLOSE from client 9 pclient 9
Apr 23 09:13:40.026: fh_io_ipc_msg: received FH_MSG_API_CLOSE client=9
Apr 23 09:13:40.026: No valid digital signature found or Tcl digital signatures are not supported in this image, registering as a user script.
Apr 23 09:13:40.026: fh_reg_policy_core failed: failed to retrieve intermediate registration result for policy eem_test.py

 

hi

not sure .. could it be directory permissions?

as a test .. can you try bootflash: instead of flash:

POC-RTR-01(config)#event manager policy bootflash:/scripts/eem_test.py

and test with copying and registering from flash..  flash:/eem_test.py instead of flash:/scripts/eem_test.py

 

HTH

Also, look at step 3 and 4 for a directory

https://www.cisco.com/c/en/us/td/docs/ios-xml/ios/prog/configuration/1612/b_1612_programmability_cg/eem_python_module.html

 

Step 3

event manager directory user policy path

Example:

Device(config)# event manager directory user policy flash:/user_library

Specifies a directory to use for storing user library files or user-defined EEM policies.

Note 

You must have a policy in the specified path. For example, in this step, the eem_script.py policy is available in the flash:/user_library folder or path.

Step 4

event manager policy policy-filename

Example:

Device(config)# event manager policy eem_script.py

Registers a policy with EEM.

  • The policy is parsed based on the file extension. If the file extension is .py, the policy is registered as Python policy.

  • EEM schedules and runs policies on the basis of an event specification that is contained within the policy itself. When the event manager policy command is invoked, EEM examines the policy and registers it to be run when the specified event occurs.

 

 

 

This was solved with TACs assistance, currently cannot run EEM python scripts from a sub directory, they have to be run from the root

Great stuff! 

i did suggest below .. but you have accepted your own solution .. no worries :)

 

not sure .. could it be directory permissions?

as a test .. can you try bootflash: instead of flash:

POC-RTR-01(config)#event manager policy bootflash:/scripts/eem_test.py

and test with copying and registering from flash..  flash:/eem_test.py instead of flash:/scripts/eem_test.py

ChrisNewnham_
Level 1
Level 1

I am still having this issue. I moved my script to bootflash:/ , using CSR v16.12:

event manager directory user policy "flash:/"

 (Note that IOS added the speech marks. Have tried "bootflash" as well)

 

R1(config)#event manager policy eem.py
EEM configuration: failed to retrieve intermediate registration result for policy eem.py
R1#dir | in eem
   24  -rw-               67  Apr 12 2022 12:52:27 +00:00  eem.py

A copy of the file:

R1#guestshell run cat eem.py
import eem
import time

eem.action_syslog("MESSAGE", "6", "TEST")


Fixed my own issue! 

 

Added to python script at the first line:

 

::cisco::eem::event_register_syslog tag "1"    pattern     COUNTER    maxrun 200