katprep
katprep copied to clipboard
Implement check_mk support
It would be handy to have check_mk support for katprep! 👍
Some hints for API calls:
- https://mathias-kettner.de/cms_web_api.html
- https://mathias-kettner.de/cms_web_api_references.html
- https://mathias-kettner.de/checkmk_multisite_automation.html
Some TODOs:
- [ ] implement
CheckMkAPIClient.py
- [ ] implement unit tests and cookbook for creating check_mk vagrant boxes
- As a workaround, before it's implemented, can be nagios/icinga url
https://${CMK_FQDN}/${CMK_SITE_NAME}/nagios/cgi-bin/status.cgi with NagiosCGIClient
- Here are some curl snippets:
output_format=python is maybe reasonable
#show all hosts
curl -ѕ 'https://'${CMK_FQDN}/${CMK_SITE_NAME}'/check_mk/webapi.py?action=get_all_hosts&output_format=json&_username='${CMK_USERNAME}'&_secret='${CMK_APIKEY} |jq -r .
#get all services of one host
curl -s 'https://'${CMK_FQDN}/${CMK_SITE_NAME}'/check_mk/view.py?_do_confirm=yes&_transid=-1&_do_actions=yes&view_name=host&site='${CMK_SITE_NAME}'&output_format=json&_username='${CMK_USERNAME}'&host='${CMK_AFFECTED_HOST}'&_secret='${CMK_APIKEY} |jq -r '.[] | tostring'
#downtime for 3 minutes recursiv from now
curl -s 'https://'${CMK_FQDN}/${CMK_SITE_NAME}'/check_mk/view.py?_do_confirm=yes&_transid=-1&_do_actions=yes&host='${CMK_AFFECTED_HOST}'&view_name=hoststatus&site=&_down_comment=reboot&_down_from_now=1&_down_minutes=3&_include_childs=1&_include_childs_recurse=1&output_format=json&_username='${CMK_USERNAME}'&_secret='${CMK_APIKEY}
#downtime for 3 minutes recursiv flexible for next hour
curl -s 'https://'${CMK_FQDN}/${CMK_SITE_NAME}'/check_mk/view.py?_do_confirm=yes&_transid=-1&_do_actions=yes&host='${CMK_AFFECTED_HOST}'&view_name=hoststatus&site=&_down_comment=reboot&_down_comment=reboot&_down_from_now=1&_down_minutes=60&_down_flexible=1&_down_duration=00:03&_include_childs=1&_include_childs_recurse=1&output_format=json&_username='${CMK_USERNAME}'&_secret='${CMK_APIKEY}
#remove host downtime
curl -s 'https://'${CMK_FQDN}/${CMK_SITE_NAME}'/check_mk/view.py?_do_confirm=yes&_transid=-1&_do_actions=yes&host='${CMK_AFFECTED_HOST}'&view_name=downtimes_of_host&site=&_remove_downtimes=Remove&output_format=json&_username='${CMK_USERNAME}'&_secret='${CMK_APIKEY}
Awesome, thank you very much for sharing @gratuxri! Looking forward to implement it soon.
There is new REST based API for CheckMK: https://docs.checkmk.com/master/de/rest_api.html It uses OpenAPI and creating a client should be very straightforward.