
    Vh=                         d dl mZmZmZ eZddgddZdZdZdZ	d d	l
mZmZ d d
lmZmZ d Zd Zd Zedk(  r e        yy)    )absolute_importdivisionprint_functionz1.1
deprecated	community)metadata_versionstatussupported_byaR  
author:
  - Kevin Breit (@kbreit)
deprecated:
  alternative: cisco.meraki.networks_alerts_settings
  removed_in: 3.0.0
  why: Updated modules released with increased functionality
description:
  - Allows for creation, management, and visibility into alert settings within Meraki.
extends_documentation_fragment: cisco.meraki.meraki
module: meraki_alert
options:
  alerts:
    description:
      - Alert-specific configuration for each type.
    elements: dict
    suboptions:
      alert_destinations:
        description:
          - A hash of destinations for this specific alert.
        suboptions:
          all_admins:
            description:
              - If true, all network admins will receive emails.
            type: bool
          emails:
            description:
              - A list of emails that will recieve the alert(s).
            elements: str
            type: list
          http_server_ids:
            description:
              - A list of HTTP server IDs to send a Webhook to.
            elements: str
            type: list
          snmp:
            description:
              - If true, then an SNMP trap will be sent if there is an SNMP trap server
                configured for this network.
            type: bool
        type: dict
      alert_type:
        description:
          - The type of alert.
        type: str
      enabled:
        description:
          - A boolean depicting if the alert is turned on or off.
        type: bool
      filters:
        default: {}
        description:
          - A hash of specific configuration data for the alert. Only filters specific
            to the alert will be updated.
          - No validation checks occur against C(filters).
        type: raw
    type: list
  default_destinations:
    description:
      - Properties for destinations when alert specific destinations aren't specified.
    suboptions:
      all_admins:
        description:
          - If true, all network admins will receive emails.
        type: bool
      emails:
        description:
          - A list of emails that will recieve the alert(s).
        elements: str
        type: list
      http_server_ids:
        description:
          - A list of HTTP server IDs to send a Webhook to.
        elements: str
        type: list
      snmp:
        description:
          - If true, then an SNMP trap will be sent if there is an SNMP trap server
            configured for this network.
        type: bool
    type: dict
  net_id:
    description:
      - ID number of a network.
    type: str
  net_name:
    aliases:
      - name
      - network
    description:
      - Name of a network.
    type: str
  state:
    choices:
      - present
      - query
    default: present
    description:
      - Create or modify an alert.
    type: str
short_description: Manage alerts in the Meraki cloud
version_added: 2.1.0
a  
- name: Update settings
  meraki_alert:
    auth_key: abc123
    org_name: YourOrg
    net_name: YourNet
    state: present
    default_destinations:
      emails:
        - youremail@yourcorp
        - youremail2@yourcorp
      all_admins: true
      snmp: false
    alerts:
      - alert_type: gatewayDown
        enabled: true
        filters:
          timeout: 60
        alert_destinations:
          emails:
            - youremail@yourcorp
            - youremail2@yourcorp
          all_admins: true
          snmp: false
      - alert_type: usageAlert
        enabled: true
        filters:
          period: 1200
          threshold: 104857600
        alert_destinations:
          emails:
            - youremail@yourcorp
            - youremail2@yourcorp
          all_admins: true
          snmp: false
- name: Query all settings
  meraki_alert:
    auth_key: abc123
    org_name: YourOrg
    net_name: YourNet
    state: query
  delegate_to: localhost
a  
data:
    description: Information about the created or manipulated object.
    returned: info
    type: complex
    contains:
        default_destinations:
            description: Properties for destinations when alert specific destinations aren't specified.
            returned: success
            type: complex
            contains:
                all_admins:
                    description: If true, all network admins will receive emails.
                    type: bool
                    sample: true
                    returned: success
                snmp:
                    description: If true, then an SNMP trap will be sent if there is an SNMP trap server configured for this network.
                    type: bool
                    sample: true
                    returned: success
                emails:
                    description: A list of emails that will recieve the alert(s).
                    type: list
                    returned: success
                http_server_ids:
                    description: A list of HTTP server IDs to send a Webhook to.
                    type: list
                    returned: success
        alerts:
            description: Alert-specific configuration for each type.
            type: complex
            contains:
                alert_type:
                    description: The type of alert.
                    type: str
                    returned: success
                enabled:
                    description: A boolean depicting if the alert is turned on or off.
                    type: bool
                    returned: success
                filters:
                    description:
                    - A hash of specific configuration data for the alert. Only filters specific to the alert will be updated.
                    - No validation checks occur against C(filters).
                    type: complex
                    returned: success
                alert_destinations:
                    description: A hash of destinations for this specific alert.
                    type: complex
                    contains:
                        all_admins:
                            description: If true, all network admins will receive emails.
                            type: bool
                            returned: success
                        snmp:
                            description: If true, then an SNMP trap will be sent if there is an SNMP trap server configured for this network.
                            type: bool
                            returned: success
                        emails:
                            description: A list of emails that will recieve the alert(s).
                            type: list
                            returned: success
                        http_server_ids:
                            description: A list of HTTP server IDs to send a Webhook to.
                            type: list
                            returned: success
)AnsibleModulejson)MerakiModulemeraki_argument_specc                 D    |j                   d   D ]  }|d   | k(  s|c S  y )Nalerts
alert_type)params)typemerakialerts      m/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/cisco/meraki/plugins/modules/meraki_alert.pyget_alert_by_typer      s1    x( $&L     c                    i }| j                   d   i |d<   | j                   d   d   | j                   d   d   |d   d<   | j                   d   d   | j                   d   d   |d   d<   | j                   d   d   C| j                   d   d   |d   d<   t        |d   d         dkD  r|d   d   d   dk(  r	|d   d   d= | j                   d   d	   C| j                   d   d	   |d   d
<   t        |d   d
         dkD  r|d   d
   d   dk(  r	|d   d
   d= | j                   d   Zg |d<   | j                   d   D cg c]  }|d   	 }}|d   D ]-  }|d   |vr|d   j                  |        t        |d   |       }dd i}|d   |d   |d<   |d   |d   |d<   |d   |d   |d<   |d   t	               |d<   |d   d   |d   d   |d   d<   |d   d   |d   d   |d   d<   |d   d   9|d   d   |d   d<   t        |d   d         dkD  r|d   d   d   dk(  r	|d   d   d= |d   d	   9|d   d	   |d   d
<   t        |d   d
         dkD  r|d   d
   d   dk(  r	|d   d
   d= |d   j                  |       0 |S c c}w )Ndefault_destinationsdefaultDestinations
all_admins	allAdminssnmpemailsr   Nonehttp_server_idshttpServerIdsr   r   r   enabledfiltersalert_destinationsalertDestinations)r   lenappendr   dict)r   currentpayloadr   modified_typescurrent_alertr   
alert_temps           r   construct_payloadr/      s	   G}}+,8)+%&==/0>J:@--H^:_`l:mG)*;7==/08D5;]]CY5Z[a5bG)*62==/0:F7=}}E[7\]e7fG)*84701(;<q@WMbEcdlEmnoEptzEz 128<Q?==/01BCO>DmmLb>cdu>vG)*?;701/BCaGGTiLjkzL{|}L~  CI  MI 12?CAF}}X* :@x9PQ$|,QQ %X. 	5MV$N:!((7)-*?H$d^
&2).|)<Jv&#/,1),<Jy)#/,1),<Jy)-.:6:fJ2312<@LGLMaGbcoGp
#67D126:FBGH\B]^dBe
#67?128<HDIJ^D_`hDi
#67Az*=>xHIAMR\]pRqrzR{|}R~  CI  SI !++@ A( KA N123DEQKPQeKfgxKy
#67Hz*=>OPSTTYcdwYx  zI  ZJ  KL  ZM  QW  ZW !++@ A/ RST U!((4=	5> NE Rs   <Jc                  H   t        t        d      t        d      t        dd      t        dd            } t        t        d      t        d      t        dd |       t        d	i 
            }t               }|j                  t        d      t        dddg      t        dddgd      t        dd |       t        dd|             t        |d      }t	        |d      }d|j
                  d<   ddi}ddi}|j                  d   j                  |       ||j                  d<   |j
                  d   }||j                  |j
                  d         }|j
                  d   }|2|j                  |       }	|j                  |j
                  d!   |	"      }|j
                  d#   dk(  rb|j                  d|$      }
|j                  |
d%&      }|j                  d'k(  r||j                  d(<    |j                  d,i |j                   nr|j
                  d#   dk(  r_|j                  d|$      }
|j                  |
d%&      }t        ||      }|j!                  ||      r|j"                  du rL|j%                  ||       ||j                  d(<   d|j                  d)<    |j                  d,i |j                   |j                  d|$      }
|j                  |
d*t'        j(                  |      +      }|j                  d'k(  rx|j%                  ||       ||j                  d(<   d|j                  d)<    |j                  d,i |j                   n+||j                  d(<    |j                  d,i |j                    |j                  d,i |j                   y )-Nbool)r   liststr)r   elements)r   r   r   r!   r)   )r   defaultoptionsraw)r   r5   )r   r#   r%   r$   namenetwork)r   aliasespresentquery)r   choicesr5   )r   r4   r6   )net_idnet_namestater   r   T)argument_specsupports_check_moder   )functionallfollow_redirectsz"/networks/{net_id}/alerts/settingsget_allupdateorg_idorg_namer>   )rH   r?   )r?   datar@   )r>   GET)method   rJ   changedPUT)rL   r+    )r)   r   rG   r   r   r   url_catalog
get_org_idget_nets
get_net_idconstruct_pathrequestr	   result	exit_jsonr/   is_update_required
check_modegenerate_diffr   dumps)destinations_arg_specalerts_arg_specrA   moduler   
query_urlsupdate_urlsrH   r>   netspathresponseoriginalr+   s                 r   mainrf   5  sx   
 !V$v%0&59	 U#&!/D
 %,O )*M569*=>	7';YO!/D
 &/J   # F
 &73F(-FMM$%?@J@AK
y!((4#.Fx 
 ]]8$F~""6==#<=]]8$F~f-""FMM*,ED"Q}}W($$Yv$>>>$u>5==C$,FMM&!)6==)	w	9	,$$Yv$>>>$u>5#FH5$$Xw7  D($$Xw7(/f%+/i(   16==1((&(AD~~d5$**WBU~VH}}#$$Xw7(0f%+/i(   16==1$,FMM&!F-v}}- F%v}}%r   __main__N)
__future__r   r   r   r   __metaclass__ANSIBLE_METADATADOCUMENTATIONEXAMPLESRETURNansible.module_utils.basicr   r   Kansible_collections.cisco.meraki.plugins.module_utils.network.meraki.merakir   r   r   r/   rf   __name__rP   r   r   <module>rq      sr    A @ n fP*XC
J ;:zY&x zF r   