本文整理汇总了Python中pynag.Plugins.PluginHelper类的典型用法代码示例。如果您正苦于以下问题:Python PluginHelper类的具体用法?Python PluginHelper怎么用?Python PluginHelper使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PluginHelper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
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')
示例2: PluginHelper
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with check_snmp_large_storage.py. If not, see <http://www.gnu.org/licenses/>.
# Import PluginHelper and some utility constants from the Plugins module
import sys
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, get_data, walk_data, add_snmpv3_options
from pynag.Plugins import PluginHelper, ok, unknown
# Create an instance of PluginHelper()
helper = PluginHelper()
# Add command line parameters
add_common_options(helper)
add_snmpv3_options(helper)
helper.parser.add_option('-p', '--partition',
dest='partition',
help='The disk / partition you want to monitor',
type='str')
helper.parser.add_option('-u', '--unit', dest="targetunit", help="The unit you want to have (MB, GB, TB)", default="GB")
helper.parser.add_option('-s', '--scan', dest='scan_flag', default=False, action="store_true",
help='Show all available storages')
helper.parse_arguments()
# get the options
示例3: PluginHelper
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with check_snmp_service.py. If not, see <http://www.gnu.org/licenses/>.
# Import PluginHelper and some utility constants from the Plugins module
import sys
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"
示例4: reload
#!/usr/bin/env python
import requests
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)
示例5: PluginHelper
# 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: reload
from dateutil.parser import parse
import requests
import sys
import time
from BeautifulSoup import BeautifulSoup
from pynag.Plugins import PluginHelper,ok,warning,critical,unknown
reload(sys)
sys.setdefaultencoding('utf-8')
helper = PluginHelper()
helper.parse_arguments()
helper.show_legacy = True
now = time.time()
url = 'http://hraun.vedur.is/ja/skjalftar/skjlisti.html'
html = requests.get(url).content
soup = BeautifulSoup(html)
tables = soup.findAll('table')
earthquakes = tables[2]
rows = earthquakes.findAll('tr')
header_row = rows.pop(0)
lines = []
recent_earthquakes = 0
major_earthquakes = 0
示例7: PluginHelper
# check_snimpy.py - Check arbitrary snmp values using snimpy. Thresholds can be specified from the commandline
# Import PluginHelper and some utility constants from the Plugins module
from pynag.Plugins import PluginHelper,ok,warning,critical,unknown
# Import Snimpy
from snimpy.manager import Manager
from snimpy.manager import load
import re
import memcache
import time
# Create an instance of PluginHelper()
helper = PluginHelper()
# Optionally, let helper handle command-line arguments for us for example --threshold
# Note: If your plugin needs any commandline arguments on its own (like --hostname) you should add them
# before this step with helper.parser.add_option()
helper.parser.add_option("-n", help="Interface name (regex)", dest="name", default='.')
helper.parser.add_option("-H", help="Hostname or IP", dest="host", default='localhost')
helper.parser.add_option("--Version", help="Snmp Version", dest="version", default='2')
helper.parser.add_option("-c", help="Snmp Comunity", dest="community", default='public')
helper.parse_arguments()
# Here starts our plugin specific logic. Lets try to read /proc/loadavg
# And if it fails, we exit immediately with UNKNOWN status
示例8: PluginHelper
#!/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()
示例9: PluginHelper
#!/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()
示例10: PluginHelper
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along check_snmp_lband.py. If not, see <http://www.gnu.org/licenses/>.
import sys
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, get_data
from pynag.Plugins import PluginHelper,ok,warning,critical,unknown
# Create an instance of PluginHelper()
helper = PluginHelper()
# Define the command line options
add_common_options(helper)
helper.parser.add_option('-U', '--unit', dest='unit', help='Select the unit you want to monitor, if no unit is selected both units will be monitored', default="1")
helper.parse_arguments()
# get the options
host, version, community = get_common_options(helper)
unit = helper.options.unit
# OIDs from 2082-141.mib.txt
unit1_oid = ".1.3.6.1.4.1.31210.52.1.9.0"
unit2_oid = ".1.3.6.1.4.1.31210.52.1.13.0"
status = {
示例11: PluginHelper
#!/usr/bin/python
# check_snimpy.py - Check arbitrary snmp values using snimpy. Thresholds can be specified from the commandline
# Import PluginHelper and some utility constants from the Plugins module
from pynag.Plugins import PluginHelper,ok,warning,critical,unknown
# Import Snimpy
from snimpy.manager import Manager
from snimpy.manager import load
# Create an instance of PluginHelper()
helper = PluginHelper()
# Optionally, let helper handle command-line arguments for us for example --threshold
# Note: If your plugin needs any commandline arguments on its own (like --hostname) you should add them
# before this step with helper.parser.add_option()
helper.parser.add_option("-H", help="Hostname or IP", dest="host", default='localhost')
helper.parser.add_option("--Version", help="Snmp Version", dest="version", default='2')
helper.parser.add_option("-c", help="Snmp Comunity", dest="community", default='public')
helper.parse_arguments()
mib='/usr/share/mibs/site/NetSure-SCU-Plus'
# Here starts our plugin specific logic. Lets try to read /proc/loadavg
# And if it fails, we exit immediately with UNKNOWN status
try:
load(mib)
except Exception, e:
helper.exit(summary="Could not read MIB file.", long_output=str(e), exit_code=unknown, perfdata='')
示例12: PluginHelper
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with check_snmp_teledyne.py. If not, see <http://www.gnu.org/licenses/>.
# Import PluginHelper and some utility constants from the Plugins module
import sys
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, get_data
from pynag.Plugins import PluginHelper,ok,critical
# Create an instance of PluginHelper()
helper = PluginHelper()
# add the common command line options
add_common_options(helper)
helper.parse_arguments()
# get the options
host, version, community = get_common_options(helper)
# OIDs from MBG-LANTIME-NG-MIB.mib
oids = {
"Unit 1" : "iso.3.6.1.4.1.20712.2.1.3.1.2.1",
"Unit 2" : "iso.3.6.1.4.1.20712.2.1.3.1.2.2",
"Unit 3" : "iso.3.6.1.4.1.20712.2.1.3.1.2.3",
"Fault Summary" : "iso.3.6.1.4.1.20712.2.1.3.1.2.4",
示例13: cmd
self.port = port
self.timeout = timeout
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")
示例14: PluginHelper
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with check_snmp_fortinet.py. If not, see <http://www.gnu.org/licenses/>.
# Import PluginHelper and some utility constants from the Plugins module
import sys
import os
import math
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, get_data, walk_data
from pynag.Plugins import PluginHelper,ok,warning,critical,unknown
# Create an instance of PluginHelper()
helper = PluginHelper()
# define the command line options
add_common_options(helper)
helper.parser.add_option('-t', '--type', dest='type', default="ressources", help = "Check type to execute. Available types are: ressources, controller, accesspoints", type='str')
helper.parse_arguments()
# get the options
type = helper.options.type
host, version, community = get_common_options(helper)
# these dicts / definitions we need to get human readable values
operational_states = {
0 : "unknown",
1 : "enabled",
示例15: main
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()