package
0.195.1
Repository: https://github.com/influxcommunity/flux.git
Documentation: pkg.go.dev

# README

Opsgenie Package

Use this Flux Package to send alerts to Atlassian Opsgenie. The implementation is using opsgenie v2 API that is described in https://docs.opsgenie.com/docs/alert-api#create-alert.

See also

opsgenie.sendAlert

sendAlert sends a message that creates an alert in Opsgenie. Arguments:

NameTypeDescription
urlstringOpsgenie API URL. Defaults to "https://api.opsgenie.com/v2/alerts".
apiKeystringAPI Authorization key.
messagestringAlert message text, at most 130 characters.
aliasstringOpsgenie alias, at most 250 characters that are use to de-deduplicate alerts. Defaults to message.
descriptionstringDescription field of an alert, at most 15000 characters. Optional.
prioritystring"P1", "P2", "P3", "P4" or "P5". Defaults to "P3".
respondersarrayArray of strings to identify responder teams or users, a 'user:' prefix is required for users, 'teams:' prefix for teams. Optional.
tagsarrayArray of string tags. Optional.
entitystringEntity of the alert, used to specify a domain of the alert. Optional.
actionsarrayArray of strings that specifies actions that will be available for the alert. Optional.
detailsstringAdditional details of an alert, it must be a JSON-encoded map of key-value string pairs. Optional.
visibleToarrayArrays of teams and users that the alert will become visible to without sending any notification. Optional.

Basic Example:

import "contrib/sranka/opsgenie"

lastReported =
  from(bucket: "example-bucket")
    |> range(start: -1m)
    |> filter(fn: (r) => r._measurement == "statuses")
    |> last()
    |> tableFind(fn: (key) => true)
    |> getRecord(idx: 0)

opsgenie.createAlert(
  apiKey: "xxhhhssdd...",
  message: "Great Scott!- Disk usage is: ${lastReported.status}.",
  alias: "example-disk-usage",
  responders: ["user:[email protected]","team:itcrowd"]
)

opsgenie.endpoint

endpoint function creates a factory function that accepts a mapping function mapFn and creates a target function for pipeline |> that sends alert messages from table rows. The mapFn accepts a table row and returns an object with properties defined in the opsgenie.sendAlert function arguments expect url. apiKey and entity. Arguments:

NameTypeDescription
urlstringOpsgenie API URL. Defaults to "https://api.opsgenie.com/v2/alerts".
apiKeystringAPI Authorization key.
entitystringEntity of the alert, used to specify domain of the alert. Optional.

Basic Example:

import "contrib/sranka/opsgenie"
import "influxdata/influxdb/secrets"

// this value can be stored in the secret-store()
apiKey = secrets.get(key: "OPSGENIE_API_KEY")

lastReported =
from(bucket: "example-bucket")
  |> range(start: -1m)
  |> filter(fn: (r) => r._measurement == "statuses")
  |> last()
  |> tableFind(fn: (key) => true)
  |> opsgenie.endpoint(apiKey: apiKey)(mapFn: (r) => ({
          message: "Great Scott!- Disk usage is: ${r.status}.", 
          alias: "disk-usage-${r.status}",
          description: "",
          priority: "P3,
          responders: ["user:scott","team:itcrowd"],
          tags: [],
          entity: "my-lab",
          actions: [],
          details: "{}",
          visibleTo: []
        })
     )()

Contact

# Functions

RespondersToJSON is a flux function converts array of responder strings to a JSON string.