
    VhQ                         d dl mZmZmZ eZdZdZd dlZd dl	Z
d dlZd dlmZ d Zd Z G d d	e      Zed
k(  r e        yy)    )absolute_importdivisionprint_functiona  
module: nagios
short_description: Perform common tasks in Nagios related to downtime and notifications
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, for example 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).
extends_documentation_fragment:
  - community.general.attributes
attributes:
  check_mode:
    support: none
  diff_mode:
    support: none
options:
  action:
    description:
      - Action to take.
      - The V(acknowledge) and V(forced_check) actions were added in community.general 1.2.0.
    required: true
    choices:
      - downtime
      - delete_downtime
      - enable_alerts
      - disable_alerts
      - silence
      - unsilence
      - silence_nagios
      - unsilence_nagios
      - command
      - servicegroup_service_downtime
      - servicegroup_host_downtime
      - acknowledge
      - forced_check
    type: str
  host:
    description:
      - Host to operate on in Nagios.
    type: str
  cmdfile:
    description:
      - Path to the nagios I(command file) (FIFO pipe). Only required if auto-detection fails.
    type: str
  author:
    description:
      - Author to leave downtime comments as. Only used when O(action) is V(downtime) or V(acknowledge).
    type: str
    default: Ansible
  comment:
    description:
      - Comment when O(action) is V(downtime) or V(acknowledge).
    type: str
    default: Scheduling downtime
  start:
    description:
      - When downtime should start, in C(time_t) format (epoch seconds).
    version_added: '0.2.0'
    type: str
  minutes:
    description:
      - Minutes to schedule downtime for.
      - Only usable with O(action=downtime).
    type: int
    default: 30
  services:
    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).'
    aliases: ["service"]
    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
  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

author: "Tim Bielawa (@tbielawa)"
a  
- 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
N)AnsibleModulec                      g d} | D ]i  }t         j                  j                  |      s#t        |      D ]9  }|j	                  d      s|j                  d      d   j                         c c S  k y )N)z/etc/nagios/nagios.cfgz/etc/nagios3/nagios.cfgz/etc/nagios2/nagios.cfgz /usr/local/etc/nagios/nagios.cfgz+/usr/local/groundwork/nagios/etc/nagios.cfgz%/omd/sites/oppy/tmp/nagios/nagios.cfgz /usr/local/nagios/etc/nagios.cfgz/usr/local/nagios/nagios.cfgz/opt/nagios/etc/nagios.cfgz/opt/nagios/nagios.cfgz/etc/icinga/icinga.cfgz /usr/local/icinga/etc/icinga.cfgcommand_file=   )ospathexistsopen
startswithsplitstrip)	locationsr   lines      l/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/nagios.pywhich_cmdfiler   	  sj    I0  677>>$T
 6??>2::c?1-335566     c                  ~   g d} t        t        t        dd|       t        dd      t        dd      t        d      t        d      t        d      t        d	d
      t        dt                     t        ddg      t        d      
      ddddgfddddgfdddgfdddgfddddgfddddgfdddgfddddgfddddgfddddgfddddgfg      }|j                  d   s|j	                  d        t        |fi |j                  }|j                  r|j                  d!       y |j                          y )"N)downtimedelete_downtimesilence	unsilenceenable_alertsdisable_alertssilence_nagiosunsilence_nagioscommandservicegroup_host_downtimeservicegroup_service_downtimeacknowledgeforced_checkstrT)typerequiredchoicesAnsible)r&   defaultzScheduling downtime)r&   int   service)r&   aliases)
actionauthorcommenthostservicegroupstartminutescmdfileservicesr    r/   r   r2   r7   r   r   r   r   r   r    r!   r3   r"   r#   r$   )argument_specrequired_ifr6   zunable to locate nagios.cfgmsg)changed)	r   dictr   params	fail_jsonNagios
check_mode	exit_jsonact)ACTION_CHOICESmoduleansible_nagioss      r   mainrG   +  s   N  UT>JUI6e-BC5!5)E"eR0e]_=uyk:e$
 zFJ#78(6:*>?y6(+{VH-(<='&*)=>y9+.3fn5MN68PQ}vz&:;~
';<
F8 ==#:;F4fmm4N&r   c                   2   e Zd ZdZd Zd Zd Z	 	 	 d,dZ	 	 d-dZd.dZ	d/d	Z
d/d
Zd0dZd1dZd2dZd Zd Zd Zd2dZd1dZd/dZd1dZd1dZd1dZd1dZd Zd Zd2dZd Zd Zd Zd Zd Z d  Z!d2d!Z"d" Z#d# Z$d$ Z%d% Z&d& Z'd' Z(d( Z)d) Z*d* Z+d+ Z,y)3r@   a  
    Perform common tasks in Nagios related to downtime and
    notifications.

    The complete set of external commands Nagios handles is documented
    on their website:

    http://old.nagios.org/developerinfo/externalcommands/commandlist.php

    Note that in the case of `schedule_svc_downtime`,
    `enable_svc_notifications`, and `disable_svc_notifications`, the
    service argument should be passed as a list.
    c                    || _         |d   | _        |d   | _        |d   | _        |d   | _        |d   | _        |d   t        |d         | _        nd | _        |d   | _        |d   | _	        |d	   | _
        |d
   |d
   dk(  s|d
   dk(  r|d
   | _        g | _        y |d
   j                  d      | _        g | _        y )Nr/   r0   r1   r2   r3   r4   r5   r6   r    r7   all,)rE   r/   r0   r1   r2   r3   r+   r4   r5   r6   r    r7   r   command_results)selfrE   kwargss      r   __init__zNagios.__init__q  s    X&X&i(6N	">2'?&VG_-DJDJi(i(i(:&F:,>&,HfU_N`diNi":.DM  " #:.44S9DM!r   c                 <    t        t        j                               S )zB
        The time in seconds since 12:00:00AM Jan 1, 1970
        )r+   timerM   s    r   _nowzNagios._now  s    
 499;r   c                    t         j                  j                  | j                        s'| j                  j                  d| j                         t        j                  t        j                  | j                        j                        s'| j                  j                  d| j                         	 t        | j                  d      5 }|j                  |       |j                          ddd       | j                  j                  |j                                y# 1 sw Y   3xY w# t        $ r* | j                  j                  d| j                         Y yw xY w)zD
        Write the given command to the Nagios command file
        z"nagios command file does not exist)r;   r6   z&nagios command file is not a fifo filewNz&unable to write to nagios command file)r   r   r   r6   rE   r?   statS_ISFIFOst_moder   writeflushrL   appendr   IOError)rM   cmdfps      r   _write_commandzNagios._write_command  s   
 ww~~dll+KK!!&J*.,, " 8}}RWWT\\2::;KK!!&N*.,, " 8	8dllC( B
   ''		4   	8KK!!&N*.,, " 8	8s*   5D+ "D-1D+ D($D+ +0EENc
                    | j                         }
||
}d|
d|d|d}|dz  }||z   }|s| j                  }|s| j                  }|8|t        |      t        |      t        |      t        |	      t        |      ||g}n6t        |      t        |      t        |      t        |	      t        |      ||g}dj	                  |      }||z   dz   }|S )aH  
        Format an external-command downtime string.

        cmd - Nagios command ID
        host - Host schedule downtime on
        duration - Minutes to schedule downtime for
        author - Name to file the downtime as
        comment - Reason for running this command (upgrade, reboot, etc)
        start - Start of downtime in seconds since 12:00AM Jan 1 1970
          Default is to use the entry time (now)
        svc - Service to schedule downtime for, omit when for host downtime
        fixed - Start now if 1, start when a problem is detected if 0
        trigger - Optional ID of event to start downtime from. Leave as 0 for
          fixed downtime.

        Syntax: [submitted] COMMAND;<host_name>;[<service_description>]
        <start_time>;<end_time>;<fixed>;<trigger_id>;<duration>;<author>;
        <comment>
        [] ;<   
rS   r0   r1   r%   join)rM   r]   r2   durationr0   r1   r4   svcfixedtrigger
entry_timehdr
duration_senddt_args
dt_arg_strdt_strs                    r   _fmt_dt_strzNagios._fmt_dt_str  s    . YY[
=E)35m
j [[FllG?CJC#e*c'l:9G 5z3s8SZW:9G XXg&
z!D(r   c	                 8   | j                         }	d|	d|d|d}
|s| j                  }|s| j                  }|$|t        |      t        |      t        |      ||g}n"t        |      t        |      t        |      ||g}dj	                  |      }|
|z   dz   }|S )a  
        Format an external-command acknowledge string.

        cmd - Nagios command ID
        host - Host schedule downtime on
        author - Name to file the downtime as
        comment - Reason for running this command (upgrade, reboot, etc)
        svc - Service to schedule downtime for, omit when for host downtime
        sticky - the acknowledgement will remain until the host returns to an UP state if set to 1
        notify -  a notification will be sent out to contacts
        persistent - survive across restarts of the Nagios process

        Syntax: [submitted] COMMAND;<host_name>;[<service_description>]
        <sticky>;<notify>;<persistent>;<author>;<comment>
        ra   rb   rc   re   rf   )rM   r]   r2   r0   r1   ri   stickynotify
persistentrl   rm   ack_argsack_arg_strack_strs                 r   _fmt_ack_strzNagios._fmt_ack_str  s    $ YY[
)35[[FllG?S[#f+s:PWXH FS[#j/67SHhhx(#d*r   c                    | j                         }d|d|d|d}|| j                  }g }||j                  |       n|j                  d       ||j                  t        |             n|j                  d       ||j                  |       n|j                  d       dj	                  |      }	||	z   dz   }
|
S )a  
        Format an external-command downtime deletion string.

        cmd - Nagios command ID
        host - Host to remove scheduled downtime from
        comment - Reason downtime was added (upgrade, reboot, etc)
        start - Start of downtime in seconds since 12:00AM Jan 1 1970
        svc - Service to remove downtime for, omit to remove all downtime for the host

        Syntax: [submitted] COMMAND;<host_name>;
        [<service_desription>];[<start_time>];[<comment>]
        ra   rb   rc    re   )rS   r1   r[   r%   rg   )rM   r]   r2   ri   r4   r1   rl   rm   dt_del_argsdt_del_arg_str
dt_del_strs              r   _fmt_dt_del_strzNagios._fmt_dt_del_str  s     YY[
)35?llG?s#r"s5z*r"w'r"+.>)D0
r   c                     | j                         }d|d|d|d}||dz   }|t        |      g}n|t        |      g}dj                  |      }||z   dz   }	|	S )a,  
        Format an external-command forced host or service check string.

        cmd - Nagios command ID
        host - Host to check service from
        svc - Service to check
        start - check time

        Syntax: [submitted] COMMAND;<host_name>;[<service_description>];<check_time>
        ra   rb   rc      re   )rS   r%   rg   )
rM   r]   r2   ri   r4   rl   rm   chk_argschk_arg_strchk_strs
             r   _fmt_chk_strzNagios._fmt_chk_str#  si     YY[
)35=NE;E
|HSZ(Hhhx(#d*r   c                 h    | j                         }d|d|}||d|z  z  }||d|z  z  }|dz  }|S )a|  
        Format an external-command notification string.

        cmd - Nagios command ID.
        host - Host to en/disable notifications on.. A value is not required
          for global downtime
        svc - Service to schedule downtime for. A value is not required
          for host downtime.

        Syntax: [submitted] COMMAND;<host_name>[;<service_description>]
        ra   rb   z;%sre   )rS   )rM   r]   r2   ri   rl   	notif_strs         r   _fmt_notif_strzNagios._fmt_notif_str?  sP     YY[
!+S1	%IUS[(	T	r   c                 l    d}|g }|D ])  }| j                  |||||      }| j                  |       + y)al  
        This command is used to schedule downtime for a particular
        service.

        During the specified downtime, Nagios will not send
        notifications out about the service.

        Syntax: SCHEDULE_SVC_DOWNTIME;<host_name>;<service_description>
        <start_time>;<end_time>;<fixed>;<trigger_id>;<duration>;<author>;
        <comment>
        SCHEDULE_SVC_DOWNTIMEN)r4   ri   rs   r_   )rM   r2   r7   r5   r4   r]   r-   
dt_cmd_strs           r   schedule_svc_downtimezNagios.schedule_svc_downtimeX  sL     &H 	,G))#tWEw)WJ
+	,r   c                 T    d}| j                  ||||      }| j                  |       y)aI  
        This command is used to schedule downtime for a particular
        host.

        During the specified downtime, Nagios will not send
        notifications out about the host.

        Syntax: SCHEDULE_HOST_DOWNTIME;<host_name>;<start_time>;<end_time>;
        <fixed>;<trigger_id>;<duration>;<author>;<comment>
        SCHEDULE_HOST_DOWNTIMEr4   Nr   rM   r2   r5   r4   r]   r   s         r   schedule_host_downtimezNagios.schedule_host_downtimen  s0     '%%c4%F
J'r   c                 h    d}|g }|D ]'  }| j                  |||      }| j                  |       ) y)aT  
        This command is used to acknowledge a particular
        service problem.

        By acknowledging the current problem, future notifications
        for the same servicestate are disabled

        Syntax: ACKNOWLEDGE_SVC_PROBLEM;<host_name>;<service_description>;
        <sticky>;<notify>;<persistent>;<author>;<comment>
        ACKNOWLEDGE_SVC_PROBLEMNri   r{   r_   )rM   r2   r7   r]   r-   ack_cmd_strs         r   acknowledge_svc_problemzNagios.acknowledge_svc_problem~  sH     (H 	-G++C7+CK,	-r   c                 N    d}| j                  ||      }| j                  |       y)a<  
        This command is used to acknowledge a particular
        host problem.

        By acknowledging the current problem, future notifications
        for the same servicestate are disabled

        Syntax: ACKNOWLEDGE_HOST_PROBLEM;<host_name>;<sticky>;<notify>;
        <persistent>;<author>;<comment>
        ACKNOWLEDGE_HOST_PROBLEMNr   )rM   r2   r]   r   s       r   acknowledge_host_problemzNagios.acknowledge_host_problem  s)     )''T2K(r   c                 R    d}| j                  ||d      }| j                  |       y)z
        This command schedules a forced active check for a particular host.

        Syntax: SCHEDULE_FORCED_HOST_CHECK;<host_name>;<check_time>
        SCHEDULE_FORCED_HOST_CHECKNr   r   r_   rM   r2   r]   chk_cmd_strs       r   schedule_forced_host_checkz!Nagios.schedule_forced_host_check  s.     +''Tt'<K(r   c                 R    d}| j                  ||d      }| j                  |       y)z
        This command schedules a forced active check for all services
        associated with a particular host.

        Syntax: SCHEDULE_FORCED_HOST_SVC_CHECKS;<host_name>;<check_time>
        SCHEDULE_FORCED_HOST_SVC_CHECKSNr   r   r   s       r   schedule_forced_host_svc_checkz%Nagios.schedule_forced_host_svc_check  s.     0''Tt'<K(r   c                 h    d}|g }|D ]'  }| j                  |||      }| j                  |       ) y)z
        This command schedules a forced active check for a particular
        service.

        Syntax: SCHEDULE_FORCED_SVC_CHECK;<host_name>;<service_description>;<check_time>
        SCHEDULE_FORCED_SVC_CHECKNr   r   )rM   r2   r7   r]   r-   r   s         r   schedule_forced_svc_checkz Nagios.schedule_forced_svc_check  sH     *H 	-G++C7+CK,	-r   c                 T    d}| j                  ||||      }| j                  |       y)ab  
        This command is used to schedule downtime for
        all services associated with a particular host.

        During the specified downtime, Nagios will not send
        notifications out about the host.

        SCHEDULE_HOST_SVC_DOWNTIME;<host_name>;<start_time>;<end_time>;
        <fixed>;<trigger_id>;<duration>;<author>;<comment>
        SCHEDULE_HOST_SVC_DOWNTIMEr   Nr   r   s         r   schedule_host_svc_downtimez!Nagios.schedule_host_svc_downtime  s0     +%%c4%F
J'r   c                     d}|&| j                  |||      }| j                  |       y|D ](  }| j                  ||||      }| j                  |       * y)z
        This command is used to remove scheduled downtime for a particular
        host.

        Syntax: DEL_DOWNTIME_BY_HOST_NAME;<host_name>;
        [<service_desription>];[<start_time>];[<comment>]
        DEL_DOWNTIME_BY_HOST_NAMENr1   )ri   r1   )r   r_   )rM   r2   r7   r1   r]   dt_del_cmd_strr-   s          r   delete_host_downtimezNagios.delete_host_downtime  sk     *!11#tW1MN/# 4!%!5!5c4WV]!5!^##N34r   c                 T    d}| j                  ||||      }| j                  |       y)ak  
        This command is used to schedule downtime for all hosts in a
        particular hostgroup.

        During the specified downtime, Nagios will not send
        notifications out about the hosts.

        Syntax: SCHEDULE_HOSTGROUP_HOST_DOWNTIME;<hostgroup_name>;<start_time>;
        <end_time>;<fixed>;<trigger_id>;<duration>;<author>;<comment>
         SCHEDULE_HOSTGROUP_HOST_DOWNTIMEr   Nr   rM   	hostgroupr5   r4   r]   r   s         r    schedule_hostgroup_host_downtimez'Nagios.schedule_hostgroup_host_downtime  s0     1%%c9gU%K
J'r   c                 T    d}| j                  ||||      }| j                  |       y)a  
        This command is used to schedule downtime for all services in
        a particular hostgroup.

        During the specified downtime, Nagios will not send
        notifications out about the services.

        Note that scheduling downtime for services does not
        automatically schedule downtime for the hosts those services
        are associated with.

        Syntax: SCHEDULE_HOSTGROUP_SVC_DOWNTIME;<hostgroup_name>;<start_time>;
        <end_time>;<fixed>;<trigger_id>;<duration>;<author>;<comment>
        SCHEDULE_HOSTGROUP_SVC_DOWNTIMEr   Nr   r   s         r   schedule_hostgroup_svc_downtimez&Nagios.schedule_hostgroup_svc_downtime   s0      0%%c9gU%K
J'r   c                 T    d}| j                  ||||      }| j                  |       y)a}  
        This command is used to schedule downtime for all hosts in a
        particular servicegroup.

        During the specified downtime, Nagios will not send
        notifications out about the hosts.

        Syntax: SCHEDULE_SERVICEGROUP_HOST_DOWNTIME;<servicegroup_name>;
        <start_time>;<end_time>;<fixed>;<trigger_id>;<duration>;<author>;
        <comment>
        #SCHEDULE_SERVICEGROUP_HOST_DOWNTIMEr   Nr   rM   r3   r5   r4   r]   r   s         r   #schedule_servicegroup_host_downtimez*Nagios.schedule_servicegroup_host_downtime  s0     4%%c<%N
J'r   c                 T    d}| j                  ||||      }| j                  |       y)a!  
        This command is used to schedule downtime for all services in
        a particular servicegroup.

        During the specified downtime, Nagios will not send
        notifications out about the services.

        Note that scheduling downtime for services does not
        automatically schedule downtime for the hosts those services
        are associated with.

        Syntax: SCHEDULE_SERVICEGROUP_SVC_DOWNTIME;<servicegroup_name>;
        <start_time>;<end_time>;<fixed>;<trigger_id>;<duration>;<author>;
        <comment>
        "SCHEDULE_SERVICEGROUP_SVC_DOWNTIMEr   Nr   r   s         r   "schedule_servicegroup_svc_downtimez)Nagios.schedule_servicegroup_svc_downtime%  s0    " 3%%c<%N
J'r   c                 N    d}| j                  ||      }| j                  |       y)a*  
        This command is used to prevent notifications from being sent
        out for all services on the specified host.

        Note that this command does not disable notifications from
        being sent out about the host.

        Syntax: DISABLE_HOST_SVC_NOTIFICATIONS;<host_name>
        DISABLE_HOST_SVC_NOTIFICATIONSNr   r_   rM   r2   r]   r   s       r   disable_host_svc_notificationsz%Nagios.disable_host_svc_notifications:  s)     /''T2	I&r   c                 N    d}| j                  ||      }| j                  |       y)a  
        This command is used to prevent notifications from being sent
        out for the specified host.

        Note that this command does not disable notifications for
        services associated with this host.

        Syntax: DISABLE_HOST_NOTIFICATIONS;<host_name>
        DISABLE_HOST_NOTIFICATIONSNr   r   s       r   disable_host_notificationsz!Nagios.disable_host_notificationsI  s)     +''T2	I&r   c                 h    d}|g }|D ]'  }| j                  |||      }| j                  |       ) y)a.  
        This command is used to prevent notifications from being sent
        out for the specified service.

        Note that this command does not disable notifications from
        being sent out about the host.

        Syntax: DISABLE_SVC_NOTIFICATIONS;<host_name>;<service_description>
        DISABLE_SVC_NOTIFICATIONSNr   r   )rM   r2   r7   r]   r-   r   s         r   disable_svc_notificationsz Nagios.disable_svc_notificationsX  sH     *H 	+G++C7+CI	*	+r   c                 N    d}| j                  ||      }| j                  |       y)aV  
        This command is used to prevent notifications from being sent
        out for all hosts in the specified servicegroup.

        Note that this command does not disable notifications for
        services associated with hosts in this service group.

        Syntax: DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS;<servicegroup_name>
        'DISABLE_SERVICEGROUP_HOST_NOTIFICATIONSNr   rM   r3   r]   r   s       r   'disable_servicegroup_host_notificationsz.Nagios.disable_servicegroup_host_notificationsl  s)     8''\:	I&r   c                 N    d}| j                  ||      }| j                  |       y)aP  
        This command is used to prevent notifications from being sent
        out for all services in the specified servicegroup.

        Note that this does not prevent notifications from being sent
        out about the hosts in this servicegroup.

        Syntax: DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS;<servicegroup_name>
        &DISABLE_SERVICEGROUP_SVC_NOTIFICATIONSNr   r   s       r   &disable_servicegroup_svc_notificationsz-Nagios.disable_servicegroup_svc_notifications{  s)     7''\:	I&r   c                 N    d}| j                  ||      }| j                  |       y)ac  
        Disables notifications for all hosts in a particular
        hostgroup.

        Note that this does not disable notifications for the services
        associated with the hosts in the hostgroup - see the
        DISABLE_HOSTGROUP_SVC_NOTIFICATIONS command for that.

        Syntax: DISABLE_HOSTGROUP_HOST_NOTIFICATIONS;<hostgroup_name>
        $DISABLE_HOSTGROUP_HOST_NOTIFICATIONSNr   rM   r   r]   r   s       r   $disable_hostgroup_host_notificationsz+Nagios.disable_hostgroup_host_notifications  s)     5''Y7	I&r   c                 N    d}| j                  ||      }| j                  |       y)a_  
        Disables notifications for all services associated with hosts
        in a particular hostgroup.

        Note that this does not disable notifications for the hosts in
        the hostgroup - see the DISABLE_HOSTGROUP_HOST_NOTIFICATIONS
        command for that.

        Syntax: DISABLE_HOSTGROUP_SVC_NOTIFICATIONS;<hostgroup_name>
        #DISABLE_HOSTGROUP_SVC_NOTIFICATIONSNr   r   s       r   #disable_hostgroup_svc_notificationsz*Nagios.disable_hostgroup_svc_notifications  s)     4''Y7	I&r   c                 N    d}| j                  ||      }| j                  |       y)z
        Enables notifications for a particular host.

        Note that this command does not enable notifications for
        services associated with this host.

        Syntax: ENABLE_HOST_NOTIFICATIONS;<host_name>
        ENABLE_HOST_NOTIFICATIONSNr   r   s       r   enable_host_notificationsz Nagios.enable_host_notifications  s)     *''T2	I&r   c                 V    d}| j                  ||      }| j                  |      }|r|S y)z
        Enables notifications for all services on the specified host.

        Note that this does not enable notifications for the host.

        Syntax: ENABLE_HOST_SVC_NOTIFICATIONS;<host_name>
        ENABLE_HOST_SVC_NOTIFICATIONS)Fail: could not write to the command filer   )rM   r2   r]   r   nagios_returns        r   enable_host_svc_notificationsz$Nagios.enable_host_svc_notifications  s7     .''T2	++I6>r   c                     d}|g }d}g }|D ]<  }| j                  |||      }| j                  |      xr |}|j                  |       > |r|S y)z
        Enables notifications for a particular service.

        Note that this does not enable notifications for the host.

        Syntax: ENABLE_SVC_NOTIFICATIONS;<host_name>;<service_description>
        ENABLE_SVC_NOTIFICATIONSTr   r   r   r_   r[   )rM   r2   r7   r]   r   return_str_listr-   r   s           r   enable_svc_notificationszNagios.enable_svc_notifications  su     )H 	.G++C7+CI //	:L}M""9-	.
 "">r   c                 V    d}| j                  ||      }| j                  |      }|r|S y)a  
        Enables notifications for all hosts in a particular hostgroup.

        Note that this command does not enable notifications for
        services associated with the hosts in this hostgroup.

        Syntax: ENABLE_HOSTGROUP_HOST_NOTIFICATIONS;<hostgroup_name>
        #ENABLE_HOSTGROUP_HOST_NOTIFICATIONSr   r   rM   r   r]   r   r   s        r   #enable_hostgroup_host_notificationsz*Nagios.enable_hostgroup_host_notifications  s7     4''Y7	++I6>r   c                 V    d}| j                  ||      }| j                  |      }|r|S y)a  
        Enables notifications for all services that are associated
        with hosts in a particular hostgroup.

        Note that this does not enable notifications for the hosts in
        this hostgroup.

        Syntax: ENABLE_HOSTGROUP_SVC_NOTIFICATIONS;<hostgroup_name>
        "ENABLE_HOSTGROUP_SVC_NOTIFICATIONSr   r   r   s        r   "enable_hostgroup_svc_notificationsz)Nagios.enable_hostgroup_svc_notifications  s7     3''Y7	++I6>r   c                 V    d}| j                  ||      }| j                  |      }|r|S y)aN  
        Enables notifications for all hosts that have services that
        are members of a particular servicegroup.

        Note that this command does not enable notifications for
        services associated with the hosts in this servicegroup.

        Syntax: ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS;<servicegroup_name>
        &ENABLE_SERVICEGROUP_HOST_NOTIFICATIONSr   r   rM   r3   r]   r   r   s        r   &enable_servicegroup_host_notificationsz-Nagios.enable_servicegroup_host_notifications  s7     7''\:	++I6>r   c                 V    d}| j                  ||      }| j                  |      }|r|S y)a  
        Enables notifications for all services that are members of a
        particular servicegroup.

        Note that this does not enable notifications for the hosts in
        this servicegroup.

        Syntax: ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS;<servicegroup_name>
        %ENABLE_SERVICEGROUP_SVC_NOTIFICATIONSr   r   r   s        r   %enable_servicegroup_svc_notificationsz,Nagios.enable_servicegroup_svc_notifications  s7     6''\:	++I6>r   c                     ddg}d}g }|D ]:  }| j                  ||      }| j                  |      xr |}|j                  |       < |r|S y)aq  
        This command is used to prevent notifications from being sent
        out for the host and all services on the specified host.

        This is equivalent to calling disable_host_svc_notifications
        and disable_host_notifications.

        Syntax: DISABLE_HOST_SVC_NOTIFICATIONS;<host_name>
        Syntax: DISABLE_HOST_NOTIFICATIONS;<host_name>
        r   r   Tr   r   rM   r2   r]   r   r   cr   s          r   silence_hostzNagios.silence_host3  so     -(
  	.A++At4I //	:L}M""9-	.
 "">r   c                     ddg}d}g }|D ]:  }| j                  ||      }| j                  |      xr |}|j                  |       < |r|S y)aX  
        This command is used to enable notifications for the host and
        all services on the specified host.

        This is equivalent to calling enable_host_svc_notifications
        and enable_host_notifications.

        Syntax: ENABLE_HOST_SVC_NOTIFICATIONS;<host_name>
        Syntax: ENABLE_HOST_NOTIFICATIONS;<host_name>
        r   r   Tr   r   r   s          r   unsilence_hostzNagios.unsilence_hostO  so     ,'
  	.A++At4I //	:L}M""9-	.
 "">r   c                 H    d}| j                  | j                  |             y)z
        This command is used to disable notifications for all hosts and services
        in nagios.

        This is a 'SHUT UP, NAGIOS' command
        DISABLE_NOTIFICATIONSNr_   r   rM   r]   s     r   r   zNagios.silence_nagiosk  s"     &D//45r   c                 H    d}| j                  | j                  |             y)z
        This command is used to enable notifications for all hosts and services
        in nagios.

        This is a 'OK, NAGIOS, GO'' command
        ENABLE_NOTIFICATIONSNr   r   s     r   r   zNagios.unsilence_nagiosu  s"     %D//45r   c                 |    dt        t        j                               z  }d}|d||}| j                  |       y)z
        This sends an arbitrary command to nagios

        It prepends the submitted time and appends a 


        You just have to provide the properly formatted command
        z[%s]re    N)r+   rQ   r_   )rM   r]   prepostcmdstrs        r   
nagios_cmdzNagios.nagios_cmd  s8     s499;''!3-F#r   c                 X
   | j                   dk(  r| j                  dk(  r4| j                  | j                  | j                  | j
                         n| j                  dk(  r4| j                  | j                  | j                  | j
                         nn| j                  | j                  | j                  | j                  | j
                         n/| j                   dk(  rU| j                  dk(  r| j                  | j                         n| j                  | j                  | j                         n| j                   dk(  r| j                  dk(  r| j                  | j                         n| j                  dk(  r| j                  | j                  d	
       nb| j                  | j                  | j                         n9| j                   dk(  r| j                  dk(  r| j                  | j                         n| j                  dk(  r| j                  | j                         n| j                  | j                  | j                         n| j                   dk(  rA| j                  r| j                  | j                  | j                  | j
                         nY| j                   dk(  rA| j                  r=| j!                  | j                  | j                  | j
                         n	| j                   dk(  r| j#                  | j                         n| j                   dk(  r| j%                  | j                         n| j                   dk(  r| j                  dk(  r| j'                  | j                         nv| j                  dk(  r| j)                  | j                         nJ| j+                  | j                  | j                         n!| j                   dk(  r~| j                  dk(  r| j-                  | j                         n| j                  dk(  r| j/                  | j                         n| j1                  | j                  | j                         n| j                   dk(  r| j3                          nt| j                   dk(  r| j5                          nT| j                   dk(  r| j7                  | j8                         n)| j:                  j=                  d| j                   z         | j:                  j?                  | j@                  d       y)zq
        Figure out what you want to do from ansible, and then do the
        needful (at the earliest).
        r   r2   )r5   r4   rJ   )r7   r5   r4   r#   )r7   r   r}   r   r$   r!   )r3   r5   r4   r"   r   r   r   r   r   r   r    zunknown action specified: '%s'r:   T)nagios_commandsr<   N)!r/   r7   r   r2   r5   r4   r   r   r   r   r   r   r   r   r3   r   r   r   r   r   r   r   r   r   r   r   r   r  r    rE   r?   rB   rL   rR   s    r   rC   z
Nagios.act  s    ;;*$}}&++DIIt||26** , >%'//		4<<6:jj 0 B **49948MM37<<15 + =
 [[M)}}&--dii8,,TYY,O[[--}}&))$))4%'))$))R)@))$))dmm)L[[N*}}&//		:%'33DII>..tyy4==.Q[[88  88dFWFWaeamamuyuu8  A[[;;  77TEVEV`d`l`ltxt~t~7 [[I%dii([[K'		* [[O+}}&..tyy9%'22499=--dii7;}} . F [[,,}}&//		:%'33DII>..tyy8< / G[[,,![[..!!#[[I%OODLL) KK!!&F&*kk'2! 3 	d.B.B&* 	 	,r   )NNNNr
   r   )NNNr   r
   r   )NNN)NN)Nr,   N)r,   N)N)-__name__
__module____qualname____doc__rO   rS   r_   rs   r{   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  rC    r   r   r@   r@   b  s    ", 8( 7;(,/00d .2LM$L'R82,,( -*) 
))-"( 4&( ((("(*''+(''' ' '?$?4?&?(?(?(?8?866$X,r   r@   __main__)
__future__r   r   r   r&   __metaclass__DOCUMENTATIONEXAMPLESrQ   os.pathr   rV   ansible.module_utils.basicr   r   rG   objectr@   r	  r  r   r   <module>r     sb    A @XtUn    4D4nD,V D,N zF r   