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

Python Plugins.simple类代码示例

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

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



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

示例1: testPlugin

class testPlugin(unittest.TestCase):
    def setUp(self):
        self.argv_store = sys.argv
        from pynag.Plugins import simple as Plugin
        self.np = Plugin()
        sys.stdout = StringIO()
        sys.stderr = StringIO()
    def tearDown(self):
        sys.argv = self.argv_store
        sys.stdout = original_stdout
        sys.stderr = original_stderr

    def run_expect(self, case, expected_exit, value):
        sys.argv = [sys.argv[0]] + case.split()
        self.np.activate()
        try:
            self.np.add_perfdata('fake', value, uom='fakes',
                                 warn=10, crit=20, minimum=-100, maximum=100)
            perfdata_string = self.np.perfdata_string()
            print perfdata_string
            self.assertEquals(perfdata_string, "| '%s'=%s%s;%s;%s;%s;%s" % (
                              'fake', value, 'fakes', 10, 20, -100, 100))
            self.np.add_message('OK', 'Some message')
            self.assertEquals(self.np.data['messages'][0], ['Some message'])
            self.np.check_range(value)
        except SystemExit, e:
            self.assertEquals(type(e), type(SystemExit()))
            self.assertEquals(e.code, expected_exit)
        except Exception, e:
            import traceback
            print traceback.format_exc()
            self.fail('unexpected exception: %s' % e)
开发者ID:bnrubin,项目名称:pynag,代码行数:32,代码来源:plugintest.py


示例2: testPluginNoThreshold

class testPluginNoThreshold(unittest.TestCase):
    def setUp(self):
        self.argv_store = sys.argv
        from pynag.Plugins import simple as Plugin
        self.np = Plugin(must_threshold=False)
    def tearDown(self):
        sys.argv = self.argv_store
    def run_expect(self, case, expected_exit, value):
        sys.argv = [sys.argv[0]] + case.split()
        self.np.activate()
        try:
            self.np.check_range(value)
        except SystemExit, e:
            self.assertEquals(type(e), type(SystemExit()))
            self.assertEquals(e.code, expected_exit)
        except Exception, e:
            self.fail('unexpected exception: %s' % e)
开发者ID:abhinav-upadhyay,项目名称:pynag,代码行数:17,代码来源:plugintest.py


示例3: PluginNoThreshold

class PluginNoThreshold(unittest.TestCase):

    def setUp(self):
        self.argv_store = sys.argv
        from pynag.Plugins import simple as Plugin
        self.np = Plugin(must_threshold=False)
        sys.stdout = StringIO()

    def tearDown(self):
        sys.argv = self.argv_store
        sys.stdout = original_stdout

    def run_expect(self, case, expected_exit, value):
        sys.argv = [sys.argv[0]] + case.split()
        self.np.activate()
        try:
            self.np.check_range(value)
        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')

    # All tests return OK since thresholds are not required
    def test_number_1(self):
        case = ''
        self.run_expect(case, 0, -23)

    def test_number_2(self):
        case = ''
        self.run_expect(case, 0, 0)

    def test_number_3(self):
        case = ''
        self.run_expect(case, 0, 2)

    def test_number_4(self):
        case = ''
        self.run_expect(case, 0, 10)

    def test_number_5(self):
        case = ''
        self.run_expect(case, 0, 15)
开发者ID:AccelerationNet,项目名称:pynag,代码行数:45,代码来源:test_plugins.py


示例4: PluginParams

class PluginParams(unittest.TestCase):

    def setUp(self):
        self.argv_store = sys.argv
        from pynag.Plugins import simple as Plugin
        self.np = Plugin(must_threshold=False)
        sys.stdout = StringIO()

    def tearDown(self):
        sys.argv = [sys.argv[0]]
        sys.stdout = original_stdout

    def create_params(self, *args):
        sys.argv.extend(args)

    def test_default_verbose(self):
        #sys.argv = [sys.argv[0]] + ['-v', '10']
        self.create_params('-v', '10')
        self.np.activate()
        self.assertEquals(self.np.data['verbosity'], 0)

    def test_verbose(self):
        self.create_params('-v', '3')
        self.np.activate()
        self.assertEquals(self.np.data['verbosity'], 3)

    def test_set_hostname(self):
        self.create_params('-H', 'testhost.example.com')
        self.np.activate()
        self.assertEquals(self.np.data['host'], 'testhost.example.com')

    def test_set_timeout(self):
        self.create_params('-t', '100')
        self.np.activate()
        self.assertEquals(self.np.data['timeout'], '100')

    def test_default_timeout(self):
        self.np.activate()
        self.assertEquals(self.np.data['timeout'], None)

    def test_shortname(self):
        from pynag.Plugins import simple as Plugin
        np = Plugin(shortname='testcase')
        self.assertEquals(np.data['shortname'], 'testcase')
开发者ID:AccelerationNet,项目名称:pynag,代码行数:44,代码来源:test_plugins.py


示例5: Plugin

#!/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
import pynag.Plugins
from pynag.Plugins import WARNING, CRITICAL, OK, UNKNOWN, simple as Plugin

np = Plugin()

# Feed fake data for range checking
np.add_arg('F', 'fakedata', 'fake data to test thresholds', required=True)

# Activate
np.activate()

# Test supplied fake data against thresholds
np.check_range(int(np['fakedata']))

开发者ID:a3linux,项目名称:pynag,代码行数:22,代码来源:fakeplugin.py


示例6: Plugin

#!/usr/bin/python
import os,sys

## This is for the custom nagios module
sys.path.insert(1, '../')
from pynag.Plugins import simple as Plugin


## Create the plugin option
np = Plugin()

## Add a command line argument
np.add_arg("l","load-file", "Enter a load average file", required=None)

## This starts the actual plugin activation
np.activate()

## Use a custom load average file, if specified to
if np['load-file']:
	load_file = np['load-file']
else:
	load_file = "/proc/loadavg"

if not os.path.isfile(load_file):
	np.nagios_exit("UNKNOWN", "Missing Load average file %s" % load_file)

## Get the check value
current_load = os.popen("cat %s" % load_file).readline().split()[0]

## Add the perdata
np.add_perfdata("1min", current_load)
开发者ID:rtucker-mozilla,项目名称:pynag,代码行数:31,代码来源:check_cpu.py


示例7: Plugin

#! /usr/bin/python

from pynag.Plugins import WARNING, CRITICAL, OK, UNKNOWN, simple as Plugin
import boto


## Create the plugin option
np = Plugin()

## Add a command line argument
np.add_arg("n","name", "Amazon ELB name", required=True)
np.add_arg("i","instance", "Amazon EC2 instance ID", required=True)

## This starts the actual plugin activation
np.activate()

## Use specified ELB name
elb_name = np['name']
instance_id = np['instance']

## Unable to connect
try:
  conn = boto.connect_elb()
except boto.exception.NoAuthHandlerFound:
  np.nagios_exit(UNKNOWN, "Unable to log into AWS. Please Check your /etc/boto.cfg file or AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variable.")

## Unable to get elbs
try:
  instances_health = conn.describe_instance_health(elb_name)
except:
  np.nagios_exit(UNKNOWN, "Unable to get elb list. Is network up ? Is region configured ? (Region %s)" % ( conn.DefaultRegionName))
开发者ID:Carpe-Hora,项目名称:nagios-ec2-plugins,代码行数:31,代码来源:check_ec2_elb_is_instance_registred.py


示例8: Plugin

#! /usr/bin/python

from pynag.Plugins import WARNING, CRITICAL, OK, UNKNOWN, simple as Plugin
import boto
import boto.ec2


## Create the plugin option
np = Plugin()

## Add a command line argument
np.add_arg("i","instance-id", "Amazon EC2 Instance ID", required=True)

## This starts the actual plugin activation
np.activate()

## Use specified Instance ID
ec2_instance_id = np['i']

## Unable to connect
try:
  conn = boto.connect_ec2()
except boto.exception.NoAuthHandlerFound:
  np.nagios_exit(UNKNOWN, "Unable to log into AWS. Please Check your /etc/boto.cfg file or AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variable.")

## Unable to get instance status
try:
  instance = conn.get_all_instance_status(ec2_instance_id)[0]
except:
  np.nagios_exit(UNKNOWN, "Unable to get instance %s. Is network up ? Is region configured ? (Region %s)" % ( ec2_instance_id, conn.DefaultRegionName))
开发者ID:Carpe-Hora,项目名称:nagios-ec2-plugins,代码行数:30,代码来源:check_ec2_instance_status.py


示例9: setUp

 def setUp(self):
     self.argv_store = sys.argv
     from pynag.Plugins import simple as Plugin
     self.np = Plugin(must_threshold=False)
     sys.stdout = StringIO()
开发者ID:bnrubin,项目名称:pynag,代码行数:5,代码来源:plugintest.py


示例10: setUp

 def setUp(self):
     self.argv_store = sys.argv
     from pynag.Plugins import simple as Plugin
     self.np = Plugin()
开发者ID:abhinav-upadhyay,项目名称:pynag,代码行数:4,代码来源:plugintest.py


示例11: Plugin

class Plugin(unittest.TestCase):

    def setUp(self):
        self.argv_store = sys.argv
        from pynag.Plugins import simple as Plugin
        self.np = Plugin()
        sys.stdout = StringIO()
        sys.stderr = StringIO()

    def tearDown(self):
        sys.argv = self.argv_store
        sys.stdout = original_stdout
        sys.stderr = original_stderr

    def run_expect(self, case, expected_exit, value):
        sys.argv = [sys.argv[0]] + case.split()
        self.np.activate()
        try:
            self.np.add_perfdata('fake', value, uom='fakes',
                                 warn=10, crit=20, minimum=-100, maximum=100)
            perfdata_string = self.np.perfdata_string()
            print(perfdata_string)
            self.assertEquals(perfdata_string, "| '%s'=%s%s;%s;%s;%s;%s" % (
                              'fake', value, 'fakes', 10, 20, -100, 100))
            self.np.add_message('OK', 'Some message')
            self.assertEquals(self.np.data['messages'][0], ['Some message'])
            self.np.check_range(value)
        except SystemExit as e:
            self.assertEquals(type(e), type(SystemExit()))
            self.assertEquals(e.code, expected_exit)
        except Exception as e:
            import traceback
            print(traceback.format_exc())
            self.fail('unexpected exception: %s' % e)
        else:
            self.fail('SystemExit exception expected')

    # Throws SystemExit, required parameter not set when activating
    def test_add_arg_req_missing(self):
        self.np.add_arg('F', 'fakedata',
                        'fake data to test thresholds', required=True)
        self.assertRaises(SystemExit, self.np.activate)

    def test_add_arg_req(self):
        self.np.add_arg('F', 'fakedata',
                        'fake data to test thresholds', required=True)
        sys.argv = [sys.argv[0]] + '-F 100 -w 1 -c 2'.split()
        self.np.activate()

    def test_add_arg(self):
        self.np.add_arg('F', 'fakedata',
                        'fake data to test thresholds', required=False)
        sys.argv = [sys.argv[0]] + '-w 1 -c 2'.split()
        self.np.activate()

    def test_codestring_to_int(self):
        code = self.np.code_string2int('OK')
        self.assertEquals(code, 0, "OK did not map to 0")

        code = self.np.code_string2int('WARNING')
        self.assertEquals(code, 1, "WARNING did not map to 1")

        code = self.np.code_string2int('CRITICAL')
        self.assertEquals(code, 2, "CRITICAL did not map to 2")

        code = self.np.code_string2int('UNKNOWN')
        self.assertEquals(code, 3, "UNKNOWN did not map to 3")

    # 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 = '-w 10 -c 20'
        self.run_expect(case, 2, -23)

    def test_number_2(self):
        case = '-w 10 -c 20'
        self.run_expect(case, 0, 3)

    def test_number_3(self):
        case = '-w 10 -c 20'
        self.run_expect(case, 1, 13)

    def test_number_4(self):
        case = '-w 10 -c 20'
        self.run_expect(case, 2, 23)

    # Same as above. Negative "stuff" is OK
    def test_number_5(self):
        case = '-w ~:10 -c ~:20'
        self.run_expect(case, 0, -23)

    def test_number_6(self):
        case = '-w ~:10 -c ~:20'
        self.run_expect(case, 0, 3)

    def test_number_7(self):
        case = '-w ~:10 -c ~:20'
        self.run_expect(case, 1, 13)

    def test_number_8(self):
#.........这里部分代码省略.........
开发者ID:AccelerationNet,项目名称:pynag,代码行数:101,代码来源:test_plugins.py


示例12: Plugin

#! /usr/bin/python

from pynag.Plugins import WARNING, CRITICAL, OK, UNKNOWN, simple as Plugin
import boto

## Create the plugin option
np = Plugin()

## Add a command line argument
np.add_arg("n","name", "Amazon ELB name", required=True)

## This starts the actual plugin activation
np.activate()

## Use specified ELB name
elb_name = np['name']

## Unable to connect
try:
  conn = boto.connect_elb()
except boto.exception.NoAuthHandlerFound:
  np.nagios_exit(UNKNOWN, "Unable to log into AWS. Please Check your /etc/boto.cfg file or AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variable.")


## Unable to get elbs
try:
  elbs = conn.get_all_load_balancers(elb_name)
except:
  np.nagios_exit(UNKNOWN, "Unable to get elb list. Is network up ? Is region configured ? (Region %s)" % ( conn.DefaultRegionName))

# Return value
开发者ID:Carpe-Hora,项目名称:nagios-ec2-plugins,代码行数:31,代码来源:check_ec2_elb_exist.py


示例13: Disque

#!/usr/bin/env python
# coding: utf-8

import sys
from pydisque.client import Client
from pynag.Plugins import CRITICAL, simple as Plugin


np = Plugin(must_threshold=False)
np.activate()


try:
    client = Client()   # Client(['127.0.0.1:7711'])
    client.connect()
except:
    np.nagios_exit(
        CRITICAL,
        'Mayby disque is down.',
    )
    sys.exit(1)

class Disque(object):
    def __init__(self):
        self.__info = client.execute_command('INFO')
        self.create_properties()

    def create_properties(self):
        for k, v in self.__info.iteritems():
            self.__dict__[k] = v
开发者ID:nabetama,项目名称:disque-info-nagios-plugin,代码行数:30,代码来源:check_disq.py


示例14: Plugin

#!/opt/zenoss/bin/python

#Script dependencies:
# pynag, subprocess

import os,sys, subprocess, re
from pynag.Plugins import WARNING, CRITICAL, OK, UNKNOWN, simple as Plugin
from pexpect import ANSI, fdpexpect, FSM, pexpect, pxssh, screen

#Create the plugin option
np = Plugin()

#Configure additional command line arguments
np.add_arg("R", "ssh_host", "Ssh remote machine name to connect to", required=True)
np.add_arg("P", "ssh_password", "Ssh romote host password", required=None)
np.add_arg("U", "ssh_username", "Ssh remote username", required=None)
np.add_arg("s", "ssh_port", "Ssh remote host port (default: 22)", required=None)
np.add_arg("l", "query_address", "Machine name to lookup", required=True)
np.add_arg("p", "port", "DNS Server port number (default: 53)", required=None)
np.add_arg("T", "record_type", "Record type to lookup (default: A)", required=None)
np.add_arg("a", "expected_address", "An address expected to be in the answer section. If not set, uses whatever was in query address", required=None)
np.add_arg("A", "dig-arguments", "Pass the STRING as argument(s) to dig", required=None)

#Plugin activation
np.activate()

#Main script logic 8-)
CMD_ITEM_1 = "dig"
CMD_ITEM_2 = " "             #Here we should insert a servername/ip
CMD_ITEM_3 = " "        #Here should be the port for a server/ip (default: 53)
CMD_ITEM_4 = " "             #Machine name to lookup
开发者ID:thomasvincent,项目名称:MonitoringPlugins,代码行数:31,代码来源:check_dig.py


示例15: Plugin

#! /usr/bin/python

from pynag.Plugins import WARNING, CRITICAL, OK, UNKNOWN, simple as Plugin
import boto


## Create the plugin option
np = Plugin()

## Add a command line argument
np.add_arg("n","name", "Amazon ELB name", required=True)
np.add_arg("N","numbers", "Numbers of desired instance running in the pool. Default will be half total number of node", required=False)

## This starts the actual plugin activation
np.activate()

## Use specified ELB name
elb_name = np['name']

## Unable to connect
try:
  conn = boto.connect_elb()
except boto.exception.NoAuthHandlerFound:
  np.nagios_exit(UNKNOWN, "Unable to log into AWS. Please Check your /etc/boto.cfg file or AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variable.")

## Unable to get elbs
try:
  instances_health = conn.describe_instance_health(elb_name)
except:
  np.nagios_exit(UNKNOWN, "Unable to get elb list. Is network up ? Is region configured ? (Region %s)" % ( conn.DefaultRegionName))
开发者ID:Carpe-Hora,项目名称:nagios-ec2-plugins,代码行数:30,代码来源:check_ec2_elb_registred_instance_number.py


示例16: main

def main():
    global np
    np = Plugin(must_threshold=False)

    np.add_arg('w', 
               'warning', 
               'Warn when X days until certificate expires', 
               required=None)
    np.add_arg('c', 
               'critical', 
               'Critical when X days until certificate expires', 
               required=None)

    np.activate()

    if np['warning'] is None:
        np['warning'] = "14"
    if np['critical'] is None:
        np['critical'] = "2"

    for t in ['warning', 'critical']:
        if np[t] and np[t].isdigit() is False:
            print "%s threshold must be a positive number" % t.capitalize()
            sys.exit(3)

    certs = getcert_list()

    for cert in certs:
        if cert['stuck'] != "no":
            np.add_message(
                   WARNING, 
                   "Certificate %s from certdb %s is stuck=%s" % (
                       cert['certificate']['nickname'], 
                       cert['certificate']['location'],
                       cert['stuck']))

        expires_diff = cert['expires'] - datetime.datetime.now()
        if expires_diff.days < 0:
            np.add_message(
                   CRITICAL,
                   "Certificate %s from certdb %s has EXPIRED %i days ago" % (
                       cert['certificate']['nickname'], 
                       cert['certificate']['location'],
                       expires_diff.days*-1))

        elif expires_diff.days < int(np['critical']):
            np.add_message(
                   CRITICAL,
                   "Certificate %s from certdb %s expires in %i days" % (
                       cert['certificate']['nickname'], 
                       cert['certificate']['location'],
                       expires_diff.days))

        elif expires_diff.days < int(np['warning']):
            np.add_message(
                   WARNING,
                   "Certificate %s from certdb %s expires in %i days" % (
                       cert['certificate']['nickname'], 
                       cert['certificate']['location'],
                       expires_diff.days))

        else:
            np.add_message(
                   OK,
                   "Certificate %s from certdb %s expires in %i days" % (
                       cert['certificate']['nickname'], 
                       cert['certificate']['location'],
                       expires_diff.days))

    code, messages = np.check_messages(joinallstr="\n")
    np.nagios_exit(code, messages)
开发者ID:tomas-edwardsson,项目名称:check_certmonger,代码行数:71,代码来源:check_certmonger.py


示例17: main

def main():
    global plugin

    plugin = Plugin(must_threshold=False)
    plugin.add_arg("l", "logical-volume",
                   "Comma seperated list of VG/LV, eg vg00/data,vg00/snap",
                   required=False)
    plugin.add_arg("V", "volume-group",
                   "Comma seperated list of VG, eg vg00,vg01",
                   required=False)
    plugin.add_arg("a", "check-all", "Check all LVs", required=False,
                   action="store_true")
    plugin.activate()

    lvs = plugin["logical-volume"] and plugin["logical-volume"].split(
        ",") or []
    vgs = plugin["volume-group"] and plugin["volume-group"].split(",") or []

    if not lvs and not vgs and not plugin['check-all']:
        plugin.parser.error(
            "Either logical-volume or volume-group must be specified")
    elif plugin['check-all'] and ( lvs or vgs ):
        plugin.parser.error(
            "Mixing check-all and logical-volume or volume-group does not make sense")

    check_mirror(lvs, vgs, plugin['check-all'], plugin['host'])

    (code, message) = (plugin.check_messages(joinallstr="\n"))
    plugin.nagios_exit(code, message)
开发者ID:carriercomm,项目名称:nagios-plugins,代码行数:29,代码来源:check_lvm_mirror.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python connection.TableConnection类代码示例发布时间:2022-05-27
下一篇:
Python Plugins.PluginHelper类代码示例发布时间: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