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

📄 checkservice.py

📁 Network Administration Visualized 网络管理可视化源码
💻 PY
字号:
#!/usr/bin/env python# -*- coding: ISO8859-1 -*-## Copyright 2003 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: $# Authors: Magnus Nordseth <magnun@itea.ntnu.no>#"""Utility which runs one service check against specified server.Useful when writing new service checks or while debugging."""import sysimport osimport getoptfrom nav.statemon import debugdebug.setDebugLevel(7)from nav.statemon import abstractCheckerfrom nav.statemon import checkermaptry:    #opts, args = getopt.getopt(sys.argv[1:], "i:s:h:a:", ["ip:", "sysname:", "handler:", "args:"])    opts, args = getopt.getopt(sys.argv[1:], "i:s:h:a:")except Exception, e:    print str(e)    sys.exit(1)serviceid=0netboxid=0sysname=""ip = ""handler = ""args={}version = ""if not opts:    print "Usage:"    print "checkService -i <ip address> -s <sysname>  -h <handler>"    print    sys.exit(1)for opt, val in opts:    if opt in ("-i", "--ip"):        ip = val    elif opt in ("-s", "--sysname"):        sysname = val    elif opt in ("-h", "--handler"):        handler = val    #elif opt in ("-a", "--args"):    #    try:    #        args = eval(val)    #    except:    #        print "%s is not a dict" % valreadArgs = 1print "Input additional arguments (key=val), empty line to continue:"while readArgs:    line = raw_input()    if not line:        readArgs = 0        break    try:        splitted = line.split('=')        key = splitted[0]        val = "=".join(splitted[1:])        args[key] = val    except Exception, e:        print line, e        print "Must be on form 'key=val'"print argsdebug.debug("Ip: %s sysname: %s handler: %s args: %s" % (ip, sysname, handler, args))checker = checkermap.get(handler)if not checker:    debug.debug("No such handler: %s" % handler)    sys.exit(1)service={'id':serviceid,         'netboxid':netboxid,         'deviceid':0,         'ip':ip,         'sysname':sysname,         'args':args,         'version':version,         'deviceid':0         }print "checking"myChecker = checker(service)print myChecker.execute()print "finished"

⌨️ 快捷键说明

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