cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2773
Views
0
Helpful
5
Replies

EEM cli command with variables and python

smolit
Level 1
Level 1

Hi Community,

 

I am trying to get an eem applet running that calls a python script in guestshell. So far so good.

But the python script expect two arguements and these arguments should be variables which are generate by the eem applet:

event manager applet SEND-TO-CMDB
event none
 action 1.00 cli command "enable"
 action 1.01 cli command "show platform | i ^Chassis type:"
 action  2.00  regexp "^Chassis type\s*:\s*(.*)" $_cli_result match pid
 action 4.00 cli command "show ver | i ^Processor board ID"
 action  5.00  regexp "^Processor board ID\s*\s*(.*)" $_cli_result match serial_num
 action 6.00 cli command "guestshell run python3 /flash/guest-share/cmdb_request.py  $serial_num  $pid"

Every single part is working well. The applet gets PID and serialnumber. I can call the python script via cli command.

But the python script in combination with the eem variables ($serial_num $pid) isn't working.

It seems that the values in the varibles weren't passed to the python script.

 

What is my fault. I would be verry thankful for a hint.

 

Greets

Sebastian

5 Replies 5

smolit
Level 1
Level 1

One comment which could be helpful...

When I print out action 6.00 and execute the guestshell command manually it works.

Only in combination with guestshell cli command my applet doesn't work.

 

Thanks Sebastian

balaji.bandi
Hall of Fame
Hall of Fame

Not that is parsed the variable i guess :

 

look at some example :

 

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

 

BB

***** Rate All Helpful Responses *****

How to Ask The Cisco Community for Help

smolit
Level 1
Level 1

Thank you for your reply @balaji.bandi .

I looked ath the examples and found this one: "Adding a Python Script in an EEM Applet". This exapmle also uses a parsed argument like mine in the same way. But unfortunately mine doesn't work.

I tihin you are right and the varibale isn't parsed, but I have no idea why.

 

I am very thankful for any further hint.

 

Sebastian

 

Hello,

 

is this the full EEM config ? At first glance, it looks like you might have to declare the environment variables below. I will do some testing...

 

event manager environment pid
event manager environment serial_num

Hi George,

 

thank you for the hint.

Yes, this is the full EEM config. I added the environment variables to the config. Unfortunately without success.

I read a lot of documents about EEM but I couldn't find any details about how to parse variblaes to a python script called vi EEM.

In BBs link (see some Post further up) there is an example "Adding a Python Script in an EEM Applet" that also doesn't work on my ISR.

I am testing on an ISR4331/K9 running IOS XE 17.3.3.

 

In the meantime it feels like I found a bug.

 

Maybe there some more further hints from the community.

 

Thanks

Sebastian

Review Cisco Networking for a $25 gift card