Skip to content

Commit

Permalink
feat: add group and common labels for templating (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxwo authored Jan 8, 2023
1 parent 62d375d commit f520c6f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
11 changes: 10 additions & 1 deletion alertparser/alert_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,16 @@ func (alertParser AlertParser) Parse(alertsData types.AlertsData) (*types.AlertB
}
key := strings.Join([]string{*oid, "[", groupID, "]"}, "")
if _, found := alertGroups[key]; !found {
alertGroups[key] = &types.AlertGroup{OID: *oid, GroupID: groupID, Severity: alertParser.getLowestSeverity(), Alerts: []types.Alert{}, DeclaredAlerts: []types.Alert{}}
alertGroups[key] = &types.AlertGroup{
OID: *oid,
GroupID: groupID,
GroupLabels: alertsData.GroupLabels,
CommonLabels: alertsData.CommonLabels,
CommonAnnotations: alertsData.CommonAnnotations,
Severity: alertParser.getLowestSeverity(),
Alerts: []types.Alert{},
DeclaredAlerts: []types.Alert{},
}
}
alertGroups[key].DeclaredAlerts = append(alertGroups[key].DeclaredAlerts, alert)
if alert.Status == "firing" {
Expand Down
12 changes: 12 additions & 0 deletions alertparser/test_mixed_bucket.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"1.3.6.1.4.1.666.0.10.1.1.1.2.1[environment=production,label=test]": {
"OID": "1.3.6.1.4.1.666.0.10.1.1.1.2.1",
"GroupID": "environment=production,label=test",
"GroupLabels": {
"environment": "production",
"label": "test"
},
"Severity": "critical",
"Alerts": [
{
Expand Down Expand Up @@ -68,6 +72,10 @@
"1.1[environment=production,label=test]": {
"OID": "1.1",
"GroupID": "environment=production,label=test",
"GroupLabels": {
"environment": "production",
"label": "test"
},
"Severity": "critical",
"Alerts": [
{
Expand Down Expand Up @@ -103,6 +111,10 @@
"1.3.6.1.4.1.666.0.10.1.1.1.1.1[environment=production,label=test]": {
"OID": "1.3.6.1.4.1.666.0.10.1.1.1.1.1",
"GroupID": "environment=production,label=test",
"GroupLabels": {
"environment": "production",
"label": "test"
},
"Severity": "info",
"Alerts": [],
"DeclaredAlerts": [
Expand Down
4 changes: 2 additions & 2 deletions scripts/local/listen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ set -ex

rm -rf /var/db/net-snmp
mkdir -p $HOME/.snmp/mibs
ln -s $PWD/../mibs/SNMP-NOTIFIER-MIB.my $HOME/.snmp/mibs/SNMP-NOTIFIER-MIB.my
snmptrapd -m ALL -m +SNMP-NOTIFIER-MIB -f -Of -Lo -c snmptrapd.conf -x 127.0.0.1 "::1"
ln -s $PWD/../mibs/SNMP-NOTIFIER-MIB.my $HOME/.snmp/mibs/SNMP-NOTIFIER-MIB.my || true
snmptrapd -m ALL -m +SNMP-NOTIFIER-MIB -f -Of -Lo -c snmptrapd.conf
13 changes: 8 additions & 5 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@ type AlertBucket struct {

// AlertGroup type, with OID and group ID
type AlertGroup struct {
OID string
GroupID string
Severity string
Alerts []Alert
DeclaredAlerts []Alert
OID string
GroupID string
GroupLabels map[string]string
CommonLabels map[string]string
CommonAnnotations map[string]string
Severity string
Alerts []Alert
DeclaredAlerts []Alert
}

// GetAlertGroupName allows to retrieve a group name from a given alert
Expand Down

0 comments on commit f520c6f

Please sign in to comment.