本文整理汇总了Python中pynag.Plugins.PluginHelper.parse_arguments方法的典型用法代码示例。如果您正苦于以下问题:Python PluginHelper.parse_arguments方法的具体用法?Python PluginHelper.parse_arguments怎么用?Python PluginHelper.parse_arguments使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pynag.Plugins.PluginHelper
的用法示例。
在下文中一共展示了PluginHelper.parse_arguments方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testPluginHelper
# 需要导入模块: from pynag.Plugins import PluginHelper [as 别名]
# 或者: from pynag.Plugins.PluginHelper import parse_arguments [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 parse_arguments [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()
示例3: PluginHelper
# 需要导入模块: from pynag.Plugins import PluginHelper [as 别名]
# 或者: from pynag.Plugins.PluginHelper import parse_arguments [as 别名]
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# This script collects key figure metrics from hagstofan.is
from pynag.Plugins import PluginHelper, ok, unknown
import requests
from BeautifulSoup import BeautifulSoup
url = 'http://hagstofan.is'
p = PluginHelper()
p.parse_arguments()
p.show_legacy = True
tmp = requests.get(url)
html = tmp.content
soup = BeautifulSoup(html, convertEntities=BeautifulSoup.HTML_ENTITIES)
keyfigures_table = soup.find('table', {'class': 'keyfigures_small'})
if not keyfigures_table:
p.exit(unknown, "Could not find any table with class=keyfigures_small'")
rows = keyfigures_table.findAll('tr')
for row in rows:
textdata = row.find('td', {'class': 'textdata'})
numberdata = row.find('td', {'class': 'numberdata'})
if not textdata or not numberdata:
continue
# Get the text content out of the <td> cells
示例4: PluginHelper
# 需要导入模块: from pynag.Plugins import PluginHelper [as 别名]
# 或者: from pynag.Plugins.PluginHelper import parse_arguments [as 别名]
import os
import netsnmp
sys.path.insert(1, os.path.join(sys.path[0], os.pardir))
from snmpSessionBaseClass import add_common_options, get_common_options, verify_host, attempt_get_data, walk_data
from pynag.Plugins import PluginHelper,ok,critical
# Create an instance of PluginHelper()
helper = PluginHelper()
# Add command line parameters
add_common_options(helper)
helper.parser.add_option('-s', '--service', help="The name of the service you want to monitor (-s scan for scanning)", dest="service", default='')
helper.parser.add_option('-S', '--scan', dest = 'scan_flag', default = False, action = "store_true", help = 'Show all available services')
helper.parse_arguments()
# get the options
host, version, community = get_common_options(helper)
service = helper.options.service
scan = helper.options.scan_flag
# that is the base id
base_oid = ".1.3.6.1.4.1.77.1.2.3.1.1"
'''
# for check_snmp_service we need to adapt the service_get_data function
def service_get_data(sess, host, version, community, oid):
var = netsnmp.Varbind(oid)
data = netsnmp.snmpget(var, Version=version, DestHost=host, Community=community)
value = data[0]
示例5: PluginHelper
# 需要导入模块: from pynag.Plugins import PluginHelper [as 别名]
# 或者: from pynag.Plugins.PluginHelper import parse_arguments [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()
示例6: cmd
# 需要导入模块: from pynag.Plugins import PluginHelper [as 别名]
# 或者: from pynag.Plugins.PluginHelper import parse_arguments [as 别名]
def cmd(self, word):
"""Connect and send a 4letter command to Zookeeper.
"""
# Zookeeper closes the socket after every command, so we must reconnect every time.
tn = Telnet(self.host, self.port, self.timeout)
tn.write('{}\n'.format(word))
return tn.read_all()
if __name__ == '__main__':
plugin = PluginHelper()
plugin.parser.add_option("-H","--hostname", help="Zookeeper's host", default='127.0.0.1')
plugin.parser.add_option("-p","--port", help="Zookeeper's port", default='2181')
plugin.parse_arguments()
try:
zk = ZkClient(plugin.options.hostname, plugin.options.port)
except socket.error:
plugin.status(critical)
plugin.add_summary("Can't connect to {}:{}".format(plugin.options.hostname, plugin.options.port))
plugin.exit()
try:
if zk.cmd('ruok') != 'imok':
plugin.status(critical)
plugin.add_summary("Command 'ruok' failed")
plugin.exit()
except socket.error, socket.timeout:
plugin.status(critical)
示例7: PluginHelper
# 需要导入模块: from pynag.Plugins import PluginHelper [as 别名]
# 或者: from pynag.Plugins.PluginHelper import parse_arguments [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)
#.........这里部分代码省略.........