03-26-2019 02:42 PM
Hi,
Like a number of people we want to use EEM to alert us to events on our N5548 via email and understand we have to use python scripts to do the emailing.
Our problem among others is that the "import smtplib" command in the script generates an error "SB: Permission denied". When we run the source command.
We are running
kickstart: version 7.3(3)N1(1)
system: version 7.3(3)N1(1)
Thanks for any ideas
05-31-2019 10:31 PM
The script will print "Permission denied" into console briefly at the line "import smtplib", but this doesn't affect functionality and comes somewhere from python calling engine, not interpreter itself, because message is printed even when all output is supressed. Anyway it doesn't affect script functionality in any way and can be ignored.
It will work starting from NX-OS 6.2 for N7k and from 6.0 for N5k.
06-04-2019 12:26 AM
Hello Pankaj,
Thank you for your reply.
below is the python script we are trying to run:
#!/usr/bin/env python
import cisco
import smtplib
port = 25
smtp_server = "ip address of SMTP gateway"
from_addr = "switch SMTP address"
to_addr = "internal SMTP address"
msg = ("Subject: Possible flapping link on core switch")
# Now send the actual email using smtplib
s = smtplib.SMTP(smtp_server,port)
s.set_debuglevel(1)
s.sendmail(from_addr, to_addr, msg)
s.quit()
When we run it on the switch we get:
switch# source sendmail2.py
SB: Permission denied. Permission denied for the role
Traceback (most recent call last):
File "/bootflash/scripts/sendmail2.py", line 15, in <module>
s = smtplib.SMTP(smtp_server,port)
File "/isan/python/scripts/smtplib.py", line 242, in __init__
(code, msg) = self.connect(host, port)
File "/isan/python/scripts/smtplib.py", line 302, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/isan/python/scripts/smtplib.py", line 277, in _get_socket
return socket.create_connection((port, host), timeout)
File "/isan/python/scripts/socket.py", line 569, in create_connection
sock = socket(af, socktype, proto)
File "/isan/python/scripts/socket.py", line 187, in __init__
_sock = _realsocket(family, type, proto)
SystemError: NULL result without error in PyObject_Call
switch#
Is there something wrong with our script?
The errors listed indicate a problem with the SMTPLIB and we do not get the expected email.
We are able to successfully send an email from the switch command line using telnet on port 25 so the switching/routing is OK.
Thanks.
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