1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

add ini config to logstash callback (#610)

* Update logstash.py

* remove version with collection

Co-authored-by: Abhijeet Kasurde <akasurde@redhat.com>

* rename the callback name with migration collection

Co-authored-by: Abhijeet Kasurde <akasurde@redhat.com>

* Update plugins/callback/logstash.py

v1

Co-authored-by: Felix Fontein <felix@fontein.de>

* Create 610_logstash_callback_add_ini_config.yml

* Update changelogs/fragments/610_logstash_callback_add_ini_config.yml

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update logstash.py

Co-authored-by: Abhijeet Kasurde <akasurde@redhat.com>
Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
chris93111 2020-07-31 10:56:12 +02:00 committed by GitHub
parent 6df7fd3026
commit 623817b0b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 17 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- "logstash callback - add ini config (https://github.com/ansible-collections/community.general/pull/610)."

View file

@ -19,16 +19,28 @@ DOCUMENTATION = '''
description: Address of the Logstash server
env:
- name: LOGSTASH_SERVER
ini:
- section: callback_logstash
key: server
version_added: 1.0.0
default: localhost
port:
description: Port on which logstash is listening
env:
- name: LOGSTASH_PORT
ini:
- section: callback_logstash
key: port
version_added: 1.0.0
default: 5000
type:
description: Message type
env:
- name: LOGSTASH_TYPE
ini:
- section: callback_logstash
key: type
version_added: 1.0.0
default: ansible
'''
@ -68,7 +80,7 @@ class CallbackModule(CallbackBase):
Requires:
python-logstash
This plugin makes use of the following environment variables:
This plugin makes use of the following environment variables or ini config:
LOGSTASH_SERVER (optional): defaults to localhost
LOGSTASH_PORT (optional): defaults to 5000
LOGSTASH_TYPE (optional): defaults to ansible
@ -79,29 +91,36 @@ class CallbackModule(CallbackBase):
CALLBACK_NAME = 'community.general.logstash'
CALLBACK_NEEDS_WHITELIST = True
def __init__(self):
super(CallbackModule, self).__init__()
def __init__(self, display=None):
super(CallbackModule, self).__init__(display=display)
if not HAS_LOGSTASH:
self.disabled = True
self._display.warning("The required python-logstash is not installed. "
"pip install python-logstash")
else:
self.start_time = datetime.utcnow()
def set_options(self, task_keys=None, var_options=None, direct=None):
super(CallbackModule, self).set_options(task_keys=task_keys, var_options=var_options, direct=direct)
self.logger = logging.getLogger('python-logstash-logger')
self.logger.setLevel(logging.DEBUG)
self.logstash_server = self.get_option('server')
self.logstash_port = self.get_option('port')
self.logstash_type = self.get_option('type')
self.handler = logstash.TCPLogstashHandler(
os.getenv('LOGSTASH_SERVER', 'localhost'),
int(os.getenv('LOGSTASH_PORT', 5000)),
self.logstash_server,
int(self.logstash_port),
version=1,
message_type=os.getenv('LOGSTASH_TYPE', 'ansible')
message_type=self.logstash_type
)
self.logger.addHandler(self.handler)
self.hostname = socket.gethostname()
self.session = str(uuid.uuid1())
self.errors = 0
self.start_time = datetime.utcnow()
def v2_playbook_on_start(self, playbook):
self.playbook = playbook._file_name