#!/usr/bin/python ## Nag Small Screen v1.04 ## Ryan McDonald 2006 http://ryanmcdonald.net/nss ## This software is distributed under the GPL. ## Tested under Python 2.4.3 and Nagios 2.5 import os.path, datetime, sys class Nag: def __init__(self): datfile="/var/nagios/status.dat" sys.stderr = sys.stdout print "Content-type: text/html" print print "Nagios PDA View" print "" print "System time:
\n " + datetime.datetime.now().strftime("%m/%d/%Y %I:%M %p") + "

" if os.path.exists(datfile) == False: print "Nagios PDA View" 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[:4] == "info": self.info() if line[:4] == "host": self.host() if line[:7] == "service": self.service() def info(self): while 1: line = self.infile.readline() line = line.strip() if line == "}": break param = line.split("=")[0] if param == "created": t = long(line[8:]) created = datetime.datetime.fromtimestamp(t).strftime("%m/%d/%Y %I:%M %p") print "Last Nagios Check:
\n " + created + "
" def host(self): while 1: line = self.infile.readline() line = line.strip() if line == "}": break param = line.split("=")[0] if param == "host_name": host_name = line[10:] 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(t).strftime("%m/%d/%Y %I:%M %p") if current_state != "0": print "
" + host_name + "
\n  Host Ping
\n  " + last_state_change + "
\n  " + plugin_output + "
" def service(self): while 1: line = self.infile.readline() 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:] 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(t).strftime("%m/%d/%Y %I:%M %p") if current_state != "0": print "
" + host_name + "
\n  " + service_description + "
\n  " + last_state_change + "
\n  " + plugin_output + "
" app = Nag()