• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python Plugins.PluginHelper类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了PluginHelper类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: PluginHelper

#!/usr/bin/env python
# 
# This script check volcano eruption status in iceland 
#
#

from PIL import Image
from collections import defaultdict
from pynag.Plugins import PluginHelper,ok,warning,critical,unknown
import requests
import cStringIO


url = 'http://hraun.vedur.is/ja/eldgos/volcano_status.png'

p = PluginHelper()
p.parse_arguments()
p.show_legacy = True

tmp = requests.get(url)
image_file = cStringIO.StringIO(tmp.content)

image = Image.open(image_file)

p.add_summary("Volcano data last updated: %s." % (tmp.headers['last-modified']))

width = image.size[0]
height = image.size[1]


colormap = defaultdict(int)
开发者ID:arthurtiteica,项目名称:monitor-iceland,代码行数:31,代码来源:check_volcano.py


示例17: PluginHelper

# check_dns.py -- Returns OK if a hostname resolves to any ip address

# check_dns plugin will need some system libraries for DNS lookup
from _socket import gaierror
import socket
import time

# Import PluginHelper and some utility constants from the Plugins module
from pynag.Plugins import PluginHelper,ok,warning,critical,unknown

# Create an instance of PluginHelper()
my_plugin = PluginHelper()

# Our Plugin will need -H and -a attributes and we will use PluginHelpers wrapper around optparse for this:
my_plugin.parser.add_option('-H', help="Hostname or ip address", dest="hostname")
my_plugin.parser.add_option('-a', help="Expected Address", dest="address")

# When parse_arguments is called some default options like --threshold and --no-longoutput are automatically added
my_plugin.parse_arguments()


#
# Here starts Plugin-specific logic
#

# Get the hostname and expected address that was provided on the command-line
# address will be optional, but we will throw and error if hostname is not provided
hostname = my_plugin.options.hostname
address = my_plugin.options.address
if hostname is None:
    my_plugin.parser.error('-H argument is required')
开发者ID:AccelerationNet,项目名称:pynag,代码行数:31,代码来源:check_dns.py


示例18: PluginHelper

#!/usr/bin/env python
####################### check_apachestatus.py #######################
# Licence : GPL - http://www.fsf.org/licenses/gpl.txt
#############################################################
# Inspired by De Bodt Lieven's perl implementation
# 20140428 <morgajel at gmail dot com> v1.6
#          rewriting in python

from pynag.Plugins import PluginHelper,ok,warning,critical,unknown
import urllib2
import re
import sys
import time

# Create an instance of PluginHelper()
my_plugin = PluginHelper()

# Add all of our wonderful flags
my_plugin.parser.add_option('-H', '--hostname', type="string",      default="127.0.0.1",    dest="hostname" )
my_plugin.parser.add_option('-p', '--port',     type="int",         default="80",           dest="port" )
my_plugin.parser.add_option('-s', '--ssl',      help="enable ssl",  action="store_true",    dest="ssl" )  
my_plugin.parser.add_option('-w', '--warning',  type="string",      default="5",            dest="warning" )
my_plugin.parser.add_option('-c', '--critical', type="string",      default="10",           dest="critical" )
my_plugin.parse_arguments()


# Set the proper protocol
if my_plugin.options.ssl:
    my_plugin.options.protocol='https'
else:
    my_plugin.options.protocol='http'
开发者ID:morgajel,项目名称:morgnagplug,代码行数:31,代码来源:check_apachestatus.py


示例19: PluginHelper

#!/usr/bin/env python

import requests

from BeautifulSoup import BeautifulSoup
from pynag.Plugins import PluginHelper,ok,warning,critical,unknown
import simplejson as json


p = PluginHelper()

p.parser.add_option('--url', dest='url', default='http://api.gulur.is/buses/?geo=true&latitude=64.1251991&longitude=-21.8108419&accuracy=20&range=restOfDay&radius=750000')
p.parse_arguments()
html = requests.get(p.options.url).content
json_data = json.loads(html)

buses_running = len(json_data)
p.add_metric('buses running', buses_running)
p.add_summary('%s buses are currently running' % (buses_running))
  
print json.dumps(json_data[0], indent=4)

p.check_all_metrics()
p.exit()

开发者ID:arthurtiteica,项目名称:monitor-iceland,代码行数:24,代码来源:check_gulur.py


示例20: walk_data

def walk_data(host, version, community, oid):
    var = netsnmp.Varbind(oid)
    try:
        data = netsnmp.snmpwalk(var, Version=version, DestHost=host, Community=community)
    except:
        helper.exit(summary="\n SNMP connection to device failed " + oid, exit_code=unknown, perfdata='')
    if not data:
        helper.exit(summary="\n SNMP connection to device failed " + oid, exit_code=unknown, perfdata='')
    return data

# function to calculate the real value
def real_value(value, digit):
    return str(float(value) / math.pow(10, float(digit)))

# Create an instance of PluginHelper()
helper = PluginHelper()

# define the command line options
helper.parser.add_option('-H', help="Hostname or ip address", dest="hostname")
helper.parser.add_option('-C', '--community', dest='community', help='SNMP community of the SNMP service on target host.', default='public')
helper.parser.add_option('-V', '--snmpversion', dest='version', help='SNMP version. (1 or 2)', default=2, type='int')
helper.parser.add_option('-t', help="The type you want to monitor (inlet, outlet, sensor)", default="inlet", dest="typ")
helper.parser.add_option('-i', help="The id of the outlet / sensor you want to monitor (1-99)", default="1", dest="id")
helper.parse_arguments()

# get the options
id = helper.options.id
typ = helper.options.typ
host = helper.options.hostname
version = helper.options.version
community = helper.options.community
开发者ID:rsmm01,项目名称:check_snmp_raritan,代码行数:31,代码来源:check_snmp_raritan.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python Plugins.simple类代码示例发布时间:2022-05-27
下一篇:
Python log.info函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap