本文整理匯總了Python中pynag.Plugins.PluginHelper.add_option方法的典型用法代碼示例。如果您正苦於以下問題:Python PluginHelper.add_option方法的具體用法?Python PluginHelper.add_option怎麽用?Python PluginHelper.add_option使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pynag.Plugins.PluginHelper
的用法示例。
在下文中一共展示了PluginHelper.add_option方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: PluginHelper
# 需要導入模塊: from pynag.Plugins import PluginHelper [as 別名]
# 或者: from pynag.Plugins.PluginHelper import add_option [as 別名]
#!/usr/bin/env python
from pynag.Plugins import PluginHelper, ok, warning, critical, unknown
from pynag.Utils import runCommand
from collections import namedtuple
valid_queries = "lsarray lsdrive lsenclosurebattery lsenclosurecanister lsenclosurepsu lsenclosureslot lsenclosure lsmdiskgrp lsmdskgrp lsmgrp lsrcrelationship lsvdisk"
p = PluginHelper()
p.add_option("-H", "--hostname", '-M', help="Hostname or ip address", dest="hostname")
p.add_option("-U", "--user", help="Log in as this user to storwize", dest="user", default="nagios")
p.add_option("-Q", "--query", help="Query to send to storwize (see also -L)", dest="query", default="lsarray")
p.add_option("-L", "--list-queries", help="List of valid queries", dest="list_queries", action="store_true")
p.add_option("--test", help="Run this plugin in test mode", dest="test", action="store_true")
p.parse_arguments()
if p.options.list_queries is True:
p.parser.error("Valid Queries: %s" % valid_queries)
if not p.options.hostname:
p.parser.error("Required options -H is missing")
if p.options.query not in valid_queries.split():
p.parser.error("%s does not look like a valid query. Use -L for a list of valid queries" % p.options.query)
query = p.options.query
# Connect to remote storwize and run a connect
def run_query():
""" Connect to a remote storwize box and run query """
command = "ssh %[email protected]%s %s -delim ':'" % (p.options.user, p.options.hostname, p.options.query)