Updating Alert Details

We’re writing some custom integrations for Grafana. As part of this work, I’m trying to update a field located in an alert.

I can extract the alerts just fine with alerting.NewDashAlertExtractor(dash, cmd.OrgId).GetAlerts(); from here I can loop through the alerts and find the one I want to update. My problem comes when trying to make those changes persist.

The field I want to update in the alert is alert.settings.conditions.evaluator.params – what I’ve tried so far is transforming each layer to it’s json object, making the update, and then working backwards to attach the new data to the original alert… this is proving to be pretty cumbersome though, and isn’t exactly working how I expect. Any guidance would be appreciated.

for key, alert := range oldLinkedAlerts {
   for key2, condition := range alert.Settings.Get("conditions").MustArray() {
      jsonCondition := simplejson.NewFromAny(condition)
      jsonEvaluator := jsonCondition.Get("evaluator")
      params := jsonEvaluator.Get("params").MustArray()
      fmt.Printf("%#v\n", params)

      // Save alert parameters from linked dashboard
      newLinkedAlert := newLinkedAlerts[key]
      newLinkedAlertSettings := newLinkedAlert.Settings
      newLinkedAlertConditions := newLinkedAlertSettings.Get("conditions").MustArray()
      for newConKey, newLinkedAlertCondition := range newLinkedAlertConditions {
         if newConKey == key2 {
            newLinkedAlertConditionEvaluator := simplejson.NewFromAny(newLinkedAlertCondition).Get("evaluator")
            newLinkedAlertConditionEvaluator.Set("params", params)

            fmt.Printf("%#v\n", newLinkedAlertCondition)
            n := simplejson.NewFromAny(newLinkedAlertCondition)
            n.Set("evaluator", newLinkedAlertConditionEvaluator.MustMap())
            newLinkedAlertCondition = n
            newLinkedAlert.Settings.Set("conditions", newLinkedAlertCondition)
            fmt.Printf("%#v\n", n)
            fmt.Printf("%#v\n", newLinkedAlertConditionEvaluator)
            fmt.Printf("%#v\n", newLinkedAlertCondition)
            fmt.Printf("%#v\n", newLinkedAlert.Settings)

            //newLinkedAlertConditionEvaluatorParams = params
            //newLinkedAlert.Settings = .Get("conditions").MustArray()[key2] = newLinkedAlertCondition
   fmt.Printf("%#v\n", newLinkedAlerts[key].Settings)

I’m not sure why the post transformed everything… it doesn’t look like this when I paste anywhere else.