moved nodequery common code to monitor/query.py
authorStephen Soltesz <soltesz@cs.princeton.edu>
Fri, 4 Sep 2009 23:47:57 +0000 (23:47 +0000)
committerStephen Soltesz <soltesz@cs.princeton.edu>
Fri, 4 Sep 2009 23:47:57 +0000 (23:47 +0000)
updated all imports to use this module
added iptables_status check to findbad
  iptables_status check to scanapi
added iptables_status, fs_status, and uptime to advanced query form
added sortability to uptime check
added nodeselect to fetch.py
added logging of bm logs from bootman.py restore actions

20 files changed:
automate/fetch.py
cron.d/copy-logs.sh
findbad.py
monitor/bootman.py
monitor/common.py
monitor/database/info/findbad.py
monitor/query.py [new file with mode: 0644]
monitor/scanapi.py
nodebad.py
nodegroups.py
nodequery.py
pcubad.py
policy.py
showlatlon.py
sitebad.py
siteleave.py
statistics/parserpms.py
upgrade/monitor-server-3.0-20.sql
web/MonitorWeb/monitorweb/controllers.py
web/MonitorWeb/monitorweb/templates/query.kid

index 8d01986..35cb9da 100755 (executable)
@@ -7,6 +7,7 @@ from glob import glob
 
 import vxargs
 from monitor import parser as parsermodule
+from monitor import common
 from automate import *
 
 def build_vx_args(shell_cmd):
@@ -47,16 +48,17 @@ if __name__ == "__main__":
        if not os.path.exists(outdir):
                os.system('mkdir -p %s' % outdir)
 
-       if config.site is not None or \
-          config.nodeselect is not None or \
-          config.nodegroup is not None:
-               print "TODO: implement support for nodeselect and site queries."
-               print "%s %s %s" % (config.site, config.nodeselect, config.nodegroup)
-               sys.exit(1)
+       #if config.site is not None or \
+       #   config.nodeselect is not None or \
+       #   config.nodegroup is not None:
+       #       print "TODO: implement support for nodeselect and site queries."
+       #       print "%s %s %s" % (config.site, config.nodeselect, config.nodegroup)
+       #       sys.exit(1)
 
-       if config.nodelist == None and config.node == None:
-               filelist="nocomon.txt"
-               filelist = vxargs.getListFromFile(open(filelist,'r'))
+       nodelist = common.get_nodeset(config)
+
+       if len(nodelist) > 0:
+               filelist = [ (x, '') for x in nodelist ]
        elif os.path.exists(str(config.nodelist)) and os.path.isfile(config.nodelist):
                filelist = vxargs.getListFromFile(open(config.nodelist,'r'))
        elif os.path.exists(str(config.nodelist)) and os.path.isdir(config.nodelist):
index 634d873..61754b5 100755 (executable)
@@ -14,3 +14,4 @@ rsync -qv -az -e ssh root@amber.cs.princeton.edu:/vservers/db-current/var/log/*-
 
 rsync -qv -az -e ssh root@janine.cs.princeton.edu:/vservers/boot-current/var/log/*-filesystem* /var/lib/monitor/filesystem
 rsync -qv -az -e ssh root@janine.cs.princeton.edu:/vservers/boot-current/var/log/*-checkrpm* /var/lib/monitor/checkrpm
+rsync -qv -az -e ssh root@janine.cs.princeton.edu:/vservers/boot-current/var/log/bm/ /var/lib/monitor/bmlogs/
index 7ae4b13..b76df4c 100755 (executable)
@@ -18,7 +18,7 @@ from monitor.sources import comon
 from monitor.wrapper import plc, plccache
 from monitor.scanapi import *
 
-from nodequery import verify,query_to_dict,node_select
+from monitor.query import verify,query_to_dict,node_select
 import traceback
 from monitor.common import nmap_port_status
 
index 25bd9f4..3ebeafe 100755 (executable)
@@ -57,7 +57,6 @@ def bootmanager_log_action(hostname, short_log_path, logtype="bm.log"):
                                                action_type=logtype,
                                                log_path=short_log_path,
                                                error_string=err)
-       session.flush(); session.clear()
        return
        
 
@@ -97,25 +96,12 @@ class NodeConnection:
        def get_bootmanager_log(self):
                bm_name = bootmanager_log_name(self.node)
                download(self.c, "/tmp/bm.log", "%s/%s" % (config.MONITOR_BOOTMANAGER_LOG, bm_name))
+               #email_exception(self.node, "collected BM log for %s" % self.node)
                bootmanager_log_action(self.node, bm_name, "collected_bm.log")
                os.system("cp %s/%s %s/bm.%s.log" % (config.MONITOR_BOOTMANAGER_LOG, bm_name, config.MONITOR_BOOTMANAGER_LOG, self.node))
                log = open("%s/bm.%s.log" % (config.MONITOR_BOOTMANAGER_LOG, self.node), 'r')
                return log
 
-
-#      def get_dmesg(self):
-#              self.c.modules.os.system("dmesg > /var/log/dmesg.bm.log")
-#              download(self.c, "/var/log/dmesg.bm.log", "log/dmesg.%s.log" % self.node)
-#              log = open("log/dmesg.%s.log" % self.node, 'r')
-#              return log
-#
-#      def get_bootmanager_log(self):
-#              download(self.c, "/tmp/bm.log", "log/bm.%s.log.gz" % self.node)
-#              #os.system("zcat log/bm.%s.log.gz > log/bm.%s.log" % (self.node, self.node))
-#              os.system("cp log/bm.%s.log.gz log/bm.%s.log" % (self.node, self.node))
-#              log = open("log/bm.%s.log" % self.node, 'r')
-#              return log
-
        def dump_plconf_file(self):
                c = self.c
                self.c.modules.sys.path.append("/tmp/source/")
@@ -802,6 +788,8 @@ def restore_basic(sitehist, hostname, config=None, forced_action=None):
 
        print "...Downloading bm.log from %s" %hostname 
        log = conn.get_bootmanager_log()
+       bm_log_data = log.read() # get data
+       log.seek(0)     # reset fd pointer for fdspawn
        child = fdpexpect.fdspawn(log)
 
        if hasattr(config, 'collect') and config.collect: return "collect"
@@ -831,7 +819,7 @@ def restore_basic(sitehist, hostname, config=None, forced_action=None):
                args = {}
                args['hostname'] = hostname
                args['sequence'] = s
-               args['bmlog'] = conn.get_bootmanager_log().read()
+               args['bmlog'] = bm_log_data
                args['viart'] = False
                args['saveact'] = True
                args['ccemail'] = True
@@ -882,7 +870,7 @@ def restore_basic(sitehist, hostname, config=None, forced_action=None):
                        args = {}
                        args['hostname'] = hostname
                        args['sequence'] = s
-                       args['bmlog'] = conn.get_bootmanager_log().read()
+                       args['bmlog'] = bm_log_data
                        args['viart'] = False
                        args['saveact'] = True
                        args['ccemail'] = True
@@ -906,7 +894,7 @@ def restore_basic(sitehist, hostname, config=None, forced_action=None):
                        if not found_within(recent_actions, 'nodeconfig_notice', 3.5):
                                args = {}
                                args['hostname'] = hostname
-                               args['bmlog'] = conn.get_bootmanager_log().read()
+                               args['bmlog'] = bm_log_data
                                sitehist.sendMessage('nodeconfig_notice', **args)
                                conn.dump_plconf_file()
                        else:
@@ -947,7 +935,7 @@ def restore_basic(sitehist, hostname, config=None, forced_action=None):
                                print "...NOTIFYING OWNERS OF MINIMAL HARDWARE FAILURE on %s!!!" % hostname
                                args = {}
                                args['hostname'] = hostname
-                               args['bmlog'] = conn.get_bootmanager_log().read()
+                               args['bmlog'] = bm_log_data
                                sitehist.sendMessage('minimalhardware_notice', **args)
                        else:
                                # NOTE: do not add a new action record
index 75f76e4..c3ece6f 100644 (file)
@@ -3,6 +3,7 @@ import time
 import struct
 from monitor import reboot
 from monitor import util
+from monitor import query
 from monitor.wrapper import plc
 
 from datetime import datetime, timedelta
@@ -208,9 +209,9 @@ def get_nodeset(config):
        # perform this query after the above options, so that the filter above
        # does not break.
        if config.nodeselect:
-               fbquery = FindbadNodeRecord.get_all_latest()
+               fbquery = HistoryNodeRecord.query.all()
                node_list = [ n.hostname for n in fbquery ]
-               l_nodes = node_select(config.nodeselect, node_list, None)
+               l_nodes = query.node_select(config.nodeselect, node_list, None)
 
        return l_nodes
 
index 615e03f..2f9251e 100644 (file)
@@ -40,6 +40,7 @@ class FindbadNodeRecord(Entity):
        bootcd_version = Field(String,default=None)
        nm_status = Field(String,default=None)
        fs_status = Field(String,default=None)
+       iptables_status = Field(String,default=None)
        dns_status = Field(String,default=None)
        external_dns_status = Field(Boolean,default=True)
        uptime = Field(String,default=None)     
diff --git a/monitor/query.py b/monitor/query.py
new file mode 100644 (file)
index 0000000..53a361e
--- /dev/null
@@ -0,0 +1,296 @@
+#!/usr/bin/python
+
+import os
+import re
+import sys
+import glob
+import time
+import string
+import traceback
+
+from monitor.common import *
+from monitor.database.info.model import FindbadNodeRecord, FindbadPCURecord
+
+class NoKeyException(Exception): pass
+
+def first(path):
+       indexes = path.split(".")
+       return indexes[0]
+       
+def get(fb, path):
+    indexes = path.split(".")
+    values = fb
+    for index in indexes:
+               if values and index in values:
+                       values = values[index]
+               elif values == {}:
+                       values = ""
+               else:
+                       print values, index
+                       raise NoKeyException(index)
+    return values
+
+def verifyType(constraints, data):
+       """
+               constraints is a list of key, value pairs.
+               # [ {... : ...}==AND , ... , ... , ] == OR
+       """
+       con_or_true = False
+       for con in constraints:
+               #print "con: %s" % con
+               if len(con.keys()) == 0:
+                       con_and_true = False
+               else:
+                       con_and_true = True
+
+               for key in con.keys():
+                       #print "looking at key: %s" % key
+                       if data is None:
+                               con_and_true = False
+                               break
+
+                       try:
+                               get(data,key)
+                               o = con[key]
+                               if o.name() == "Match":
+                                       if get(data,key) is not None:
+                                               value_re = re.compile(o.value)
+                                               con_and_true = con_and_true & (value_re.search(get(data,key)) is not None)
+                                       else:
+                                               con_and_true = False
+                               elif o.name() == "ListMatch":
+                                       if get(data,key) is not None:
+                                               match = False
+                                               for listitem in get(data,key):
+                                                       value_re = re.compile(o.value)
+                                                       if value_re.search(listitem) is not None:
+                                                               match = True
+                                                               break
+                                               con_and_true = con_and_true & match
+                                       else:
+                                               con_and_true = False
+                               elif o.name() == "Is":
+                                       con_and_true = con_and_true & (get(data,key) == o.value)
+                               elif o.name() == "FilledIn":
+                                       con_and_true = con_and_true & (len(get(data,key)) > 0)
+                               elif o.name() == "PortOpen":
+                                       if get(data,key) is not None:
+                                               v = get(data,key)
+                                               con_and_true = con_and_true & (v[str(o.value)] == "open")
+                                       else:
+                                               con_and_true = False
+                               else:
+                                       value_re = re.compile(o.value)
+                                       con_and_true = con_and_true & (value_re.search(get(data,key)) is not None)
+
+                       except NoKeyException, key:
+                               print "missing key %s" % key,
+                               pass
+                               #print "missing key %s" % key
+                               #con_and_true = False
+
+               con_or_true = con_or_true | con_and_true
+
+       return con_or_true
+
+def verifyDBrecord(constraints, record):
+       """
+               constraints is a list of key, value pairs.
+               # [ {... : ...}==AND , ... , ... , ] == OR
+       """
+       def has_key(obj, key):
+               try:
+                       x = obj.__getattribute__(key)
+                       return True
+               except:
+                       return False
+
+       def get_val(obj, key):
+               try:
+                       return obj.__getattribute__(key)
+               except:
+                       return None
+
+       def get(obj, path):
+               indexes = path.split("/")
+               value = get_val(obj,indexes[0])
+               if value is not None and len(indexes) > 1:
+                       for key in indexes[1:]:
+                               if key in value:
+                                       value = value[key]
+                               else:
+                                       raise NoKeyException(key)
+               return value
+
+       #print constraints, record
+
+       con_or_true = False
+       for con in constraints:
+               #print "con: %s" % con
+               if len(con.keys()) == 0:
+                       con_and_true = False
+               else:
+                       con_and_true = True
+
+               for key in con.keys():
+                       #print "looking at key: %s" % key
+                       if has_key(record, key):
+                               value_re = re.compile(con[key])
+                               if type([]) == type(get(record,key)):
+                                       local_or_true = False
+                                       for val in get(record,key):
+                                               local_or_true = local_or_true | (value_re.search(val) is not None)
+                                       con_and_true = con_and_true & local_or_true
+                               else:
+                                       if get(record,key) is not None:
+                                               con_and_true = con_and_true & (value_re.search(get(record,key)) is not None)
+                       else:
+                               print "missing key %s" % key,
+                               pass
+
+               con_or_true = con_or_true | con_and_true
+
+       return con_or_true
+
+def verify(constraints, data):
+       """
+               constraints is a list of key, value pairs.
+               # [ {... : ...}==AND , ... , ... , ] == OR
+       """
+       con_or_true = False
+       for con in constraints:
+               #print "con: %s" % con
+               if len(con.keys()) == 0:
+                       con_and_true = False
+               else:
+                       con_and_true = True
+
+               for key in con.keys():
+                       #print "looking at key: %s" % key
+                       if first(key) in data: 
+                               value_re = re.compile(con[key])
+                               if type([]) == type(get(data,key)):
+                                       local_or_true = False
+                                       for val in get(data,key):
+                                               local_or_true = local_or_true | (value_re.search(val) is not None)
+                                       con_and_true = con_and_true & local_or_true
+                               else:
+                                       if get(data,key) is not None:
+                                               con_and_true = con_and_true & (value_re.search(get(data,key)) is not None)
+                       elif first(key) not in data:
+                               print "missing key %s" % first(key)
+
+               con_or_true = con_or_true | con_and_true
+
+       return con_or_true
+
+def query_to_dict(query):
+       
+       ad = []
+
+       or_queries = query.split('||')
+       for or_query in or_queries:
+               and_queries = or_query.split('&&')
+
+               d = {}
+
+               for and_query in and_queries:
+                       (key, value) = and_query.split('=')
+                       d[key] = value
+
+               ad.append(d)
+       
+       return ad
+
+def pcu_in(fbdata):
+       #if 'plcnode' in fbdata:
+       if 'plc_node_stats' in fbdata:
+               if fbdata['plc_node_stats'] and 'pcu_ids' in fbdata['plc_node_stats']:
+                       if len(fbdata['plc_node_stats']['pcu_ids']) > 0:
+                               return True
+       return False
+
+def pcu_select(str_query, nodelist=None):
+       pcunames = []
+       nodenames = []
+       if str_query is None: return (nodenames, pcunames)
+
+       if True:
+               fbquery = FindbadNodeRecord.get_all_latest()
+               fb_nodelist = [ n.hostname for n in fbquery ]
+       if True:
+               # NOTE: this doesn't work when there are only a few records current.
+               # pcu_select should apply to all pcus globally, not just the most recent records.
+               fbpcuquery = FindbadPCURecord.get_all_latest()
+               fbpcu_list = [ p.plc_pcuid for p in fbpcuquery ]
+
+       dict_query = query_to_dict(str_query)
+       print "dict_query", dict_query
+       print 'length %s' % len(fbpcuquery)
+
+       #for pcurec in fbpcuquery:
+       #       pcuinfo = pcurec.to_dict()
+       #       if verify(dict_query, pcuinfo):
+       #               #nodenames.append(noderec.hostname)
+       #               #print 'appending %s' % pcuinfo['plc_pcuid']
+       #               pcunames.append(pcuinfo['plc_pcuid'])
+
+       for noderec in fbquery:
+               if nodelist is not None: 
+                       if noderec.hostname not in nodelist: continue
+       
+               fb_nodeinfo  = noderec.to_dict()
+               if pcu_in(fb_nodeinfo):
+                       pcu_id = get(fb_nodeinfo, 'plc_node_stats.pcu_ids')[0]
+                       pcurec = FindbadPCURecord.get_by(plc_pcuid=pcu_id)
+
+                       if pcurec:
+                               pcuinfo = pcurec.to_dict()
+                               if verify(dict_query, pcuinfo):
+                                       nodenames.append(noderec.hostname)
+                                       pcunames.append(pcuinfo['plc_pcuid'])
+
+       return (nodenames, pcunames)
+
+def node_select(str_query, nodelist=None, fb=None):
+
+       hostnames = []
+       if str_query is None: return hostnames
+
+       #print str_query
+       dict_query = query_to_dict(str_query)
+       #print dict_query
+
+       for node in nodelist:
+               #if nodelist is not None: 
+               #       if node not in nodelist: continue
+
+               try:
+                       fb_noderec = None
+                       #fb_noderec = FindbadNodeRecord.query.filter(FindbadNodeRecord.hostname==node).order_by(FindbadNodeRecord.date_checked.desc()).first()
+                       fb_noderec = FindbadNodeRecord.get_latest_by(hostname=node)
+               except KeyboardInterrupt:
+                       print "Exiting at user request: Ctrl-C"
+                       sys.exit(1)
+               except:
+                       print traceback.print_exc()
+                       continue
+
+               if fb_noderec:
+                       fb_nodeinfo = fb_noderec.to_dict()
+
+                       #fb_nodeinfo['pcu'] = color_pcu_state(fb_nodeinfo)
+                       #if 'plcnode' in fb_nodeinfo:
+                       #       fb_nodeinfo.update(fb_nodeinfo['plcnode'])
+
+                       if verify(dict_query, fb_nodeinfo):
+                               #print fb_nodeinfo.keys()
+                               #print node #fb_nodeinfo
+                               hostnames.append(node)
+                       else:
+                               #print "NO MATCH", node
+                               pass
+       
+       return hostnames
+
+
index 454bcd5..119f7fd 100644 (file)
@@ -239,6 +239,7 @@ class ScanNodeInternal(ScanInterface):
                                        echo '  "bootcd_version":"'`cat /mnt/cdrom/bootme/ID`'",'
                                        echo '  "nm_status":"'`ps ax | grep nm.py | grep -v grep`'",'
                                        echo '  "dns_status":"'`host boot.planet-lab.org 2>&1`'",'
+                                       echo '  "iptables_status":"'`iptables -t mangle -nL | awk '$1~/^[A-Z]+$/ {modules[$1]=1;}END{for (k in modules) {if (k) printf "%s ",k;}}'`'",'
                                        echo '  "princeton_comon_dir":"'`ls -d /vservers/princeton_comon`'",'
                                        echo '  "uptime":"'`cat /proc/uptime`'",'
 
index e7fc819..dc86664 100755 (executable)
@@ -6,7 +6,7 @@ import string
 import time
 from datetime import datetime,timedelta
 
-from nodequery import verify,query_to_dict,node_select
+from monitor.query import verify,query_to_dict,node_select
 
 from monitor.common import *
 
index 999902f..dee3cec 100755 (executable)
@@ -21,7 +21,7 @@ from monitor import parser as parsermodule
 
 api = plc.getAuthAPI()
 
-from nodequery import verify,query_to_dict,node_select
+from monitor.query import verify,query_to_dict,node_select
 from monitor.common import *
 from sets import Set
 
index 2fe0e4a..c78d6b4 100755 (executable)
@@ -4,6 +4,7 @@
 import sys
 from monitor import database
 from monitor.common import *
+from monitor.query import *
 from monitor.model import Record
 import glob
 import os
@@ -21,8 +22,6 @@ from monitor.util import file as utilfile
 from monitor import config
 
 
-class NoKeyException(Exception): pass
-
 def daysdown_print_nodeinfo(fbnode, hostname):
        fbnode['hostname'] = hostname
        fbnode['daysdown'] = Record.getStrDaysDown(fbnode)
@@ -66,282 +65,6 @@ def fb_print_nodeinfo(fbnode, hostname, fields=None):
                        format += "%%(%s)s " % f
                print format % fbnode
 
-def first(path):
-       indexes = path.split(".")
-       return indexes[0]
-       
-def get(fb, path):
-    indexes = path.split(".")
-    values = fb
-    for index in indexes:
-               if values and index in values:
-                       values = values[index]
-               else:
-                       raise NoKeyException(index)
-    return values
-
-def verifyType(constraints, data):
-       """
-               constraints is a list of key, value pairs.
-               # [ {... : ...}==AND , ... , ... , ] == OR
-       """
-       con_or_true = False
-       for con in constraints:
-               #print "con: %s" % con
-               if len(con.keys()) == 0:
-                       con_and_true = False
-               else:
-                       con_and_true = True
-
-               for key in con.keys():
-                       #print "looking at key: %s" % key
-                       if data is None:
-                               con_and_true = False
-                               break
-
-                       try:
-                               get(data,key)
-                               o = con[key]
-                               if o.name() == "Match":
-                                       if get(data,key) is not None:
-                                               value_re = re.compile(o.value)
-                                               con_and_true = con_and_true & (value_re.search(get(data,key)) is not None)
-                                       else:
-                                               con_and_true = False
-                               elif o.name() == "ListMatch":
-                                       if get(data,key) is not None:
-                                               match = False
-                                               for listitem in get(data,key):
-                                                       value_re = re.compile(o.value)
-                                                       if value_re.search(listitem) is not None:
-                                                               match = True
-                                                               break
-                                               con_and_true = con_and_true & match
-                                       else:
-                                               con_and_true = False
-                               elif o.name() == "Is":
-                                       con_and_true = con_and_true & (get(data,key) == o.value)
-                               elif o.name() == "FilledIn":
-                                       con_and_true = con_and_true & (len(get(data,key)) > 0)
-                               elif o.name() == "PortOpen":
-                                       if get(data,key) is not None:
-                                               v = get(data,key)
-                                               con_and_true = con_and_true & (v[str(o.value)] == "open")
-                                       else:
-                                               con_and_true = False
-                               else:
-                                       value_re = re.compile(o.value)
-                                       con_and_true = con_and_true & (value_re.search(get(data,key)) is not None)
-
-                       except NoKeyException, key:
-                               print "missing key %s" % key,
-                               pass
-                               #print "missing key %s" % key
-                               #con_and_true = False
-
-               con_or_true = con_or_true | con_and_true
-
-       return con_or_true
-
-def verifyDBrecord(constraints, record):
-       """
-               constraints is a list of key, value pairs.
-               # [ {... : ...}==AND , ... , ... , ] == OR
-       """
-       def has_key(obj, key):
-               try:
-                       x = obj.__getattribute__(key)
-                       return True
-               except:
-                       return False
-
-       def get_val(obj, key):
-               try:
-                       return obj.__getattribute__(key)
-               except:
-                       return None
-
-       def get(obj, path):
-               indexes = path.split("/")
-               value = get_val(obj,indexes[0])
-               if value is not None and len(indexes) > 1:
-                       for key in indexes[1:]:
-                               if key in value:
-                                       value = value[key]
-                               else:
-                                       raise NoKeyException(key)
-               return value
-
-       #print constraints, record
-
-       con_or_true = False
-       for con in constraints:
-               #print "con: %s" % con
-               if len(con.keys()) == 0:
-                       con_and_true = False
-               else:
-                       con_and_true = True
-
-               for key in con.keys():
-                       #print "looking at key: %s" % key
-                       if has_key(record, key):
-                               value_re = re.compile(con[key])
-                               if type([]) == type(get(record,key)):
-                                       local_or_true = False
-                                       for val in get(record,key):
-                                               local_or_true = local_or_true | (value_re.search(val) is not None)
-                                       con_and_true = con_and_true & local_or_true
-                               else:
-                                       if get(record,key) is not None:
-                                               con_and_true = con_and_true & (value_re.search(get(record,key)) is not None)
-                       else:
-                               print "missing key %s" % key,
-                               pass
-
-               con_or_true = con_or_true | con_and_true
-
-       return con_or_true
-
-def verify(constraints, data):
-       """
-               constraints is a list of key, value pairs.
-               # [ {... : ...}==AND , ... , ... , ] == OR
-       """
-       con_or_true = False
-       for con in constraints:
-               #print "con: %s" % con
-               if len(con.keys()) == 0:
-                       con_and_true = False
-               else:
-                       con_and_true = True
-
-               for key in con.keys():
-                       #print "looking at key: %s" % key
-                       if first(key) in data: 
-                               value_re = re.compile(con[key])
-                               if type([]) == type(get(data,key)):
-                                       local_or_true = False
-                                       for val in get(data,key):
-                                               local_or_true = local_or_true | (value_re.search(val) is not None)
-                                       con_and_true = con_and_true & local_or_true
-                               else:
-                                       if get(data,key) is not None:
-                                               con_and_true = con_and_true & (value_re.search(get(data,key)) is not None)
-                       elif first(key) not in data:
-                               print "missing key %s" % first(key)
-
-               con_or_true = con_or_true | con_and_true
-
-       return con_or_true
-
-def query_to_dict(query):
-       
-       ad = []
-
-       or_queries = query.split('||')
-       for or_query in or_queries:
-               and_queries = or_query.split('&&')
-
-               d = {}
-
-               for and_query in and_queries:
-                       (key, value) = and_query.split('=')
-                       d[key] = value
-
-               ad.append(d)
-       
-       return ad
-
-def pcu_in(fbdata):
-       #if 'plcnode' in fbdata:
-       if 'plc_node_stats' in fbdata:
-               if fbdata['plc_node_stats'] and 'pcu_ids' in fbdata['plc_node_stats']:
-                       if len(fbdata['plc_node_stats']['pcu_ids']) > 0:
-                               return True
-       return False
-
-def pcu_select(str_query, nodelist=None):
-       pcunames = []
-       nodenames = []
-       if str_query is None: return (nodenames, pcunames)
-
-       if True:
-               fbquery = FindbadNodeRecord.get_all_latest()
-               fb_nodelist = [ n.hostname for n in fbquery ]
-       if True:
-               # NOTE: this doesn't work when there are only a few records current.
-               # pcu_select should apply to all pcus globally, not just the most recent records.
-               fbpcuquery = FindbadPCURecord.get_all_latest()
-               fbpcu_list = [ p.plc_pcuid for p in fbpcuquery ]
-
-       dict_query = query_to_dict(str_query)
-       print "dict_query", dict_query
-       print 'length %s' % len(fbpcuquery.all())
-
-       for pcurec in fbpcuquery:
-               pcuinfo = pcurec.to_dict()
-               if verify(dict_query, pcuinfo):
-                       #nodenames.append(noderec.hostname)
-                       #print 'appending %s' % pcuinfo['plc_pcuid']
-                       pcunames.append(pcuinfo['plc_pcuid'])
-
-       #for noderec in fbquery:
-       #       if nodelist is not None: 
-       #               if noderec.hostname not in nodelist: continue
-#      
-#              fb_nodeinfo  = noderec.to_dict()
-#              if pcu_in(fb_nodeinfo):
-#                      pcurec = FindbadPCURecord.get_latest_by(plc_pcuid=get(fb_nodeinfo, 
-#                                                                                                      'plc_node_stats.pcu_ids')[0]).first()
-#                      if pcurec:
-#                              pcuinfo = pcurec.to_dict()
-#                              if verify(dict_query, pcuinfo):
-#                                      nodenames.append(noderec.hostname)
-#                                      pcunames.append(pcuinfo['plc_pcuid'])
-       return (nodenames, pcunames)
-
-def node_select(str_query, nodelist=None, fb=None):
-
-       hostnames = []
-       if str_query is None: return hostnames
-
-       #print str_query
-       dict_query = query_to_dict(str_query)
-       #print dict_query
-
-       for node in nodelist:
-               #if nodelist is not None: 
-               #       if node not in nodelist: continue
-
-               try:
-                       fb_noderec = None
-                       #fb_noderec = FindbadNodeRecord.query.filter(FindbadNodeRecord.hostname==node).order_by(FindbadNodeRecord.date_checked.desc()).first()
-                       fb_noderec = FindbadNodeRecord.get_latest_by(hostname=node)
-               except KeyboardInterrupt:
-                       print "Exiting at user request: Ctrl-C"
-                       sys.exit(1)
-               except:
-                       print traceback.print_exc()
-                       continue
-
-               if fb_noderec:
-                       fb_nodeinfo = fb_noderec.to_dict()
-
-                       #fb_nodeinfo['pcu'] = color_pcu_state(fb_nodeinfo)
-                       #if 'plcnode' in fb_nodeinfo:
-                       #       fb_nodeinfo.update(fb_nodeinfo['plcnode'])
-
-                       if verify(dict_query, fb_nodeinfo):
-                               #print fb_nodeinfo.keys()
-                               #print node #fb_nodeinfo
-                               hostnames.append(node)
-                       else:
-                               #print "NO MATCH", node
-                               pass
-       
-       return hostnames
-
-
 def main():
 
        from monitor import parser as parsermodule
@@ -399,18 +122,17 @@ def main():
        elif config.select is not None:
                nodelist = node_select(config.select, nodelist, fb)
        elif config.pcuselect is not None:
+               print "thirhd node select"
                nodelist, pculist = pcu_select(config.pcuselect, nodelist)
 
-       if pculist:
-               for pcu in pculist:
-                       print pcu
+       #if pculist:
+       #       for pcu in pculist:
+       #               print pcu
 
+       print "len: %s" % len(nodelist)
        for node in nodelist:
                config.node = node
 
-               if node not in nodelist:
-                       continue
-
                try:
                        # Find the most recent record
                        fb_noderec = FindbadNodeRecord.get_latest_by(hostname=node) 
@@ -443,9 +165,10 @@ def main():
                                                fields = None
 
                                        fb_print_nodeinfo(fb_nodeinfo, node, fields)
-                               elif not config.select and 'state' in fb_nodeinfo:
+                               elif not config.select and 'observed_status' in fb_nodeinfo:
                                        fb_print_nodeinfo(fb_nodeinfo, node)
                                else:
+                                       print "passing..."
                                        pass
                
 if __name__ == "__main__":
index 33a25be..085389f 100755 (executable)
--- a/pcubad.py
+++ b/pcubad.py
@@ -17,7 +17,7 @@ from monitor.wrapper import plc,plccache
 from monitor.const import MINUP
 
 from monitor.common import *
-from nodequery import verify,query_to_dict,node_select
+from monitor.query import verify,query_to_dict,node_select
 from monitor.model import *
 
 api = plc.getAuthAPI()
index d3af8e5..54ac80e 100755 (executable)
--- a/policy.py
+++ b/policy.py
@@ -27,7 +27,7 @@ from monitor.wrapper import plccache
 from monitor.database.info.model import *
 from monitor.database.info.interface import *
 
-from nodequery import verify,query_to_dict,node_select
+from monitor.query import verify,query_to_dict,node_select
 
 api = plc.getAuthAPI()
 
index 2176462..31fbeb1 100755 (executable)
@@ -4,10 +4,10 @@ from monitor.wrapper import plc, plccache
 api = plc.getAuthAPI()
 
 import sys
-import reboot
+#import reboot
 from datetime import datetime, timedelta
 
-import database
+from monitor.database.info.model import *
 import comon
 from monitor.common import color_pcu_state, datetime_fromstr, email_exception
 from nodehistory import get_filefromglob
index df4e522..1261bcc 100755 (executable)
@@ -14,7 +14,7 @@ from monitor.wrapper import plc, plccache
 from monitor.const import MINUP
 
 from monitor.common import *
-from nodequery import verify,query_to_dict,node_select
+from monitor.query import verify,query_to_dict,node_select
 from monitor.model import *
 
 api = plc.getAuthAPI()
index 31e68d2..e38f4d2 100755 (executable)
@@ -24,8 +24,9 @@ for loginbase in sys.argv[1:]:
                        name = "%s %s %s (%s)" % (person['title'], person['first_name'], person['last_name'], person['email'])
 
        if not name:
-               print "no pis at %s" % loginbase
-               sys.exit(1)
+               print "no PIs at %s" % loginbase
+               name = "no PIs"
+               #sys.exit(1)
 
        date = time.strftime("%Y/%m/%d", time.gmtime(time.time()))
 
index 64144d7..54183c0 100755 (executable)
@@ -36,16 +36,16 @@ def main():
     parser.set_defaults( select=None,
                          input=None,
                          frequency=False,
-                         package=False,
+                         package=True,
                         )
 
     parser.add_option("", "--input", dest="input", 
                         help="the input file")
-    parser.add_option("", "--select", dest="select", 
+    parser.add_option("", "--pattern", dest="select", 
                         help="the pattern to pull out from rpm list")
     parser.add_option("", "--frequency", dest="frequency", action="store_true",
                         help="print the frequency of packages matched by select")
-    parser.add_option("", "--package", dest="package", action="store_true",
+    parser.add_option("", "--disablepackage", dest="package", action="store_false",
                         help="print the frequency of each pl package")
     (config, args) = parser.parse_args()
     if len(sys.argv) == 1 or config.input is None:
@@ -100,14 +100,18 @@ def main():
                 return_sums[sum]['diff'] = set(rpms) - set(current_packages) 
 
         if config.frequency:
-            print "Frequency for packages that matched: %s" % pattern
+            #print "Frequency for packages that matched: %s" % pattern
             sum_list = []
             for sum in return_sums:
                 sum_list.append((len(return_sums[sum]['hosts']), sum))
 
             sum_list.sort(lambda a,b: cmp(b[0], a[0]))
             for sum in sum_list:
-                print sum[0], sum[1], map(lambda x: x.replace('.planetlab', ''), return_sums[sum[1]]['diff'])
+                #print sum[0], sum[1], map(lambda x: x.replace('.planetlab', ''), return_sums[sum[1]]['diff'])
+                print sum[0], sum[1], len(map(lambda x: x.replace('.planetlab', ''), return_sums[sum[1]]['diff']))
 
 if __name__ == "__main__":
-    main()
+       try:
+               main()
+       except IOError:
+               pass
index 03b665e..2bb1c3f 100644 (file)
@@ -1,3 +1,6 @@
 -- If there's an existing database, these commands will upgrade it to the
 -- current version
 ALTER TABLE actionrecord ADD COLUMN log_path varchar DEFAULT NULL;
+
+ALTER TABLE findbadnoderecord ADD COLUMN iptables_status varchar DEFAULT NULL;
+ALTER TABLE findbadnoderecord_history ADD COLUMN iptables_status varchar DEFAULT NULL;
index be51959..c46dc42 100644 (file)
@@ -41,9 +41,11 @@ class NodeQueryFields(widgets.WidgetsList):
 
        hostname = widgets.CheckBox(label="Hostname")
        firewall = widgets.CheckBox(label="Firewall?")
+       fs_status = widgets.CheckBox(label="Filesystem Status")
        ssh_status = widgets.CheckBox(label="SSH Status")
        ssh_error = widgets.CheckBox(label="SSH Errors")
        dns_status = widgets.CheckBox(label="DNS Status")
+       iptables_status = widgets.CheckBox(label="IP Tables Status")
        nm_status = widgets.CheckBox(label="NM Status")
        princeton_comon_dir = widgets.CheckBox(label="CoMon Dir")
        princeton_comon_running = widgets.CheckBox(label="CoMon Running")
@@ -52,6 +54,7 @@ class NodeQueryFields(widgets.WidgetsList):
        kernel_version = widgets.CheckBox(label="Kernel")
        bootcd_version = widgets.CheckBox(label="BootCD")
        observed_status = widgets.CheckBox(label="Observed Status")
+       uptime = widgets.CheckBox(label="Uptime")
        port_status = widgets.CheckBox(label="Port Status")
        rpms = widgets.CheckBox(label="RPM")
        rpmvalue = widgets.TextField(label="RPM Pattern")
@@ -875,6 +878,7 @@ class Root(controllers.RootController, MonitorXmlrpcServer):
                print "write data: %s" % abs_target_filename
                util.file.dumpFile(abs_target_filename, log.file.read())
                bootman.bootmanager_log_action(hostname, short_target_filename, logtype)
+               session.flush()
 
                print "redirecting 3"
 
index c44202a..55bcd30 100644 (file)
@@ -46,7 +46,12 @@ from links import *
                <!-- for keys show each th -->
                <tr>
                        <span py:for="key in sorted(fields.keys())" >
-                               <th class="sortable plekit_table">${key}</th>
+                               <span py:if="key == 'uptime'">
+                                       <th class="sortable-numeric plekit_table">${key}</th>
+                               </span>
+                               <span py:if="key != 'uptime'">
+                                       <th class="sortable plekit_table">${key}</th>
+                               </span>
                        </span>
                </tr>
        </thead>