
    Vh                          d dl mZmZmZ eZdZdZd dlZd dl	m
Z
 d dlmZ d dlmZ d dlmZ d	Z ed
d      ZdZdZdZdZd Zd Zd Zd Zedk(  r e        yy)    )absolute_importdivisionprint_functionaQ  
module: uptimerobot
short_description: Pause and start Uptime Robot monitoring
description:
  - This module lets you start and pause Uptime Robot Monitoring.
author: "Nate Kingsley (@nate-kingsley)"
requirements:
  - Valid Uptime Robot API Key
extends_documentation_fragment:
  - community.general.attributes
attributes:
  check_mode:
    support: none
  diff_mode:
    support: none
options:
  state:
    type: str
    description:
      - Define whether or not the monitor should be running or paused.
    required: true
    choices: ["started", "paused"]
  monitorid:
    type: str
    description:
      - ID of the monitor to check.
    required: true
  apikey:
    type: str
    description:
      - Uptime Robot API key.
    required: true
notes:
  - Support for adding and removing monitors and alert contacts has not yet been implemented.
a)  
- name: Pause the monitor with an ID of 12345
  community.general.uptimerobot:
    monitorid: 12345
    apikey: 12345-1234512345
    state: paused

- name: Start the monitor with an ID of 12345
  community.general.uptimerobot:
    monitorid: 12345
    apikey: 12345-1234512345
    state: started
N)AnsibleModule)	urlencode)	fetch_url)to_textzhttps://api.uptimerobot.com/zgetMonitors?zeditMonitor?)statuseditMonitorjson   Fc                     t        |      }t        t        d   z   |z   }t        | |      \  }}t	        |j                               }t        j                  |      }|j                          |S )Nr
   	r   API_BASEAPI_ACTIONSr   r	   readr   loadsclosemoduleparamsdatafull_urireqinforesult
jsonresults           q/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/uptimerobot.pycheckIDr   R   s]    VD+h//$6H&(+ICSXXZ FF#JIIK    c                     d|d<   t        |      }t        t        d   z   |z   }t        | |      \  }}t	        |j                               }t        j                  |      }|j                          |d   S )Nr   monitorStatusr   statr   r   s           r   startMonitorr$   ]   l    F?VD+m44t;H&(+ICSXXZ FF#JIIKfr    c                     d|d<   t        |      }t        t        d   z   |z   }t        | |      \  }}t	        |j                               }t        j                  |      }|j                          |d   S )Nr   r"   r   r#   r   r   s           r   pauseMonitorr'   i   r%   r    c            	         t        t        t        dddg      t        dd      t        d            t              } t        | j                  d	   | j                  d
   | j                  d
   t        t
              }t        | |      }|d   dk7  r| j                  d|d          | j                  d   dk(  rt        | |      }nt        | |      }| j                  d|       y )NTstartedpaused)requiredchoices)r+   no_log)r+   )stateapikey	monitorid)argument_specsupports_check_moder/   r0   )apiKeymonitors	monitorIDformatnoJsonCallbackr#   okfailedmessage)msgr   r.   success)r   dictSUPPORTS_CHECK_MODEr   
API_FORMATAPI_NOJSONCALLBACKr   	fail_jsonr$   r'   	exit_json)r   r   check_resultmonitor_results       r   mainrE   u   s    y(.CDd3D)

 0F }}X&{+--,)F 66*LFt#	* 	 	

 }}W*%ff5%ff5
  r    __main__)
__future__r   r   r   type__metaclass__DOCUMENTATIONEXAMPLESr   ansible.module_utils.basicr   +ansible.module_utils.six.moves.urllib.parser   ansible.module_utils.urlsr   +ansible.module_utils.common.text.convertersr	   r   r=   r   r?   r@   CHANGED_STATEr>   r   r$   r'   rE   __name__ r    r   <module>rS      s    A @"H  4 A / ? *
 
  		#L zF r    