
    Vhm                     f    d dl mZmZmZ eZdZdZd dlm	Z	 ddZ
ddZd Zd	 Zed
k(  r e        yy)    )absolute_importdivisionprint_functiona  
module: logentries
author: "Ivan Vanderbyl (@ivanvanderbyl)"
short_description: Module for tracking logs using U(logentries.com)
description:
  - Sends logs to LogEntries in realtime.
extends_documentation_fragment:
  - community.general.attributes
attributes:
  check_mode:
    support: full
  diff_mode:
    support: none
options:
  path:
    type: str
    description:
      - Path to a log file.
    required: true
  state:
    type: str
    description:
      - Following state of the log.
    choices: ['present', 'absent', 'followed', 'unfollowed']
    required: false
    default: present
  name:
    type: str
    description:
      - Name of the log.
    required: false
  logtype:
    type: str
    description:
      - Type of the log.
    required: false
    aliases: [type]

notes:
  - Requires the LogEntries agent which can be installed following the instructions at U(logentries.com).
a  
- name: Track nginx logs
  community.general.logentries:
    path: /var/log/nginx/access.log
    state: present
    name: nginx-access-log

- name: Stop tracking nginx logs
  community.general.logentries:
    path: /var/log/nginx/error.log
    state: absent
)AnsibleModulec                 L    |dk(  r| j                  |d|g      \  }}}|dk(  ryyy)z+ Returns whether a log is followed or not. presentfollowedr   TFN)run_command)modulele_pathpathstatercouterrs          p/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/logentries.pyquery_log_statusr   F   s;     	))7J*EFC7     Nc                    d}|D ]  }t        | ||      r| j                  r| j                  d       |d|g}|r|j                  d|g       |r|j                  d|g       | j	                  |      \  }}	}
t        | ||      s&| j                  d|d|
j                         	       |d
z  } |dkD  r| j                  dd|fz         | j                  dd       y)z3 Follows one or more logs if not already followed. r   Tchangedfollowz--namez--typezfailed to follow '': msg   zfollowed %d log(s)r   r   Fzlogs(s) already followedN)r   
check_mode	exit_jsonextendr
   	fail_jsonstrip)r   r   logsnamelogtypefollowed_countlogcmdr   r   r   s              r   
follow_logr)   Q   s     N FGS1T*#&JJ$'(JJ'*+))#.C5SYY[!QR!#& +?>BS+ST
U(BCr   c                 j   d}|D ]~  }t        | ||      s| j                  r| j                  d       | j                  |d|g      \  }}}t        | ||      r&| j	                  d|d|j                                |dz  } |dkD  r| j                  dd	|z  
       | j                  dd
       y)z) Unfollows one or more logs if followed. r   Tr   rmzfailed to remove 'r   r   r   zremoved %d package(s)r   Fzlogs(s) already unfollowedN)r   r   r   r
   r!   r"   )r   r   r#   removed_countr'   r   r   r   s           r   unfollow_logr-   o   s     M  5T*))7D#*>?CFGS1SYY[!QR q+B]+RS
U(DEr   c                     t        t        t        d      t        dg d      t        dd d      t        dd dd	g
            d      } | j                  dddg      }| j                  }|d   j	                  d      }t        d |      }|d   dv rt        | |||d   |d          y |d   dv rt        | ||       y y )NT)requiredr   )r   r	   absent
unfollowed)defaultchoicesFstr)r/   r2   typer5   )r/   r2   r5   aliases)r   r   r$   r%   )argument_specsupports_check_modelez/usr/local/binr   ,r   )r   r	   r$   r%   )r$   r%   )r0   r1   )r   dictget_bin_pathparamssplitfilterr)   r-   )r   r   pr#   s       r   mainrA      s    t$y2abud?%EF8T	
 !F !!$/?.@AGA V9??3D$Dz,,67Dqy!I,O	
7/	/VWd+ 
0r   __main__)r   )NN)
__future__r   r   r   r5   __metaclass__DOCUMENTATIONEXAMPLESansible.module_utils.basicr   r   r)   r-   rA   __name__ r   r   <module>rJ      sQ    A @(T 5D<F4,4 zF r   