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

📄 statussections.py

📁 Network Administration Visualized 网络管理可视化源码
💻 PY
📖 第 1 页 / 共 5 页
字号:
        SYSNAME = 0        IP = 1        STARTTIME = 2        DOWNTIME = 3        UP = 4        ALERTTYPE = 5        BOXID = 6        # Create list of components on maintenance        onmaint = {}        for line in result_maint:            onmaint[line[BOXID]] = True        for line in result:            # If on maintenance, skip this component            if line[BOXID] in onmaint:                boxesMaintenance += 1                continue                        row = []            style = None            if line[ALERTTYPE] == 'boxShadow':                boxesShadow += 1                #style = 'shadow'             else:                boxesDown += 1             # Sysname            row.append((line[SYSNAME],                        urlbuilder.createUrl(id=line[BOXID],division='netbox'),                        None,                        style))            # Ip            row.append((line[IP],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=boxes&id=%s' % (line[BOXID],),                        ('/images/status/status-history.png',                        'View history for this box'),                        None))            self.rows.append([line[self.sortBy],row])        self.sort()        boxesDown = str(boxesDown)        boxesShadow = str(boxesShadow)        boxesMaintenance = str(boxesMaintenance)        if boxesDown == '0':            boxesDown = 'No'        if boxesShadow == '0':            boxesShadow = 'No'        if boxesMaintenance == '0':            boxesMaintenance = 'No'        if not self.listStates.count('s') and self.listStates.count('n'):            self.summary = boxesDown + ' IP devices down'        elif not self.listStates.count('n') and self.listStates.count('s'):            self.summary = boxesShadow + ' IP devices in shadow'        else:            self.summary = boxesDown + ' IP devices down, ' + \                           boxesShadow.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 NetboxMaintenanceSectionBox(SectionBox):    " Section displaying netboxes that are on maintenance "    name = 'IP devices on maintenance'    typeId = 'netboxmaint'    prefsOptions = None    defaultSort = 3    sortReverse = False     sortBy = defaultSort    def __init__(self, controlBaseName, getArgs, title, filterSettings):        # Sort reverse by column 4 (downtime)        self.headings = []        self.headingDefs = [('Sysname',None),                            ('IP',self.ipCompare),                            ('Down since',None),                            ('Downtime',None),                            ('',None),                            ('',None)]        self.rows = []        self.summary = None        self.historyLink = []        self.historyLink.append(('/maintenance/calendar',                                 'maintenance schedule'))        self.filterSettings = filterSettings        SectionBox.__init__(self, controlBaseName, title, getArgs, None)        self.addHeadings()        return    def fill(self):        filterSettings = self.filterSettings        sql = """SELECT DISTINCT n.sysname, n.ip, ah.start_time,                now() - ah.start_time AS downtime, n.up, at.alerttype,                n.netboxid, ahv.val AS maint_taskid            FROM alerthist AS ah NATURAL JOIN alerthistvar AS ahv,                netbox AS n, alerttype AS at            WHERE ah.netboxid = n.netboxid                AND ah.alerttypeid = at.alerttypeid                AND ah.end_time = 'infinity'                AND ah.eventtypeid = 'maintenanceState'                AND ahv.var = 'maint_taskid'"""        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 += "n.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 += "n.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 += "n.up = '" + state + "'"                    first_line = False                where_clause += ") "        sql = sql + where_clause + " ORDER BY now()-ah.start_time"        connection = nav.db.getConnection('status', 'manage')        database = connection.cursor()        database.execute(sql)        result = database.fetchall()        # If components is down, get down since and downtime        sql = """SELECT DISTINCT n.sysname, n.ip, ah.start_time,                now() - ah.start_time AS downtime, n.up, at.alerttype,                n.netboxid            FROM alerthist AS ah, netbox AS n, alerttype AS at            WHERE ah.netboxid = n.netboxid                AND ah.alerttypeid = at.alerttypeid                AND ah.end_time = 'infinity'                AND ah.eventtypeid = 'boxState'"""        sql = sql + where_clause + " ORDER BY now()-start_time"        database.execute(sql)        result_down = database.fetchall()        height = len(result)        if self.maxHeight:            if height > self.maxHeight:                height = self.maxHeight        boxesMaintenance = 0        boxesMaintenanceUp = 0        boxesMaintenanceDown = 0        boxesMaintenanceShadow = 0        SYSNAME = 0        IP = 1        STARTTIME = 2        DOWNTIME = 3        UP = 4        ALERTTYPE = 5        BOXID = 6        MAINTID = 7        downtimes = {}        for line in result_down:            downtimes[(line[SYSNAME], line[IP])] = \                (line[STARTTIME], line[DOWNTIME])        for line in result:            row = []            style = None            boxesMaintenance += 1            if line[UP] == 'y':                boxesMaintenanceUp += 1            elif line[UP] == 'n':                boxesMaintenanceDown += 1            else:                boxesMaintenanceShadow += 1            # Sysname            row.append((line[SYSNAME],                        urlbuilder.createUrl(id=line[BOXID], division='netbox'),                        None, style))            # Ip            row.append((line[IP], None, None, style))            if line[UP] == 'y':                # Down since                row.append(('Up', None, None, style))                # Downtime                row.append(('', None, None, style))            else:                (starttime, downtime) = \                    downtimes[(line[SYSNAME], line[IP])]                # Down since                row.append((starttime.strftime('%Y-%m-%d %H:%M'),                            None, None, style))                # Downtime                downtime = '%s d, %s h, %s m' % (                    str(downtime.absvalues()[0]),                    downtime.strftime('%H'),                    downtime.strftime('%M'))                row.append((downtime, None, None, style))            # Wrench icon            row.append((None,                        '/maintenance/view?id=%s' % line[MAINTID],                        ('/images/wrench.gif',                        'Maintenance details'),                        None))            # History icon            row.append((None,                        BASEPATH + 'history/?type=boxes&id=%s' % line[BOXID],                        ('/images/status/status-history.png',                        'View history for this box'),                        None))            if line[UP] != 'y' and self.sortBy == STARTTIME:                self.rows.append([starttime, row])            elif line[UP] != 'y' and self.sortBy == DOWNTIME:                self.rows.append([downtime, row])            else:                self.rows.append([line[self.sortBy], row])        self.sort()        boxesMaintenance = str(boxesMaintenance)        boxesMaintenanceUp = str(boxesMaintenanceUp)        boxesMaintenanceDown = str(boxesMaintenanceDown)        boxesMaintenanceShadow = str(boxesMaintenanceShadow)        if boxesMaintenance == '0':            boxesMaintenance = 'No'        if boxesMaintenanceUp == '0':            boxesMaintenanceUp = 'No'        if boxesMaintenanceDown == '0':            boxesMaintenanceDown = 'No'        if boxesMaintenanceShadow == '0':            boxesMaintenanceShadow = 'No'        self.summary = boxesMaintenance + ' IP devices on maintenance (' + \            boxesMaintenanceUp + ' up, ' + \            boxesMaintenanceDown.lower() + ' down, ' + \            boxesMaintenanceShadow.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 ModuleSectionBox(SectionBox):    " Section displaying modules that are down or in shadow "        # attribs for preferences    name = 'Modules down'    typeId = 'module'          prefsOptions = None    defaultSort = 4          sortReverse = False     sortBy = defaultSort    def __init__(self, controlBaseName,getArgs,title,filterSettings):        # Sort reverse by column 4 (downtime)        self.headings = []        self.headingDefs = [('Sysname',None),                            ('IP',self.ipCompare),                            ('Module',None),

⌨️ 快捷键说明

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