summaryrefslogtreecommitdiffstats
path: root/abs/core/xymon/hbnotes.py
diff options
context:
space:
mode:
authorCecil <knoppmyth@gmail.com>2011-12-09 17:18:27 (GMT)
committerCecil <knoppmyth@gmail.com>2011-12-09 17:18:27 (GMT)
commitc034db2c880091379f7e58c2938a9689d78fbaa9 (patch)
tree8a074205a2f3bf6ee7fb5945c53e1a1618d41973 /abs/core/xymon/hbnotes.py
parent73b42144585c603fc64e7b1d6a126ceb7c486870 (diff)
parentb0c5755ade92ee5b76a6d56248e64254876bc931 (diff)
downloadlinhes_pkgbuild-c034db2c880091379f7e58c2938a9689d78fbaa9.zip
linhes_pkgbuild-c034db2c880091379f7e58c2938a9689d78fbaa9.tar.gz
linhes_pkgbuild-c034db2c880091379f7e58c2938a9689d78fbaa9.tar.bz2
Merge branch 'testing' of ssh://cesman@linhes.org/mount/repository/linhes_pkgbuild into testing
Diffstat (limited to 'abs/core/xymon/hbnotes.py')
-rw-r--r--abs/core/xymon/hbnotes.py352
1 files changed, 352 insertions, 0 deletions
diff --git a/abs/core/xymon/hbnotes.py b/abs/core/xymon/hbnotes.py
new file mode 100644
index 0000000..e08992c
--- /dev/null
+++ b/abs/core/xymon/hbnotes.py
@@ -0,0 +1,352 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+# import MySQL module
+
+import MySQLdb
+import sys
+import getopt
+import socket
+import os
+global ignorehostlist
+try:
+ import ignoreclient
+ ignorehostlist=ignoreclient.ignorehosts
+except:
+ print "could not find the ignore list"
+ ignorehostlist="'ignoreme'"
+
+
+
+
+
+def createdropdown():
+ dir = "/data/database_backup"
+ dropdown=" "
+ #dropdown='''
+ #<input name="param2" type="radio" value="Restore" />Restore database </>
+ #<select name="param1">
+ #'''
+ #if os.path.exists(dir):
+ #files = os.listdir(dir)
+ #for file in os.listdir(dir):
+ #if (file.endswith(".tgz")):
+ #dropdown+='<option value="' + file + '">' + file + '</option> '
+ dropdown+='</select> <br><input name="param2" type="radio" value="Backup" checked="checked" />Backup database<br /> '
+ dropdown+='<input name="param2" type="radio" value="Optimize" />Optimize database<br /> '
+ dropdown+='<input name="param2" type="radio" value="ShutdownAll" />Shutdown All Systems (expect MBE)<br /> '
+ #dropdown+='''<input name="param2" type="radio" value="UpdateAll" />Update All Systems </> <select name="param5">
+ #<option value="Myth_only">Myth only</option>
+ #<option value="All"> Full System</option>
+ #</select>
+ #</br>
+ #</br>
+ #</br>'''
+
+ dropdown+=''' </br></br>'''
+ return dropdown
+
+def main(argv):
+ db = MySQLdb.connect(host="localhost", user="mythtv", passwd="mythtv", db="mythconverg")
+
+ # create a cursor
+ cursor = db.cursor()
+#------------------------------write client-config------------------------------------------------
+ SQL="SELECT DISTINCT(hostname) from settings where hostname not in(%s)"
+ cursor.execute(SQL %ignorehostlist)
+ result = cursor.fetchall()
+ frontonly="_FRONTEND_"
+ masterbackend="_MASTERBACKEND_"
+ masterbacked_w_fe="_MASTERFE_"
+ slave_w_fe="_SLAVEFE_"
+ slave="_SLAVEBACKEND_"
+ stand_alone="_STANDALONE_"
+ dotMBE=""
+ dotfrontend=list()
+ dotslave=list()
+ dotslavefe=list()
+ tunerdict = {}
+ currenthostype=''
+ for row in result:
+ # print row[0]
+ #Find the system type
+ cursor.execute("select value,data from settings where hostname=%s and value in ('HostSystemType','HostRunFrontend');",(row))
+ hostvalues=cursor.fetchall()
+ if len(hostvalues) == 2:
+ if hostvalues[1][1] == 'Frontend_only':
+ frontonly+=","+row[0]
+ dotfrontend.append(row[0])
+
+ elif hostvalues[1][1] == 'Standalone':
+ stand_alone+=","+row[0]
+ dotMBE="MBE" + " [ label=\"" + row[0] + " \\n Standalone \" shapefile=\"/data/srv/httpd/htdocs/xymon/gifs/be.png\" fontcolor=\"white\" color=blue4 style=filled ] "
+ dotfrontend.append(row[0])
+ cursor.execute("select cardtype,defaultinput from capturecard where hostname=%s;",(row))
+ tuners=cursor.fetchall()
+ tstring=""
+
+ if len(tuners) == 0:
+ tunerdict["MBE"]="no tuners \\n"
+ else:
+ for t in tuners:
+ tstring+=t[0]
+ tstring+=t[1]
+ tstring+='\\n'
+ tunerdict["MBE"]=tstring
+
+ elif hostvalues[1][1] == 'Master_backend':
+ print "found MBE"
+ print hostvalues
+ if hostvalues[0][1]=='0':
+ masterbackend+=","+row[0]
+ #dotMBE=row[0] + "\\n Master Backend"
+ #This is wrong, but it's enough to get it working
+ dotMBE=''
+ else:
+ masterbacked_w_fe+=","+row[0]
+ dotMBE="MBE" + " [ label=\"" + row[0] + " \\n Master Backend with frontend \" shapefile=\"/data/srv/httpd/htdocs/xymon/gifs/be.png\" fontcolor=\"white\" color=blue4 style=filled ] "
+ cursor.execute("select cardtype,defaultinput from capturecard where hostname=%s;",(row))
+ tuners=cursor.fetchall()
+ tstring=""
+ if len(tuners) == 0:
+ tunerdict["MBE"]="no tuners \\n"
+ else:
+ for t in tuners:
+ tstring+=t[0]
+ tstring+=t[1]
+ tstring+='\\n'
+ tunerdict["MBE"]=tstring
+ dotfrontend.append(row[0])
+
+ elif hostvalues[1][1] == 'Slave_backend':
+ if hostvalues[0][1]=='0':
+ slave+=","+row[0]
+ dotslave.append(row[0])
+ cursor.execute("select cardtype,defaultinput from capturecard where hostname=%s;",(row))
+ tuners=cursor.fetchall()
+ tstring=""
+ for t in tuners:
+ tstring+=t[0]
+ tstring+=t[1]
+ tstring+='\\n'
+ tunerdict["STUNER"+row[0]]=tstring
+ #dotfrontend.append(row[0])
+ else:
+ cursor.execute("select cardtype,defaultinput from capturecard where hostname=%s;",(row))
+ tuners=cursor.fetchall()
+ tstring=""
+ for t in tuners:
+ tstring+=t[0]
+ tstring+=t[1]
+ tstring+='\\n'
+ tunerdict["STUNER"+row[0]]=tstring
+ print tstring
+
+ slave_w_fe+=","+row[0]
+ dotslave.append(row[0])
+ dotfrontend.append(row[0])
+
+#----------------------------------Create graphviz dot files
+ dotfilename="/data/srv/xymon/server/etc/mythdot"
+
+ dotfile=open(dotfilename,'w')
+ dotfile.write("digraph G { " + "\n" )
+ dotfile.write("graph [bgcolor=transparent]" + "\n" )
+
+
+#define the nodes
+ dotfile.write( dotMBE + " \n" )
+
+ dotfile.write("tunermbe"+ " [ label= \"" + tunerdict["MBE"] + "\" , shapefile=\"/data/srv/httpd/htdocs/xymon/gifs/tuner.png\" fontcolor=\"white\" color=red ] \n" )
+
+ for fe in dotfrontend:
+ dotfile.write("FEND"+fe + "[ label=\"frontend \\n " + fe + "\" ,shapefile=\"/data/srv/httpd/htdocs/xymon/gifs/tv.png\" , fontcolor=\"white\" , imagescale=\"true\" color=\"gold2\" ] \n" )
+
+ for fe in dotslave:
+ cslave="STUNER"+fe
+ if tunerdict[cslave] != "" :
+ dotfile.write(cslave+ " [ label= \"" + tunerdict[cslave] + "\" , shape=box ] \n" )
+ dotfile.write("SLAVE"+fe + "[ label=\"slave backend \\n " + fe + "\" shapefile=\"/data/srv/httpd/htdocs/xymon/gifs/be.png\" fontcolor=\"white\" color=green ] \n" )
+
+
+#connect up the nodes!
+ dotfile.write("tunermbe -> MBE [color=\"red\"] \n " )
+
+ for fe in dotfrontend:
+ dotfile.write("MBE -> FEND" + fe + "[color=\"gold2\"] \n " )
+
+ for fe in dotslave:
+ cslave="STUNER"+fe
+ dotfile.write("SLAVE" + fe + "-> MBE [color=\"green\"] \n " )
+ if tunerdict[cslave] != "" :
+ dotfile.write(cslave + "-> SLAVE"+fe + "\n" )
+
+
+
+ dotfile.write("} " + "\n" )
+ dotfile.close()
+
+
+ cmd="/usr/bin/unflatten -l6 -c3 -f " + dotfilename + " |/usr/bin/dot -Tpng -o/data/srv/httpd/htdocs/xymon/gifs/network.png "
+ # cmd="/usr/bin/circo -Tpng -o/data/srv/httpd/htdocs/xymon/gifs/network.png " + dotfilename
+
+ results=os.popen(cmd,'r')
+
+ #--------------------------------------------------
+ #hobbitfile="/data/srv/xymon/server/etc/hobbit-clients.cfg"
+ hobbitfile="/data/srv/xymon/server/etc/tasks.cfg"
+ hobbitf=open(hobbitfile,'r')
+ hobbitconfig=hobbitf.readlines()
+ hobbitf.close()
+ hobbitf=open(hobbitfile,'w')
+ print "FE",frontonly
+ print "MBE",masterbackend
+ print "MBEwFW",masterbacked_w_fe
+ print "SLAVEwFW",slave_w_fe
+ print "SLAVE",slave
+ print "STD",stand_alone
+
+ for line in hobbitconfig:
+ if line.startswith("HOST"):
+ cline=line.split("=")
+ if cline[1].startswith("_FRONTEND_"):
+ pline="HOST="
+ pline+=frontonly.strip()
+ hobbitf.write(pline + "\n")
+ elif cline[1].startswith("_MASTERBACKEND_"):
+ pline="HOST="
+ pline+=masterbackend.strip()
+ #print pline
+ hobbitf.write(pline+ "\n")
+ elif cline[1].startswith("_MASTERFRONTEND_"):
+ pline="HOST="
+ pline+=masterbacked_w_fe.strip()
+ #print pline
+ hobbitf.write(pline+ "\n")
+ elif cline[1].startswith("_SLAVEBACKEND_"):
+ pline="HOST="
+ pline+=slave.strip()
+ #print pline
+ hobbitf.write(pline+ "\n")
+ elif cline[1].startswith("_SLAVEFE_"):
+ pline="HOST="
+ pline+=slave_w_fe.strip()
+ #print pline
+ hobbitf.write(pline+ "\n")
+ else:
+ #print line
+ hobbitf.write(line)
+ else:
+ #print line
+ hobbitf.write(line)
+
+#-----------------------------------------------------------END CLIENT CONFIG
+
+ # execute SQL statement
+ cursor.execute("SELECT DISTINCT(hostname) from settings")
+ result = cursor.fetchall()
+
+ for row in result:
+ cursor.execute("select value,data from settings where hostname=%s and value in ('HostSystemType','HostHwuuid');",(row))
+ hostvalues=cursor.fetchall()
+ found_uuid="false"
+ filename="/data/srv/xymon/server/www/notes/"
+ filename+=str(row[0])
+ filename+=(".html")
+
+ file = open(filename,'w')
+ string='''
+ <html>
+ <head>
+ <style type="text/css">@import "/frame.css";</style>
+ </head>
+ '''
+ file.write(string)
+
+
+ for i in range( 0 , len(hostvalues)):
+ value=hostvalues[i][0]
+ data=hostvalues[i][1]
+ currenthostype=''
+ currenthostname=''
+ if value == "HostHwuuid" :
+ if data != "blank" :
+ found_uuid="true"
+ uuid=data
+ if value == "HostSystemType" :
+
+ currenthostname= str(row[0]).strip()
+ currenthostype=str(data).strip()
+ header="<h1>" + currenthostname + " (" + currenthostype + ") </h1>"
+ file.write(header + '\n')
+
+
+ if found_uuid == "true" :
+ string=str("http://smolt.mythvantage.com/client/show?uuid=")
+ string+=str(uuid)
+ file.write("<A href=\"" )
+ file.write(string)
+ file.write("\" >" + str(uuid) + "</A>")
+ else:
+ file.write( "uuid not found, please submit a hardware profile" )
+
+
+
+ buttonform_top='''
+ <div class="content" style="solid #aaa; width:500px; height:350px; overflow:auto; color:#FFF;text-align:left;">
+ <form action="/process.py" method="get">
+ '''
+
+
+ buttonform_bottom='''
+ <input name="param2" type="radio" value="Update" />Update System </>
+ <select name="param3">
+ <option value="Myth_only">Myth only</option>
+ <option value="All"> Full System</option>
+ </select>
+ </br>
+ <input name="param2" type="radio" value="Kill" />Restart interface: </>
+ <select name="param6">
+ <option value="killX">Full UI</option>
+ <option value="killmyth">MythFrontend</option>
+ </select>
+ </br>
+ <input name="param2" type="radio" value="Shutdown" />Shutdown System<br />
+ <input name="param2" type="radio" value="Reboot" />Reboot System<br />
+ <input name="param2" type="radio" value="WOL" />Wake on Lan<br />
+ <input name="hiddenparam" type="hidden" value="
+ '''
+ oldurlform='''
+ "/>
+ <input name="param4" type="hidden" value="
+ '''
+
+
+ closetag='''
+ "/>
+ </br>
+ <input id="submitbutton" type="submit" />
+ </form>
+ </div>
+ '''
+
+ if currenthostype == "Master_backend":
+ mbeoptions=createdropdown()
+ else:
+ mbeoptions=''
+ returnurl="/xymon/notes/"
+ returnurl+=str(row[0])
+ returnurl+=(".html")
+ file.write('</br> </br> ')
+ file.write(buttonform_top)
+ file.write(mbeoptions)
+ file.write(buttonform_bottom)
+ file.write(str(row[0]))
+ file.write(oldurlform)
+ file.write(returnurl)
+ file.write(closetag)
+
+ string=(' </html>')
+ file.write(string)
+
+if __name__ == "__main__":
+ main(sys.argv[1:])