icinga

Icinga module.

exception spicerack.icinga.IcingaError[source]

Bases: spicerack.exceptions.SpicerackError

Custom exception class for errors of this module.

exception spicerack.icinga.IcingaStatusNotFoundError[source]

Bases: spicerack.icinga.IcingaError

Custom exception class for errors while parsing the Icinga status.

exception spicerack.icinga.IcingaStatusParseError[source]

Bases: spicerack.icinga.IcingaError

Custom exception class for errors while parsing the Icinga status.

class spicerack.icinga.HostStatus(*, name: str, state: str, optimal: bool, failed_services: Sequence[Mapping])[source]

Bases: object

Represent the status of all Icinga checks for a single host.

Initialize the instance.

Parameters
  • name (str) -- the hostname.

  • state (str) -- the Icinga state for the host, one of UP, DOWN, UNREACHABLE``.

  • optimal (bool) -- whether the host is in optimal state (all green).

  • failed_services (list) -- a list of dictionaries representing the failed services.

STATE_UP = 'UP'

the Icinga value for a host that is up and running. The other values for the Icinga host state are DOWN and UNREACHABLE.

Type

str

property failed_services

Return the list of service names that are failing.

Returns

a list of strings with the check names.

Return type

list

class spicerack.icinga.HostsStatus[source]

Bases: dict

Represent the status of all Icinga checks for a set of hosts.

property failed_hosts

Return the list of hostnames that are not up and running. They can either be down or unreachable.

Returns

the list of strings with the hostnames.

Return type

list

property failed_services

Return the list of service names that are failing for each host that has at least one.

Returns

a dict with hostnames as keys and list of failing service name strings as values.

Return type

dict

property non_optimal_hosts

Return the list of hostnames that are not in an optimal state.

They can either not being up and running or have at least one failed service.

Returns

a list of strings with the hostnames.

Return type

list

property optimal

Returns True if all the hosts are optimal, False otherwise.

Returns

whether all hosts are optimal.

Return type

bool

class spicerack.icinga.Icinga(icinga_host: spicerack.remote.RemoteHosts, *, config_file: str = '/etc/icinga/icinga.cfg')[source]

Bases: object

Class to interact with the Icinga server.

Initialize the instance.

Todo

Add an IcingaHosts class that performs actions for a given set of hosts instead of passing them to all methods.

Parameters
  • icinga_host (spicerack.remote.RemoteHosts) -- the RemoteHosts instance for the Icinga server.

  • config_file (str, optional) -- the path to the Icinga main configuration file.

downtime_hosts(hosts: TypeHosts, reason: spicerack.administrative.Reason, *, duration: datetime.timedelta = datetime.timedelta(seconds=14400))None[source]

Downtime hosts on the Icinga server for the given time with a message.

Parameters
  • hosts (spicerack.typing.TypeHosts) -- the set of hostnames or FQDNs to downtime.

  • reason (spicerack.administrative.Reason) -- the reason to set for the downtime on the Icinga server.

  • duration (datetime.timedelta, optional) -- the length of the downtime period.

get_status(hosts: TypeHosts)spicerack.icinga.HostsStatus[source]

Get the current status of the given hosts from Icinga.

Parameters

hosts (spicerack.typing.TypeHosts) -- the set of hostnames or FQDNs to iterate the command to.

Returns

the instance that represents the status for the given hosts.

Return type

spicerack.icinga.HostsStatus

Raises
host_command(command: str, hosts: TypeHosts, *args: str)None[source]

Execute a host-specific Icinga command on the Icinga server for a set of hosts.

Parameters
  • command (str) -- the Icinga command to execute.

  • hosts (spicerack.typing.TypeHosts) -- the set of hostnames or FQDNs to iterate the command to.

  • *args (str) -- optional positional arguments to pass to the command.

hosts_downtimed(hosts: TypeHosts, reason: spicerack.administrative.Reason, *, duration: datetime.timedelta = datetime.timedelta(seconds=14400), remove_on_error: bool = False) → Iterator[None][source]

Context manager to perform actions while the hosts are downtimed on Icinga.

Parameters
  • hosts (spicerack.typing.TypeHosts) -- the set of hostnames or FQDNs to downtime.

  • reason (spicerack.administrative.Reason) -- the reason to set for the downtime on the Icinga server.

  • duration (datetime.timedelta, optional) -- the length of the downtime period.

  • remove_on_error -- should the downtime be removed even if an exception was raised.

Yields

None -- it just yields control to the caller once Icinga has been downtimed and deletes the downtime once getting back the control.

recheck_all_services(hosts: TypeHosts)None[source]

Force recheck of all services associated with a set of hosts.

Parameters

hosts (spicerack.typing.TypeHosts) -- the set of hostnames or FQDNs to recheck.

remove_downtime(hosts: TypeHosts)None[source]

Remove a downtime from a set of hosts.

Parameters

hosts (spicerack.typing.TypeHosts) -- the set of hostnames or FQDNs to remove the downtime from.

property command_file

Getter for the command_file property.

Returns

the path of the Icinga command file.

Return type

str

Raises

spicerack.icinga.IcingaError -- if unable to get the command file path.