HEX
Server: Apache
System: Linux pdx1-shared-a1-38 6.6.104-grsec-jammy+ #3 SMP Tue Sep 16 00:28:11 UTC 2025 x86_64
User: mmickelson (3396398)
PHP: 8.1.31
Disabled: NONE
Upload Files
File: //usr/local/lib/python3.8/dist-packages/pyzabbix/__pycache__/api.cpython-38.pyc
U

�o�e;&�@s�ddlZddlmZmZmZmZmZddlmZddl	m
Z
ddlmZdddd	d
gZ
e�e�Ze�e���e
d�Ze
d�ZGd
d�de�ZGdd�d�ZGdd�d�ZGdd	�d	�ZGdd
�d
e�ZdS)�N)�Mapping�Optional�Sequence�Tuple�Union)�warn)�Version)�Session�	ZabbixAPI�ZabbixAPIException�ZabbixAPIMethod�ZabbixAPIObject�ZabbixAPIObjectClassz5.4.0z6.4.0cs eZdZdZ�fdd�Z�ZS)ra�Generic Zabbix API exception

    Codes:
      -32700: invalid JSON. An error occurred on the server while
              parsing the JSON text (typo, wrong quotes, etc.)
      -32600: received JSON is not a valid JSON-RPC Request
      -32601: requested remote-procedure does not exist
      -32602: invalid method parameters
      -32603: Internal JSON-RPC error
      -32400: System error
      -32300: Transport error
      -32500: Application error
    cst�j|�|�dd�|_dS)N�error)�super�__init__�getr��self�args�kwargs��	__class__��0/tmp/pip-unpacked-wheel-3fqz2ouq/pyzabbix/api.pyr(szZabbixAPIException.__init__)�__name__�
__module__�__qualname__�__doc__r�
__classcell__rrrrrsc@s�eZdZd%eeeeeeee	e
e	e	ffed�dd�Zdd�d	d
�Zdd�Z
d&eeeedd�dd�Zdd�Zeed�dd��Zd'eeeed�dd�Zed�dd�Zd(eeeeefed�dd�Zedd�dd �Zedd�d!d"�Zedd�d#d$�ZdS))r
�http://localhost/zabbixNFT)�server�session�use_authenticate�timeout�detect_versioncCs||pt�|_|jj�dddd��||_d|_d|_d|_||_|�	d�sX|�
d	�d}||_t�
d
|j�d|_||_dS)aR
        :param server: Base URI for zabbix web interface (omitting /api_jsonrpc.php)
        :param session: optional pre-configured requests.Session instance
        :param use_authenticate: Use old (Zabbix 1.8) style authentication
        :param timeout: optional connect and read timeout in seconds, default: None
                        If you're using Requests >= 2.4 you can set it as
                        tuple: "(connect, read)" which is used to set individual
                        connect and read timeouts.
        :param detect_version: autodetect Zabbix API version
        zapplication/json-rpczpython/pyzabbixzno-cache)zContent-Typez
User-Agentz
Cache-ControlF�rz/api_jsonrpc.php�/zJSON-RPC Server Endpoint: %sN)r	r"�headers�updater#�
use_api_token�auth�idr$�endswith�rstrip�url�logger�info�version�_detect_version)rr!r"r#r$r%rrrr1s$��
zZabbixAPI.__init__)�returncCs|S�Nr�rrrr�	__enter__]szZabbixAPI.__enter__cCs0t|ttd�f�r,|jr(|js(|j��dSdS)NT)�
isinstancer�type�is_authenticatedr*�userZlogout)r�exception_typeZexception_value�	tracebackrrr�__exit__as

zZabbixAPI.__exit__r&)r;�password�	api_tokenr4cCs�|jr"t|���|_t�d|j�|dk	r:d|_||_dSd|_|jrZ|j	j
||d�|_n6|jr~|jtkr~|j	j||d�|_n|j	j||d�|_dS)a�Convenience method for calling user.authenticate
        and storing the resulting auth token for further commands.

        If use_authenticate is set, it uses the older (Zabbix 1.8)
        authentication command

        :param password: Password used to login into Zabbix
        :param user: Username used to login into Zabbix
        :param api_token: API Token to authenticate with
        zZabbix API version is: %sNTr&)r;r?)�usernamer?)
r3r�api_versionr2r0r1r*r+r#r;Zauthenticate�ZABBIX_5_4_0�login)rr;r?r@rrrrDiszZabbixAPI.logincCs|jr
dS|jj|jd�S)NT�Z	sessionid)r*r;�checkAuthenticationr+r6rrr�check_authentication�szZabbixAPI.check_authenticationcCs:|jr
dSz|jj|jd�Wntk
r4YdSXdS)NTrEF)r*r;rFr+rr6rrrr:�szZabbixAPI.is_authenticated)�
confformat�source�rulesr4cCs tdtd�|jd|||d�S)z�Alias for configuration.import because it clashes with
        Python's import reserved keyword
        :param rules:
        :param source:
        :param confformat:
        z�ZabbixAPI.confimport(format, source, rules) has been deprecated, please use ZabbixAPI.configuration['import'](format=format, source=source, rules=rules) instead��import)�formatrIrJ)r�DeprecationWarning�
configuration)rrHrIrJrrr�
confimport�s��zZabbixAPI.confimportcCs
|j��Sr5)Zapiinfor2r6rrrrB�szZabbixAPI.api_version)�method�paramsr4c

CsXd||p
i|jd�}i}dddh}|jr\||kr\|jrR|jtkrRd|j��|d<n
|j|d<t�d	|�|jj|j|||j	d
�}t�d|j
�|��|js�t
d��z|��}Wn4tk
r�}zt
d
|j���|�W5d}~XYnXt�d|�|jd7_d|k�rT|d}	d|	k�r$d|	d<t
d|	d�d|	d�d|	d��|	d|	d��|S)Nz2.0)ZjsonrpcrQrRr,zapiinfo.versionzuser.checkAuthenticationz
user.loginzBearer �
Authorizationr+zSending: %s)�jsonr(r$zResponse Code: %szReceived empty responsezUnable to parse json: zResponse Body: %s�r�datazNo datazError �codez: �messagez, )r)r,r+r2�ZABBIX_6_4_0r0�debugr"�postr/r$�status_code�raise_for_status�textrrT�
ValueError)
rrQrR�payloadr(Zanonymous_methods�resp�response�	exceptionrrrr�
do_request�sZ��
�
��

 �zZabbixAPI.do_requestr
��attrr4cCs
t||�S)z-Dynamically create an object class (ie: host))r
�rrfrrr�_objectszZabbixAPI._objectcCs
|�|�Sr5�rhrgrrr�__getattr__szZabbixAPI.__getattr__cCs
|�|�Sr5rirgrrr�__getitem__szZabbixAPI.__getitem__)r NFNT)r&r&N)r&r&r&)N)rrr�strrr	�boolr�float�intrrr7r>rDrG�propertyr:�dictrPrBrrrdrhrjrkrrrrr
/sZ��,
��%
����Dc@s$eZdZeed�dd�Zdd�ZdS)r)rQ�parentcCs||_||_dSr5)�_method�_parent)rrQrrrrrrszZabbixAPIMethod.__init__cOs(|r|rtd��|j�|j|p |�dS)NzFound both args and kwargs�result)�	TypeErrorrtrdrsrrrr�__call__szZabbixAPIMethod.__call__N)rrrrlr
rrwrrrrr
sc@sLeZdZeed�dd�Zeed�dd�Zeed�dd�Zeed�d	d
�Z	dS)r
)�namerrcCs||_||_dSr5)�_namert)rrxrrrrrrszZabbixAPIObject.__init__recCst|j�d|��|j�S)z%Dynamically create a method (ie: get)�.)rryrtrgrrrrsszZabbixAPIObject._methodcCs
|�|�Sr5�rsrgrrrrj#szZabbixAPIObject.__getattr__cCs
|�|�Sr5r{rgrrrrk&szZabbixAPIObject.__getitem__N)
rrrrlr
rrrsrjrkrrrrr
scseZdZ�fdd�Z�ZS)rcstdtd�t�j||�dS)Nz8ZabbixAPIObjectClass has been renamed to ZabbixAPIObjectrK)rrNrrrrrrr+s�zZabbixAPIObjectClass.__init__)rrrrrrrrrr*s)�logging�typingrrrrr�warningsrZpackaging.versionr�requestsr	�__all__�	getLoggerrr0�
addHandler�NullHandlerrCrY�	Exceptionrr
rr
rrrrr�<module>s(�
_