本文整理汇总了Python中pynag.Plugins.simple.check_range方法的典型用法代码示例。如果您正苦于以下问题:Python simple.check_range方法的具体用法?Python simple.check_range怎么用?Python simple.check_range使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pynag.Plugins.simple
的用法示例。
在下文中一共展示了simple.check_range方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testPlugin
# 需要导入模块: from pynag.Plugins import simple [as 别名]
# 或者: from pynag.Plugins.simple import check_range [as 别名]
class testPlugin(unittest.TestCase):
def setUp(self):
self.argv_store = sys.argv
from pynag.Plugins import simple as Plugin
self.np = Plugin()
sys.stdout = StringIO()
sys.stderr = StringIO()
def tearDown(self):
sys.argv = self.argv_store
sys.stdout = original_stdout
sys.stderr = original_stderr
def run_expect(self, case, expected_exit, value):
sys.argv = [sys.argv[0]] + case.split()
self.np.activate()
try:
self.np.add_perfdata('fake', value, uom='fakes',
warn=10, crit=20, minimum=-100, maximum=100)
perfdata_string = self.np.perfdata_string()
print perfdata_string
self.assertEquals(perfdata_string, "| '%s'=%s%s;%s;%s;%s;%s" % (
'fake', value, 'fakes', 10, 20, -100, 100))
self.np.add_message('OK', 'Some message')
self.assertEquals(self.np.data['messages'][0], ['Some message'])
self.np.check_range(value)
except SystemExit, e:
self.assertEquals(type(e), type(SystemExit()))
self.assertEquals(e.code, expected_exit)
except Exception, e:
import traceback
print traceback.format_exc()
self.fail('unexpected exception: %s' % e)
示例2: testPluginNoThreshold
# 需要导入模块: from pynag.Plugins import simple [as 别名]
# 或者: from pynag.Plugins.simple import check_range [as 别名]
class testPluginNoThreshold(unittest.TestCase):
def setUp(self):
self.argv_store = sys.argv
from pynag.Plugins import simple as Plugin
self.np = Plugin(must_threshold=False)
def tearDown(self):
sys.argv = self.argv_store
def run_expect(self, case, expected_exit, value):
sys.argv = [sys.argv[0]] + case.split()
self.np.activate()
try:
self.np.check_range(value)
except SystemExit, e:
self.assertEquals(type(e), type(SystemExit()))
self.assertEquals(e.code, expected_exit)
except Exception, e:
self.fail('unexpected exception: %s' % e)
示例3: PluginNoThreshold
# 需要导入模块: from pynag.Plugins import simple [as 别名]
# 或者: from pynag.Plugins.simple import check_range [as 别名]
class PluginNoThreshold(unittest.TestCase):
def setUp(self):
self.argv_store = sys.argv
from pynag.Plugins import simple as Plugin
self.np = Plugin(must_threshold=False)
sys.stdout = StringIO()
def tearDown(self):
sys.argv = self.argv_store
sys.stdout = original_stdout
def run_expect(self, case, expected_exit, value):
sys.argv = [sys.argv[0]] + case.split()
self.np.activate()
try:
self.np.check_range(value)
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')
# All tests return OK since thresholds are not required
def test_number_1(self):
case = ''
self.run_expect(case, 0, -23)
def test_number_2(self):
case = ''
self.run_expect(case, 0, 0)
def test_number_3(self):
case = ''
self.run_expect(case, 0, 2)
def test_number_4(self):
case = ''
self.run_expect(case, 0, 10)
def test_number_5(self):
case = ''
self.run_expect(case, 0, 15)
示例4: Plugin
# 需要导入模块: from pynag.Plugins import simple [as 别名]
# 或者: from pynag.Plugins.simple import check_range [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
import pynag.Plugins
from pynag.Plugins import WARNING, CRITICAL, OK, UNKNOWN, simple as Plugin
np = Plugin()
# Feed fake data for range checking
np.add_arg('F', 'fakedata', 'fake data to test thresholds', required=True)
# Activate
np.activate()
# Test supplied fake data against thresholds
np.check_range(int(np['fakedata']))
示例5: Plugin
# 需要导入模块: from pynag.Plugins import simple [as 别名]
# 或者: from pynag.Plugins.simple import check_range [as 别名]
## This is for the custom nagios module
sys.path.insert(1, '../')
from pynag.Plugins import simple as Plugin
## Create the plugin option
np = Plugin()
## Add a command line argument
np.add_arg("l","load-file", "Enter a load average file", required=None)
## This starts the actual plugin activation
np.activate()
## Use a custom load average file, if specified to
if np['load-file']:
load_file = np['load-file']
else:
load_file = "/proc/loadavg"
if not os.path.isfile(load_file):
np.nagios_exit("UNKNOWN", "Missing Load average file %s" % load_file)
## Get the check value
current_load = os.popen("cat %s" % load_file).readline().split()[0]
## Add the perdata
np.add_perfdata("1min", current_load)
np.check_range(current_load)
示例6: Plugin
# 需要导入模块: from pynag.Plugins import simple [as 别名]
# 或者: from pynag.Plugins.simple import check_range [as 别名]
class Plugin(unittest.TestCase):
def setUp(self):
self.argv_store = sys.argv
from pynag.Plugins import simple as Plugin
self.np = Plugin()
sys.stdout = StringIO()
sys.stderr = StringIO()
def tearDown(self):
sys.argv = self.argv_store
sys.stdout = original_stdout
sys.stderr = original_stderr
def run_expect(self, case, expected_exit, value):
sys.argv = [sys.argv[0]] + case.split()
self.np.activate()
try:
self.np.add_perfdata('fake', value, uom='fakes',
warn=10, crit=20, minimum=-100, maximum=100)
perfdata_string = self.np.perfdata_string()
print(perfdata_string)
self.assertEquals(perfdata_string, "| '%s'=%s%s;%s;%s;%s;%s" % (
'fake', value, 'fakes', 10, 20, -100, 100))
self.np.add_message('OK', 'Some message')
self.assertEquals(self.np.data['messages'][0], ['Some message'])
self.np.check_range(value)
except SystemExit as e:
self.assertEquals(type(e), type(SystemExit()))
self.assertEquals(e.code, expected_exit)
except Exception as e:
import traceback
print(traceback.format_exc())
self.fail('unexpected exception: %s' % e)
else:
self.fail('SystemExit exception expected')
# Throws SystemExit, required parameter not set when activating
def test_add_arg_req_missing(self):
self.np.add_arg('F', 'fakedata',
'fake data to test thresholds', required=True)
self.assertRaises(SystemExit, self.np.activate)
def test_add_arg_req(self):
self.np.add_arg('F', 'fakedata',
'fake data to test thresholds', required=True)
sys.argv = [sys.argv[0]] + '-F 100 -w 1 -c 2'.split()
self.np.activate()
def test_add_arg(self):
self.np.add_arg('F', 'fakedata',
'fake data to test thresholds', required=False)
sys.argv = [sys.argv[0]] + '-w 1 -c 2'.split()
self.np.activate()
def test_codestring_to_int(self):
code = self.np.code_string2int('OK')
self.assertEquals(code, 0, "OK did not map to 0")
code = self.np.code_string2int('WARNING')
self.assertEquals(code, 1, "WARNING did not map to 1")
code = self.np.code_string2int('CRITICAL')
self.assertEquals(code, 2, "CRITICAL did not map to 2")
code = self.np.code_string2int('UNKNOWN')
self.assertEquals(code, 3, "UNKNOWN did not map to 3")
# 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 = '-w 10 -c 20'
self.run_expect(case, 2, -23)
def test_number_2(self):
case = '-w 10 -c 20'
self.run_expect(case, 0, 3)
def test_number_3(self):
case = '-w 10 -c 20'
self.run_expect(case, 1, 13)
def test_number_4(self):
case = '-w 10 -c 20'
self.run_expect(case, 2, 23)
# Same as above. Negative "stuff" is OK
def test_number_5(self):
case = '-w ~:10 -c ~:20'
self.run_expect(case, 0, -23)
def test_number_6(self):
case = '-w ~:10 -c ~:20'
self.run_expect(case, 0, 3)
def test_number_7(self):
case = '-w ~:10 -c ~:20'
self.run_expect(case, 1, 13)
def test_number_8(self):
#.........这里部分代码省略.........