Alerts not creating while creating new panel using /api/dashboards/db API

I am using grafana 9.4.7.
I am trying to create new panel using exiting panel which already configured panel for panel.

{
  "alert": {
    "alertRuleTags": {},
    "id": 1,
    "conditions": [
      {
        "evaluator": {
          "params": [
            5
          ],
          "type": "lt"
        },
        "operator": {
          "type": "and"
        },
        "query": {
          "params": [
            "A",
            "2m",
            "now"
          ]
        },
        "reducer": {
          "params": [],
          "type": "last"
        },
        "type": "query"
      }
    ],
    "executionErrorState": "alerting",
    "for": "2m",
    "frequency": "30s",
    "handler": 1,
    "message": "chethan Done0 workers down",
    "name": "chethan Done0 workers down alert",
    "noDataState": "no_data",
    "notifications": [
    ]
  },
  "datasource": {
    "type": "prometheus",
    "uid": "kSJ1BUCMz"
  },
  "fieldConfig": {
    "defaults": {
      "color": {
        "mode": "palette-classic"
      },
      "custom": {
        "axisCenteredZero": false,
        "axisColorMode": "text",
        "axisLabel": "",
        "axisPlacement": "auto",
        "barAlignment": 0,
        "drawStyle": "line",
        "fillOpacity": 10,
        "gradientMode": "none",
        "hideFrom": {
          "legend": false,
          "tooltip": false,
          "viz": false
        },
        "lineInterpolation": "linear",
        "lineWidth": 1,
        "pointSize": 5,
        "scaleDistribution": {
          "type": "linear"
        },
        "showPoints": "never",
        "spanNulls": true,
        "stacking": {
          "group": "A",
          "mode": "none"
        },
        "thresholdsStyle": {
          "mode": "off"
        }
      },
      "mappings": [],
      "min": 0,
      "thresholds": {
        "mode": "absolute",
        "steps": [
          {
            "color": "green",
            "value": null
          },
          {
            "color": "red",
            "value": 80
          }
        ]
      },
      "unit": "none"
    },
    "overrides": [
      {
        "__systemRef": "hideSeriesFrom",
        "matcher": {
          "id": "byNames",
          "options": {
            "mode": "exclude",
            "names": [
              "No. of pods"
            ],
            "prefix": "All except:",
            "readOnly": true
          }
        },
        "properties": [
          {
            "id": "custom.hideFrom",
            "value": {
              "legend": false,
              "tooltip": false,
              "viz": true
            }
          }
        ]
      }
    ]
  },
  "gridPos": {
    "h": 6,
    "w": 4,
    "x": 16,
    "y": 0
  },
  "id": 52,
  "options": {
    "legend": {
      "calcs": [],
      "displayMode": "list",
      "placement": "bottom",
      "showLegend": true
    },
    "tooltip": {
      "mode": "single",
      "sort": "none"
    }
  },
  "pluginVersion": "8.3.3",
  "targets": [
    {
      "datasource": {
        "type": "prometheus",
        "uid": "kSJ1BUCMz"
      },
      "editorMode": "code",
      "exemplar": true,
      "expr": "rajkumar_workers_count{job=\"Done/chethan-metrics\"}",
      "instant": false,
      "interval": "",
      "legendFormat": "No. of pods",
      "refId": "A"
    }
  ],
  "thresholds": [
    {
      "colorMode": "critical",
      "op": "lt",
      "value": 5,
      "visible": true
    }
  ],
  "title": "chethan rajkumar Done0 workers count",
  "type": "timeseries"
}

Above is the panel array am using to create new panel.

  • I am using new panel id while creating new panel.
  • i am using same datasource for all panel.

Expected result

  • Create new panel with alerts configuring.

Current result

Welcome @chethan4046

Apologies, but updating or recreating a dashboard’s alert rule via API was only possible in legacy Alerting.

We will update the docs to reflect that. Thank you for bringing this up!

@antonio Thank you for your replay.
I think legacy Alerting will deprecated right.
(Legacy alerting | Grafana documentation).

@antonio Any why my requirement is. I want to create alerts for new panel
or Create new panel along with alerts configured using API,
So can you suggest me which API i need to use along with example,
Thanks in advance

I am afraid that, In Unified Alerting, no API can accomplish that. You would need to manually associate the panels and the alerts.

To do so, you can either

  • edit the panel and add an alert to it
    image

OR

  • edit the alert rule via: Alerting > Manage Alert rules > Edit rule, and associate the dashboard and the panel