From de6558ec7ee4926837f245a1e19c577ed6b4186c Mon Sep 17 00:00:00 2001 From: "willem.serruys" Date: Mon, 29 Dec 2025 06:06:46 +0100 Subject: [PATCH] chore: updated docker --- docker-compose.yml | 1 + microservices/power_control/Program.cs | 10 +++- .../power_control/example_body_firing.json | 51 ++++++++++++++++++ .../power_control/example_body_resolved.json | 53 +++++++++++++++++++ 4 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 microservices/power_control/example_body_firing.json create mode 100644 microservices/power_control/example_body_resolved.json diff --git a/docker-compose.yml b/docker-compose.yml index 9c76557..6c4b282 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -139,3 +139,4 @@ services: build: context: . dockerfile: ./dockerfiles/power_control.Dockerfile + network_mode: "host" diff --git a/microservices/power_control/Program.cs b/microservices/power_control/Program.cs index f4d7771..5cab238 100644 --- a/microservices/power_control/Program.cs +++ b/microservices/power_control/Program.cs @@ -6,10 +6,13 @@ var app = builder.Build(); app.MapPost( "/high_power_alert", - (object body) => + async (AlertBody body) => { Console.WriteLine("high power alert was received."); Console.WriteLine(System.Text.Json.JsonSerializer.Serialize(body)); + + using var client = new HttpClient(); + await client.GetAsync("http://192.168.1.121/control?cmd=heatpump&set_power_mode=off"); return new OkResult(); } ) @@ -26,3 +29,8 @@ app.MapPost( .WithName("Low Power Alert"); app.Run(); + +record AlertBody +{ + string status; +} diff --git a/microservices/power_control/example_body_firing.json b/microservices/power_control/example_body_firing.json new file mode 100644 index 0000000..8d3fe01 --- /dev/null +++ b/microservices/power_control/example_body_firing.json @@ -0,0 +1,51 @@ +{ + "receiver": "REST API", + "status": "firing", + "alerts": [ + { + "status": "firing", + "labels": { + "alertname": "Alert if peak is too high", + "domain": "sensor", + "entity_id": "thienpont_serruys_load_grid", + "grafana_folder": "Power" + }, + "annotations": { + "description": "Disable some devices to lower the peak.", + "summary": "Peak is too high!" + }, + "startsAt": "2025-12-29T04:58:50Z", + "endsAt": "0001-01-01T00:00:00Z", + "generatorURL": "http://localhost:3000/alerting/grafana/ef6m5j923ruv4f/view?orgId=1", + "fingerprint": "2c3f0f9ffb7d8c5d", + "silenceURL": "http://localhost:3000/alerting/silence/new?alertmanager=grafana\u0026matcher=__alert_rule_uid__%3Def6m5j923ruv4f\u0026matcher=domain%3Dsensor\u0026matcher=entity_id%3Dthienpont_serruys_load_grid\u0026orgId=1", + "dashboardURL": "http://localhost:3000/d/2990096a-3ff9-4217-a629-2152a260b6b6?from=1766980730000\u0026orgId=1\u0026to=1766984335061", + "panelURL": "http://localhost:3000/d/2990096a-3ff9-4217-a629-2152a260b6b6?from=1766980730000\u0026orgId=1\u0026to=1766984335061\u0026viewPanel=3", + "values": { "B": 4015.25, "C": 1 }, + "valueString": "[ var=\u0027B\u0027 labels={domain=sensor, entity_id=thienpont_serruys_load_grid} value=4015.25 ], [ var=\u0027C\u0027 labels={domain=sensor, entity_id=thienpont_serruys_load_grid} value=1 ]", + "orgId": 1 + } + ], + "groupLabels": { + "alertname": "Alert if peak is too high", + "grafana_folder": "Power" + }, + "commonLabels": { + "alertname": "Alert if peak is too high", + "domain": "sensor", + "entity_id": "thienpont_serruys_load_grid", + "grafana_folder": "Power" + }, + "commonAnnotations": { + "description": "Disable some devices to lower the peak.", + "summary": "Peak is too high!" + }, + "externalURL": "http://localhost:3000/", + "version": "1", + "groupKey": "{}/{__grafana_autogenerated__=\u0022true\u0022}/{__grafana_receiver__=\u0022REST API\u0022}:{alertname=\u0022Alert if peak is too high\u0022, grafana_folder=\u0022Power\u0022}", + "truncatedAlerts": 0, + "orgId": 1, + "title": "[FIRING:1] Alert if peak is too high Power (sensor thienpont_serruys_load_grid)", + "state": "alerting", + "message": "**Firing**\n\nValue: B=4015.25, C=1\nLabels:\n - alertname = Alert if peak is too high\n - domain = sensor\n - entity_id = thienpont_serruys_load_grid\n - grafana_folder = Power\nAnnotations:\n - description = Disable some devices to lower the peak.\n - summary = Peak is too high!\nSource: http://localhost:3000/alerting/grafana/ef6m5j923ruv4f/view?orgId=1\nSilence: http://localhost:3000/alerting/silence/new?alertmanager=grafana\u0026matcher=__alert_rule_uid__%3Def6m5j923ruv4f\u0026matcher=domain%3Dsensor\u0026matcher=entity_id%3Dthienpont_serruys_load_grid\u0026orgId=1\nDashboard: http://localhost:3000/d/2990096a-3ff9-4217-a629-2152a260b6b6?from=1766980730000\u0026orgId=1\u0026to=1766984335061\nPanel: http://localhost:3000/d/2990096a-3ff9-4217-a629-2152a260b6b6?from=1766980730000\u0026orgId=1\u0026to=1766984335061\u0026viewPanel=3\n" +} diff --git a/microservices/power_control/example_body_resolved.json b/microservices/power_control/example_body_resolved.json new file mode 100644 index 0000000..866b6c5 --- /dev/null +++ b/microservices/power_control/example_body_resolved.json @@ -0,0 +1,53 @@ +{ + "receiver": "REST API", + "status": "resolved", + "alerts": [ + { + "status": "resolved", + "labels": { + "alertname": "Alert if peak is too high", + "domain": "sensor", + "entity_id": "thienpont_serruys_load_grid", + "grafana_folder": "Power" + }, + "annotations": { + "description": "Disable some devices to lower the peak.", + "grafana_state_reason": "Updated", + "summary": "Peak is too high!" + }, + "startsAt": "2025-12-29T04:58:50Z", + "endsAt": "2025-12-29T04:59:25.018228513Z", + "generatorURL": "http://localhost:3000/alerting/grafana/ef6m5j923ruv4f/view?orgId=1", + "fingerprint": "2c3f0f9ffb7d8c5d", + "silenceURL": "http://localhost:3000/alerting/silence/new?alertmanager=grafana\u0026matcher=__alert_rule_uid__%3Def6m5j923ruv4f\u0026matcher=domain%3Dsensor\u0026matcher=entity_id%3Dthienpont_serruys_load_grid\u0026orgId=1", + "dashboardURL": "http://localhost:3000/d/2990096a-3ff9-4217-a629-2152a260b6b6?from=1766980730000\u0026orgId=1\u0026to=1766984365018", + "panelURL": "http://localhost:3000/d/2990096a-3ff9-4217-a629-2152a260b6b6?from=1766980730000\u0026orgId=1\u0026to=1766984365018\u0026viewPanel=3", + "values": null, + "valueString": "[ var=\u0027B\u0027 labels={domain=sensor, entity_id=thienpont_serruys_load_grid} value=3826.9 ], [ var=\u0027C\u0027 labels={domain=sensor, entity_id=thienpont_serruys_load_grid} value=1 ]", + "orgId": 1 + } + ], + "groupLabels": { + "alertname": "Alert if peak is too high", + "grafana_folder": "Power" + }, + "commonLabels": { + "alertname": "Alert if peak is too high", + "domain": "sensor", + "entity_id": "thienpont_serruys_load_grid", + "grafana_folder": "Power" + }, + "commonAnnotations": { + "description": "Disable some devices to lower the peak.", + "grafana_state_reason": "Updated", + "summary": "Peak is too high!" + }, + "externalURL": "http://localhost:3000/", + "version": "1", + "groupKey": "{}/{__grafana_autogenerated__=\u0022true\u0022}/{__grafana_receiver__=\u0022REST API\u0022}:{alertname=\u0022Alert if peak is too high\u0022, grafana_folder=\u0022Power\u0022}", + "truncatedAlerts": 0, + "orgId": 1, + "title": "[RESOLVED] Alert if peak is too high Power (sensor thienpont_serruys_load_grid)", + "state": "ok", + "message": "**Resolved**\n\nValue: [no value]\nLabels:\n - alertname = Alert if peak is too high\n - domain = sensor\n - entity_id = thienpont_serruys_load_grid\n - grafana_folder = Power\nAnnotations:\n - description = Disable some devices to lower the peak.\n - grafana_state_reason = Updated\n - summary = Peak is too high!\nSource: http://localhost:3000/alerting/grafana/ef6m5j923ruv4f/view?orgId=1\nSilence: http://localhost:3000/alerting/silence/new?alertmanager=grafana\u0026matcher=__alert_rule_uid__%3Def6m5j923ruv4f\u0026matcher=domain%3Dsensor\u0026matcher=entity_id%3Dthienpont_serruys_load_grid\u0026orgId=1\nDashboard: http://localhost:3000/d/2990096a-3ff9-4217-a629-2152a260b6b6?from=1766980730000\u0026orgId=1\u0026to=1766984365018\nPanel: http://localhost:3000/d/2990096a-3ff9-4217-a629-2152a260b6b6?from=1766980730000\u0026orgId=1\u0026to=1766984365018\u0026viewPanel=3\n" +}