diff --git a/.werks/17219.md b/.werks/17219.md new file mode 100644 index 00000000000..ed607ce2675 --- /dev/null +++ b/.werks/17219.md @@ -0,0 +1,22 @@ +[//]: # (werk v2) +# gcp_status: Fix KeyError: 'global' + +key | value +---------- | --- +date | 2025-01-02T13:02:00+00:00 +version | 2.4.0b1 +class | fix +edition | cre +component | checks +level | 1 +compatible | yes + +This change affects users which have configured the rule 'Google Cloud Platform (GCP) Status'. +Previously, Checkmk did not handle incidents correctly, which had set `global` as an associated location. +This was the corresponding traceback: +``` + File "/omd/sites/mon_home/lib/python3/cmk/plugins/gcp/agent_based/gcp_status.py", line 72, in parse + data.setdefault(constants.RegionMap[location.id_], []).append(incident) +KeyError: 'global' +``` +With this werk, the crash is fixed. diff --git a/cmk/plugins/gcp/agent_based/gcp_status.py b/cmk/plugins/gcp/agent_based/gcp_status.py index 11c39f9ef18..528f942c00d 100644 --- a/cmk/plugins/gcp/agent_based/gcp_status.py +++ b/cmk/plugins/gcp/agent_based/gcp_status.py @@ -69,7 +69,8 @@ def parse(string_table: StringTable) -> Section: data: dict[str, list[Incident]] = {} for incident in output.health_info: for location in incident.currently_affected_locations: - data.setdefault(constants.RegionMap[location.id_], []).append(incident) + item = "Global" if location.id_ == "global" else constants.RegionMap[location.id_] + data.setdefault(item, []).append(incident) return Section(discovery_param=output.discovery_param, data=data) diff --git a/tests/unit/cmk/plugins/gcp/agent_based/test_gcp_status.py b/tests/unit/cmk/plugins/gcp/agent_based/test_gcp_status.py index fddfe10604e..fd021d3558f 100644 --- a/tests/unit/cmk/plugins/gcp/agent_based/test_gcp_status.py +++ b/tests/unit/cmk/plugins/gcp/agent_based/test_gcp_status.py @@ -112,6 +112,91 @@ def test_parsing(section: gcp_status.Section) -> None: } +def test_parsing_global() -> None: + # This is an agent output, which is edited to only have a single (unedited) incident. + string_table = [ + [ + r"""{ + "discovery_param": { + "regions": [ + "europe-west3" + ] + }, + "health_info": [ + { + "id": "rZvZvSKVdDHyWh4dZJ8D", + "number": "15564124031412553730", + "begin": "2023-03-10T14:09:43+00:00", + "created": "2023-03-10T14:26:24+00:00", + "end": "2023-03-10T14:54:50+00:00", + "modified": "2023-03-10T14:54:50+00:00", + "external_desc": "Retry errors for Google BigQuery in global", + "updates": [ + { + "created": "2023-03-10T14:26:17+00:00", + "modified": "2023-03-10T14:26:28+00:00", + "when": "2023-03-10T14:26:17+00:00", + "text": "Summary: Retry errors for Google BigQuery in global\nDescription: We are experiencing an issue with Google BigQuery.\nOur engineering team continues to investigate the issue.\nWe will provide an update by Friday, 2023-03-10 07:30 US/Pacific with current details.\nDiagnosis: Customers may experience retry errors when running DatasetService.*, TableService.*, BigQueryRead.CreateReadSession, BigQueryRead.ReadRows and BigQueryWrite.* commands for Google BigQuery in global\nWorkaround: Retry requests", + "status": "SERVICE_INFORMATION", + "affected_locations": [ + { + "title": "Finland (global)", + "id": "global" + } + ] + } + ], + "most_recent_update": { + "created": "2023-03-10T14:26:17+00:00", + "modified": "2023-03-10T14:26:28+00:00", + "when": "2023-03-10T14:26:17+00:00", + "text": "Summary: Retry errors for Google BigQuery in global\nDescription: We are experiencing an issue with Google BigQuery.\nOur engineering team continues to investigate the issue.\nWe will provide an update by Friday, 2023-03-10 07:30 US/Pacific with current details.\nDiagnosis: Customers may experience retry errors when running DatasetService.*, TableService.*, BigQueryRead.CreateReadSession, BigQueryRead.ReadRows and BigQueryWrite.* commands for Google BigQuery in global\nWorkaround: Retry requests", + "status": "SERVICE_INFORMATION", + "affected_locations": [ + { + "title": "Finland (global)", + "id": "global" + } + ] + }, + "status_impact": "SERVICE_INFORMATION", + "severity": "low", + "service_key": "9CcrhHUcFevXPSVaSxkf", + "service_name": "Google BigQuery", + "affected_products": [ + { + "title": "Google BigQuery", + "id": "9CcrhHUcFevXPSVaSxkf" + } + ], + "uri": "incidents/rZvZvSKVdDHyWh4dZJ8D", + "currently_affected_locations": [ + { + "title": "Finland (global)", + "id": "global" + } + ], + "previously_affected_locations": [] + } + ] + } + """ + ] + ] + section_global = gcp_status.parse(string_table) + assert section_global.discovery_param == gcp_status.DiscoveryParam(regions=["europe-west3"]) + assert section_global.data == { + "Global": [ + gcp_status.Incident( + affected_products=[gcp_status.AffectedProduct(title="Google BigQuery")], + currently_affected_locations=[gcp_status.AffectedLocation(id="global")], + external_desc="Retry errors for Google BigQuery in global", + uri="incidents/rZvZvSKVdDHyWh4dZJ8D", + ) + ] + } + + def test_no_indicents() -> None: discovery_param = gcp_status.DiscoveryParam(regions=["us-east"]) section = gcp_status.Section(discovery_param=discovery_param, data={})