-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "grafana, use alertmanager v2 alerts api"
* the prometheus v1 API rules at least provides the current state, as opposed to: * /api/ruler/grafana/api/v1/rules/ * /api/alertmanager/grafana/api/v2/alerts * /api/prometheus/grafana/api/v1/alerts * /api/v1/provisioning/alert-rules * /api/alerts * This reverts commit a2214be.
- Loading branch information
Showing
2 changed files
with
172 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package grafana | ||
|
||
import "time" | ||
|
||
// https://raw.githubusercontent.com/grafana/grafana/main/pkg/services/ngalert/api/tooling/post.json | ||
|
||
type ruleResponse struct { | ||
Status string `json:"status"` | ||
Data ruleDiscovery `json:"data,omitempty"` | ||
} | ||
|
||
type ruleDiscovery struct { | ||
Groups []ruleGroup `json:"groups"` | ||
} | ||
|
||
type ruleGroup struct { | ||
Name string `json:"name"` | ||
File string `json:"file"` | ||
Rules []alertingRule `json:"rules"` | ||
} | ||
|
||
type alertingRule struct { | ||
State alertingState `json:"state"` | ||
Name string `json:"name"` | ||
ActiveAt string `json:"activeAt"` | ||
Health string `json:"health"` | ||
Annotations map[string]string `json:"annotations"` | ||
Labels map[string]string `json:"labels,omitempty"` | ||
Alerts []alert `json:"alerts,omitempty"` | ||
Type string `json:"type"` | ||
} | ||
|
||
type alert struct { | ||
Labels map[string]string `json:"labels"` | ||
Annotations map[string]string `json:"annotations"` | ||
State string `json:"state"` | ||
ActiveAt string `json:"activeAt"` | ||
Value string `json:"value"` | ||
} | ||
|
||
type alertingState = string | ||
|
||
const ( | ||
alertingStatePending = "pending" | ||
alertingStateFiring = "firing" | ||
alertingStateInactive = "inactive" | ||
) | ||
|
||
const ( | ||
alertingStateAlerting = "alerting" | ||
alertingStateNoData = "nodata" | ||
alertingStateNormal = "normal" | ||
alertingStateError = "error" | ||
) | ||
|
||
// https://grafana.com/docs/grafana/latest/developers/http_api/alerting_provisioning/#provisioned-alert-rules | ||
|
||
type provisionedAlertRule struct { | ||
Annotations map[string]string `json:"annotations"` | ||
Condition string `json:"condition"` | ||
ExecErrState string `json:"execErrState"` | ||
Uid int64 `json:"id"` | ||
IsPaused bool `json:"isPaused"` | ||
Labels map[string]string `json:"labels"` | ||
NoDataState string `json:"noDataState"` | ||
For time.Duration `json:"for"` | ||
Title string `json:"title"` | ||
RuleGroup string `json:"ruleGroup"` | ||
} | ||
|
||
const ( | ||
noDataStateNoData = "NoData" | ||
noDataStateOk = "OK" | ||
execErrStateAlerting = "Alerting" | ||
execErrStateError = "Error" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters