wip: icingatools webcheck

This commit is contained in:
2026-04-20 23:12:34 +02:00
parent bb5aaa47ad
commit ed039833c5

View File

@@ -1,5 +1,15 @@
import icinga2api import icinga2api
import icinga2api.client import icinga2api.client
from urllib.parse import urlparse
def split_url(url):
parsed = urlparse(url)
http_vhost = parsed.hostname
http_uri = parsed.path or "/"
http_ssl = parsed.scheme == "https"
return http_vhost, http_uri, http_ssl
def _create_client(app): def _create_client(app):
@@ -39,7 +49,7 @@ def _build_service_name(user, async_service_name):
return "{}_async_{}".format(user, async_service_name) return "{}_async_{}".format(user, async_service_name)
def create_service(user, async_service_name, app): def create_service(user, async_service_name, app, webcheck=False):
if not app.config.get("ICINGA_API_URL"): if not app.config.get("ICINGA_API_URL"):
return return
@@ -48,6 +58,29 @@ def create_service(user, async_service_name, app):
name = _build_service_name(user, async_service_name) name = _build_service_name(user, async_service_name)
host_name = app.config["ASYNC_ICINGA_DUMMY_HOST"] host_name = app.config["ASYNC_ICINGA_DUMMY_HOST"]
# TODO: query service from DB
accepted_return_codes = [200, 204]
if webcheck:
http_vhost, http_uri, http_ssl = split_url(url)
service_config = {
"templates": ["generic-service"],
"attrs": {
"display_name": name,
"check_command": "http",
"host_name": host_name,
"vars": {
"http_vhost": http_vhost,
"http_uri": http_uri,
"http_expect": http_expect,
"http_accept_status": accepted_return_codes, # array
"http_ssl": True,
"http_sni": True
}
}
}
else:
service_config = { service_config = {
"templates": ["generic-service"], "templates": ["generic-service"],
"attrs": { "attrs": {