cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2130
Views
0
Helpful
2
Replies

Python script run by EEM on cisco Nexus 7k

Chemist2k
Level 1
Level 1

Hi!

I'm trying to boost my EEM on Nexus 7009 switch by making it possible to send emails using python. I have a python script that sends emails without any problems if I run it manually but when I try to run it via EEM applet I get an error message:

 

eem_policy_dir:  %eem_policy_dir-2-LOG: test2: Error: AAA authorization failed AAA_AUTHOR_STATUS_METHOD=16(0x10)^M

 

Seems like EEM doesn't have enough privileges to run python scrips etc. We use TACACS to authenticate users, no local authentications is allowed.

 

These are my scrips and EEM applet:

 

#!/bin/env python

import smtplib
import cisco

from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

set_vrf('default')

# me == my email address
# you == recipient's email address
me = "switch@company.com"
you = "myemail@company.com"

# Create message container - the correct MIME type is multipart/alternative.
msg = MIMEMultipart('alternative')
msg['Subject'] = "Python EEM"
msg['From'] = me
msg['To'] = you

# Create the body of the message (a plain-text and an HTML version).
text = cli('show processes cpu sort | exc "0.00% 0.00% 0.00%"')

# Record the MIME types of both parts - text/plain and text/html.
part1 = MIMEText(text, 'plain')

# Attach parts into message container.
# According to RFC 2046, the last part of a multipart message, in this case
# the HTML message, is best and preferred.
msg.attach(part1)

# Send the message via local SMTP server.
s = smtplib.SMTP('ip address', 25)
# sendmail function takes 3 arguments: sender's address, recipient's address
# and message to send - here it is sent as one string.
s.sendmail(me, you, msg.as_string())
s.quit()

 

event manager applet test
event cli match "show clock"
action 1 cli command "source test4.py"
action 2 event-default
action 3 syslog priority critical msg "$_cli_result"

 

Any help would be appreciated :)

1 Accepted Solution

Accepted Solutions

Joe Clarke
Cisco Employee
Cisco Employee

Check your AAA logs.  You'll likely need to make sure the source command is authorized for your eem user.  If you have an admin profile in AAA, try adding the eem user to that profile.

View solution in original post

2 Replies 2

Joe Clarke
Cisco Employee
Cisco Employee

Check your AAA logs.  You'll likely need to make sure the source command is authorized for your eem user.  If you have an admin profile in AAA, try adding the eem user to that profile.

Thank you so much!

 

Apparently Nexus switch runs eem commands using some system user "svc-isan", so I just created a new user with the same name on our ISE server and gave it admin privileges and it worked! Now I'm able to receive emails generated by python scripts.  Though, I keep on getting some error message it doesn't really affect emails, will try to fix it later with TAC.

 

%eem_policy_dir-2-LOG: CPU1: Permission denied. <Wed Jun 20 09:46:26 2018> <1> The System Manager library is unloading for PID 24649.^M

Review Cisco Networking for a $25 gift card