
    Vh>                     |    d dl mZmZmZ eZdZdZdZd dl	Z	d dl
Z
d dlmZ d dlmZ d Zd	 Zd
 Zedk(  r e        yy)    )absolute_importdivisionprint_functiona  
module: syslogger
short_description: Log messages in the syslog
description:
  - Uses syslog to add log entries to the host.
extends_documentation_fragment:
  - community.general.attributes
attributes:
  check_mode:
    support: none
  diff_mode:
    support: none
options:
  msg:
    type: str
    description:
      - This is the message to place in syslog.
    required: true
  priority:
    type: str
    description:
      - Set the log priority.
    choices: ["emerg", "alert", "crit", "err", "warning", "notice", "info", "debug"]
    default: "info"
  facility:
    type: str
    description:
      - Set the log facility.
    choices:
      - kern
      - user
      - mail
      - daemon
      - auth
      - lpr
      - news
      - uucp
      - cron
      - syslog
      - local0
      - local1
      - local2
      - local3
      - local4
      - local5
      - local6
      - local7
    default: "daemon"
  log_pid:
    description:
      - Log the PID in brackets.
    type: bool
    default: false
  ident:
    description:
      - Specify the name of application name which is sending the log to syslog.
    type: str
    default: 'ansible_syslogger'
    version_added: '0.2.0'
author:
  - Tim Rightnour (@garbled1)
a  
- name: Simple Usage
  community.general.syslogger:
    msg: "I will end up as daemon.info"

- name: Send a log message with err priority and user facility with log_pid
  community.general.syslogger:
    msg: "Hello from Ansible"
    priority: "err"
    facility: "user"
    log_pid: true

- name: Specify the name of application which is sending log message
  community.general.syslogger:
    ident: "MyApp"
    msg: "I want to believe"
    priority: "alert"
a  
ident:
  description: Name of application sending the message to log.
  returned: always
  type: str
  sample: "ansible_syslogger"
  version_added: '0.2.0'
priority:
  description: Priority level.
  returned: always
  type: str
  sample: "daemon"
facility:
  description: Syslog facility.
  returned: always
  type: str
  sample: "info"
log_pid:
  description: Log PID status.
  returned: always
  type: bool
  sample: true
msg:
  description: Message sent to syslog.
  returned: always
  type: str
  sample: "Hello from Ansible"
N)AnsibleModule)	to_nativec                    i dt         j                  dt         j                  dt         j                  dt         j                  dt         j
                  dt         j                  dt         j                  dt         j                  d	t         j                  d
t         j                  dt         j                  dt         j                  dt         j                  dt         j                  dt         j                  dt         j                   dt         j"                  dt         j$                  ij'                  | t         j                        S )Nkernusermaildaemonauthlprnewsuucpcronsysloglocal0local1local2local3local4local5local6local7)r   LOG_KERNLOG_USERLOG_MAIL
LOG_DAEMONLOG_AUTHLOG_LPRLOG_NEWSLOG_UUCPLOG_CRON
LOG_SYSLOG
LOG_LOCAL0
LOG_LOCAL1
LOG_LOCAL2
LOG_LOCAL3
LOG_LOCAL4
LOG_LOCAL5
LOG_LOCAL6
LOG_LOCAL7get)facilitys    o/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/syslogger.pyget_facilityr0      sP    	 	&##	
 	 	v~~ 	 	 	 	&## 	&## 	&## 	&## 	&## 	&##  	&##!" 	&###$ 	&##%& 
c(F%%&''    c           	      4   t         j                  t         j                  t         j                  t         j                  t         j
                  t         j                  t         j                  t         j                  dj                  | t         j                        S )Nemergalertcriterrwarningnoticeinfodebug)
r   	LOG_EMERG	LOG_ALERTLOG_CRITLOG_ERRLOG_WARNING
LOG_NOTICELOG_INFO	LOG_DEBUGr-   )prioritys    r/   get_priorityrE      s`    !!!!~~%%##!!	 
c(FOO$	%r1   c                  n   t        t        dd      t        dd      t        ddg dd	      t        ddg d
d	      t        ddd            } t        |       }t        d|j                  d   |j                  d   |j                  d   |j                  d   |j                  d         }	 t        j                  |j                  d   |j                  d   rt        j
                  ndt        |j                  d                t        j                  t        |j                  d         |j                  d          t        j                          d|d<    |j                  di | y # t        $ r=} |j                  ddt        |      z  t        j                         d| Y d }~Td }~ww xY w)Nstransible_syslogger)typedefaultT)rI   requiredFr3   r:   )rI   rK   choicesrJ   )r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   bool)rI   rK   rJ   )identmsgrD   r.   log_pid)argument_specrN   rD   r.   rP   rO   )changedrN   rD   r.   rP   rO   r   rR   zFailed to write to syslog %s)error	exception )dictr   paramsr   openlogLOG_PIDr0   rE   closelog	Exception	fail_jsonr   	traceback
format_exc	exit_json)module_argsmoduleresultexcs       r/   mainrd      s    ':;ed+55:$& 55G '( &5%@K  !F mmG$z*z*i(MM% F
|v}}W-)/y)Av~~q#FMM*$=>	@ 	l6==#<=mmE*	, y
 Fv  |{=	#NZcZnZnZp{tz{|s   0B+E. .	F473F//F4__main__)
__future__r   r   r   rI   __metaclass__DOCUMENTATIONEXAMPLESRETURNr   r]   ansible.module_utils.basicr   +ansible.module_utils.common.text.convertersr   r0   rE   rd   __name__rU   r1   r/   <module>rn      s[    A @=~&
:   4 A'.
%-` zF r1   