File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/uptime.cpython-310.pyc
o
�N�g� � @ s~ d Z ddlZddlmZ zddlZdZW n ey dZY nw e�e�Z dd� Z
dd � Zd
d� Zdd
� Z
dd� Zdd� ZdS )z5
Wrapper around uptime API
=========================
� N)�CommandExecutionErrorTFc C s t rdS dS )zJ
Only load this module if the requests python module is available
Zuptime)Fz6uptime module needs the python requests module to work)�ENABLED� r r �G/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/uptime.py�__virtual__ s r c K s� t | �rd| � �}t�|� t|��t� }t�d� |j| d� tj|� d�|dd�}|j s6td|j
� ���t�d� |�� d S )
aP Create a check on a given URL.
Additional parameters can be used and are passed to API (for
example interval, maxTime, etc). See the documentation
https://github.com/fzaninotto/uptime for a full list of the
parameters.
CLI Example:
.. code-block:: bash
salt '*' uptime.create http://example.org
z-Trying to create check that already exists : z[uptime] trying PUT request��url�/api/checks�x )�data�timeout�request to uptime failed : z[uptime] PUT request successful�_id)�check_exists�log�errorr �_get_application_url�debug�update�requests�put�ok�reason�json)�name�params�msg�application_url�reqr r r �create s
r c s� t � �sd� � �}t�|� t|��t� }t�d� tj|� d�dd��� }� fdd�|D �d }tj |� d |� �dd�}|j
sHtd
|j� ���t�d� dS )
z�
Delete a check on a given URL
CLI Example:
.. code-block:: bash
salt '*' uptime.delete http://example.org
z-Trying to delete check that doesn't exists : z[uptime] trying DELETE requestr r
�r c s g | ]}|d � kr|d �qS )r r r ��.0�x�r r r �
<listcomp>K s zdelete.<locals>.<listcomp>r z/api/checks/r
z"[uptime] DELETE request successfulT)r r r r r r r �getr �deleter r )r r r �jcontentZurl_idr r r$ r r'