Skip to content

Commit 733a20f

Browse files
a little bit of clean up work for names being in a-z order, also added "category"
1 parent 227bfb1 commit 733a20f

File tree

3 files changed

+37
-37
lines changed

3 files changed

+37
-37
lines changed

internal/openmetrics-exporter/alerts_collector.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"fmt"
55
client "purestorage/fa-openmetrics-exporter/internal/rest-client"
66
"strings"
7-
"strconv"
7+
88
"github.com/prometheus/client_golang/prometheus"
99
)
1010

@@ -24,22 +24,24 @@ func (c *AlertsCollector) Collect(ch chan<- prometheus.Metric) {
2424
}
2525
al := make(map[string]float64)
2626
for _, alert := range alerts.Items {
27-
al[fmt.Sprintf("%s,%s,%s,%s,%s,%s,%s",
27+
al[fmt.Sprintf("%s,%d,%s,%d,%s,%s,%s,%s",
28+
alert.Category,
29+
alert.Code,
2830
alert.ComponentType,
29-
alert.Severity,
30-
strconv.Itoa(alert.Created),
31+
alert.Created,
32+
alert.Issue,
3133
alert.Name,
32-
strconv.Itoa(alert.Code),
34+
alert.Severity,
3335
alert.Summary,
34-
alert.Issue)] += 1
36+
)] += 1
3537
}
3638
for a, n := range al {
3739
alert := strings.Split(a, ",")
3840
ch <- prometheus.MustNewConstMetric(
3941
c.AlertsDesc,
4042
prometheus.GaugeValue,
4143
n,
42-
alert[0], alert[1], alert[2], alert[3], alert[4], alert[5], alert[6],
44+
alert[0], alert[1], alert[2], alert[3], alert[4], alert[5], alert[6], alert[7],
4345
)
4446
}
4547
}
@@ -49,7 +51,7 @@ func NewAlertsCollector(fa *client.FAClient) *AlertsCollector {
4951
AlertsDesc: prometheus.NewDesc(
5052
"purefa_alerts_open",
5153
"FlashArray open alert events",
52-
[]string{"component_type", "severity", "created", "name", "code", "summary", "issue"},
54+
[]string{"category", "code", "component_type", "created", "issue", "name", "severity", "summary"},
5355
prometheus.Labels{},
5456
),
5557
Client: fa,

internal/openmetrics-exporter/alerts_collector_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,13 @@ func TestAlertsCollector(t *testing.T) {
4444
e := endp[len(endp)-1]
4545
al := make(map[string]float64)
4646
for _, a := range aopen.Items {
47-
al[fmt.Sprintf("%s,%s", a.ComponentType, a.Severity, a.Created, a.Name, a.Code, a.Summary, a.Issue)] += 1
47+
al[fmt.Sprintf("%s,%d,%s,%d,%s,%s,%s,%s", a.Category, a.Code, a.ComponentType, a.Created, a.Issue, a.Name, a.Severity, a.Summary)] += 1
4848
}
4949
want := make(map[string]bool)
5050
for a, n := range al {
5151
alert := strings.Split(a, ",")
52-
// want[fmt.Sprintf("label:{name:\"component_type\" value:\"%s\"} label:{name:\"severity\" value:\"%s\"} gauge:{value:%g}", alert[0], alert[1], n)] = true
53-
// want[fmt.Sprintf("label:{name:\"component_type\" value:\"%s\"} label:{name:\"severity\" value:\"%s\"} gauge:{value:%g}", alert[0], alert[1], n)] = true
54-
want[fmt.Sprintf("label:{name:\"component_type\" value:\"%s\"} label:{name:\"severity\" value:\"%s\"} gauge:{value:%g}", alert[0], alert[1], alert[2], alert[3], alert[4], alert[5], alert[6], n)] = true
52+
53+
want[fmt.Sprintf("label:{name:\"category\" value:\"%s\"} label:{name:\"code\" value:\"%s\"} label:{name:\"component_type\" value:\"%s\"} label:{name:\"created\" value:\"%s\"} label:{name:\"issue\" value:\"%s\"} label:{name:\"name\" value:\"%s\"} label:{name:\"severity\" value:\"%s\"} label:{name:\"summary\" value:\"%s\"} gauge:{value:%g}", alert[0], alert[1], alert[2], alert[3], alert[4], alert[5], alert[6], alert[7], n)] = true
5554
}
5655
c := client.NewRestClient(e, "fake-api-token", "latest", false)
5756
ac := NewAlertsCollector(c)

internal/rest-client/alerts.go

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,32 @@
11
package client
22

3-
43
type Alert struct {
5-
Id string `json:"id"`
6-
Name string `json:"name"`
7-
Actual string `json:"actual"`
8-
Closed int `json:"closed"`
9-
Code int `json:"code"`
10-
ComponentName string `json:"component_name"`
11-
ComponentType string `json:"component_type"`
12-
Created int `json:"created"`
13-
Description string `json:"description"`
14-
Expected string `json:"expected"`
15-
Flagged bool `json:"flagged"`
16-
Issue string `json:"issue"`
17-
Index int `json:"index"`
18-
KnowledgeBaseUrl string `json:"knowledge_base_url"`
19-
Notified int `json:"notified"`
20-
Severity string `json:"severity"`
21-
State string `json:"state"`
22-
Summary string `json:"summary"`
23-
Updated int `json:"updated"`
4+
Id string `json:"id"`
5+
Name string `json:"name"`
6+
Actual string `json:"actual"`
7+
Category string `json:"category"`
8+
Closed int64 `json:"closed"`
9+
Code int64 `json:"code"`
10+
ComponentName string `json:"component_name"`
11+
ComponentType string `json:"component_type"`
12+
Created int64 `json:"created"`
13+
Description string `json:"description"`
14+
Expected string `json:"expected"`
15+
Flagged bool `json:"flagged"`
16+
Issue string `json:"issue"`
17+
KnowledgeBaseUrl string `json:"knowledge_base_url"`
18+
Notified int64 `json:"notified"`
19+
Severity string `json:"severity"`
20+
State string `json:"state"`
21+
Summary string `json:"summary"`
22+
Updated int64 `json:"updated"`
2423
}
2524

2625
type AlertsList struct {
27-
ContinuationToken string `json:"continuation_token"`
28-
TotalItemCount int `json:"total_item_count"`
29-
MoreItemsRemaining bool `json:"more_items_remaining"`
30-
Items []Alert `json:"items"`
26+
ContinuationToken string `json:"continuation_token"`
27+
TotalItemCount int32 `json:"total_item_count"`
28+
MoreItemsRemaining bool `json:"more_items_remaining"`
29+
Items []Alert `json:"items"`
3130
}
3231

3332
func (fa *FAClient) GetAlerts(filter string) *AlertsList {
@@ -48,6 +47,6 @@ func (fa *FAClient) GetAlerts(filter string) *AlertsList {
4847
if err != nil {
4948
fa.Error = err
5049
}
51-
50+
5251
return result
5352
}

0 commit comments

Comments
 (0)