nagios¶
Utilities for interacting with the nagios server
- exception accre.nagios.NagiosConnectError[source]¶
Bases:
ACCREError
An error occurred connecting to the Nagios server
- class accre.nagios.NagiosStatus[source]¶
Bases:
object
Parses and stores Nagios status file into a dictionary of object types, i.e. hostdowntime, servicestatus, etc… for each object type a list of configured entities is the value. In each list each object is a dictionary of keys and values specific to that object.
- host_aggregate_status_time(host)[source]¶
Returns a tuple containing the highest hard status code, 0 (OK) - 3 (UNKNOWN) for all services and host status for the given host, and the timestamp of the last hard status change for any service on the host or the host itself. Rasies a ValueError if no checks are found for the host.
- Parameters:
host (str) – Name of the host to report
- Returns:
tuple of the highest hard status code and a timestamp of the last hard status change
- Return type:
tuple(int, int)
- parse(status)[source]¶
Parse the nagios status file and store all objects in the result attribute. If multiple files are parsed, results will be aggregated and duplicate objects may result in the list of objects multiple times.
- Parameters:
status (str) – Nagios status file text to parse
- Returns:
The Nagios status result dictionary
- Return type:
dict(str, list(dict(str, str)))
- service_status_time(host, serv_desc)[source]¶
Returns a tuple containing the hard status code, 0 (OK) - 3 (UNKNOWN) for a service and status for the given host and service description, and the timestamp of the last hard status change for the service on the host. Rasies a ValueError if the service on the host is not found.
- Parameters:
host (str) – Name of the host to report
serv_desc (str) – Service description identifier
- Returns:
tuple of the hard status code and a timestamp of the last hard status change
- Return type:
tuple(int, int)
- class accre.nagios.ObjectCache[source]¶
Bases:
object
Parses and stores Nagios object cache file into a dictionary of object types, i.e. command, hostgroup, host, service, etc… for each object type a list of configured entities is the value. In each list each object is a dictionary of keys and values specific to that object.
- managed_hosts(hostgroups=None)[source]¶
Return a list of currently managed hosts in the parsed object cache. If no configuration has been parsed, the result will be empty.
- Parameters:
hostgroups (list(str)) – If not None, restrict managed host names returned to those in one or more of the given hostgroups
- Returns:
List of managed host names from the object cache
- Return type:
list(string)
- parse(cache)[source]¶
Parse the object cache file and store all objects in the result attribute. If multiple files are parsed, results will be aggregated and duplicate objects may result in the list of objects multiple times.
- Parameters:
cache (str) – Nagios object cache file text to parse
- Returns:
The object cache result dictionary
- Return type:
dict(str, list(dict(str, str)))
- accre.nagios.retrieve_current_status(timeout=60)[source]¶
Reads the Nagios status file on the configured server and returns a parser object containing the resulting parsed status data.
- Parameters:
timeout (int) – Seconds to wait on status file retrieval before failing
- Returns:
Nagios current status data
- Return type:
- accre.nagios.retrieve_object_cache(timeout=60)[source]¶
Reads the Nagios object cache on the configured server and returns a parser object containing the resulting parsed object cache data.
- Parameters:
timeout (int) – Seconds to wait on object cache retrieval before failing
- Returns:
Nagios object cache data
- Return type:
- accre.nagios.send_nsca_notification(host_name, svc_description, return_code=0, plugin_output='', timeout=60)[source]¶
Send a nagios NSCA push notification to the configured nagios server.
See nagios NSCA passive check documentation for further details on the formatting and meaning of the check parameters.
- Parameters:
host_name (str) – the short name of the host associated with the service in the service definition
svc_description (str) – the description of the service as specified in the service definition
return_code (int) – the return code of the check (0-3)
plugin_output (str) – text output of the service check, may be truncated if it is over approximately 5000 bytes in utf-8 format
timeout (int) – Time to wait for NSCA command to complete