https://github.com/jackfazackerley/logrus-opsgenie-hook
Hook for logrus that sends errors to OpsGenie as alerts.
https://github.com/jackfazackerley/logrus-opsgenie-hook
golang logging logrus opsgenie
Last synced: 6 months ago
JSON representation
Hook for logrus that sends errors to OpsGenie as alerts.
- Host: GitHub
- URL: https://github.com/jackfazackerley/logrus-opsgenie-hook
- Owner: JackFazackerley
- License: mit
- Created: 2018-09-03T23:14:37.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-09-03T23:46:54.000Z (almost 8 years ago)
- Last Synced: 2025-08-15T01:47:37.118Z (11 months ago)
- Topics: golang, logging, logrus, opsgenie
- Language: Go
- Homepage:
- Size: 3.91 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# OpsGenie Hook for Logrus
[](https://travis-ci.org/JackFazackerley/logrus-opsgenie-hook) [](https://godoc.org/github.com/JackFazackerley/logrus-opsgenie-hook)
This hook is used to send your errors to [OpsGenie](https://www.opsgenie.com/) as an alert. It uses the [opsgenie-go-sdk](https://github.com/opsgenie/opsgenie-go-sdk) to handle the requests. The levels that are blocked by this hook are `log.Error`, `log.Fatal`, and `log.Panic`.
## Usage
The only configuration needed for this hook is the OpsGenie API key you wish to use. However the alert struct must be created yourself with the fields you wish to use and added as a `logrus.Entry` using `WithField("request", alert)`.
The message of the alert will default to the log level message: `Error("some error")`, although if `WithError(err)` is used that will become a priority.
```go
import (
"fmt"
"github.com/jackfazackerley/logrus-opsgenie-hook"
"github.com/opsgenie/opsgenie-go-sdk/alertsv2"
"github.com/sirupsen/logrus"
)
func main() {
log := logrus.New()
hook, err := opsgenie.NewHook("some API key")
if err != nil {
panic(err)
}
log.AddHook(hook)
alert := alertsv2.CreateAlertRequest{
Alias: "some alias here",
Description: "some description here",
Teams: []alertsv2.TeamRecipient{
&alertsv2.Team{
Name: "Dev",
},
},
Source: "some source here",
Priority: alertsv2.P5,
}
// Uses default message as the alert message
log.WithField("alert", alert).Error("default message value")
// WithError is made priority for the alert message
log.WithField("alert", alert).WithError(fmt.Errorf("made priority")).Error("default message value")
}
```
The structure for the OpsGenie alert is documented [Here](https://godoc.org/github.com/opsgenie/opsgenie-go-sdk/alertsv2#CreateAlertRequest).