#!/usr/bin/python

import os, sys, subprocess, smtplib
from email.mime.text import MIMEText

command = '/usr/sbin/pcs status'

ierr = 0
virts = []
msgbody = "\n"


proc = subprocess.Popen( [ command ], stdout=subprocess.PIPE, shell=True )
( procout, err ) = proc.communicate()
proc.terminate
msgbody = msgbody + procout + '\n'
msgbody = msgbody + '\n'
#
msg = MIMEText( msgbody )
msg['Subject'] = 'VPR Cluster Status'
if ( procout.find('Stopped') >= 0 ):
    msg['Subject'] = 'VPR Cluster Status - STOPPED Resource Detected'
#
if ( procout.find('OFFLINE') >= 0 ):
    msg['Subject'] = 'VPR Cluster Status - OFFLINE Node Detected'
#
msg['From'] = 'root@rccc.ou.edu'
msg['To'] = 'jsummers@ou.edu'

# Send the message via our own SMTP server.

s = smtplib.SMTP('smtp.ou.edu')
s.sendmail( 'root@rccc.ou.edu', 'jsummers@ou.edu', msg.as_string())
s.quit()

sys.exit()
#
