本文整理汇总了Python中pynag.Plugins.PluginHelper.status方法的典型用法代码示例。如果您正苦于以下问题:Python PluginHelper.status方法的具体用法?Python PluginHelper.status怎么用?Python PluginHelper.status使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pynag.Plugins.PluginHelper
的用法示例。
在下文中一共展示了PluginHelper.status方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from pynag.Plugins import PluginHelper [as 别名]
# 或者: from pynag.Plugins.PluginHelper import status [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()
示例2:
# 需要导入模块: from pynag.Plugins import PluginHelper [as 别名]
# 或者: from pynag.Plugins.PluginHelper import status [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()
示例3: str
# 需要导入模块: from pynag.Plugins import PluginHelper [as 别名]
# 或者: from pynag.Plugins.PluginHelper import status [as 别名]
service_ascii = [ord(c) for c in s]
# we need the length of the service name
length = str(len(s))
# make the oid
oid = base_oid + "." + length + "." + ".".join(str(x) for x in service_ascii)
return oid
if __name__ == "__main__":
# verify that a hostname is set
verify_host(host, helper)
sess = netsnmp.Session(Version=version, DestHost=host, Community=community)
# The default return value should be always OK
helper.status(ok)
# if no partition / disk is set, we will do a scan
if service == "" or service is None:
scan = True
##########
# Here we do a scan
##########
if scan:
services = walk_data(sess, base_oid, helper)[0]
if not services:
print "No services found - SNMP disabled?"
quit()
示例4: reload
# 需要导入模块: from pynag.Plugins import PluginHelper [as 别名]
# 或者: from pynag.Plugins.PluginHelper import status [as 别名]
import string
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
from BeautifulSoup import BeautifulSoup
from pynag.Plugins import PluginHelper,ok,warning,critical,unknown
p = PluginHelper()
default_url = 'http://www.isanicelandicvolcanoerupting.com'
p.parser.add_option('--url', dest='url', default=default_url)
p.parse_arguments()
p.show_legacy = True
html = requests.get(p.options.url).content
soup = BeautifulSoup(html)
answer = soup.find('h3').text
p.add_summary('Source says: "%s"' % answer)
if 'yes' in answer.lower():
p.status(warning)
elif 'no' in answer.lower():
p.status(ok)
else:
p.status(unknown)
p.check_all_metrics()
p.exit()
示例5: usage
# 需要导入模块: from pynag.Plugins import PluginHelper [as 别名]
# 或者: from pynag.Plugins.PluginHelper import status [as 别名]
descriptions=["Uptime", "Signal Strength", "CPU usage (1 Minute Average)", "CPU usage (5 Minute Average)",
"CPU usage (15 Minute Average)", "Total memory", "Free memory", "Tx Rate", "Rx Rate" ]
oids=[".1.3.6.1.2.1.1.3.0", ".1.3.6.1.4.1.14988.1.1.1.1.1.4", ".1.3.6.1.4.1.10002.1.1.1.4.2.1.3.1",
".1.3.6.1.4.1.10002.1.1.1.4.2.1.3.2",".1.3.6.1.4.1.10002.1.1.1.4.2.1.3.3",".1.3.6.1.4.1.10002.1.1.1.1.1.0",
".1.3.6.1.4.1.10002.1.1.1.1.2.0",".1.3.6.1.4.1.14988.1.1.1.1.1.2",".1.3.6.1.4.1.14988.1.1.1.1.1.3"]
units =['', '', '', '%', '%', '%', '', 'Byte', '', '' ]
##############
## Main ##
###############
if __name__ == '__main__':
# The default return value should be always OK
helper.status(ok)
# shows the list of possible types if the flag is set
if flag_list == True:
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
示例6: reload
# 需要导入模块: from pynag.Plugins import PluginHelper [as 别名]
# 或者: from pynag.Plugins.PluginHelper import status [as 别名]
reload(sys)
sys.setdefaultencoding('utf-8')
helper = PluginHelper()
helper.parse_arguments()
now = time.time()
url = 'http://www.einkamal.is'
html = requests.get(url).content
soup = BeautifulSoup(html)
tables = soup.find('div', {'class':'welcomemsg'})
p = tables.findAll('p')
li = soup.find('li',{'class':'accounts'})
active_accounts = li.find('b').text
active_accounts = active_accounts.replace('.','')
li = soup.find('li',{'class':'active'})
logged_in = li.find('b').text
logged_in = logged_in.replace('.','')
helper.add_metric('active users', active_accounts)
helper.add_metric('logged in users', logged_in)
helper.status(ok)
helper.add_summary("%s logged in users. %s active accounts" % (logged_in,active_accounts))
helper.exit()
示例7: PluginHelper
# 需要导入模块: from pynag.Plugins import PluginHelper [as 别名]
# 或者: from pynag.Plugins.PluginHelper import status [as 别名]
#!/usr/bin/env python
import requests
from BeautifulSoup import BeautifulSoup
from pynag.Plugins import PluginHelper,ok,warning,critical,unknown
p = PluginHelper()
p.parser.add_option('--url', dest='url', default='http://www.vedur.is')
p.parse_arguments()
html = requests.get(p.options.url).content
soup = BeautifulSoup(html)
warnings = soup.findAll('div', {'class':'warning'})
p.add_summary('%s warnings are being displayed on vedur.is' % len(warnings))
for i in warnings:
p.status(warning)
p.add_long_output( i.text )
p.status(ok)
p.check_all_metrics()
p.exit()
示例8: Thresholds
# 需要导入模块: from pynag.Plugins import PluginHelper [as 别名]
# 或者: from pynag.Plugins.PluginHelper import status [as 别名]
hostname = my_plugin.options.hostname
address = my_plugin.options.address
if hostname is None:
my_plugin.parser.error('-H argument is required')
# Here comes the specific check logic
try:
start_time = time.time()
result = socket.gethostbyname( hostname ) # result will contain the ip address resolved
end_time = time.time()
# If no address was specified with -a, then we return
# OK if hostname resolved to anything at all
if address is None or address == result:
my_plugin.status(ok)
my_plugin.add_summary("%s resolves to %s" % (hostname, result))
else:
my_plugin.status(critical)
my_plugin.add_summary("%s resolves to %s but should resolve to %s" % (hostname,result,address))
# Add run_time metric, so we can also alert if lookup takes to long
run_time = end_time - start_time
my_plugin.add_metric('run_time', run_time)
except gaierror:
# If any exceptions happened in the code above, lets return a critical status
my_plugin.status(critical)
my_plugin.add_summary('Could not resolve host "%s"' % hostname )
# when check_all_metrics() is run, any metrics we have added with add_metric() will be processed against
# Thresholds (like --threshold). This part will allow our plugin users to alert on lookup_time
示例9: PluginHelper
# 需要导入模块: from pynag.Plugins import PluginHelper [as 别名]
# 或者: from pynag.Plugins.PluginHelper import status [as 别名]
from BeautifulSoup import BeautifulSoup
from pynag.Plugins import PluginHelper,ok,warning,critical,unknown
p = PluginHelper()
default_url = 'https://api.eveonline.com/server/ServerStatus.xml.aspx/'
p.parser.add_option('--url', dest='url', default=default_url)
p.parse_arguments()
p.show_legacy = True
try:
html = requests.get(p.options.url).content
except Exception, e:
p.status(unknown)
p.add_summary("%s error encountered while trying to connect to EVE api: %s" % (type(e), e))
p.exit()
soup = BeautifulSoup(html)
serverOpen = soup.findAll('serveropen')
onlinePlayers = soup.findAll('onlineplayers')
if not serverOpen or not onlinePlayers:
p.status(unknown)
p.add_summary("Failed to get all metrics from EVE API")
p.add_long_output("HTTP request returned:")
p.add_long_output(html)
p.exit()
示例10: PluginHelper
# 需要导入模块: from pynag.Plugins import PluginHelper [as 别名]
# 或者: from pynag.Plugins.PluginHelper import status [as 别名]
from BeautifulSoup import BeautifulSoup
from pynag.Plugins import PluginHelper,ok,warning,critical,unknown
p = PluginHelper()
chars = string.letters + string.digits
randomstring= ''.join([random.choice(chars) for i in xrange(4)]) # avoid cache
default_url = 'http://www.vedur.is/ofanflod/snjoflodaspa'
p.parser.add_option('--url', dest='url', default=default_url)
p.parse_arguments()
p.show_legacy = True
html = requests.get(p.options.url).content
# Initial Status is OK, unless avalanche threats detected.
p.status(ok)
# We are going to parse the html and look for certain divs, according to the vedur.is page
# it should have the following threat codes:
# <div class="lev1"> <!-- Low risk -->
# <div class="lev2"> <!-- some risk-->
# <div class="lev3"> <!-- Considerable risk -->
# <div class="lev4"> <!-- High risk -->
# <div class="lev5"> <!-- Very high risk -->
soup = BeautifulSoup(html)
lev1 = soup.findAll('div', {'class':'lev1'})
lev2 = soup.findAll('div', {'class':'lev2'})
lev3 = soup.findAll('div', {'class':'lev3'})
lev4 = soup.findAll('div', {'class':'lev4'})
lev5 = soup.findAll('div', {'class':'lev5'})
示例11: sensor
# 需要导入模块: from pynag.Plugins import PluginHelper [as 别名]
# 或者: from pynag.Plugins.PluginHelper import status [as 别名]
9 : "%",
10: "ms",
11: "Pa",
12: "psi",
13: "g",
14: "F",
15: "feet",
16: "inches",
17: "cm",
18: "meters",
19: "rpm",
20: "degrees",
}
# The default return value should be always OK
helper.status(ok)
######
## here we check the inlet
######
if typ.lower() == "inlet":
# OIDs for Inlet from PDU2-MIB
oid_inlet_value = '.1.3.6.1.4.1.13742.6.5.2.3.1.4' # the value from the sensor (must be devided by the digit)
oid_inlet_unit = '.1.3.6.1.4.1.13742.6.3.3.4.1.6' # the unit of the value
oid_inlet_digits = '.1.3.6.1.4.1.13742.6.3.3.4.1.7' # the digit we need for the real_value
oid_inlet_state = '.1.3.6.1.4.1.13742.6.5.2.3.1.3' # the state if this is ok or not ok
oid_inlet_warning_upper = '.1.3.6.1.4.1.13742.6.3.3.4.1.24' # warning_upper_threhsold (must be divided by the digit)
oid_inlet_critical_upper = '.1.3.6.1.4.1.13742.6.3.3.4.1.23' # critical_upper_threhold (must be divided by the digit)
oid_inlet_warning_lower = '.1.3.6.1.4.1.13742.6.3.3.4.1.22'
oid_inlet_critical_lower = '.1.3.6.1.4.1.13742.6.3.3.4.1.21'
示例12:
# 需要导入模块: from pynag.Plugins import PluginHelper [as 别名]
# 或者: from pynag.Plugins.PluginHelper import status [as 别名]
# Lets Parse the data:
my_plugin.add_summary( "%s seconds response time" % results['ResponseTime'])
# and add metrics:
my_plugin.add_metric( label='Total Accesses', value=results['Total Accesses'], uom='c', )
my_plugin.add_metric( label='Total kBytes', value=results['Total kBytes'], uom='kb', )
my_plugin.add_metric( label='CPULoad', value=float(results['CPULoad'])*100, uom='%', )
my_plugin.add_metric( label='Uptime', value=results['Uptime'], uom='c', )
my_plugin.add_metric( label='ReqPerSec', value=results['ReqPerSec'], )
my_plugin.add_metric( label='BytesPerSec', value=results['BytesPerSec'], uom='b', )
my_plugin.add_metric( label='BytesPerReq', value=results['BytesPerReq'], uom='b', )
my_plugin.add_metric( label='BusyWorkers', value=results['BusyWorkers'], )
my_plugin.add_metric( label='IdleWorkers', value=results['IdleWorkers'], )
my_plugin.add_metric( label='ResponseTime', value=results['ResponseTime'], uom='s',warn=my_plugin.options.warning, crit=my_plugin.options.critical )
my_plugin.add_metric( label='Open slots', value=results['OpenSlots'] )
# By default assume everything is ok. Any thresholds specified with --threshold can overwrite this status:
my_plugin.status(ok)
# Here all metrics will be checked against thresholds that are either
# built-in or added via --threshold from the command-line
my_plugin.check_all_metrics()
# Print out plugin information and exit nagios-style
my_plugin.exit()
示例13: Telnet
# 需要导入模块: from pynag.Plugins import PluginHelper [as 别名]
# 或者: from pynag.Plugins.PluginHelper import status [as 别名]
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)
plugin.add_summary("Can't connect to {}:{}".format(plugin.options.hostname, plugin.options.port))
plugin.exit()
try:
if zk.cmd('isro') != 'rw':