📄 statussections.py
字号:
optionsList.append((cat.catid,cat.catid,False)) filterSelects.append((controlBaseName + '_' + 'catid',optionsList)) # Alerttype #filterSelects.append((controlBaseName + '_' + 'type',\ #[(FILTER_ALL_SELECTED,'All',True), # ('exceededThreshold','exceededThreshold',False),\ # ('belowThreshold','belowThreshold',False)])) return (filterHeadings,filterSelects) getFilters = staticmethod(getFilters)#### History sections##class NetboxHistoryBox(SectionBox): " Section showing the history of netboxes that have been down or in shadow " defaultSort = 2 sortBy = defaultSort sortReverse = True def __init__(self,controlBaseName,getArgs,title,date,boxid=None): self.headings = [] self.rows = [] if boxid: # Don't show history icon when we're looking at one box self.headingDefs = [('Sysname',None), ('IP',self.ipCompare), ('From',None), ('To',None), ('Downtime',None), ('boxState',None)] else: self.headingDefs = [('Sysname',None), ('IP',self.ipCompare), ('From',None), ('To',None), ('Downtime',None), ('boxState',None), ('',None)] self.date = date self.boxid = boxid SectionBox.__init__(self,controlBaseName,title,getArgs,None) self.addHeadings() return def fill(self): sql = "SELECT netbox.sysname,netbox.ip," +\ "alerthist.start_time,alerthist.end_time," +\ "netbox.netboxid,alerttype.alerttype " +\ "FROM alerthist,netbox,alerttype WHERE " + \ "alerthist.netboxid=netbox.netboxid AND " +\ "alerthist.alerttypeid=alerttype.alerttypeid AND " +\ "alerthist.eventtypeid='boxState' AND " +\ "(alerttype.alerttype='boxDown' OR " +\ "alerttype.alerttype='boxUp' OR " +\ "alerttype.alerttype='boxShadow' OR " +\ "alerttype.alerttype='boxSunny') AND " +\ "date(start_time) = '%s' " %(self.date,) if self.boxid: sql += " AND alerthist.netboxid='%s'" % (self.boxid,) connection = nav.db.getConnection('status', 'manage') database = connection.cursor() database.execute(sql) result = database.fetchall() height = len(result) if self.maxHeight: if height > self.maxHeight: height = self.maxHeight SYSNAME = 0 IP = 1 FROM = 2 TO = 3 DOWNTIME = 4 BOXID = 5 ALERTTYPE = 6 for tmpline in result: # Must insert downtime if not tmpline[TO] or tmpline[TO]==INFINITY: downTime = mx.DateTime.now() - tmpline[FROM] else: downTime = tmpline[TO] - tmpline[FROM] line = list(tmpline[0:4]) + [downTime] + list(tmpline[4:6]) row = [] style = None #if (line[ALERTTYPE]=='boxShadow' or line[ALERTTYPE]=='boxSunny'): # style = 'shadow' # Sysname row.append((line[SYSNAME], urlbuilder.createUrl(id=line[BOXID],division='netbox'), None,style)) # IP row.append((line[IP],None,None,style)) # From row.append((line[FROM].strftime('%Y-%m-%d %H:%M'), None, None, style)) # To if not line[TO] or line[TO]==INFINITY: row.append(('Still down',None,None,style)) else: row.append((line[TO].strftime('%Y-%m-%d %H:%M'), None, None, style)) # Downtime downTime = str(line[DOWNTIME].absvalues()[0]) + ' d, ' + \ line[DOWNTIME].strftime('%H') + ' h, ' +\ line[DOWNTIME].strftime('%M') + ' min' row.append((downTime,None,None,style)) # boxState row.append((line[ALERTTYPE],None,None,style)) # History if not self.boxid: row.append((None, BASEPATH + 'history/?type=boxes&id=%s' \ % (line[BOXID],), ('/images/status/status-history.png', 'View history for thix box'), style)) self.rows.append([line[self.sortBy],row]) self.sort()class ServiceHistoryBox(SectionBox): " Section showing history for services " defaultSort = 2 sortBy = defaultSort sortReverse = True def __init__(self,controlBaseName,getArgs,title,date,serviceid=None): self.headings = [] self.rows = [] self.date = date self.serviceid = serviceid if serviceid: # Don't show history icon when we're looking at one box self.headingDefs = [('Sysname',None), ('Handler',None), ('From',None), ('To',None), ('Downtime',None)] else: self.headingDefs = [('Sysname',None), ('Handler',None), ('From',None), ('To',None), ('Downtime',None), ('',None)] SectionBox.__init__(self,controlBaseName,title,getArgs,None) self.addHeadings() return def fill(self): sql = "SELECT netbox.sysname,service.handler," +\ "alerthist.start_time,alerthist.end_time,netbox.netboxid,"+\ "alerttype.alerttype,service.serviceid FROM netbox,"+\ "service,alerthist LEFT JOIN alerttype using(alerttypeid) "+\ "WHERE alerthist.netboxid = netbox.netboxid AND "+\ "alerthist.subid=service.serviceid AND " +\ "alerthist.eventtypeid='serviceState' AND " +\ "date(start_time) = '%s' " %(self.date,) if self.serviceid: sql += " AND service.serviceid='%s'" % (self.serviceid,) connection = nav.db.getConnection('status', 'manage') database = connection.cursor() database.execute(sql) result = database.fetchall() height = len(result) if self.maxHeight: if height > self.maxHeight: height = self.maxHeight SYSNAME = 0 HANDLER = 1 FROM = 2 TO = 3 DOWNTIME = 4 BOXID = 5 ALERTTYPE = 6 SERVICEID = 7 for tmpline in result: # Must insert downtime if not tmpline[TO] or tmpline[TO]==INFINITY: downTime = mx.DateTime.now() - tmpline[FROM] else: downTime = tmpline[TO] - tmpline[FROM] line = list(tmpline[0:4]) + [downTime] + list(tmpline[4:7]) row = [] style = None #if (line[ALERTTYPE]=='boxShadow' or line[ALERTTYPE]=='boxSunny'): # style = 'shadow' # Sysname row.append((line[SYSNAME], urlbuilder.createUrl(id=line[BOXID],division='netbox'), None,style)) # Handler row.append((line[HANDLER],None,None,style)) # From row.append((line[FROM].strftime('%Y-%m-%d %H:%M'), None, None, style)) # To if not line[TO] or line[TO]==INFINITY: row.append(('Still down',None,None,style)) else: row.append((line[TO].strftime('%Y-%m-%d %H:%M'), None, None, style)) # Downtime downTime = str(line[DOWNTIME].absvalues()[0]) + ' d, ' + \ line[DOWNTIME].strftime('%H') + ' h, ' +\ line[DOWNTIME].strftime('%M') + ' min' row.append((downTime,None,None,style)) # History if not self.serviceid: row.append((None, BASEPATH + 'history/?type=services&id=%s' \ % (line[SERVICEID],), ('/images/status/status-history.png', 'View history for this service'), style)) self.rows.append([line[self.sortBy],row]) self.sort()class ModuleHistoryBox(SectionBox): " Section showing history for modules " defaultSort = 2 sortBy = defaultSort sortReverse = True def __init__(self,controlBaseName,getArgs,title,date,moduleid=None): self.headings = [] self.rows = [] self.date = date self.moduleid = moduleid if moduleid: # Don't show history icon when we're looking at one box self.headingDefs = [('Sysname',None), ('Module',None), ('From',None), ('To',None), ('Downtime',None)] else: self.headingDefs = [('Sysname',None), ('Module',None), ('From',None), ('To',None), ('Downtime',None), ('',None)] SectionBox.__init__(self,controlBaseName,title,getArgs,None) self.addHeadings() return def fill(self): sql = "SELECT netbox.sysname,module.module," +\ "alerthist.start_time,alerthist.end_time,netbox.netboxid,"+\ "alerttype.alerttype,module.moduleid FROM netbox,"+\ "module,alerthist LEFT JOIN alerttype using(alerttypeid) "+\ "WHERE alerthist.netboxid = netbox.netboxid AND "+\ "alerthist.subid=module.moduleid AND " +\ "alerthist.eventtypeid='moduleState' AND " +\ "(alerttype.alerttype='moduleDown' OR " +\ "alerttype.alerttype='moduleUp') AND " +\ "date(start_time) = '%s' " %(self.date,) if self.moduleid: sql += " AND module.moduleid='%s'" % (self.moduleid,) connection = nav.db.getConnection('status', 'manage') database = connection.cursor() database.execute(sql) result = database.fetchall() height = len(result) if self.maxHeight: if height > self.maxHeight: height = self.maxHeight SYSNAME = 0 MODULE = 1 FROM = 2 TO = 3 DOWNTIME = 4 BOXID = 5 ALERTTYPE = 6 MODULEID = 7 for tmpline in result: # Must insert downtime if not tmpline[TO] or tmpline[TO]==INFINITY: downTime = mx.DateTime.now() - tmpline[FROM] else: downTime = tmpline[TO] - tmpline[FROM] line = list(tmpline[0:4]) + [downTime] + list(tmpline[4:7]) row = [] style = None #if (line[ALERTTYPE]=='boxShadow' or line[ALERTTYPE]=='boxSunny'): # style = 'shadow' # Sysname row.append((line[SYSNAME], urlbuilder.createUrl(id=line[BOXID],division='netbox'), None,style)) # Handler row.append((str(line[MODULE]),None,None,style)) # From row.append((line[FROM].strftime('%Y-%m-%d %H:%M'), None, None, style)) # To if not line[TO] or line[TO]==INFINITY: row.append(('Still down',None,None,style)) else: row.append((line[TO].strftime('%Y-%m-%d %H:%M'), None, None, style)) # Downtime downTime = str(line[DOWNTIME].absvalues()[0]) + ' d, ' + \ line[DOWNTIME].strftime('%H') + ' h, ' +\ line[DOWNTIME].strftime('%M') + ' min' row.append((downTime,None,None,sty
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -