⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 statussections.py

📁 Network Administration Visualized 网络管理可视化源码
💻 PY
📖 第 1 页 / 共 5 页
字号:
                            ('Down since',None),                            ('Downtime',None),                            ('',None)]        self.rows = []        self.summary = None        self.historyLink = []        self.historyLink.append((BASEPATH + 'history/?type=modules',                                 'history'))        self.filterSettings = filterSettings        SectionBox.__init__(self, controlBaseName,title,getArgs,None)         self.addHeadings()        return     def fill(self):        filterSettings = self.filterSettings            sql = "SELECT netbox.sysname,netbox.ip," +\              "module.module,alerthist.start_time," +\              "now()-alerthist.start_time,netbox.up," +\              "alerttype.alerttype,module.moduleid,netbox.netboxid FROM " + \              "alerthist,netbox,alerttype,module " + \              "WHERE alerthist.netboxid=netbox.netboxid AND " +\              "alerthist.subid = module.moduleid AND " +\              "alerttype.alerttypeid=alerthist.alerttypeid AND " +\              "alerthist.end_time='infinity' AND " +\              "alerthist.eventtypeid='moduleState' AND " +\              "alerttype.alerttype='moduleDown' "         where_clause = ''        if filterSettings:            # orgid            if not filterSettings['orgid'].count(FILTER_ALL_SELECTED):                where_clause += " AND ("                first_line = True                for org in filterSettings['orgid']:                    if not first_line:                        where_clause += " OR "                    where_clause += "netbox.orgid = '" + org + "'"                    first_line = False                where_clause += ") "            # catid            if not filterSettings['catid'].count(FILTER_ALL_SELECTED):                where_clause += " AND ("                first_line = True                for cat in filterSettings['catid']:                    if not first_line:                        where_clause += " OR "                    where_clause += "netbox.catid = '" + cat + "'"                    first_line = False                where_clause += ") "            # state            self.listStates = filterSettings['state']            if not filterSettings['state'].count(FILTER_ALL_SELECTED):                where_clause += " AND ("                first_line = True                for state in filterSettings['state']:                    if not first_line:                        where_clause += " OR "                    where_clause += "module.up = '" + state + "'"                    first_line = False                where_clause += ") "            else:              where_clause += "AND (module.up='n' OR module.up='s') "        sql = sql + where_clause + " ORDER BY now()-start_time"         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        modulesDown = 0        modulesShadow = 0        SYSNAME = 0        IP = 1        MODULE = 2        STARTTIME = 3        DOWNTIME = 4        UP = 5        ALERTTYPE = 6        MODULEID = 7        BOXID = 8                for line in result:            row = []            style = None                if line[UP] == 's':                modulesShadow += 1                style = 'shadow'             else:                modulesDown += 1             # Sysname            row.append((line[SYSNAME],                        urlbuilder.createUrl(id=line[BOXID],division='netbox'),                        None,                        style))            # Ip            row.append((line[IP],None,None,style))             # Module            row.append((str(line[MODULE]),None,None,style))            # Down since            row.append((line[STARTTIME].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') + ' m'            row.append((downTime,None,None,style))            # History icon            row.append((None,                        BASEPATH + 'history/?type=modules&id=%s' \                        % (line[MODULEID],),                        ('/images/status/status-history.png',                        'View history for this module'),                        None))            self.rows.append([line[self.sortBy],row])        self.sort()        modulesDown = str(modulesDown)        modulesShadow = str(modulesShadow)        if modulesDown=='0':            modulesDown = 'No'        if modulesShadow=='0':            modulesShadow = 'No'        if not self.listStates.count('s') and self.listStates.count('n'):            self.summary = modulesDown + ' modules down'        elif not self.listStates.count('n') and self.listStates.count('s'):            self.summary = modulesShadow + ' modules in shadow'        else:            self.summary = modulesDown + ' modules down, ' + \                           modulesShadow.lower() + ' in shadow'    def getFilters(controlBaseName,orgList):        """        Return the filters that this section accepts        """        filterHeadings = ['Organisation','Category','State']        filterSelects = []        # Org        table = nav.db.manage.Org        # Restrict to orgs where user belongs        #whereOrg = makeWhereList(orgList)        optionsList = [(FILTER_ALL_SELECTED,'All',True)]        for org in table.getAllIterator(orderBy='orgid'):            optionsList.append((org.orgid,org.orgid,False))        filterSelects.append((controlBaseName + '_' + 'orgid',optionsList))        # Cat        table = nav.db.manage.Cat        optionsList = [(FILTER_ALL_SELECTED,'All',True)]        for cat in table.getAllIterator():             optionsList.append((cat.catid,cat.catid,False))        filterSelects.append((controlBaseName + '_' + 'catid',optionsList))        # State        filterSelects.append((controlBaseName + '_' + 'state',\        [(FILTER_ALL_SELECTED,'All',True),('n','Down',False),\        ('s','Shadow',False)]))        return (filterHeadings,filterSelects)    getFilters = staticmethod(getFilters)class ThresholdSectionBox(SectionBox):    " Section displaying threshold events "    # attribs for preferences    name = 'Thresholds exceeded'    typeId = 'threshold'    prefsOptions = None    defaultSort = 3         # -3, thus sortReverse = True    sortReverse = False     sortBy = defaultSort    def __init__(self, controlBaseName,getArgs,title,filterSettings):        # Sort reverse by column 3 (downtime)        self.headings = []        self.headingDefs = [('Sysname',None),                            ('Description',None),                            ('Exceeded since',None),                            ('Time exceeded',None),                            ('',None)]        self.rows = []        self.summary = None        self.historyLink = []        self.historyLink.append((BASEPATH + 'history/?type=thresholds',                                 'history'))        self.filterSettings = filterSettings        SectionBox.__init__(self, controlBaseName,title,getArgs,None)         self.addHeadings()        return     def fill(self):        filterSettings = self.filterSettings            sql = "SELECT netbox.sysname," +\              "alerthist.start_time,now()-alerthist.start_time," +\              "rrd_datasource.descr,rrd_datasource.units," +\	          "rrd_datasource.threshold,netbox.netboxid," +\              "rrd_datasource.rrd_datasourceid " +\              "FROM alerthist,alerttype,netbox,rrd_datasource " + \              "WHERE alerthist.netboxid=netbox.netboxid AND " +\              "alerthist.end_time='infinity' AND " +\              "alerthist.eventtypeid='thresholdState' AND " +\              "alerthist.alerttypeid=alerttype.alerttypeid AND " +\    	      "alerttype.alerttype='exceededThreshold' AND " +\	          "alerthist.subid=rrd_datasource.rrd_datasourceid  "         # parse filter settings        where_clause = ''        if filterSettings:            # orgid            if not filterSettings['orgid'].count(FILTER_ALL_SELECTED):                where_clause += " AND ("                first_line = True                for org in filterSettings['orgid']:                    if not first_line:                        where_clause += " OR "                    where_clause += "netbox.orgid = '" + org + "'"                    first_line = False                where_clause += ") "            # catid            if not filterSettings['catid'].count(FILTER_ALL_SELECTED):                where_clause += " AND ("                first_line = True                for cat in filterSettings['catid']:                    if not first_line:                        where_clause += " OR "                    where_clause += "netbox.catid = '" + cat + "'"                    first_line = False                where_clause += ") "            # state            #self.listStates = filterSettings['type']            #if not filterSettings['type'].count(FILTER_ALL_SELECTED):            #    where_clause += " and ("            #    first_line = True            #    for atype in filterSettings['type']:            #        if not first_line:            #            where_clause += " or "            #        where_clause += "alerthist.alerttype = '" + atype + "'"            #        first_line = False            #    where_clause += ") "        sql = sql + where_clause + " ORDER BY now()-start_time"         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        thresholdsExceeded = 0        SYSNAME = 0        DESCRIPTION = 1        STARTTIME = 2        DOWNTIME = 3        DATASOURCE_DESCR = 4        DATASOURCE_UNITS = 5        DATASOURCE_THRESHOLD = 6        BOXID = 7        DATASOURCEID = 8                for tmpline in result:            tmpline = list(tmpline)            # Must insert description (-1 since description isnt there yet)            if not tmpline[DATASOURCE_DESCR-1]:                tmpline[DATASOURCE_DESCR-1] = 'Unknown datasource '            if not tmpline[DATASOURCE_THRESHOLD-1]:                tmpline[DATASOURCE_THRESHOLD-1] = ''            if not tmpline[DATASOURCE_UNITS-1]:                tmpline[DATASOURCE_UNITS-1] = ''            descr = tmpline[DATASOURCE_DESCR-1] + ' exceeded ' +\                    str(tmpline[DATASOURCE_THRESHOLD-1]) +\                    str(tmpline[DATASOURCE_UNITS-1])            line = list(tmpline[0:1]) + [descr] + list(tmpline[1:8])            row = []            style = None                thresholdsExceeded += 1            # Sysname            row.append((line[SYSNAME],                        urlbuilder.createUrl(id=line[BOXID],division='netbox'),                        None,style))            # Description            row.append((line[DESCRIPTION],None,None,style))            # Start            row.append((line[STARTTIME].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') + ' m'            row.append((downTime,None,None,style))            # History link            row.append((None,                        BASEPATH + 'history/?type=thresholds&id=%s' \                        % (line[DATASOURCEID],),                        ('/images/status/status-history.png',                        'View history for this datasource'),                        None))            self.rows.append([line[self.sortBy],row])        self.sort()        thresholdsExceeded = str(thresholdsExceeded)        if thresholdsExceeded=='0':            thresholdsExceeded = 'No'        if thresholdsExceeded=='1':            self.summary = thresholdsExceeded + ' threshold exceeded'        else:            self.summary = thresholdsExceeded + ' thresholds exceeded'    def getFilters(controlBaseName,orgList):        """        Returns the filters that this section box accepts        """        filterHeadings = ['Organisation','Category']        filterSelects = []        table = nav.db.manage.Org        # Org        optionsList = [(FILTER_ALL_SELECTED,'All',True)]        # Restrict to orgs where user belongs        #whereOrg = makeWhereList(orgList)        for org in table.getAllIterator(orderBy = 'orgid'):            optionsList.append((org.orgid,org.orgid,False))        filterSelects.append((controlBaseName + '_' + 'orgid',optionsList))        # Cat        table = nav.db.manage.Cat        optionsList = [(FILTER_ALL_SELECTED,'All',True)]        for cat in table.getAllIterator():

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -