本文整理汇总了Python中pynag.Plugins.PluginHelper.add_status方法的典型用法代码示例。如果您正苦于以下问题:Python PluginHelper.add_status方法的具体用法?Python PluginHelper.add_status怎么用?Python PluginHelper.add_status使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pynag.Plugins.PluginHelper
的用法示例。
在下文中一共展示了PluginHelper.add_status方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testPluginHelper
# 需要导入模块: from pynag.Plugins import PluginHelper [as 别名]
# 或者: from pynag.Plugins.PluginHelper import add_status [as 别名]
class testPluginHelper(unittest.TestCase):
def setUp(self):
self.argv_store = sys.argv
from pynag.Plugins import PluginHelper
self.my_plugin = PluginHelper()
self.my_plugin.parser.add_option('-F',
dest='fakedata',
help='fake data to test thresholds')
sys.stdout = StringIO()
def tearDown(self):
sys.argv = self.argv_store
sys.stdout = original_stdout
def run_expect(self, case, value, expected_exit):
sys.argv = [sys.argv[0]] + case.split() + ('-F %s' % value).split()
self.my_plugin.parse_arguments()
self.my_plugin.add_status(pynag.Plugins.ok)
self.my_plugin.add_summary(self.my_plugin.options.fakedata)
self.my_plugin.add_metric('fakedata', self.my_plugin.options.fakedata)
try:
self.my_plugin.check_all_metrics()
self.my_plugin.exit()
except SystemExit, e:
self.assertEquals(type(e), type(SystemExit()))
self.assertEquals(e.code, expected_exit)
except Exception, e:
self.fail('unexpected exception: %s' % e)
示例2: main
# 需要导入模块: from pynag.Plugins import PluginHelper [as 别名]
# 或者: from pynag.Plugins.PluginHelper import add_status [as 别名]
def main():
p = PluginHelper()
# Warn on inactive
level = 2
service_status = get_service_status(sys.argv[1])
if loaded(service_status)[0] is False:
p.exit(3,
"%s - %s" % (service_status['name'],
loaded(service_status)[1]),
"\n" + service_status['unparsed'])
active = service_status['headers']['Active'][0]
if active.startswith("inactive") or active.startswith('failed'):
p.add_status(level)
elif active.startswith("active"):
p.add_status(0)
else:
p.add_status(3)
p.add_summary("%s - %s" % ( service_status['name'], active))
p.add_long_output("\n" + service_status['unparsed'])
p.exit()
示例3: PluginHelper
# 需要导入模块: from pynag.Plugins import PluginHelper [as 别名]
# 或者: from pynag.Plugins.PluginHelper import add_status [as 别名]
#!/usr/bin/python
import os.path
import sys
pynagbase = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir))
sys.path[0] = pynagbase
# Standard init
from pynag.Plugins import PluginHelper,ok
# Create an instance of PluginHelper()
my_plugin = PluginHelper()
# Feed fake data for range checking
my_plugin.parser.add_option('-F', dest='fakedata', help='fake data to test thresholds')
# Activate
my_plugin.parse_arguments()
my_plugin.add_status(ok)
my_plugin.add_summary(my_plugin.options.fakedata)
my_plugin.add_metric('fakedata', my_plugin.options.fakedata)
my_plugin.check_all_metrics()
my_plugin.exit()
示例4: PluginHelper
# 需要导入模块: from pynag.Plugins import PluginHelper [as 别名]
# 或者: from pynag.Plugins.PluginHelper import add_status [as 别名]
class PluginHelper(unittest.TestCase):
def setUp(self):
self.argv_store = sys.argv
from pynag.Plugins import PluginHelper
self.my_plugin = PluginHelper()
self.my_plugin.parser.add_option('-F',
dest='fakedata',
help='fake data to test thresholds')
sys.stdout = StringIO()
def tearDown(self):
sys.argv = self.argv_store
sys.stdout = original_stdout
def run_expect(self, case, value, expected_exit):
sys.argv = [sys.argv[0]] + case.split() + ('-F %s' % value).split()
self.my_plugin.parse_arguments()
self.my_plugin.add_status(pynag.Plugins.ok)
self.my_plugin.add_summary(self.my_plugin.options.fakedata)
self.my_plugin.add_metric('fakedata', self.my_plugin.options.fakedata)
try:
self.my_plugin.check_all_metrics()
self.my_plugin.exit()
except SystemExit as e:
self.assertEquals(type(e), type(SystemExit()))
self.assertEquals(e.code, expected_exit)
except Exception as e:
self.fail('unexpected exception: %s' % e)
else:
self.fail('SystemExit exception expected')
finally:
signal.alarm(0)
# Critical if "stuff" is over 20, else warn if over 10
# (will be critical if "stuff" is less than 0)
def test_number_1(self):
case = '--th=metric=fakedata,ok=0..10,warn=10..20'
self.run_expect(case, -23, 2)
def test_number_2(self):
case = '--th=metric=fakedata,ok=0..10,warn=10..20'
self.run_expect(case, 3, 0)
def test_number_3(self):
case = '--th=metric=fakedata,ok=0..10,warn=10..20'
self.run_expect(case, 13, 1)
def test_number_4(self):
case = '--th=metric=fakedata,ok=0..10,warn=10..20'
self.run_expect(case, 23, 2)
# Same as above. Negative "stuff" is OK
def test_number_5(self):
case = '--th=metric=fakedata,ok=inf..10,warn=10..20'
self.run_expect(case, '-23', 0)
def test_number_6(self):
case = '--th=metric=fakedata,ok=inf..10,warn=10..20'
self.run_expect(case, '3', 0)
def test_number_7(self):
case = '--th=metric=fakedata,ok=inf..10,warn=10..20'
self.run_expect(case, '13', 1)
def test_number_8(self):
case = '--th=metric=fakedata,ok=inf..10,warn=10..20'
self.run_expect(case, '23', 2)
# Critical if "stuff" is over 20, else warn if "stuff" is below 10
# (will be critical if "stuff" is less than 0)
def test_number_9(self):
case = '--th=metric=fakedata,warn=0..10,crit=20..inf'
self.run_expect(case, '-23', 0)
def test_number_10(self):
case = '--th=metric=fakedata,warn=0..10,crit=20..inf'
self.run_expect(case, '3', 1)
def test_number_11(self):
case = '--th=metric=fakedata,warn=0..10,crit=20..inf'
self.run_expect(case, '13', 0)
def test_number_12(self):
case = '--th=metric=fakedata,warn=0..10,crit=20..inf'
self.run_expect(case, '23', 2)
# Critical if "stuff" is less than 1
def test_number_13(self):
case = '--th=metric=fakedata,ok=1..inf'
self.run_expect(case, '-23', 2)
def test_number_14(self):
case = '--th=metric=fakedata,ok=1..inf'
self.run_expect(case, '0', 2)
def test_number_15(self):
case = '--th=metric=fakedata,ok=1..inf'
self.run_expect(case, '13', 0)
#.........这里部分代码省略.........