Send Alerts to Opsgenie
5 minute read
Overview
This guide demonstrates how to create Opsgenie alerts from EdgeDelta using the Alert API. Opsgenie is an incident management platform that routes alerts to the right on-call responders and enables effective incident response.
Prerequisites
- Opsgenie Account: Access to create API integrations
- API Key: A GenieKey from an Opsgenie integration
- EdgeDelta Pipeline: A configured threshold node or monitor generating signals
Pipeline Flow
Configuration
Step 1: Create an Opsgenie API Integration
- Log in to your Opsgenie account
- Navigate to Settings → Integration List
- Search for API and select it
- Click Add
- Configure the integration name and team assignment
- Copy the API Key (GenieKey)
- Save the integration
Step 2: Store the API Key
Store the API key as an environment variable:
export OPSGENIE_API_KEY="your-opsgenie-api-key"
Step 3: Configure the Webhook Node
Create a webhook node that sends alerts to Opsgenie:
- name: opsgenie_alerts
type: webhook_output
endpoint: https://api.opsgenie.com/v2/alerts
headers:
- header: Content-Type
value: "application/json"
- header: Authorization
value: "GenieKey ${OPSGENIE_API_KEY}"
suppression_window: 20m
payload: |
{
"message": "{{ .item.signal.title }}",
"alias": "{{ .item.signal.signal_id }}",
"description": "{{ .item.signal.description }}\n\nHost: {{ index .item.resource \"host.name\" }}\nSource: {{ index .item.resource \"ed.source_name\" }}\nValue: {{ .item.signal.value }}\nThreshold: {{ .item.signal.threshold_value }}",
"tags": [
"EdgeDelta",
"{{ index .item.resource \"ed.source_type\" }}",
"{{ index .item.resource \"host.name\" }}"
],
"details": {
"signal_id": "{{ .item.signal.signal_id }}",
"metric_name": "{{ .item.signal.name }}",
"current_value": "{{ .item.signal.value }}",
"threshold": "{{ .item.signal.threshold_value }}",
"threshold_type": "{{ .item.signal.threshold_type }}",
"host": "{{ index .item.resource \"host.name\" }}",
"source_name": "{{ index .item.resource \"ed.source_name\" }}",
"source_type": "{{ index .item.resource \"ed.source_type\" }}",
"agent_tag": "{{ index .item.resource \"ed.tag\" }}",
"timestamp": "{{ .item.timestamp }}"
},
"priority": "P2"
}
Step 4: Connect to a Threshold Node
nodes:
- name: memory_threshold
type: threshold
filter: item.name == "system.memory.usage"
condition: value > 85
- name: opsgenie_alerts
type: webhook_output
# ... configuration from above ...
links:
- from: memory_threshold
to: opsgenie_alerts
Alert API Payload Reference
Required Fields
| Field | Description | Example |
|---|---|---|
message | Alert title (max 130 chars) | {{ .item.signal.title }} |
Recommended Fields
| Field | Description | Usage |
|---|---|---|
alias | Unique identifier for deduplication | Signal ID |
description | Detailed information (max 15000 chars) | Alert details and context |
priority | Alert priority: P1 to P5 | P2 for standard alerts |
Optional Fields
| Field | Description | Usage |
|---|---|---|
responders | Teams, users, or escalations to notify | Team assignment |
visibleTo | Teams/users who can see the alert | Access control |
actions | Custom actions for the alert | ["Restart Service", "Check Logs"] |
tags | Labels for categorization | ["EdgeDelta", "production"] |
details | Custom key-value properties | Metric details |
entity | Domain/entity the alert relates to | Service name |
source | Source of the alert | EdgeDelta |
note | Additional note for the alert | Context for responders |
Dynamic Priority Mapping
Map priority based on metric severity:
payload: |
{
"message": "{{ .item.signal.title }}",
"alias": "{{ .item.signal.signal_id }}",
"priority": "{{ if gt .item.signal.value (mul .item.signal.threshold_value 3) }}P1{{ else if gt .item.signal.value (mul .item.signal.threshold_value 2) }}P2{{ else if gt .item.signal.value .item.signal.threshold_value }}P3{{ else }}P4{{ end }}",
...
}
Priority mapping:
- P1: Critical - value exceeds 3x threshold
- P2: High - value exceeds 2x threshold
- P3: Moderate - value exceeds threshold
- P4: Low - informational
Routing to Specific Teams
Route alerts to specific responders based on source:
payload: |
{
"message": "{{ .item.signal.title }}",
"responders": [
{
"type": "team",
"name": "{{ if contains (index .item.resource \"ed.source_name\") \"database\" }}Database Team{{ else }}Infrastructure Team{{ end }}"
}
],
...
}
Or use static team assignments:
payload: |
{
"responders": [
{"type": "team", "name": "Infrastructure"},
{"type": "user", "username": "oncall@company.com"}
],
...
}
Adding Custom Actions
Include action buttons in the Opsgenie alert:
payload: |
{
"message": "{{ .item.signal.title }}",
"actions": [
"View in EdgeDelta",
"Restart Service",
"Acknowledge",
"Add Note"
],
...
}
Auto-Close Alerts
Create a separate webhook to close alerts when metrics return to normal:
- name: opsgenie_close
type: webhook_output
endpoint: https://api.opsgenie.com/v2/alerts/{{ .item.signal.signal_id }}/close?identifierType=alias
headers:
- header: Content-Type
value: "application/json"
- header: Authorization
value: "GenieKey ${OPSGENIE_API_KEY}"
payload: |
{
"note": "Alert auto-closed by EdgeDelta at {{ .item.timestamp }}. Metric returned to normal."
}
Note: The
aliasmust match the original alert’s alias for the close operation to work.
EU Region Configuration
If your Opsgenie account is in the EU region, use the EU endpoint:
endpoint: https://api.eu.opsgenie.com/v2/alerts
Testing
Test with Opsgenie’s API Console
- Go to Settings → Integration List → Your API integration
- Use the Test section to verify connectivity
- Check the Logs tab for request/response details
Test with a Local Endpoint
Verify your payload structure before connecting to Opsgenie:
endpoint: http://localhost:8080/webhook-test
Expected Response
Successful alert creation returns:
{
"result": "Request will be processed",
"took": 0.302,
"requestId": "43a29c5c-3dbf-4fa4-9c26-f4f71023e120"
}
Troubleshooting
| Issue | Solution |
|---|---|
401 Unauthorized | Verify GenieKey and Authorization header format |
403 Forbidden | Check API integration permissions |
422 Unprocessable Entity | Validate payload fields and character limits |
| Duplicate alerts | Use consistent alias values |
| Alerts not auto-closing | Verify alias matches and endpoint format |
Character Limits
message: 130 characters maxalias: 512 characters maxdescription: 15000 characters maxtags: 20 tags max, 50 characters each
Best Practices
- Use aliases for deduplication: Prevent duplicate alerts with consistent signal IDs
- Set appropriate priorities: Reserve P1 for genuine critical issues
- Include context in details: Custom details help responders investigate faster
- Tag consistently: Use tags for filtering and reporting
- Configure suppression windows: 20-30 minutes works well for most alerts
- Route to the right teams: Use responders to ensure proper escalation
- Test in non-production first: Validate payloads before production deployment
See Also
- Webhook Destination - Full webhook reference
- Trigger a Metric Threshold - Configure threshold alerts
- Opsgenie Alert API Documentation