from monitor.database.info.model import *
import sys
-fbquery = HistoryNodeRecord.query.all()
-hostnames = [ n.hostname for n in fbquery ]
if True:
- for hn in hostnames:
- fbrec = FindbadNodeRecord.query.filter_by(hostname=hn).order_by(FindbadNodeRecord.version.desc()).first()
- if len(fbrec.versions) >= 2:
- if fbrec.version != fbrec.versions[-2].version + 1:
- print fbrec.hostname, fbrec.version, fbrec.versions[-2].version
- fbrec.version = fbrec.versions[-2].version + 1
- fbrec.flush()
-
- session.flush()
-
-fbquery = HistoryPCURecord.query.all()
-pcus = [ n.plc_pcuid for n in fbquery ]
-
-for pcuid in pcus:
- fbrec = FindbadPCURecord.query.filter_by(plc_pcuid=pcuid).order_by(FindbadPCURecord.version.desc()).first()
- if len(fbrec.versions) >= 2:
- if fbrec.version != fbrec.versions[-2].version + 1:
- print fbrec.plc_pcuid, fbrec.version, fbrec.versions[-2].version
- fbrec.version = fbrec.versions[-2].version + 1
- fbrec.flush()
+ fbquery = HistorySiteRecord.query.all()
+ loginbases = [ h.loginbase for h in fbquery ]
+
+ for lb in loginbases:
+ h = HistorySiteRecord.query.filter_by(loginbase=lb).first()
+ if len(h.versions) >= 2:
+ if h.version != h.versions[-2].version + 1:
+ print h.loginbase, h.version, h.versions[-2].version
+ h.version = h.versions[-2].version + 1
+ h.flush()
+
+ session.flush()
+
+
+
+if True:
+ fbquery = HistoryNodeRecord.query.all()
+ hostnames = [ n.hostname for n in fbquery ]
+
+ for hn in hostnames:
+ fbrec = FindbadNodeRecord.query.filter_by(hostname=hn).order_by(FindbadNodeRecord.version.desc()).first()
+ if len(fbrec.versions) >= 2:
+ if fbrec.version != fbrec.versions[-2].version + 1:
+ print fbrec.hostname, fbrec.version, fbrec.versions[-2].version
+ fbrec.version = fbrec.versions[-2].version + 1
+ fbrec.flush()
+
+ session.flush()
+
+
+if True:
+ fbquery = HistoryPCURecord.query.all()
+ pcus = [ n.plc_pcuid for n in fbquery ]
+
+ for pcuid in pcus:
+ fbrec = FindbadPCURecord.query.filter_by(plc_pcuid=pcuid).order_by(FindbadPCURecord.version.desc()).first()
+ if len(fbrec.versions) >= 2:
+ if fbrec.version != fbrec.versions[-2].version + 1:
+ print fbrec.plc_pcuid, fbrec.version, fbrec.versions[-2].version
+ fbrec.version = fbrec.versions[-2].version + 1
+ fbrec.flush()
session.flush()
def co_print_nodeinfo(co_nodeinfo, hostname, fields=None):
- # co_nodeinfo['bootstate'] : unknown pattern
co_nodeinfo['name'] = hostname
if 'uptime' in co_nodeinfo and co_nodeinfo['uptime'] != "null":
else:
format = ""
for f in fields:
- format += "%%(%s)s " % f
+ format += "%%(%s)s," % f
print format % co_nodeinfo
def main():
dns=False,
listkeys=False,
pcuselect=None,
+ cache=False,
nodelist=None,
daysdown=None,
fields=default_fields)
help="A list of nodes to bring out of debug mode.")
parser.add_option("", "--listkeys", dest="listkeys", action="store_true",
help="A list of nodes to bring out of debug mode.")
+ parser.add_option("", "--cache", dest="cache", action="store_true",
+ help="Specify whether the command should perform a live query or save/use a cached values.")
parser.add_option("", "--dns", dest="dns", action="store_true",
help="A convenience query for dns values")
parser = parsermodule.getParser(['defaults'], parser)
config = parsermodule.parse_args(parser)
- #if config.fromtime:
- # fb = None
- #else:
- # fb = None
-
# lastcotop measures whether cotop is actually running. this is a better
# metric than sshstatus, or other values from CoMon
cotop_url = COMON_COTOPURL + "&limit=1"
cotop = comon.Comon()
- cohash = cotop.coget(cotop_url)
+ if database.cachedRecently(cotop_url):
+ print >>sys.stderr, "loading cached query :%s" % cotop_url
+ cohash = database.dbLoad(cotop_url)
+ else:
+ cohash = cotop.coget(cotop_url)
+ if config.cache:
+ print >>sys.stderr, "saving query :%s" % cotop_url
+ database.dbDump(cotop_url, cohash)
if config.nodelist:
nodelist = file.getListFromFile(config.nodelist)
# NOTE: list of nodes should come from comon query.
nodelist = cohash.keys()
- print "%(name)-40s %(sshstatus)5.5s %(resptime)6.6s %(lastcotop)6.6s %(uptime)s" % {
- 'name' : 'hostname',
- 'sshstatus' : 'sshstatus',
- 'resptime' : 'resptime',
- 'lastcotop' : 'lastcotop',
- 'uptime' : 'uptime'}
+ fields = config.fields.split(",")
+ f_info = {}
+ for f in fields: f_info[f]=f
+ co_print_nodeinfo(f_info, "hostname", fields)
+
for node in nodelist:
config.node = node
co_nodeinfo = cohash[node]
if config.listkeys:
- print "Primary keys available in the comon object:"
+ print >>sys.stderr, "Primary keys available in the comon object:"
for key in co_nodeinfo.keys():
print "\t",key
sys.exit(0)