Alerting: set dashboard and panel id using annotations in provisioning api (#53221)

This commit is contained in:
Jean-Philippe Quéméner
2022-08-03 16:05:32 +02:00
committed by GitHub
parent 97ce40577b
commit 54217a2037
3 changed files with 37 additions and 15 deletions
@@ -3,7 +3,6 @@ package api
import (
"errors"
"fmt"
"strconv"
"time"
"github.com/grafana/grafana/pkg/models"
@@ -120,20 +119,9 @@ func validateRuleNode(
newAlertRule.Annotations = ruleNode.ApiRuleNode.Annotations
newAlertRule.Labels = ruleNode.ApiRuleNode.Labels
dashUID := ruleNode.ApiRuleNode.Annotations[ngmodels.DashboardUIDAnnotation]
panelID := ruleNode.ApiRuleNode.Annotations[ngmodels.PanelIDAnnotation]
if dashUID != "" && panelID == "" || dashUID == "" && panelID != "" {
return nil, fmt.Errorf("both annotations %s and %s must be specified", ngmodels.DashboardUIDAnnotation, ngmodels.PanelIDAnnotation)
}
if dashUID != "" {
panelIDValue, err := strconv.ParseInt(panelID, 10, 64)
if err != nil {
return nil, fmt.Errorf("annotation %s must be a valid integer Panel ID", ngmodels.PanelIDAnnotation)
}
newAlertRule.DashboardUID = &dashUID
newAlertRule.PanelID = &panelIDValue
err = newAlertRule.SetDashboardAndPanel()
if err != nil {
return nil, err
}
}
return &newAlertRule, nil