mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Allow syslog_json callback options to be set in an Ansible configurat… (#57232)
* Allow syslog_json callback options to be set in an Ansible configuration file. The syslog_json documentation says that it supports options via an Ansible configuration file. In fact, they can only be specified via environment variables. I've updated the module to use the standard "get_options" handling which means that it can now support options via environment variables *or* the configuration file. Options can be set in the configuration file as follows: ``` callback_whitelist = syslog_json [callback_syslog_json] syslog_server = localhost syslog_port = 514 syslog_facility = user ``` * Use the original, documented, names for the modules options. In the documentation text change syslog_server to server, syslog_port to port and syslog_facility to facility. * Add an item to the changelog. * Update 57232-syslog-json-configuration-options.yml Fix a YAML syntax error / typo.
This commit is contained in:
parent
fd95c7b506
commit
2ef7759be1
2 changed files with 11 additions and 3 deletions
|
@ -0,0 +1,2 @@
|
|||
minor_changes:
|
||||
- "syslog_json - Allow configuration of the syslog_json plugin via an Ansible configuration file."
|
|
@ -14,7 +14,7 @@ DOCUMENTATION = '''
|
|||
version_added: "1.9"
|
||||
description:
|
||||
- This plugin logs ansible-playbook and ansible runs to a syslog server in JSON format
|
||||
- Before 2.4 only environment variables were available for configuration
|
||||
- Before 2.9 only environment variables were available for configuration
|
||||
options:
|
||||
server:
|
||||
description: syslog server that will receive the event
|
||||
|
@ -67,12 +67,18 @@ class CallbackModule(CallbackBase):
|
|||
|
||||
super(CallbackModule, self).__init__()
|
||||
|
||||
self.set_options()
|
||||
|
||||
syslog_host = self.get_option("server")
|
||||
syslog_port = int(self.get_option("port"))
|
||||
syslog_facility = self.get_option("facility")
|
||||
|
||||
self.logger = logging.getLogger('ansible logger')
|
||||
self.logger.setLevel(logging.DEBUG)
|
||||
|
||||
self.handler = logging.handlers.SysLogHandler(
|
||||
address=(os.getenv('SYSLOG_SERVER', 'localhost'), int(os.getenv('SYSLOG_PORT', 514))),
|
||||
facility=os.getenv('SYSLOG_FACILITY', logging.handlers.SysLogHandler.LOG_USER)
|
||||
address=(syslog_host, syslog_port),
|
||||
facility=syslog_facility
|
||||
)
|
||||
self.logger.addHandler(self.handler)
|
||||
self.hostname = socket.gethostname()
|
||||
|
|
Loading…
Reference in a new issue