Skip to content

JackFazackerley/logrus-opsgenie-hook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OpsGenie Hook for Logrus :walrus: Build Status godoc reference

This hook is used to send your errors to OpsGenie as an alert. It uses the 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.

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.

About

Hook for logrus that sends errors to OpsGenie as alerts.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages