mirror of
https://github.com/drewkerrigan/nagios-http-json.git
synced 2024-11-22 10:23:50 +01:00
Add and format some doc_strings
This commit is contained in:
parent
ba9d9b1c39
commit
95912246a2
@ -28,7 +28,10 @@ __version__ = '2.0.0'
|
|||||||
__version_date__ = '2022-02-16'
|
__version_date__ = '2022-02-16'
|
||||||
|
|
||||||
class NagiosHelper:
|
class NagiosHelper:
|
||||||
"""Help with Nagios specific status string formatting."""
|
"""
|
||||||
|
Help with Nagios specific status string formatting.
|
||||||
|
"""
|
||||||
|
|
||||||
message_prefixes = {OK_CODE: 'OK',
|
message_prefixes = {OK_CODE: 'OK',
|
||||||
WARNING_CODE: 'WARNING',
|
WARNING_CODE: 'WARNING',
|
||||||
CRITICAL_CODE: 'CRITICAL',
|
CRITICAL_CODE: 'CRITICAL',
|
||||||
@ -39,8 +42,11 @@ class NagiosHelper:
|
|||||||
unknown_message = ''
|
unknown_message = ''
|
||||||
|
|
||||||
def getMessage(self):
|
def getMessage(self):
|
||||||
"""Build a status-prefixed message with optional performance data
|
"""
|
||||||
generated externally"""
|
Build a status-prefixed message with optional performance data
|
||||||
|
generated externally
|
||||||
|
"""
|
||||||
|
|
||||||
text = "%s: Status %s." % (self.message_prefixes[self.getCode()],
|
text = "%s: Status %s." % (self.message_prefixes[self.getCode()],
|
||||||
self.message_prefixes[self.getCode()])
|
self.message_prefixes[self.getCode()])
|
||||||
text += self.warning_message
|
text += self.warning_message
|
||||||
@ -77,8 +83,11 @@ class NagiosHelper:
|
|||||||
|
|
||||||
|
|
||||||
class JsonHelper:
|
class JsonHelper:
|
||||||
"""Perform simple comparison operations against values in a given
|
"""
|
||||||
JSON dict"""
|
Perform simple comparison operations against values in a given
|
||||||
|
JSON dict
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self, json_data, separator):
|
def __init__(self, json_data, separator):
|
||||||
self.data = json_data
|
self.data = json_data
|
||||||
self.separator = separator
|
self.separator = separator
|
||||||
@ -132,8 +141,11 @@ class JsonHelper:
|
|||||||
return (self.get(key) != (None, 'not_found'))
|
return (self.get(key) != (None, 'not_found'))
|
||||||
|
|
||||||
def get(self, key, temp_data=''):
|
def get(self, key, temp_data=''):
|
||||||
"""Can navigate nested json keys with a dot format
|
"""
|
||||||
(Element.Key.NestedKey). Returns (None, 'not_found') if not found"""
|
Can navigate nested json keys with a dot format
|
||||||
|
(Element.Key.NestedKey). Returns (None, 'not_found') if not found
|
||||||
|
"""
|
||||||
|
|
||||||
if temp_data:
|
if temp_data:
|
||||||
data = temp_data
|
data = temp_data
|
||||||
else:
|
else:
|
||||||
@ -192,8 +204,11 @@ def _getKeyAlias(original_key):
|
|||||||
|
|
||||||
|
|
||||||
class JsonRuleProcessor:
|
class JsonRuleProcessor:
|
||||||
"""Perform checks and gather values from a JSON dict given rules
|
"""
|
||||||
and metrics definitions"""
|
Perform checks and gather values from a JSON dict given rules
|
||||||
|
and metrics definitions
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self, json_data, rules_args):
|
def __init__(self, json_data, rules_args):
|
||||||
self.data = json_data
|
self.data = json_data
|
||||||
self.rules = rules_args
|
self.rules = rules_args
|
||||||
@ -338,8 +353,11 @@ class JsonRuleProcessor:
|
|||||||
return unknown
|
return unknown
|
||||||
|
|
||||||
def checkMetrics(self):
|
def checkMetrics(self):
|
||||||
"""Return a Nagios specific performance metrics string given keys
|
"""
|
||||||
and parameter definitions"""
|
Return a Nagios specific performance metrics string given keys
|
||||||
|
and parameter definitions
|
||||||
|
"""
|
||||||
|
|
||||||
metrics = ''
|
metrics = ''
|
||||||
warning = ''
|
warning = ''
|
||||||
critical = ''
|
critical = ''
|
||||||
@ -381,10 +399,15 @@ class JsonRuleProcessor:
|
|||||||
|
|
||||||
|
|
||||||
def parseArgs():
|
def parseArgs():
|
||||||
|
"""
|
||||||
|
CLI argument definitions and parsing
|
||||||
|
"""
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
description = plugin_description + '\n\nVersion: %s (%s)'
|
description = plugin_description + '\n\nVersion: %s (%s)'
|
||||||
%(__version__, __version_date__),
|
%(__version__, __version_date__),
|
||||||
formatter_class=argparse.RawDescriptionHelpFormatter)
|
formatter_class=argparse.RawDescriptionHelpFormatter
|
||||||
|
)
|
||||||
|
|
||||||
parser.add_argument('-d', '--debug', action='store_true',
|
parser.add_argument('-d', '--debug', action='store_true',
|
||||||
help='debug mode')
|
help='debug mode')
|
||||||
@ -478,6 +501,10 @@ def parseArgs():
|
|||||||
|
|
||||||
|
|
||||||
def debugPrint(debug_flag, message, pretty_flag=False):
|
def debugPrint(debug_flag, message, pretty_flag=False):
|
||||||
|
"""
|
||||||
|
Print debug messages if -d (debug_flat ) is set.
|
||||||
|
"""
|
||||||
|
|
||||||
if debug_flag:
|
if debug_flag:
|
||||||
if pretty_flag:
|
if pretty_flag:
|
||||||
pprint(message)
|
pprint(message)
|
||||||
@ -537,8 +564,10 @@ if __name__ == "__main__":
|
|||||||
url += ":%s" % args.port
|
url += ":%s" % args.port
|
||||||
if args.path:
|
if args.path:
|
||||||
url += "/%s" % args.path
|
url += "/%s" % args.path
|
||||||
|
|
||||||
debugPrint(args.debug, "url:%s" % url)
|
debugPrint(args.debug, "url:%s" % url)
|
||||||
json_data = ''
|
json_data = ''
|
||||||
|
|
||||||
try:
|
try:
|
||||||
req = urllib.request.Request(url)
|
req = urllib.request.Request(url)
|
||||||
req.add_header("User-Agent", "check_http_json")
|
req.add_header("User-Agent", "check_http_json")
|
||||||
|
Loading…
Reference in New Issue
Block a user