當前位置: 首頁>>代碼示例>>Python>>正文


Python Plugins.PluginHelper類代碼示例

本文整理匯總了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')
開發者ID:dekimsey,項目名稱:pynag,代碼行數:7,代碼來源:plugintest.py

示例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
開發者ID:rsmuc,項目名稱:health_monitoring_plugins,代碼行數:31,代碼來源:check_snmp_large_storage.py

示例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"
開發者ID:rsmuc,項目名稱:health_monitoring_plugins,代碼行數:31,代碼來源:check_snmp_service.py

示例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)
開發者ID:arthurtiteica,項目名稱:monitor-iceland,代碼行數:30,代碼來源:check_takktakkvolcano.py

示例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()
開發者ID:AccelerationNet,項目名稱:pynag,代碼行數:15,代碼來源:check_stuff.py

示例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
開發者ID:arthurtiteica,項目名稱:monitor-iceland,代碼行數:29,代碼來源:check_earthquake.py

示例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
開發者ID:jasperGreve,項目名稱:monplugs,代碼行數:31,代碼來源:check_interfaces_byName.py

示例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()

開發者ID:arthurtiteica,項目名稱:monitor-iceland,代碼行數:23,代碼來源:check_weather.py

示例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()
開發者ID:abhinav-upadhyay,項目名稱:pynag,代碼行數:26,代碼來源:fakepluginhelper.py

示例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 = {
開發者ID:rsmuc,項目名稱:health_monitoring_plugins,代碼行數:31,代碼來源:check_snmp_lband.py

示例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='')
開發者ID:jasperGreve,項目名稱:monplugs,代碼行數:31,代碼來源:check_scu_plus.py

示例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",
開發者ID:rsmuc,項目名稱:health_monitoring_plugins,代碼行數:31,代碼來源:check_snmp_teledyne.py

示例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")
開發者ID:funollet,項目名稱:nagios-plugins,代碼行數:31,代碼來源:check_zookeeper.py

示例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",    
開發者ID:rsmuc,項目名稱:health_monitoring_plugins,代碼行數:31,代碼來源:check_snmp_fortinet.py

示例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()
開發者ID:triicst,項目名稱:nagios-plugins,代碼行數:49,代碼來源:check_memory.py


注:本文中的pynag.Plugins.PluginHelper類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。