-
Notifications
You must be signed in to change notification settings - Fork 14
Description
Does "CMK_JINJA_USE_REPLACERS_FOR_HOSTNAMES" in the config.py / cmk_cleanup_hostname(input_str) in application/modules/checkmk/helpers.py work properly?
It seems like i dont get it running properly.
little explanation what i am trying to do/Context:
I am using CMDBSyncer to sync hosts from NetBox to Checkmk. During the sync process:
- Hosts are imported into CMDBSyncer from NetBox with their original names (this works as intended and should remain unchanged in CMDBSyncer).
- However, I would like to rewrite the hostname only during the export to Checkmk, as some hostnames do not match Checkmk's required pattern:
'^[-0-9a-zA-Z_.]+\\\\Z'
I changed following two lines in the config.py
CMK_JINJA_USE_REPLACERS = True
CMK_JINJA_USE_REPLACERS_FOR_HOSTNAMES = True
in the helpers.py the comment [...] you wan't to use as tag_id in cmk is wrong, :
def cmk_cleanup_hostname(input_str):
"""
Cleans Invalid Chars out
of strings you wan't to use as tag_id in cmk
"""
if app.config['CMK_JINJA_USE_REPLACERS_FOR_HOSTNAMES']:
for needle, replacer in app.config['REPLACERS']:
input_str = input_str.replace(needle, replacer)
return re.sub('[^a-zA-Z0-9_-]', '_', input_str.strip()).lower()
maybe i am missing something?
I also tried to create some rules, but they dont change the Hostname, they just add an Attribute named Hostname with the cleaned-up hostname as value.
I found a workaround, after editing application/modules/checkmk/syncer.py it work - but i dont know if this is the right implementation:
# .-- Run Sync
def run(self):
"""Run Job"""
# In Order to delete Hosts from Checkmk, we collect the ones we sync
[...]
self.console = progress.console.print
for hostname, data in host_actions.items():
#added following 2 lines
if app.config['CMK_JINJA_USE_REPLACERS_FOR_HOSTNAMES']:
hostname = cmk_cleanup_hostname(hostname)
export_details = []
progress.console.print(f"* {hostname}")
[...]
Or is this feature not 100% implemented right now?