# -*- Mode: Python; tab-width: 4 -*-
import os,sys
#sys.path.append("./newman")
import time, string, socket, re
import asyncore
import event_loop
import auth_handler
import rpc_server
import status_handler
import sendmail
import HtmlKit
import StateDb
import marshal
import DataLogFile
import urllib
import Process
import pop
import collector
import config_server
Version = ''
Registry = {}
ConfigurationData = {}
Config = {}
RawConfigurationData = ''
StartTime = 0
PagingOn = 1
DebugConfigGet = 0
DebugReportIn = 0
DebugReportStatus = 0
DebugPeriodic = 0
PeriodicCounter = 0
SubEntMarkStore = {}
AgentsNotReporting = {}
OneShotEvents = []
PagingMode = 0
PagingBad = 0
PagingMesg = 0
EscalateCounter = 0
EscalateLevel = 0
AckTime = 0
AckMesg = 0
class MainPage:
def display (self, request):
request['Content-Type'] = 'text/html'
s = '<html><head>'
s = s + '<style>\n'
s = s + 'BODY, A, INPUT, TD, TABLE, TR {font-family: helvetica;}\n'
s = s + '</style>\n'
s = s + '<title>QOS ver %s</title>' % Version
s = s + '<script Language="javascript">\n'
s = s + 'function newStatusWin() {\n'
s = s + ' settings = "toolbar=no,location=no,status=no,menubar=yes,scrollbars=yes";\n'
s = s + ' xwin=window.open("/qos/status", "status", settings);\n'
s = s + '}\n'
s = s + 'function newAgentWin() {\n'
s = s + ' settings = "toolbar=no,location=no,status=no,menubar=yes,scrollbars=yes";\n'
s = s + ' xwin=window.open("/qos/agents", "status", settings);\n'
s = s + '}\n'
s = s + 'function newDisabledWin() {\n'
s = s + ' settings = "toolbar=no,location=no,status=no,menubar=yes,scrollbars=yes";\n'
s = s + ' xwin=window.open("/qos/disabled", "status", settings);\n'
s = s + '}\n'
s = s + '</script>\n'
s = s + '</head>\n'
s = s + '<body BGCOLOR=#FFFFFF>'
s = s + '<center>\n'
s = s + '<h1>QOS ver %s</h1>' % Version
s = s + '</center>\n'
if not PagingOn:
s = s + '<center>\n'
s = s + '<h1><font color=#FF0000>** PAGING OFF **</font></h1>'
s = s + '</center>\n'
if AckTime:
s = s + '<center>\n'
s = s + '<h1><font color=#FF0000>** ACK MODE : ending at %s **</font></h1>' % time.asctime(time.localtime(AckTime))
s = s + '<h1><font color=#FF0000>** ACK MODE : %s **</font></h1>' % AckMesg
s = s + '</center>\n'
s = s + '<br>\n'
s = s + '<B>User:</B> %s \n' % request.auth_info[0]
s = s + '<br>\n'
s = s + string.join(status_handler.english_time(time.time() - StartTime))
s = s + '<br>\n'
s = s + '<form method=GET action="/qos/action">\n'
s = s + '<input type=submit name="shutdown" value="Shutdown"><p>\n'
s = s + '<input type=submit name="checkpoint" value="CheckpointQOS"><p>\n'
s = s + '<input type=submit name="pushConfigs" value="PushConfigs"><p>\n'
s = s + '<input type=submit name="togglePaging" value="Toggle Paging"><p>\n'
s = s + '</form>'
s = s + '<br>\n'
#s = s + '<input type=submit name="dynaPage" value="DynaPage"><p>\n'
s = s + '<A HREF="/qos/incident">Go to Incident Form</A>\n'
s = s + '<BR>\n'
s = s + '<A HREF="#" onClick="newStatusWin(); return false">Go to Status Page</A>\n'
s = s + '<BR>\n'
s = s + '<A HREF="#" onClick="newAgentWin(); return false">Go to Agents Page</A>\n'
s = s + '<BR>\n'
s = s + '<A HREF="#" onClick="newDisabledWin(); return false">Go to Disabled Entities Page</A>\n'
s = s + '<BR>\n'
s = s + '<A HREF="/qos/config">Go to Config Page</A>\n'
s = s + '<BR>\n'
s = s + '<br>\n'
s = s + '<form method=GET action="/qos/ack">\n'
s = s + '<input type=text name="mesg" value="" size="40">\n'
s = s + '<input type=submit name="ackSubmit" value="Perform ACK"><p>\n'
s = s + 'Please enter a message with the Ack that will be seen by others. (Your name for example)\n'
s = s + '</form>'
s = s + '<br>\n'
s = s + '</body></html>'
request.push (s)
request.done()
class IncidentPage:
def display (self, request):
request['Content-Type'] = 'text/html'
p = HtmlKit.Page()
p.title_('QOS: Incident Form')
p.append('<H1>QOS: Incident Form</H1><BR>')
f = HtmlKit.Form()
f.method_('GET')
f.action_('/qos/incidentSubmit')
p.append(f)
f.append('Date:')
tb = HtmlKit.Input(value = time.strftime("%a %b %d %Y", time.gmtime()))
tb.name_('date')
f.append(tb)
f.append('<BR>')
f.append('Time:')
tb = HtmlKit.Input(value = time.strftime("%H:%M:%S +0000", time.gmtime()))
tb.name_('time')
f.append(tb)
f.append('<BR><BR>')
f.append('Duration:')
tb = HtmlKit.Select()
tb.name_('duration')
tb.newOption('5 min')
tb.newOption('15 min')
tb.newOption('30 min')
tb.newOption('45 min')
tb.newOption('60 min')
tb.newOption('90 min')
tb.newOption('120 min')
tb.newOption('>120 min')
f.append(tb)
f.append('<BR>')
f.append('Reporter: ')
tb = HtmlKit.Select()
tb.name_('reporter')
tb.newOption('Dru')
tb.newOption('Joe')
tb.newOption('Greg')
tb.newOption('Doug')
f.append(tb)
f.append('<BR><BR>')
f.append('<STRONG>Impact:</STRONG><BR>')
tb = HtmlKit.TextArea()
tb.name_('impact')
tb.rows_(5)
tb.cols_(60)
f.append(tb)
f.append('<BR>')
f.append('<STRONG>Resolution:</STRONG><BR>')
tb = HtmlKit.TextArea()
tb.name_('resolution')
tb.rows_(5)
tb.cols_(60)
f.append(tb)
f.append('<BR>')
f.append('<STRONG>Notes:</STRONG><BR>')
tb = HtmlKit.TextArea()
tb.name_('notes')
tb.rows_(5)
tb.cols_(60)
f.append(tb)
f.append('<BR><BR>')
tb = HtmlKit.Button()
tb.name_('Submit Incident')
f.append(tb)
f.append('<BR><BR><A HREF="/">Return to Main Page</A>')
request.push ( str(p) )
request.done()
class StatusPage:
def display (self, request):
request['Content-Type'] = 'text/html'
# Get the Data
rows = []
for host in SystemState.state.keys():
for ent in SystemState.state[host].keys():
for se in SystemState.state[host][ent].keys():
if SystemState.state[host][ent][se]['state'] != 'G':
row = {}
row['id'] = '%s_%s_%s' %(host, ent, se)
row['state'] = SystemState.state[host][ent][se]['state']
try:
row['date'] = SystemState.state[host][ent][se]['date']
except:
print SystemState.state[host][ent][se]
if SystemState.state[host][ent][se].has_key('textMessage'):
row['mesg'] = SystemState.state[host][ent][se]['textMessage']
else:
row['mesg'] = "No message"
rows.append(row)
nonReportInRows = AgentsNotReporting.keys()
nonReportInRows.sort()
# Render the data
p = HtmlKit.Page()
p.title_('QOS: Quick Status Page')
# <meta http-equiv="Refresh" content="30">
#p.metaRefresh_(10, 'http://xo2.zabootbs.com:9991/qos/status')
#p.metaNoCache_()
# Javascript to reload the page in 30 seconds
p.append('<script language="Javascript">\n')
# I don't know if this works with IE
p.append(' self.setTimeout("window.location.reload(true);", (30 * 1000));\n')
p.append('</script>\n')
p.append(time.ctime(time.time()))
if not PagingOn:
p.append('<center>\n')
p.append('<h1><font color=#FF0000>** PAGING OFF **</font></h1>')
p.append('</center>\n')
if AckTime:
s = ''
s = s + '<center>\n'
s = s + '<h1><font color=#FF0000>** ACK MODE : ending at %s **</font></h1>' % time.asctime(time.localtime(AckTime))
s = s + '<h1><font color=#FF0000>** ACK MODE : %s **</font></h1>' % AckMesg
s = s + '</center>\n'
p.append(s)
if len(nonReportInRows) != 0:
p.append('<br><br><b>Agents Not Reporting In</b><br>')
# Show Agents not checking in
rt = HtmlKit.RowTable()
p.append(rt)
th = HtmlKit.TableHeader()
rt.addHeader_(th)
th.append('Date')
th.bgcolor_('#0000FF')
th = HtmlKit.TableHeader()
rt.addHeader_(th)
th.append('System')
th.bgcolor_('#0000FF')
# Render Rows
for row in nonReportInRows:
r = HtmlKit.Row()
col = r.newColumn()
col.append(time.ctime(AgentsNotReporting[row]))
col.bgcolor_('#DDDDFF')
col = r.newColumn()
col.append(row)
col.bgcolor_('#DDDDFF')
rt.addRow_(r)
p.append('<br><br>')
if len(OneShotEvents) != 0:
p.append('<br><br>One Shot Events<br>')
# Show One-Shot Events
rt = HtmlKit.RowTable()
p.append(rt)
th = HtmlKit.TableHeader()
rt.addHeader_(th)
th.append('Date')
th.bgcolor_('#0000FF')
th = HtmlKit.TableHeader()
rt.addHeader_(th)
th.append('Mesg')
th.bgcolor_('#0000FF')
# Render Rows
OneShotEvents.sort()
OneShotEvents.reverse()
for row in OneShotEvents:
r = HtmlKit.Row()
col = r.newColumn()
col.append(time.asctime(time.localtime(row[0])))
col.bgcolor_('#DDDDFF')
col = r.newColumn()
col.append(row[1])
col.bgcolor_('#DDDDFF')
rt.addRow_(r)
p.append('<br><br>')
# Actual data
rt = HtmlKit.RowTable()
p.append(rt)
th = HtmlKit.TableHeader()
rt.addHeader_(th)
th.append('Elapsed')
th.bgcolor_('#0000FF')
th = HtmlKit.TableHeader()
rt.addHeader_(th)
th.append('System')
th.bgcolor_('#0000FF')
th = HtmlKit.TableHeader()
rt.addHeader_(th)
th.append('State')
th.bgcolor_('#0000FF')
th = HtmlKit.TableHeader()
rt.addHeader_(th)
th.append('Message')
th.bgcolor_('#0000FF')
# Render Rows
for row in rows:
r = HtmlKit.Row()
col = r.newColumn()
# col.append(row['date'])
if row.has_key('date'):
col.append(string.join(status_handler.english_time(time.time() - int(row['date']))))
else:
col.append('')
col.bgcolor_('#DDDDFF')
col = r.newColumn()
col.append(row['id'])
col.bgcolor_('#DDDDFF')
col = r.newColumn()
col.append(row['state'])
col.bgcolor_('#DDDDFF')
col = r.newColumn()
col.append(row['mesg'])
col.bgcolor_('#DDDDFF')
rt.addRow_(r)
request.push ( str(p) )
#print "####"
#print str(p)
#print "####"
request.done()
class StatusText:
def display (self, request):
request['Content-Type'] = 'text/plain'
rows = []
for host in SystemState.state.keys():
for ent in SystemState.state[host].keys():
for se in SystemState.state[host][ent].keys():
if SystemState.state[host][ent][se]['state'] != 'G':
row = {}
row['id'] = '%s_%s_%s' %(host, ent, se)
row['state'] = SystemState.state[host][ent][se]['state']
row['date'] = SystemState.state[host][ent][se]['date']
if SystemState.state[host][ent][se].has_key('textMessage'):
row['mesg'] = SystemState.state[host][ent][se]['textMessage']
else:
row['mesg'] = "No message"
rows.append(row)
nonReportInRows = AgentsNotReporting.keys()
nonReportInRows.sort()
p = ''
if not PagingOn:
p = "paging=0\n"
else:
p = "paging=1\n"
if AckTime:
p = p + 'time="' + time.strftime('%H:%M:%S', time.localtime(AckTime)) + '"\n'
p = p + 'ack="%s"\n' %( AckMesg )
if len(nonReportInRows) != 0:
for row in nonReportInRows:
p = 'missed=' + row + '\n'
for row in rows:
p = p + 'status="' + row['id'] + '","' + row['state'] + '","' + row['mesg'] + '"\n'
request.push ( str(p) )
request<