Skip to main content

Grafana

In this example you are going to create a webhook integration between Grafana and Port, which will ingest alert entities.

Port configuration​

Create the following blueprint definition:

Alert blueprint
{
"identifier": "grafanaAlert",
"description": "This blueprint represents a Grafana alert in your software catalog",
"title": "Grafana Alert",
"icon": "Grafana",
"schema": {
"properties": {
"status": {
"title": "Status",
"description": "Current status of the alert, firing or resolved",
"type": "string",
"enum": ["firing", "resolved"],
"enumColors": {
"firing": "red",
"resolved": "green"
}
},
"labels": {
"title": "Labels",
"type": "object",
"description": "Labels that are part of this alert, map of string keys to string values"
},
"description": {
"title": "Description",
"type": "string"
},
"createdAt": {
"title": "Created at",
"description": "Start time of the alert",
"type": "string",
"format": "date-time"
},
"resolvedAt": {
"title": "Resolved At",
"type": "string",
"description": "End time of the alert",
"format": "date-time"
},
"values": {
"title": "Values",
"type": "object",
"description": "Values that triggered the current status"
},
"generatorURL": {
"title": "Generator URL",
"type": "string",
"description": "URL of the alert rule in the Grafana UI",
"format": "url"
},
"fingerprint": {
"title": "Fingerprint",
"description": "The labels fingerprint, alarms with the same labels will have the same fingerprint",
"type": "string"
},
"silenceURL": {
"title": "Silence URL",
"description": "URL to silence the alert rule in the Grafana UI",
"type": "string",
"format": "url"
},
"summary": {
"title": "Summary",
"type": "string"
},
"runbookURL": {
"title": "Runbook URL",
"type": "string",
"description": "URL of the runbook in the Grafana UI",
"format": "url"
}
},
"required": []
},
"mirrorProperties": {},
"calculationProperties": {},
"relations": {}
}

Create the following webhook configuration using Port's UI

Alert webhook configuration
  1. Basic details tab - fill the following details:

    1. Title : Grafana Alert Mapper;
    2. Identifier : grafana_alert_mapper;
    3. Description : A webhook configuration to map Grafana alerts to Port;
    4. Icon : Grafana;
  2. Integration configuration tab - fill the following JQ mapping:

    [
    {
    "blueprint": "grafanaAlert",
    "filter": "true",
    "itemsToParse": ".body.alerts",
    "entity": {
    "identifier": ".item.labels.alertname + \"-\" + .item.fingerprint | gsub(\"[^a-zA-Z0-9@_.:/=-]\"; \"-\") | tostring",
    "title": ".item.labels.alertname",
    "properties": {
    "status": ".item.status",
    "labels": ".item.labels",
    "description": ".item.annotations.description",
    "summary": ".item.annotations.summary",
    "runbookURL": ".item.annotations.runbook_url",
    "createdAt": ".item.startsAt",
    "resolvedAt": ".item.endsAt",
    "values": ".item.values",
    "generatorURL": "if .item.generatorURL != \"\" then .item.generatorURL else null end",
    "fingerprint": ".item.fingerprint",
    "silenceURL": "if .item.silenceURL != \"\" then .item.silenceURL else null end"
    }
    }
    }
    ]
  3. Click Save at the bottom of the page.

Create a webhook in Grafana​

  1. Go to Alerting in your Grafana account;
  2. Under Contact points click Add contact point;
  3. Input the following details:
    1. Name - use a meaningful name such as Port Webhook;
    2. Integration - select Webhook from the list;
    3. URL - enter the value of the url key you received after creating the webhook configuration;
  4. Click Save contact point to save the contact;
  5. Go to Notification policies and add the Port Webhook contact point to your Default policy and be notified of any alert in Grafana;
  6. You can optionally add the contact point to an existing notification policy or create a new policy depending on your use case;
  7. Click Save policy.

Done! any change that happens to your alerts in Grafana will trigger a webhook event to the webhook URL provided by Port. Port will parse the events according to the mapping and update the catalog entities accordingly.