📄 servicemon.py
字号:
#!/usr/bin/env python# -*- coding: ISO-8859-1 -*-## Copyright 2002-2004 Norwegian University of Science and Technology## This file is part of Network Administration Visualized (NAV)## NAV is free software; you can redistribute it and/or modify# it under the terms of the GNU General Public License as published by# the Free Software Foundation; either version 2 of the License, or# (at your option) any later version.## NAV is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.## You should have received a copy of the GNU General Public License# along with NAV; if not, write to the Free Software# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA### $Id: servicemon.py 3963 2007-04-12 08:58:37Z mortenv $# Authors: Magnus Nordseth <magnun@itea.ntnu.no>#"""This program controls the service monitoring in NAV."""import osimport typesimport timeimport getoptimport randomimport gcimport threadingimport signaltry: import nav.pathexcept: # Not properly installed passfrom nav.statemon import RunQueuefrom nav.statemon import abstractCheckerfrom nav.statemon import configfrom nav.statemon import dbfrom nav.statemon import mailAlertfrom nav.statemon import debugclass controller: def __init__(self, **kwargs): signal.signal(signal.SIGHUP, self.signalhandler) signal.signal(signal.SIGTERM, self.signalhandler) self.conf=config.serviceconf() debug.setDebugLevel(self.conf.get('debuglevel',4)) self._deamon=kwargs.get("fork", 1) self._isrunning=1 self._checkers=[] self._looptime=int(self.conf.get("checkinterval",60)) debug.debug("Setting checkinterval=%i"% self._looptime) self.db=db.db(config.dbconf("db.conf")) debug.debug("Reading database config") debug.debug("Setting up runqueue") self._runqueue=RunQueue.RunQueue(controller=self) #self.alerter=mailAlert.mailAlert() #self.alerter.start() self.dirty = 1 def createStatusFile(self): """ Dumps the current status to a file. """ filename = os.path.join(nav.path.webroot, "services/status.txt") try: outputfile = open(filename, 'w') except: debug.debug("Failed to open outputfile: %s" % filename,2) return try: outputlines = [] for each in self._checkers: outputlines.append("%-25s %-5s %-5s %s\n" % (each.getSysname(), each.getType(), each.getStatus(), each.getVersion())) outputlines.sort() map(outputfile.write, outputlines) outputfile.write("\n\nLast updated: %s" % time.asctime()) outputfile.close() except: debug.debug("Failed to write to %s" % outputfile,2) def getCheckers(self): """ Fetches new checkers from the NAV database and appends them to the runqueue. """ newcheckers = self.db.getCheckers(self.dirty) self.dirty=0 # make sure we don't delete all checkers if we get an empty # list from the database (maybe we have lost connection to # the db) if newcheckers: s=[] for i in newcheckers: if i in self._checkers: oldchecker = self._checkers[self._checkers.index(i)] s.append(oldchecker) else: s.append(i) self._checkers=s #randomiserer rekkef鴏gen p
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -