changes for 3.0
[monitor.git] / showlatlon.py
index 6406c49..ea0891c 100755 (executable)
@@ -1,14 +1,13 @@
 #!/usr/bin/python
 
 import plc
-import auth
-api = plc.PLC(auth.auth, auth.plc)
+api = plc.getAuthAPI()
 
 import sys
 import reboot
 from datetime import datetime, timedelta
 
-import soltesz
+import database
 import comon
 from nodecommon import color_pcu_state, datetime_fromstr
 from nodehistory import get_filefromglob
@@ -21,19 +20,19 @@ import time
 # up with good hardware & functional pcu
 
 #cm_url="http://summer.cs.princeton.edu/status/tabulator.cgi?table=table_nodeviewshort&format=formatcsv&dumpcols='name,cpuspeed,memsize,disksize'"
-#cm = soltesz.if_cached_else(1, "cmhardware", lambda : comon.comonget(cm_url))
+#cm = database.if_cached_else(1, "cmhardware", lambda : comon.comonget(cm_url))
 
 def gethardwarequality(nodename, fb):
-       if nodename in fb['nodes']:
+       if nodename in fb['nodes'] and 'comonstats' in fb['nodes'][nodename]['values']:
                cstat = fb['nodes'][nodename]['values']['comonstats']
                for field in ['cpuspeed', 'memsize', 'disksize']:
                        if field not in cstat: cstat[field] = "null"
 
-               if cstat['cpuspeed'] != "null" and float(cstat['cpuspeed']) < 2.4:
+               if cstat['cpuspeed'] != "null" and float(cstat['cpuspeed']) < 2.2:
                        return "BAD" # "cpu_slow",
-               if cstat['memsize'] != "null" and float(cstat['memsize']) < 2.9:
+               if cstat['memsize'] != "null" and float(cstat['memsize']) < 2.8:
                        return "BAD" # "mem_small",
-               if cstat['disksize'] != "null" and float(cstat['disksize']) < 320.0:
+               if cstat['disksize'] != "null" and float(cstat['disksize']) < 250.0:
                        return "BAD" # "disk_small",
 
                if cstat['disksize'] == "null" and \
@@ -42,9 +41,9 @@ def gethardwarequality(nodename, fb):
                        return "N/A"
 
                try:
-                       if  float(cstat['cpuspeed']) >= 2.4 and \
-                               float(cstat['memsize']) >= 2.9 and \
-                               (cstat['disksize'] == "null" or float(cstat['disksize']) >= 320.0):
+                       if  float(cstat['cpuspeed']) >= 2.2 and \
+                               float(cstat['memsize']) >= 2.8 and \
+                               (cstat['disksize'] == "null" or float(cstat['disksize']) >= 250.0):
                                return "A-OK"
                except:
                        print cstat
@@ -72,7 +71,7 @@ def main():
 
        stats = {}
        path = "archive-pdb"
-       archive = soltesz.SPickle(path)
+       archive = database.SPickle(path)
 
        if len(sys.argv) > 2:
                timestr = sys.argv[1]
@@ -83,12 +82,12 @@ def main():
                begin = time.strftime(format)
 
        d = datetime_fromstr(begin)
-       fbstr = get_filefromglob(d, "production.findbad")
-       fbpcustr = get_filefromglob(d, "production.findbadpcus")
+       fbstr = get_filefromglob(d, "production.findbad")[0]
+       fbpcustr = get_filefromglob(d, "production.findbadpcus")[0]
 
-       l_plcnodes = soltesz.dbLoad("l_plcnodes")
-       l_plcsites = soltesz.dbLoad("l_plcsites")
-       lb2hn = soltesz.dbLoad("plcdb_lb2hn")
+       l_plcnodes = database.dbLoad("l_plcnodes")
+       l_plcsites = database.dbLoad("l_plcsites")
+       lb2hn = database.dbLoad("plcdb_lb2hn")
        fb = archive.load(fbstr) 
        fbpcu = archive.load(fbpcustr)
        reboot.fb = fbpcu
@@ -138,12 +137,20 @@ def main():
                                        CC=fields[-1]
 
                                if hostname in fb['nodes']:
+                                       if 'state' in fb['nodes'][hostname]['values']:
+                                               state = fb['nodes'][hostname]['values']['state'].lower()
+                                       else:
+                                               state = "unknown"
+
                                        args = {'cc': CC, 
                                                'site' : site['login_base'],
                                                'host' : hostname,
-                                               'status' : fb['nodes'][hostname]['values']['state'].lower(),
+                                               'status' : state,
                                                'hardware' : gethardwarequality(hostname, fb),
                                                'pcuok' : color_pcu_state(fb['nodes'][hostname]['values']) }
+                                       #except:
+                                       #       print args
+                                       #       print fb['nodes'][hostname]['values']
                                        results.append("%(cc)7s %(status)8s %(hardware)8s %(pcuok)8s %(site)15s %(host)42s " % args)
                                        addtostats(stats, args)
                else: