community.general.nagios (8.5.0) — module

Perform common tasks in Nagios related to downtime and notifications

Authors: Tim Bielawa (@tbielawa)

Install collection

Install with ansible-galaxy collection install community.general:==8.5.0


Add to requirements.yml

  collections:
    - name: community.general
      version: 8.5.0

Description

The C(nagios) module has two basic functions: scheduling downtime and toggling alerts for services or hosts.

The C(nagios) module is not idempotent.

All actions require the O(host) parameter to be given explicitly. In playbooks you can use the C({{inventory_hostname}}) variable to refer to the host the playbook is currently running on.

You can specify multiple services at once by separating them with commas, .e.g. O(services=httpd,nfs,puppet).

When specifying what service to handle there is a special service value, O(host), which will handle alerts/downtime/acknowledge for the I(host itself), for example O(services=host). This keyword may not be given with other services at the same time. B(Setting alerts/downtime/acknowledge for a host does not affect alerts/downtime/acknowledge for any of the services running on it.) To schedule downtime for all services on particular host use keyword "all", for example O(services=all).

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Set 30 minutes of apache downtime
  community.general.nagios:
    action: downtime
    minutes: 30
    service: httpd
    host: '{{ inventory_hostname }}'
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Schedule an hour of HOST downtime
  community.general.nagios:
    action: downtime
    minutes: 60
    service: host
    host: '{{ inventory_hostname }}'
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Schedule an hour of HOST downtime starting at 2019-04-23T02:00:00+00:00
  community.general.nagios:
    action: downtime
    start: 1555984800
    minutes: 60
    service: host
    host: '{{ inventory_hostname }}'
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Schedule an hour of HOST downtime, with a comment describing the reason
  community.general.nagios:
    action: downtime
    minutes: 60
    service: host
    host: '{{ inventory_hostname }}'
    comment: Rebuilding machine
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Schedule downtime for ALL services on HOST
  community.general.nagios:
    action: downtime
    minutes: 45
    service: all
    host: '{{ inventory_hostname }}'
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Schedule downtime for a few services
  community.general.nagios:
    action: downtime
    services: frob,foobar,qeuz
    host: '{{ inventory_hostname }}'
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Set 30 minutes downtime for all services in servicegroup foo
  community.general.nagios:
    action: servicegroup_service_downtime
    minutes: 30
    servicegroup: foo
    host: '{{ inventory_hostname }}'
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Set 30 minutes downtime for all host in servicegroup foo
  community.general.nagios:
    action: servicegroup_host_downtime
    minutes: 30
    servicegroup: foo
    host: '{{ inventory_hostname }}'
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Delete all downtime for a given host
  community.general.nagios:
    action: delete_downtime
    host: '{{ inventory_hostname }}'
    service: all
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Delete all downtime for HOST with a particular comment
  community.general.nagios:
    action: delete_downtime
    host: '{{ inventory_hostname }}'
    service: host
    comment: Planned maintenance
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Acknowledge an HOST with a particular comment
  community.general.nagios:
    action: acknowledge
    service: host
    host: '{{ inventory_hostname }}'
    comment: 'power outage - see casenr 12345'
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Acknowledge an active service problem for the httpd service with a particular comment
  community.general.nagios:
    action: acknowledge
    service: httpd
    host: '{{ inventory_hostname }}'
    comment: 'service crashed - see casenr 12345'
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Reset a passive service check for snmp trap
  community.general.nagios:
    action: forced_check
    service: snmp
    host: '{{ inventory_hostname }}'
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Force an active service check for the httpd service
  community.general.nagios:
    action: forced_check
    service: httpd
    host: '{{ inventory_hostname }}'
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Force an active service check for all services of a particular host
  community.general.nagios:
    action: forced_check
    service: all
    host: '{{ inventory_hostname }}'
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Force an active service check for a particular host
  community.general.nagios:
    action: forced_check
    service: host
    host: '{{ inventory_hostname }}'
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Enable SMART disk alerts
  community.general.nagios:
    action: enable_alerts
    service: smart
    host: '{{ inventory_hostname }}'
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Disable httpd and nfs alerts
  community.general.nagios:
    action: disable_alerts
    service: httpd,nfs
    host: '{{ inventory_hostname }}'
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Disable HOST alerts
  community.general.nagios:
    action: disable_alerts
    service: host
    host: '{{ inventory_hostname }}'
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Silence ALL alerts
  community.general.nagios:
    action: silence
    host: '{{ inventory_hostname }}'
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Unsilence all alerts
  community.general.nagios:
    action: unsilence
    host: '{{ inventory_hostname }}'
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Shut up nagios
  community.general.nagios:
    action: silence_nagios
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Annoy me negios
  community.general.nagios:
    action: unsilence_nagios
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Command something
  community.general.nagios:
    action: command
    command: DISABLE_FAILURE_PREDICTION

Inputs

    
host:
    description:
    - Host to operate on in Nagios.
    type: str

start:
    description:
    - When downtime should start, in C(time_t) format (epoch seconds).
    type: str
    version_added: 0.2.0
    version_added_collection: community.general

action:
    choices:
    - downtime
    - delete_downtime
    - enable_alerts
    - disable_alerts
    - silence
    - unsilence
    - silence_nagios
    - unsilence_nagios
    - command
    - servicegroup_service_downtime
    - servicegroup_host_downtime
    - acknowledge
    - forced_check
    description:
    - Action to take.
    - servicegroup options were added in 2.0.
    - delete_downtime options were added in 2.2.
    - The V(acknowledge) and V(forced_check) actions were added in community.general 1.2.0.
    required: true
    type: str

author:
    default: Ansible
    description:
    - Author to leave downtime comments as. Only used when O(action) is V(downtime) or
      V(acknowledge).
    type: str

cmdfile:
    description:
    - Path to the nagios I(command file) (FIFO pipe). Only required if auto-detection
      fails.
    type: str

command:
    description:
    - The raw command to send to nagios, which should not include the submitted time header
      or the line-feed.
    - B(Required) option when using the V(command) O(action).
    type: str

comment:
    default: Scheduling downtime
    description:
    - Comment when O(action) is V(downtime) or V(acknowledge).
    type: str

minutes:
    default: 30
    description:
    - Minutes to schedule downtime for.
    - Only usable with O(action=downtime).
    type: int

services:
    aliases:
    - service
    description:
    - What to manage downtime/alerts for. Separate multiple services with commas.
    - 'B(Required) option when O(action) is one of: V(downtime), V(acknowledge), V(forced_check),
      V(enable_alerts), V(disable_alerts).'
    type: str

servicegroup:
    description:
    - The Servicegroup we want to set downtimes/alerts for.
    - B(Required) option when using the V(servicegroup_service_downtime) and V(servicegroup_host_downtime)
      O(action).
    type: str