Rule for automatic discovery of labels

Hello community,

using Raw edition 1.6.0p7. Recently discovered the potential of labels for dynamic configurations, and wrote a little agent plugin that returns labels for some site-specific facts. But now I’m stuck with the correct discovery rule. As far as I have seen, there is only one rule for automatic discovery that does everything for labels AND services. But I would want to:

  • always accept any labels whether they appear or disappear (no manual intervention needed)
  • keep at least the property that vanished services are never autoaccepted but rather alerted as CRIT.

Is there a recipe for these two goals?

Many thanks and keep up the good work!

Regards,
sultansofswing.

1 Like

You can do this at the moment only as a web request if i see it correctly.
Inside the WATO Api is no command to update only the host labels.

If i inspect the button “Update host labels” then i can see a request to the URL
http://<monitoring server>/<site>/check_mk/ajax_service_discovery.py
With request in the following style

{“host_name”:“HOSTNAME”,“folder_path”:"",“discovery_options”:{“action”:“update_host_labels”,“ignore_errors”:true},}

1 Like

Thank you @andreas-doehler, issuing web requests is something I didn’t consider at all. But you’re right: such a ‘polling’ solution is better than nothing as long as it does the job.

Is this call also available inside the check_mk/webapi.py namespace? This would save me from fiddling with session cookies or any special requirements of the web frontend - it would feel more portable.

By the way, I did not get CMK to alert me whenever a label changed its value - only if a label appears or disappears. I guess, labels are a moving target for now, and I’ll investigate how the handling will be changed in the near future.

Thanks again,
sultansofswing.

Inside the webapi it is not present at the moment. You are right this would be the best solution.
I think you don’t need session cookies and so on. Automation user with secret should be ok for such a request.

Hi @andreas-doehler, no problem if we have to use a ‘not-so-clean’ solution. Currently, I’m writing a loop over hosts in cmk -l and comparing the output of cmk -D <host> against cmk -d <host> with regard to labels. So at least my polling won’t waste network cycles. Thanks for your help. Marking your answer as a solution.

1 Like

Hi all, now I got it to work. Some hints for those who want to do it too:

  • You don’t need to use POST at all; all parameters to the ajax_service_discovery.py call can be urlencoded GET arguments.
  • For the web request to work at all, the three parameters _transid (with value ‘-1’), _username and _secret have to be present.
  • The call has to contain folder_path (empty, or whatever path) and host_name (obviously) arguments.
  • Finally an arg request has to be present, with the JSON-encoded variables action (update_host_labels) and five flags: ignore_errors, show_checkboxes, show_parameters, show_discovered_labels, show_plugin_names (all set to “true”).
  • Afterwards, you have to do the ‘apply changes’ action, just as you would do in the web frontend, do it according to https://checkmk.com/cms_web_api_references.html.

Regards,
sultansofswing.

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.