community.general.nagios 模块 – 执行与 Nagios 相关的停机和通知的常见任务
注意
此模块是 community.general 集合(版本 10.1.0)的一部分。
如果您正在使用 ansible 包,您可能已经安装了这个集合。它不包含在 ansible-core 中。要检查它是否已安装,请运行 ansible-galaxy collection list。
要安装它,请使用:ansible-galaxy collection install community.general。
要在 playbook 中使用它,请指定:community.general.nagios。
概要
- nagios模块有两个基本功能:调度停机时间和切换服务或主机的警报。
- nagios模块不是幂等的。
- 所有操作都需要显式给出 - host参数。在 playbook 中,您可以使用- {{inventory_hostname}}变量来引用 playbook 当前正在运行的主机。
- 您可以通过用逗号分隔来一次指定多个服务,例如 - services=httpd,nfs,puppet。
- 在指定要处理的服务时,有一个特殊的服务值 - host,它将处理主机本身的警报/停机/确认,例如- services=host。此关键字不能与其他服务同时给出。设置主机的警报/停机/确认不会影响其上运行的任何服务的警报/停机/确认。要为特定主机上的所有服务安排停机时间,请使用关键字 “all”,例如- services=all。
参数
| 参数 | 注释 | 
|---|---|
| 要执行的操作。 
 选项 
 | |
| 留下停机时间注释的作者。仅当  默认值:  | |
| nagios命令文件(FIFO 管道)的路径。仅在自动检测失败时才需要。 | |
| 要发送到 nagios 的原始命令,其中不应包括提交的时间头或换行符。 当使用  | |
| 当  默认值:  | |
| 要在 Nagios 中操作的主机。 | |
| 我们要设置停机/警报的服务组。 当使用  | |
| 要管理停机/警报的内容。用逗号分隔多个服务。 当  | |
| 停机应该开始的时间,以  | 
属性
| 属性 | 支持 | 描述 | 
|---|---|---|
| 支持: 无 | 可以在  | |
| 支持: 无 | 当处于差异模式时,将返回有关已更改(或可能需要在  | 
示例
- name: Set 30 minutes of apache downtime
  community.general.nagios:
    action: downtime
    minutes: 30
    service: httpd
    host: '{{ inventory_hostname }}'
- name: Schedule an hour of HOST downtime
  community.general.nagios:
    action: downtime
    minutes: 60
    service: host
    host: '{{ inventory_hostname }}'
- 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 }}'
- 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
- name: Schedule downtime for ALL services on HOST
  community.general.nagios:
    action: downtime
    minutes: 45
    service: all
    host: '{{ inventory_hostname }}'
- name: Schedule downtime for a few services
  community.general.nagios:
    action: downtime
    services: frob,foobar,qeuz
    host: '{{ inventory_hostname }}'
- 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 }}'
- 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 }}'
- name: Delete all downtime for a given host
  community.general.nagios:
    action: delete_downtime
    host: '{{ inventory_hostname }}'
    service: all
- name: Delete all downtime for HOST with a particular comment
  community.general.nagios:
    action: delete_downtime
    host: '{{ inventory_hostname }}'
    service: host
    comment: Planned maintenance
- name: Acknowledge an HOST with a particular comment
  community.general.nagios:
    action: acknowledge
    service: host
    host: '{{ inventory_hostname }}'
    comment: 'power outage - see casenr 12345'
- 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'
- name: Reset a passive service check for snmp trap
  community.general.nagios:
    action: forced_check
    service: snmp
    host: '{{ inventory_hostname }}'
- name: Force an active service check for the httpd service
  community.general.nagios:
    action: forced_check
    service: httpd
    host: '{{ inventory_hostname }}'
- name: Force an active service check for all services of a particular host
  community.general.nagios:
    action: forced_check
    service: all
    host: '{{ inventory_hostname }}'
- name: Force an active service check for a particular host
  community.general.nagios:
    action: forced_check
    service: host
    host: '{{ inventory_hostname }}'
- name: Enable SMART disk alerts
  community.general.nagios:
    action: enable_alerts
    service: smart
    host: '{{ inventory_hostname }}'
- name: Disable httpd and nfs alerts
  community.general.nagios:
    action: disable_alerts
    service: httpd,nfs
    host: '{{ inventory_hostname }}'
- name: Disable HOST alerts
  community.general.nagios:
    action: disable_alerts
    service: host
    host: '{{ inventory_hostname }}'
- name: Silence ALL alerts
  community.general.nagios:
    action: silence
    host: '{{ inventory_hostname }}'
- name: Unsilence all alerts
  community.general.nagios:
    action: unsilence
    host: '{{ inventory_hostname }}'
- name: Shut up nagios
  community.general.nagios:
    action: silence_nagios
- name: Annoy me negios
  community.general.nagios:
    action: unsilence_nagios
- name: Command something
  community.general.nagios:
    action: command
    command: DISABLE_FAILURE_PREDICTION
作者
- Tim Bielawa (@tbielawa) 
