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/states/__pycache__/icinga2.cpython-310.pyc
o

�N�g�#�@s`dZddlZddlZddlZddlmZdd�Zddd�Z	d	d
�Z
dd�Zddd�Zdd�Z
dS)a�
Icinga2 state
=============

.. versionadded:: 2017.7.0

:depends:   - Icinga2 Python module
:configuration: See :py:mod:`salt.modules.icinga2` for setup instructions.

The icinga2 module is used to execute commands.
Its output may be stored in a file or in a grain.

.. code-block:: yaml

    command_id:
      icinga2.generate_ticket:
        - name: domain.tld
        - output:  "/tmp/query_id.txt"
�N)�get_certs_pathcCsdtvrdSdS)zB
    Only load if the icinga2 module is available in __salt__
    �icinga2.generate_ticketT)Fz"icinga2 module could not be loaded)�__salt__�rr�G/opt/saltstack/salt/lib/python3.10/site-packages/salt/states/icinga2.py�__virtual__srTc
Csn|iddd�}|dkrr|r3|s3|s!|td�vr!d�|�|d<|Stdr2d	|d
<d�|�|d<|Sns|rh|td�vrCtd|�}ni}|sU||vrUd
�||�|d<|Stdrgd	|d
<d�||�|d<|Sn>d|d
<d|d<|S|r�|s�tj�|�r�d|�d�|d<|Stdr�d	|d
<d�|�|d<|Sntdr�d	|d
<d|d<|Std|�}|d}|ds�t|�|d<|dkr�|r�|s�td||�d|��|dd<|S|r�|td�vr�td|�}ni}|||<td||�d�||�|dd<|S|�r/d|��|dd<tjj	�
|d��}	|	�tjj�
|��Wd	�|S1�s(wY|Sd|dd<|S) a8
    Generate an icinga2 ticket on the master.

    name
        The domain name for which this ticket will be generated

    output
        grain: output in a grain
        other: the file to store results
        None:  output to the result comment (default)

    grain:
        grain to store the output (need output=grain)

    key:
        the specified grain will be treated as a dictionary, the result
        of this state will be stored under the specified key.

    overwrite:
        The file or grain will be overwritten if it already exists (default)
    T���name�changes�result�comment�grainz	grains.lsz)No execution needed. Grain {} already setr
�testNrz@Ticket generation would be executed, storing result in grain: {}z
grains.getz,No execution needed. Grain {}:{} already setzCTicket generation would be executed, storing result in grain: {}:{}Fz5Error: output type 'grain' needs the grain parameter
zNo execution needed. File z already setz?Ticket generation would be executed, storing result in file: {}z7Ticket generation would be executed, not storing resultr�stdout�retcodez
grains.setvalzExecuted. Output into grain: r�ticketz"Executed. Output into grain: {}:{}zExecuted. Output into �wZExecuted)r�format�__opts__�os�path�isfile�str�salt�utils�filesZfopen�writeZstringutilsZto_str)
r
�outputr�keyZ	overwrite�retZgrain_valueZ
ticket_resrZoutput_filerrr�generate_ticket%s�������������
�
���r!cCs�|iddd�}t��|�d�}t��|�d�}tj�|�r-tj�|�r-d�||�|d<|Stdr;d	|d
<d|d<|Std|�}|d
s[d|d<d|��|dd<d|��|dd<|S)z�
    Generate an icinga2 certificate and key on the client.

    name
        The domain name for which this certificate and key will be generated
    Trr	z.crtz.keyz<No execution needed. Cert: {} and key: {} already generated.r
rNrz0Certificate and key generation would be executedzicinga2.generate_certrzCertificate and key generated�Executed. Certificate saved: r�certzExecuted. Key saved: r)rrrrrrr)r
r r#r�	cert_saverrr�
generate_cert�s&��r%cCs�|iddd�}t��d�}tj�|�rd|�d�|d<|Stdr+d	|d
<d|d<|Std||�}|d
sCd|d<d|��|dd<|S)z�
    Save the certificate on master icinga2 node.

    name
        The domain name for which this certificate will be saved

    master
        Icinga2 master node for which this certificate will be saved
    Trr	ztrusted-master.crt�No execution needed. Cert: z already saved.r
rNrz5Certificate save for icinga2 master would be executedzicinga2.save_certrz$Certificate for icinga2 master savedr"rr#)rrrrrr)r
�masterr r#r$rrr�	save_cert�s
r(�5665cCs�|iddd�}t��d�}tj�|�rd|�d�|d<|Stdr+d	|d
<d|d<|Std||||�}|d
sGd|d<d|��|dd<|Sd�|d�|d<d|d
<|S)aM
    Request CA certificate from master icinga2 node.

    name
        The domain name for which this certificate will be saved

    master
        Icinga2 master node for which this certificate will be saved

    ticket
        Authentication ticket generated on icinga2 master

    port
        Icinga2 port, defaults to 5665
    Trr	zca.crtr&z already exists.r
rNrz9Certificate request from icinga2 master would be executedzicinga2.request_certrz0Certificate request from icinga2 master executedz!Executed. Certificate requested: rr#z4FAILED. Certificate requested failed with output: {}rF�rrrrrrr)r
r'r�portr r#Zcert_requestrrr�request_cert�s&�r,cCs�|iddd�}t��|�d�}t��|�d�}tj�|�r)tj�|�r)d|d<|Stdr7d	|d
<d|d<|Std|||�}|d
sOd|d<d|dd<|Sd�|d�|d<d|d
<|S)a
    Setup the icinga2 node.

    name
        The domain name for which this certificate will be saved

    master
        Icinga2 master node for which this certificate will be saved

    ticket
        Authentication ticket generated on icinga2 master
    Trr	z	.crt.origz	.key.origz-No execution needed. Node already configured.r
rNrzNode setup will be executed.zicinga2.node_setuprzNode setup executed.z!Node setup finished successfully.rr#z(FAILED. Node setup failed with outpu: {}rFr*)r
r'rr r#r�
node_setuprrrr-�s(
�r-)NNNT)r))�__doc__Zos.pathrZsalt.utils.filesrZsalt.utils.stringutilsZsalt.utils.icinga2rrr!r%r(r,r-rrrr�<module>s
	l!
*