From b011be560added4f99d77cee3b0e5037fe2be955 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Fra=C3=9F?= Date: Fri, 28 Apr 2023 13:14:27 +0200 Subject: [PATCH] [mod] check:http_request:missing header --- source/localization/de.json | 3 ++- source/localization/en.json | 1 + source/logic/checks/http_request.py | 21 ++++++++++++++++----- todo.md | 1 + 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/source/localization/de.json b/source/localization/de.json index f650cdb..6e19097 100644 --- a/source/localization/de.json +++ b/source/localization/de.json @@ -22,7 +22,8 @@ "checks.generic_remote.overflow": "Laufwerk fast voll", "checks.http_request.request_failed": "HTTP-Abfrage fehlgeschlagen", "checks.http_request.status_code_mismatch": "Status-Code {{status_code_actual}} stimmt nicht mit dem erwarteten Wert {{status_code_expected}} überein", - "checks.http_request.header_value_mismatch": "Header-Wert für Schlüssel '{{key}}' '{{value_actual}}' stimmt nicht mit erwartetem Wert {{value_expected}} überein", + "checks.http_request.header_missing": "Header '{{key}}' ist nicht gesetzt und hat somit nicht den erwarteten Wert '{{value_expected}}'", + "checks.http_request.header_value_mismatch": "Header-Wert für Schlüssel '{{key}}' '{{value_actual}}' stimmt nicht mit erwartetem Wert '{{value_expected}}' überein", "checks.http_request.body_misses_part": "Rumpf enthält nicht den erwarteten Teil '{{part}}'", "misc.state_file_path": "Pfad zur Zustands-Datei", "misc.check_procedure_failed": "Prüfungs-Prozedur fehlgeschlagen", diff --git a/source/localization/en.json b/source/localization/en.json index 54d0442..00f2167 100644 --- a/source/localization/en.json +++ b/source/localization/en.json @@ -22,6 +22,7 @@ "checks.generic_remote.overflow": "disk drive almost full", "checks.http_request.request_failed": "HTTP request failed", "checks.http_request.status_code_mismatch": "actual status code {{status_code_actual}} does not match expected value {{status_code_expected}}", + "checks.http_request.header_missing": "header '{{key}}' is unset and hence does not match the expected value '{{value_expected}}'", "checks.http_request.header_value_mismatch": "actual header value for key '{{key}}' '{{value_actual}}' and does not match the expected value {{value_expected}}", "checks.http_request.body_misses_part": "body does not contain the expected part '{{part}}'", "misc.state_file_path": "state file path", diff --git a/source/logic/checks/http_request.py b/source/logic/checks/http_request.py index d1e10a4..258e2eb 100644 --- a/source/logic/checks/http_request.py +++ b/source/logic/checks/http_request.py @@ -167,19 +167,30 @@ class implementation_check_kind_http_request(interface_check_kind): ) elif (key == "headers"): for (header_key, header_value, ) in value.items(): - if (response.headers[header_key] == header_value): - pass - else: + if (not (header_key in response.headers)): faults.append( translation_get( - "checks.http_request.header_value_mismatch", + "checks.http_request.header_missing", { "key": header_key, - "value_actual": response.headers[header_key], "value_expected": header_value, } ) ) + else: + if (not (response.headers[header_key] == header_value)): + faults.append( + translation_get( + "checks.http_request.header_value_mismatch", + { + "key": header_key, + "value_actual": response.headers[header_key], + "value_expected": header_value, + } + ) + ) + else: + pass elif (key == "body_part"): if (response.text.find(value) >= 0): pass diff --git a/todo.md b/todo.md index 9239ecb..693d397 100644 --- a/todo.md +++ b/todo.md @@ -1,4 +1,5 @@ - auf DB umstellen? +- Schreib-Operationen vermindern - Benachrichtigungen versenden, wenn ein Zustand sich wieder normalisiert hat (aber vorher über dem Schwellwert oft nicht OK war) - längere Statistiken über Metriken führen um auch Anstiege/Abfälle auszuwerten (z.B. "Speicherplatzverbrauch innerhalb einer Woche um 5GB gestiegen") - Selbst-Test