本文整理汇总了Python中pynag.Plugins.simple.nagios_exit方法的典型用法代码示例。如果您正苦于以下问题:Python simple.nagios_exit方法的具体用法?Python simple.nagios_exit怎么用?Python simple.nagios_exit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pynag.Plugins.simple
的用法示例。
在下文中一共展示了simple.nagios_exit方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from pynag.Plugins import simple [as 别名]
# 或者: from pynag.Plugins.simple import nagios_exit [as 别名]
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)
示例2: Plugin
# 需要导入模块: from pynag.Plugins import simple [as 别名]
# 或者: from pynag.Plugins.simple import nagios_exit [as 别名]
## 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)
np.check_range(current_load)
示例3: main
# 需要导入模块: from pynag.Plugins import simple [as 别名]
# 或者: from pynag.Plugins.simple import nagios_exit [as 别名]
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)
示例4: len
# 需要导入模块: from pynag.Plugins import simple [as 别名]
# 或者: from pynag.Plugins.simple import nagios_exit [as 别名]
## 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))
## Get desired instance
instance_health = [instance for instance in instances_health if instance.instance_id == instance_id]
## If instance is not registered
if len(instance_health) == 0:
np.nagios_exit(WARNING, "Instance %s is not registered into %s" % ( instance_id, elb_name))
## Return value
示例5: Plugin
# 需要导入模块: from pynag.Plugins import simple [as 别名]
# 或者: from pynag.Plugins.simple import nagios_exit [as 别名]
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
disque = Disque()
info_properties = [
示例6: Plugin
# 需要导入模块: from pynag.Plugins import simple [as 别名]
# 或者: from pynag.Plugins.simple import nagios_exit [as 别名]
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
if not elbs:
np.nagios_exit(CRITICAL, "No ELB named %s" % elb_name)
else:
np.nagios_exit(OK, "ELB exist")
示例7: Plugin
# 需要导入模块: from pynag.Plugins import simple [as 别名]
# 或者: from pynag.Plugins.simple import nagios_exit [as 别名]
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))
## Confioguration return messge + code
map_instance_status = {}
map_instance_status[0] = ('instance is pending (maybe starting)', UNKNOWN)
map_instance_status[16] = ('instance is running', OK)
map_instance_status[32] = ('instance is shutting down', WARNING)
map_instance_status[48] = ('instance is terminated', CRITICAL)
map_instance_status[64] = ('instance is stopping', WARNING)
map_instance_status[80] = ('instance is stopped', CRITICAL)
示例8:
# 需要导入模块: from pynag.Plugins import simple [as 别名]
# 或者: from pynag.Plugins.simple import nagios_exit [as 别名]
## 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))
number_of_instance=len(instances_health)
number_of_running_instance=0
for instance_health in instances_health:
if instance_health.state == 'InService':
number_of_running_instance += 1
if np["numbers"] == None:
desired_number = number_of_instance/2