https://github.com/kubesphere/alertmanager-kit
alertmanager-kit encapsulates the interface to alertmanager in a neat way.
https://github.com/kubesphere/alertmanager-kit
Last synced: over 1 year ago
JSON representation
alertmanager-kit encapsulates the interface to alertmanager in a neat way.
- Host: GitHub
- URL: https://github.com/kubesphere/alertmanager-kit
- Owner: kubesphere
- License: apache-2.0
- Created: 2020-03-27T05:36:34.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-11-08T08:08:48.000Z (almost 3 years ago)
- Last Synced: 2024-04-13T21:43:07.233Z (over 2 years ago)
- Language: Go
- Size: 35.2 KB
- Stars: 2
- Watchers: 4
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# alertmanager-kit
alertmanager-kit encapsulates the interface to alertmanager in a neat way.
# compatibility
It currently only works on newer versions of alertmanager which provide v2 api.
# usage
The following example demonstrates an usual usage. It fetches the Alertmanager status from the service, post/get alerts, post/get/delete silence.
```go
// Init the config
//config := kit.ClientConfig{
// URL: "http://139.198.112.79:59093",
//}
// Use this if running on kubernetes
config := kit.ClientConfig{
Service: &kit.ServiceReference{
Namespace: "monitoring",
Name: "alertmanager",
},
}
// Create client for alertmanager service
client, e := kit.NewClient(config)
if e != nil {
panic(e)
}
ctx, _ := context.WithTimeout(context.Background(), time.Second*10)
// Get status
status, e := client.GetStatus(ctx)
prettyPrintlnOrPanic(status, e)
// Post alerts
e = client.PostAlerts(ctx, []*kit.RawAlert{{
Labels: map[string]string{
"alertname": "test",
"alerttype": "test",
"namespace": "test",
"pod": "test"},
Annotations: map[string]string{"message": "test"},
}})
prettyPrintlnOrPanic(nil, e)
// Get alerts
alerts, e := client.GetAlerts(ctx,
kit.NewAlertsFilter().WithFilter([]string{"alertname=\"test\""}))
prettyPrintlnOrPanic(alerts, e)
// Post silence
silenceId, e := client.PostSilence(ctx, &kit.RawSilence{
StartsAt: strfmt.DateTime(time.Now()),
EndsAt: strfmt.DateTime(time.Now().Add(time.Minute)),
CreatedBy: "test",
Matchers: []*kit.Matcher{{
Name: "alertname",
Value: "test",
}},
})
prettyPrintlnOrPanic(silenceId, e)
// Get silence
silence, e := client.GetSilence(ctx, silenceId)
prettyPrintlnOrPanic(silence, e)
// Delete silence
e = client.DeleteSilence(ctx, silenceId)
prettyPrintlnOrPanic(nil, e)
```