#!/usr/local/bin/python import os import string import sys logfile=open('/usr/local/nagios/DCS/loadl.status','w') reslist=[] # iterate over 1..8 for i in range(1,9): host="esmf0"+str(i)+"m" # just for testing to see what this script will do when there's an # error # if host == 'esmf03m': # port = 3000 # else: # port = 9605 port = 9605 pipe=os.popen("/usr/local/nagios/libexec/check_tcp -H "+host+" -p "+str(port),"r") state_descrip = string.strip(pipe.readline()) retval = pipe.close() # this is a bit strange: Python makes the return value of popen # "None" if the # exit status is 0 if retval == None: retval = 0 sretval = str(retval/256) reslist.append(sretval) logfile.write(host+' '+sretval+' '+state_descrip+'\n') logfile.close() data=string.joinfields(reslist,",") pipe = os.popen("/usr/local/nagios/libexec/check_cluster2 --service --label 'loadleveler' -w 1 -c 1 -d "+data,"r") result_text = pipe.readline() status_code = pipe.close() # this is a bit strange: Python makes the return value of popen "None" # if the # exit status is 0 if status_code == None: status_code = 0 sys.stdout.write(result_text) status_code = status_code/256 sys.exit(status_code)
esmf01m 0 TCP OK - 0 second response time on port 9605 esmf02m 0 TCP OK - 0 second response time on port 9605 esmf03m 0 TCP OK - 0 second response time on port 9605 esmf04m 0 TCP OK - 0 second response time on port 9605 esmf05m 0 TCP OK - 0 second response time on port 9605 esmf06m 0 TCP OK - 0 second response time on port 9605 esmf07m 0 TCP OK - 0 second response time on port 9605 esmf08m 0 TCP OK - 0 second response time on port 9605
The first column of zeros is the exit status from the check_tcp plugin, which is what gets fed into check_cluster2 by the wrapper script.