11-15-2014 02:03 AM
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!
Solved! Go to Solution.
11-16-2014 03:07 AM
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.
09-09-2016 01:15 PM
Yeah, it appears to be all asynchronous on the Nexus.
11-16-2014 03:07 AM
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.
11-17-2014 12:58 AM
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!
09-09-2016 08:39 AM
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
09-09-2016 09:08 AM
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.
09-09-2016 09:53 AM
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
09-09-2016 10:25 AM
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.
09-09-2016 12:31 PM
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
09-09-2016 01:15 PM
Yeah, it appears to be all asynchronous on the Nexus.
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