From cf2317696d5d2d64453699788bfea2bca32e5790 Mon Sep 17 00:00:00 2001 From: Alex Ellis Date: Sun, 22 Jan 2017 11:13:45 +0000 Subject: [PATCH] Unmarshall the service name --- gateway/requests/requests.go | 17 ++++++++++++++--- gateway/tests/unmarshall_test.go | 10 ++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/gateway/requests/requests.go b/gateway/requests/requests.go index fb40469c..0cfd2f9f 100644 --- a/gateway/requests/requests.go +++ b/gateway/requests/requests.go @@ -22,7 +22,18 @@ type AlexaRequestBody struct { Request AlexaRequest `json:"request"` } -type PrometheusAlert struct { - Status string `json:"status"` - Receiver string `json:"receiver"` +type PrometheusInnerAlertLabel struct { + AlertName string `json:"alertname"` + FunctionName string `json:"function_name"` +} + +type PrometheusInnerAlert struct { + Status string `json:"status"` + Labels PrometheusInnerAlertLabel `json:"labels"` +} + +type PrometheusAlert struct { + Status string `json:"status"` + Receiver string `json:"receiver"` + Alerts []PrometheusInnerAlert `json:"alerts"` } diff --git a/gateway/tests/unmarshall_test.go b/gateway/tests/unmarshall_test.go index 989dcd33..4fa52288 100644 --- a/gateway/tests/unmarshall_test.go +++ b/gateway/tests/unmarshall_test.go @@ -26,4 +26,14 @@ func TestUnmarshallAlert(t *testing.T) { if (len(alert.Receiver)) == 0 { t.Fatal("No status read") } + if (len(alert.Alerts)) == 0 { + t.Fatal("No alerts read") + } + if (len(alert.Alerts[0].Labels.AlertName)) == 0 { + t.Fatal("No alerts name") + } + if (len(alert.Alerts[0].Labels.FunctionName)) == 0 { + t.Fatal("No function name read") + } + }