ansible-collections / community.general

Ansible Community General Collection
https://galaxy.ansible.com/ui/repo/published/community/general/
GNU General Public License v3.0
788 stars 1.45k forks source link

Enable Logdna callback plugin to pass in custom log ingestion url #8297

Open kirkhw opened 2 months ago

kirkhw commented 2 months ago

Summary

With many Cloud Service Providers (CSP) offering a managed hosted version of Logdna on their platforms, it is necessary to send logs for aggregation and analysis against Logdna endpoints for that CSP's service endpoints.

The Ansbile 2.9 implementation of this callback does not expose a method to pass in a custom url (i.e. conf_url) to which the dependent Logdna Python Library does support as an inbound option (url). As a result the Logdna Python Library uses it's default config url at https://logs.logdna.com/logs/ingest. An example endpoint url is https://logs.ca-tor.logging.cloud.ibm.com/logs/ingest for an instance provisioned in the Toronto multizone region of this CSP. We believe the same applies to the latest implementation too.

By modifying the file python/3.8.19/lib/python3.8/site-packages/ansible/plugins/callback/logdna.py, this can be easily achieved. Line 145 for example can be expanded to pass the url option from a new Ansible callback plugin variable conf_url (naming convention to match existing variables).

Before: self.options = {'hostname': self.conf_hostname, 'mac': self.mac, 'index_meta': True} After: self.conf_url = self.get_option('conf_url') self.options = {'hostname': self.conf_hostname, 'mac': self.mac, 'index_meta': True, 'url': self.conf_url}

We'd also appreciate guidance on how we could extend this plugin for the short term. These alterations worked in a local development workspace. Managing the manual edits on remote bare metal and virtual servers is something we haven't figured out yet.

Issue Type

Feature Idea

Component Name

logdna callback

Additional Information

[defaults]
log_path = ansible.log
callback_whitelist = logdna
callback_enabled = logdna

[callback_logdna]
conf_tags = mycustomtag
conf_url = https://logs.ca-tor.logging.cloud.ibm.com/logs/ingest
conf_key = mykey
plugin_ignore_errors = no
    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.conf_url = self.get_option('conf_ur') <------ HERE
         ............
         ............
         if HAS_LOGDNA:
             self.log = logging.getLogger('logdna')
             self.log.setLevel(logging.INFO)
             self.options = {'hostname': self.conf_hostname, 'mac': self.mac, 'index_meta': True, 'url': self.conf_url}   <----- HERE
             self.log.addHandler(LogDNAHandler(self.conf_key, self.options))
             self.disabled = False
         else:
         ..........

Code of Conduct

kirkhw commented 2 months ago

For an interim work around, can someone point out how we might deploy our own customization to this plugin?

felixfontein commented 2 months ago

!component =plugins/callback/logdna.py

kirkhw commented 2 months ago

Another finding is self.conf_tags though being pulled in from [callback_logdna] var conf_tags is not being passed to the Logdna Python Library and as such unable to set the Logdna tagging desired.