HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/zenoss.cpython-310.pyc
o

�N�g��@s�dZddlZddlZddlZddlZe�e�ZdZ	dd�Z
dddd	d
ddd
dddd�Zdd�Zd"dd�Z
dd�Zd"dd�Zd"dd�Zd#dd�Zd"d d!�ZdS)$a�
Module for working with the Zenoss API

.. versionadded:: 2016.3.0

:configuration: This module requires a 'zenoss' entry in the master/minion config.

    For example:

    .. code-block:: yaml

        zenoss:
          hostname: https://zenoss.example.com
          username: admin
          password: admin123
          verify_ssl: True
          ca_bundle: /etc/ssl/certs/ca-certificates.crt
�N�zenosscCstS)z,
    Only load if requests is installed
    )�__virtualname__�rr�G/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/zenoss.py�__virtual__srZ	messagingZ	evconsole�processZservice�device�network�templateZ	detailnav�reportZmibZzenpack)ZMessagingRouterZEventsRouterZ
ProcessRouterZ
ServiceRouter�DeviceRouterZ
NetworkRouterZTemplateRouterZDetailNavRouterZReportRouterZ	MibRouterZ
ZenPackRoutercCsBtdd�}tjjj|�d�|�d�|�dd�|�d�dd	id
�S)z@
    Create a session to be used when connecting to Zenoss.
    �
config.optionr�username�password�
verify_sslT�	ca_bundlezContent-typezapplication/json; charset=utf-8)�userrrr�headers)�__salt__�salt�utils�http�session�get)�configrrr�_session5s
�rc	Cs�|tvrdStjj�t|||ddd�g�}tdd�}t�d||�d�	|�
d	�t|�}t�j||d
�}t
�d|j�rEt�d�td��tjj�|j��
d
d�S)z1
    Make a request to the Zenoss API router
    FZrpc�)�action�method�data�type�tidr
rz*Making request to router %s with method %sz{}/zport/dmd/{}_router�hostname�rzname="__ac_name"z&Request failed. Bad username/password.�resultN)�ROUTERSrr�json�dumps�dictr�log�debug�formatrrZpost�re�search�content�error�	Exception�loads)ZrouterrrZreq_datar�url�responserrr�_router_requestDs�
r4cCstdd�dkr
dSdS)zP
    If no device class is given when adding a device, this helps determine
    �
grains.getZkernel�Linuxz
/Server/LinuxN)rrrrr�_determine_device_class^s�r7cCsfdidd�g}tdd|d�}|dD]}|d|kr*|d	|d	<t�d
|�|Sqt�d|�dS)z�
    Find a device in Zenoss. If device not found, returns None.

    Parameters:
        device:         (Optional) Will use the grain 'fqdn' by default

    CLI Example:

    .. code-block:: bash

        salt '*' zenoss.find_device
    z/zport/dmd/DevicesN)�uid�params�limitrZ
getDevicesr#Zdevices�name�hashzFound device %s in Zenossz"Unable to find device %s in Zenoss)r4r)�info)rrZall_devices�devrrr�find_devicefs�r?cCs |stdd�}t|�rdSdS)z�
    Check to see if a device already exists in Zenoss.

    Parameters:
        device:         (Optional) Will use the grain 'fqdn' by default

    CLI Example:

    .. code-block:: bash

        salt '*' zenoss.device_exists
    r5�fqdnTF)rr?)rrrr�
device_exists�s
rA�	localhost��cCsL|stdd�}|s
t�}t�d|�t||d||d�}tdd|gd�}|S)	a5
    A function to connect to a zenoss server and add a new device entry.

    Parameters:
        device:         (Optional) Will use the grain 'fqdn' by default.
        device_class:   (Optional) The device class to use. If none, will determine based on kernel grain.
        collector:      (Optional) The collector to use for this device. Defaults to 'localhost'.
        prod_state:     (Optional) The prodState to set on the device. If none, defaults to 1000 ( production )

    CLI Example:

    .. code-block:: bash

        salt '*' zenoss.add_device
    r5r@zAdding device %s to zenossT)Z
deviceNameZdeviceClassZmodel�	collectorZproductionStaterZ	addDevicer#)rr7r)r=r(r4)rZdevice_classrD�
prod_staterr3rrr�
add_device�s�rFcCsZ|stdd�}t|�}|sd|��St�d||�t|dg||dd�}tdd	|g�S)
a+
    A function to set the prod_state in zenoss.

    Parameters:
        prod_state:     (Required) Integer value of the state
        device:         (Optional) Will use the grain 'fqdn' by default.

    CLI Example:

    .. code-block:: bash

        salt zenoss.set_prod_state 1000 hostname
    r5r@z&Unable to find a device in Zenoss for z$Setting prodState to %d on %s devicer8r<)ZuidsZ	prodStateZ	hashcheckrZsetProductionState)rr?r)r=r(r4)rErZ
device_objectrrrr�set_prod_state�s
�rG)N)NNrBrC)�__doc__�loggingr,Zsalt.utils.httprZsalt.utils.json�	getLogger�__name__r)rrr%rr4r7r?rArFrGrrrr�<module>s6
�



"