#!/usr/bin/env python # Vinny Valdez # This is the runable version of the instance report script that is created from the template.xml when built by Aeolus # If you want to use this, enable cgi below and drop it in cgi-bin import cgi, cgitb, socket, datetime, os # Enable cgi here #cgitb.enable() def htmlHeader(hostname): '''Build HTML data header''' print "Content-Type: text/html" print print """ %s Report """ % str(hostname).split('.')[0] def htmlCloser(): '''Close out HTML tags''' print """

Script source: instance_report.py

' """ def findUptime(): '''Read uptime from /proc/uptime and confert it to human readable output''' try: f = open( "/proc/uptime" ) contents = f.read().split() f.close() except: return "UNKNOWN" raw_uptime = float(contents[0]) minute = 60 hour = minute * 60 day = hour * 24 days = int( raw_uptime / day ) hours = int( ( raw_uptime % day ) / hour ) minutes = int( ( raw_uptime % hour ) / minute ) seconds = int( raw_uptime % minute ) return "%s days, %s hours, %s minutes, %s seconds" % (days, hours, minutes, seconds) def getDateTime(): raw_now = datetime.datetime.now() return raw_now.strftime("%Y %b %d %H:%M:%S") def getData(): '''Collect system data for use in reporting''' try: hostname = socket.getfqdn(socket.getfqdn()) except: hostname = "UNKNOWN" try: ip = socket.gethostbyname(socket.gethostname()) except: ip = "UNKNOWN" try: f = open('/etc/issue') release = f.readline().strip('\n') except: release = "UNKNOWN" try: now = getDateTime() except: now = "UNKNOWN" try: uptime = findUptime() except: uptime = "UNKNOWN" return hostname, ip, release, now, uptime def printData(hostname, ip, release, now, uptime): '''Construct HTML table of reporting data collected''' headers = [ { 'Hostname' : hostname }, { 'IP Address' : ip }, { 'Release' : release }, { 'Current Time' : now }, { 'System Uptime' : uptime }, ] print '' for header in headers: for k, v in header.items(): print "" % (k, v) print '
%s%s
' return #main hostname, ip, release, now, uptime = getData() htmlHeader(hostname) printData(hostname, ip, release, now, uptime) htmlCloser()