Coverage for lib/ansible/plugins/callback/syslog_json.py : 63%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# (c) 2017 Ansible Project # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Make coding more python3-ish
callback: syslog_json callback_type: notification requirements: - whitelist in configuration short_description: sends JSON events to syslog 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 options: server: description: syslog server that will receive the event env: - name: SYSLOG_SERVER default: localhost ini: - section: callback_syslog_json key: syslog_server port: description: port on which the syslog server is listening env: - name: SYSLOG_PORT default: 514 ini: - section: callback_syslog_json key: syslog_port facility: description: syslog facility to log as env: - name: SYSLOG_FACILITY default: user ini: - section: callback_syslog_json key: syslog_facility '''
""" logs ansible-playbook and ansible runs to a syslog server in json format """
super(CallbackModule, self).__init__()
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) ) self.logger.addHandler(self.handler) self.hostname = socket.gethostname()
self.logger.error('%s ansible-command: task execution FAILED; host: %s; message: %s', self.hostname, host, self._dump_results(res))
self.logger.info('%s ansible-command: task execution OK; host: %s; message: %s', self.hostname, host, self._dump_results(res))
self.logger.info('%s ansible-command: task execution SKIPPED; host: %s; message: %s', self.hostname, host, 'skipped')
self.logger.error('%s ansible-command: task execution UNREACHABLE; host: %s; message: %s', self.hostname, host, self._dump_results(res))
self.logger.error('%s ansible-command: task execution FAILED; host: %s; message: %s', self.hostname, host, self._dump_results(res))
self.logger.info('%s ansible-command: playbook IMPORTED; host: %s; message: imported file %s', self.hostname, host, imported_file)
self.logger.info('%s ansible-command: playbook NOT IMPORTED; host: %s; message: missing file %s', self.hostname, host, missing_file) |