Merge pull request #6818 from lmskater/add-watch-slave-offline

[Jenkins][ci skip] Add check slave online status to watchdog
This commit is contained in:
minggo 2014-05-19 18:32:37 +08:00
commit 1fe836ff79
1 changed files with 41 additions and 0 deletions

View File

@ -1,8 +1,39 @@
import jenkinsapi import jenkinsapi
from jenkinsapi.jenkins import Jenkins from jenkinsapi.jenkins import Jenkins
from jenkinsapi.node import Node
import sys import sys
import time import time
import os import os
from email.mime.text import MIMEText
import smtplib
def send_mail(sub,title,content):
to_list = os.environ['EMAIL_LIST'].split(' ')
mail_user = os.environ['EMAIL_USER']
mail_pass = os.environ['EMAIL_PWD']
mail_postfix = 'gmail.com'
me = mail_user + "<" + mail_user + "@" + mail_postfix + ">"
msg = MIMEText(content, _subtype='plain', _charset='gb2312')
msg['Subject'] = sub
msg['From'] = me
msg['To'] = " ".join(to_list)
print 'to users:', msg['To']
msg['Content'] = 'test'
try:
s = smtplib.SMTP('smtp.gmail.com', 587)
s.ehlo()
s.starttls()
s.login(mail_user,mail_pass)
s.sendmail(me, to_list, str(msg))
print 'info:', me, to_list, str(msg)
s.close()
return True
except Exception, e:
print str(e)
return False
def sendEmail(msg):
send_mail("Jenkins node " + msg + " is offline", 'for offline.', msg + ' is offline')
#check & kill dead buid #check & kill dead buid
def build_time(_job,_threshold): def build_time(_job,_threshold):
@ -43,6 +74,16 @@ def main():
else: else:
threshold = int(os.environ['jenkins-job-watchdog-threshold']) threshold = int(os.environ['jenkins-job-watchdog-threshold'])
build_time(job,threshold) build_time(job,threshold)
#check node status
node_names = os.environ['NODE_LIST'].split(' ')
for node_name in node_names:
node = J.get_node(node_name)
if node.is_online():
print node_name, ' : is online'
else:
sendEmail(node_name)
print node_name, ' : is offline'
return(0) return(0)