SHARE
TWEET

Untitled

a guest Jul 22nd, 2017 254 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python3
  2. import smtplib
  3. from email.mime.text import MIMEText
  4. import requests
  5. try:
  6.         diskstat = requests.get("http://vmserver/ui/rlogs/disks.txt", verif                                                                                                             y=False)
  7.         diskstat.close()
  8. except ConnectionError:
  9.         dikstat = "Error in connecion to ESXi"
  10. try:
  11.         arraystat = requests.get("http://vmserver/ui/rlogs/LDinfo.txt", ver                                                                                                             ify=False)
  12.         arraystat.close()
  13. except ConnectionError:
  14.         arraystat = "Error in connecion to ESXi"
  15. ebody = ''
  16.  
  17. for l in diskstat.iter_lines():
  18.                 line = l.decode('utf-8')
  19.                 if 'Enclosure Device ID' in line:
  20.                                 ebody = ebody + line + '\n'
  21.                 if 'Slot Number' in line:
  22.                                 ebody = ebody + line + '\n'
  23.                 if 'Device Id' in line:
  24.                                 ebody = ebody + line + '\n'
  25.                 if 'Media Error Count' in line:
  26.                                 ebody = ebody + line + '\n'
  27.                 if 'Drive has flagged a S.M.A.R.T alert' in line:
  28.                                 ebody = ebody + line + '\n'
  29. ebody = ebody + arraystat.text
  30. for i in ebody.splitlines():
  31.     if 'State' in i:
  32.         astatus = i[7:]
  33. msg = MIMEText(ebody)
  34. msg['Subject'] = 'Array status:' + astatus
  35. msg['From'] = 'email@fromaddress'
  36. msg['To'] = 'email@toaddress'
  37. s = smtplib.SMTP('localhost')
  38. s.sendmail('email@fromaddress', 'email@toaddress', msg.as_string())
  39. s.quit()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top