All pastes #816048 Raw Edit

Untitled

public text v1 · immutable
·published 2007-12-14 16:35 UTC
rendered paste body
import os.path, datetime, sys, time, subprocess

class NagiosServices():
	def __init__(self, condor_hostname):
		datfile="/var/cache/nagios2/status.dat"

		sys.stderr = sys.stdout
	
        	if os.path.exists(datfile) == False:
	    		print "Nagios status file not found.  Check file path."
            		return
		self.infile = open(datfile,"r")
        	while 1:
            		line = self.infile.readline()
			if line == "":
				break
			if line[:7] == "service":
				self.service(condor_hostname)

    	def service(self, condor_hostname):
                output = []
		for line in self.infile.readlines()
			line = line.strip()
			if line == "}":
				break
			param = line.split("=")[0]
			if param == "host_name":
				host_name = line[10:]
			if param == "service_description":
				service_description = line[20:]
                                output.append(service_description)
			if param == "current_state":
				current_state = line[14:]
			if param == "plugin_output":
				plugin_output = line[14:]
			if param == "last_state_change":
				t = long(line[18:])
				last_state_change = datetime.datetime.fromtimestamp(long(t)).strftime("%d/%m/%Y %I:%M") # %p")
		if host_name == condor_hostname :
			if len(output) > 0 :
                                #print service_description
				return output