当前位置: 首页>>代码示例>>Python>>正文


Python PluginHelper.check_all_metrics方法代码示例

本文整理汇总了Python中pynag.Plugins.PluginHelper.check_all_metrics方法的典型用法代码示例。如果您正苦于以下问题:Python PluginHelper.check_all_metrics方法的具体用法?Python PluginHelper.check_all_metrics怎么用?Python PluginHelper.check_all_metrics使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pynag.Plugins.PluginHelper的用法示例。


在下文中一共展示了PluginHelper.check_all_metrics方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: testPluginHelper

# 需要导入模块: from pynag.Plugins import PluginHelper [as 别名]
# 或者: from pynag.Plugins.PluginHelper import check_all_metrics [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)
开发者ID:bnrubin,项目名称:pynag,代码行数:29,代码来源:plugintest.py

示例2: main

# 需要导入模块: from pynag.Plugins import PluginHelper [as 别名]
# 或者: from pynag.Plugins.PluginHelper import check_all_metrics [as 别名]
def main():
        helper = PluginHelper()

        helper.parser.add_option('-w', help='warning free (X% or XM)', dest='warning')
        helper.parser.add_option('-c', help='critical free (X% or XM)', dest='critical')
        helper.parse_arguments()
        warn = helper.options.warning
        crit = helper.options.critical

	memory = getMemory()


	if helper.options.warning is not None:
		warn = helper.options.warning
		if re.match('.*%$', warn):
			warn = str(memory['total'] * int(re.search('\d*', warn).group(0)) / 100)
	else:
		warn = '0'

	if helper.options.critical is not None:
		crit = helper.options.critical
		if re.match('.*%$', crit):
			crit = str(memory['total'] * int(re.search('\d*', crit).group(0)) / 100)
	else:
		crit = '0'

        helper.status(ok)
	status = "OK"

	if memory['totalfree'] <= int(warn):
		helper.status(warning)
		status = "WARNING"

	if memory['totalfree'] <= int(crit):
		helper.status(critical)
		status = "CRITICAL"

	helper.add_summary(status + ': Memory free: %(totalfree)s %% (%(free)s %% including buffers/cached)' % {'totalfree': (round((float(memory['totalfree']) / float(memory['total']) * 100), 1 )), 'free': (round((float(memory['free']) / float(memory['total']) * 100), 1 ))})
        helper.add_metric(label='total',value=memory['total'])
        helper.add_metric(label='free',value=memory['free'])
        helper.add_metric(label='totalfree',value=memory['totalfree'], warn=warn+'..0', crit=crit+'..0')
        helper.add_metric(label='used',value=memory['used'])
        helper.add_metric(label='buffers',value=memory['buffers'])
        helper.add_metric(label='cached',value=memory['cached'])
        helper.add_metric(label='swapcached',value=memory['swapcached'])


	helper.check_all_metrics()
        helper.exit()
开发者ID:triicst,项目名称:nagios-plugins,代码行数:51,代码来源:check_memory.py

示例3:

# 需要导入模块: from pynag.Plugins import PluginHelper [as 别名]
# 或者: from pynag.Plugins.PluginHelper import check_all_metrics [as 别名]
    # Now lets find those keyfigures, the content of textdata is dynamic so
    # some guesswork is required
    if 'Mannfj' in textdata:
        p.add_metric(label="mannfjoldi", value=numberdata)
    elif "Hagv" in textdata:
        p.add_metric(label="hagvoxtur", value=numberdata)
    elif "VLF" in textdata:
        p.add_metric("verg landsframleidsla", value=numberdata, uom="Mkr")
    elif "VNV" in textdata:
        p.add_metric(label="VNV", value=numberdata)
    elif "Launav" in textdata:
        p.add_metric(label="launavisitala", value=numberdata)
    elif "Bygg.v" in textdata:
        p.add_metric(label="byggingavisitala", value=numberdata)
    elif "sit. framl" in textdata:
        p.add_metric(label="visitala framleidsluverds", value=numberdata)
    elif "Fiskafli" in textdata:
        p.add_metric(label="fiskafli", value=numberdata, uom="tonn")
    elif "ruskipti" in textdata:
        p.add_metric(label="voruskipti", value=numberdata, uom="Mkr")

summary = "%s metrics collected from hagstofan" % (len(p._perfdata.metrics))
p.add_summary(summary)

p.status(ok)


p.check_all_metrics()
p.exit()
开发者ID:asbela,项目名称:monitor-iceland,代码行数:31,代码来源:check_hagstofan.py

示例4: zip

# 需要导入模块: from pynag.Plugins import PluginHelper [as 别名]
# 或者: from pynag.Plugins.PluginHelper import check_all_metrics [as 别名]
    for w,v in zip(names, descriptions):
      print w + ' = ' + v
    helper.status(unknown)
    helper.exit(summary='This is just a list and not a check!')
  
  # verify that a hostname is set
  verify_host(host, helper)
  
  # open session after validated host
  sess = netsnmp.Session(Version=version, DestHost=host, Community=community)
  
  # verify, that status(/type) parameter is not empty
  if (status == None) or (status not in names):
    helper.status(unknown)
    helper.exit(summary='Argument -t is missing or false!')
  
  # snmp gets for all oids in type-list
  ind = names.index(status)
  value = get_data(sess, oids[ind],helper)
  
  if names.index(status) == 0:
    value = str(datetime.timedelta(seconds=int(value)))
    helper.exit(summary='Uptime = %s'%value)
  
  # metric compares
  helper.add_metric(label='type', value = value, uom =' '+units[ind]+' ')
  helper.check_all_metrics()
  
  # programm end
  helper.exit()
开发者ID:rsmuc,项目名称:health_monitoring_plugins,代码行数:32,代码来源:check_snmp_ubiquiti.py

示例5: PluginHelper

# 需要导入模块: from pynag.Plugins import PluginHelper [as 别名]
# 或者: from pynag.Plugins.PluginHelper import check_all_metrics [as 别名]
# check_stuff.py Takes any arguments from the command_line and treats them as performance metrics.


from pynag.Plugins import PluginHelper

my_plugin = PluginHelper()
my_plugin.parse_arguments()

# Any perfdatastring added as argument will be treated as a performance metric
for i in my_plugin.arguments:
    my_plugin.add_metric(perfdatastring=i)


my_plugin.check_all_metrics()
my_plugin.exit()
开发者ID:AccelerationNet,项目名称:pynag,代码行数:17,代码来源:check_stuff.py

示例6: show_response

# 需要导入模块: from pynag.Plugins import PluginHelper [as 别名]
# 或者: from pynag.Plugins.PluginHelper import check_all_metrics [as 别名]
    auth = (plugin.options.user, plugin.options.password)
    # Build the metric URL.
    api = 'http://{}:{}/api/overview'.format(plugin.options.hostname, plugin.options.port)
    payload = { 
        'msg_rates_age': '3600',
        'msg_rates_incr': '10',
        'columns': 'message_stats.deliver_get_details.avg_rate',
    }

    # No need to specify a timeout: pynag has --timeout option for the whole plugin.
    r = requests.get(api, params=payload, auth=auth)

    if plugin.options.show_debug:
        show_response()

    if r.status_code == 401:
        plugin.add_summary("Login failed")
        plugin.exit()

    try:
        deliver_rate = r.json()["message_stats"]["deliver_get_details"]["avg_rate"]
    except ValueError:
        plugin.add_summary("Can't decode server's response")
        plugin.exit()
 
    plugin.add_metric('deliver_rate', deliver_rate)
    plugin.add_summary('message.deliver.avg_rate: {}'.format(deliver_rate))
    plugin.check_all_metrics()
    plugin.exit()

开发者ID:funollet,项目名称:nagios-plugins,代码行数:31,代码来源:check_rabbitmq_metrics.py

示例7: PluginHelper

# 需要导入模块: from pynag.Plugins import PluginHelper [as 别名]
# 或者: from pynag.Plugins.PluginHelper import check_all_metrics [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)

#.........这里部分代码省略.........
开发者ID:AccelerationNet,项目名称:pynag,代码行数:103,代码来源:test_plugins.py


注:本文中的pynag.Plugins.PluginHelper.check_all_metrics方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。