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
-
Basic details tab - fill the following details:
- Title :
Grafana Alert Mapper
; - Identifier :
grafana_alert_mapper
; - Description :
A webhook configuration to map Grafana alerts to Port
; - Icon :
Grafana
;
- Title :
-
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"
}
}
}
] -
Click Save at the bottom of the page.
Create a webhook in Grafana​
- Go to Alerting in your Grafana account;
- Under Contact points click Add contact point;
- Input the following details:
Name
- use a meaningful name such as Port Webhook;Integration
- selectWebhook
from the list;URL
- enter the value of theurl
key you received after creating the webhook configuration;
- Click Save contact point to save the contact;
- Go to Notification policies and add the Port Webhook contact point to your Default policy and be notified of any alert in Grafana;
- You can optionally add the contact point to an existing notification policy or create a new policy depending on your use case;
- 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.