Advertisement
Guest User

Untitled

a guest
Sep 21st, 2015
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. #!/usr/bin/python3
  2.  
  3. import os
  4.  
  5. import smtplib
  6.  
  7. from email.mime.text import MIMEText
  8.  
  9. from email.mime.multipart import MIMEMultipart
  10.  
  11. loadout = os.getloadavg() #this returns a tuple (0.34, 0.1, 0.07)
  12.  
  13. if loadout[1] > 0:
  14.  
  15. msg = MIMEMultipart() #msg is instance obj of mimemultipart
  16.  
  17. msg['From'] = "nagios@localhost" # this is seen as from: in receiving end
  18.  
  19. msg['To'] = "sysadmin@gmail.com" #put any thing here
  20.  
  21. msg['Subject']="System load warning !!"
  22.  
  23. body = str(loadout)
  24.  
  25. msg.attach(MIMEText(body, 'plain'))
  26.  
  27. fromaddr="pythoncheckload@localhost" #returnpath
  28.  
  29. toaddr="usenet2011@gmail.com" #actual receiving address
  30.  
  31. server = smtplib.SMTP('localhost')
  32.  
  33. server.set_debuglevel(True) #for verbose output while testing
  34.  
  35. text = msg.as_string()
  36.  
  37. server.sendmail(fromaddr,toaddr,text)
  38.  
  39. #server.sendmail(fromaddr,[toaddr],text)
  40.  
  41. server.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement