cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
4623
Views
10
Helpful
8
Replies

Running Python Script with EEM on Nexus 9K

davidclin
Level 1
Level 1

Hi!

I'm trying to run the example provided in the following link for "Running Scripts with Embedded Event Manager":

http://www.cisco.com/c/en/us/td/docs/switches/datacenter/nexus9000/sw/6-x/programmability/guide/b_Cisco_Nexus_9000_Series_NX-OS_Programmability_Guide/b_Cisco_Nexus_9000_Series_NX-OS_Programmability_Configuration_Guide_chapter_01.html#concept_3B13FE65D40D4251BAE1AE074A0539C2

 

Here's my Nexus 9K switch EEM configuration:

 

NX9K-Standalone-Pod-1# sh run eem

!Command: show running-config eem
!Time: Sat Nov 15 09:54:52 2014

version 6.1(2)I3(1)
event manager applet a1
  event cli match "show clock"
  action 1 cli python bootflash:pydate.py
  action 2 event-default
  action 3 syslog msg I love EEM

And here's a working example of pydate.py that I grabbed from GitHub:

GitHub Repo: https://github.com/haya14busa/pydate/blob/master/pydate.py

NX9K-Standalone-Pod-1# python bootflash:pydate.py
DATETIME = 2014-11-15 09:47:03
TIMESTAMP = 1416044823
DateTime: 2014-11-15 09:47:03 -> TimeStamp: 1416044823
TimeStamp: 1416044823 -> DateTime: 2014-11-15 09:47:03
NX9K-Standalone-Pod-1#

 

Finally, here's what happens when I issue the command "show clock" in an attempt to trigger the EEM applet:

NX9K-Standalone-Pod-1# sh clock
09:54:58.746 UTC Sat Nov 15 2014
NX9K-Standalone-Pod-1# 2014 Nov 15 09:54:58 NX9K-Standalone-Pod-1 %VSHD-5-VSHD_SYSLOG_CONFIG_I: Configured from vty by admin on vsh.8883
2014 Nov 15 09:54:58 NX9K-Standalone-Pod-1 %VSHD-5-VSHD_SYSLOG_CONFIG_I: Configured from vty by admin on vsh.8894

  

Any help is appreciated!

 

2 Accepted Solutions

Accepted Solutions

Joe Clarke
Cisco Employee
Cisco Employee

The syslog message needs to come before "event-default".  As for what the Python script prints, that won't happen when called from EEM.  But you can, as the Cisco.com article says, look at the log to make sure the script ran.

View solution in original post

Yeah, it appears to be all asynchronous on the Nexus.

View solution in original post

8 Replies 8

Joe Clarke
Cisco Employee
Cisco Employee

The syslog message needs to come before "event-default".  As for what the Python script prints, that won't happen when called from EEM.  But you can, as the Cisco.com article says, look at the log to make sure the script ran.

Thanks, Joe.

That's a bit unfortunate but helps clarify things. 

Honestly, the example provided isn't very useful without the output from the Python script.

If the documentation provided a better example that demonstrates the use of running a Python script using EEM to perform say a series of configuration changes, in my opinion, that would be far more meaningful than the existing example.

I was also a bit shocked to find that NXOS doesn't have a "none" event detector or the capability to trigger an event based on a custom (non-CLI) pattern.  Or perhaps, those capabilities are implemented differently in NXOS?

Anyway, you helped answer my question and saved me alot of time second guessing myself!     

 

 

 

Nathan Sowatskey
Cisco Employee
Cisco Employee

Hi Joe

Could you expand on: "As for what the Python script prints, that won't happen when called from EEM." please?

I have a similar example where I would like to run a python script and see the output. I am using NXOSv 7.3.

Many thanks

Nathan

I haven't tried this on 7.3 to see if 7.x changed the behavior, but this would not work previously.  You'd need to use the "logit" CLI command to send the stdout via syslog.

What I tried as a workaround was to have the Python script write to a file, and use a CLI command in the applet to show that file, but that does not seem to work either.

I then tried reading the file to a variable, and puts'ing the variable. But no.

I then tried puts'ing a string. Nope.

So, it seems that one can't actually print a string to the console in anyway at all from an EEM applet in NXOS. That makes me think I must have something wrong somewhere ...

What do you mean by the "logit" CLI command please?

Thanks

Nathan

What does your applet look like?  This worked for me on 7.3:

event manager applet test

 event none

 action 1.0 cli command "source test.py"

 action 2.0 puts "$_cli_result"

The "puts" printed to syslog, but I did get the output of the script.

The logit command is a hidden CLI command that sends syslog messages.  Use "logit TEXT" to print TEXT via syslog.

Thanks for this Joe.

What I was expecting was to see the puts string at the console.

I also get the message in syslog. I was hoping to see the message as a typical CLI response output, but I get the sense that this does not work on NXOS. Is that correct?

Regards

Nathan

Yeah, it appears to be all asynchronous on the Nexus.