Hello All,
I have folders like A_alerts, B_alerts, C_alerts
where each folder have the same alerts but the data is from different organization like the influxdB bucket is different… the name and functionality of the all the alerts in folders are same.
I am importing these alerts into grafana using the following API:
curl_output=$(curl -s -X POST
-H “Authorization: Bearer $GRAFANA_TOKEN”
-H “Content-type: application/json”
“$GRAFANA_URL/api/ruler/grafana/api/v1/rules/$FOLDER_NAME”
-d “{"folderUid": "$FOLDER_NAME", "message": "Updated alert rules", "overwrite": true}”
-d @“$file” 2>&1)
it is working fine. When I modified the json and retry to upload it is not overwriting.
My JSON file looks like:
{
“uid”: “${tenant_value}_DMS_Alerts”,
“overwrite”: true,
“name”: “No OM Data Alert CU UP”,
“interval”: “15m”,
“rules”: [
{
“expr”: “”,
“for”: “0s”,
“labels”: {
“KPI_Name”: “No OM Data Alert CU UP”,
“category”: “DMS_MONITORING”
},
“annotations”: {
“VNFID”: “{{ $labels.VNFID }}”,
“additionalInformation”: “No data”,
“additionalText”: “{{ $labels.VNFID }} : OMs not available”,
“alarmIdentifier”: “chronos-{{ $labels.VNFID }}”,
“description”: “No data found in last 1 hr for {{ $labels.setup }} {{ $labels.GNBID }}”,
“eventType”: “Logging”,
“managedObjectInstance”: “Chronos”,
“probableCause”: “Connection might be broken”,
“source”: “{{ $labels.VNFID }}”,
“specificProblem”: “Unable to fetch OMs”,
“summary”: “No data found in last 1 hr for {{ $labels.setup }} {{ $labels.GNBID }}”
},
“grafana_alert”: {
“id”: null,
“orgId”: 1,
“title”: “No OM Data Alert CU UP”,
“condition”: “C”,
“data”: [
{
“refId”: “A”,
“queryType”: “”,
“relativeTimeRange”: { “from”: 3600, “to”: 0 },
“datasourceUid”: “$ds_uid”,
“model”: {
“hide”: false,
“intervalMs”: 1000,
“maxDataPoints”: 43200,
“query”: “from(bucket: "$om_record_count") \r\n|\u003erange(start: v.timeRangeStart, stop: v.timeRangeStop) \r\n|\u003efilter(fn:(r) =\u003e r["_measurement"] == "cu-up_om_count") \r\n|\u003efilter(fn:(r) =\u003e r["_field"] == "cu-up_om") \r\n|\u003efilter(fn:(r) =\u003e r["GNBID"] == "9901" or r["GNBID"] == "9902") \r\n”,
“refId”: “A”
}
},
{
“refId”: “B”,
“queryType”: “”,
“relativeTimeRange”: { “from”: 3600, “to”: 0 },
“datasourceUid”: “-100”,
“model”: {
“conditions”: [
{
“evaluator”: { “params”: [3], “type”: “gt” },
“operator”: { “type”: “and” },
“query”: { “params”: [“A”] },
“reducer”: { “params”: , “type”: “last” },
“type”: “query”
}
],
“expression”: “A”,
“hide”: false,
“intervalMs”: 1000,
“maxDataPoints”: 43200,
“reducer”: “sum”,
“refId”: “B”,
“type”: “reduce”
}
},
{
“refId”: “C”,
“queryType”: “”,
“relativeTimeRange”: { “from”: 600, “to”: 0 },
“datasourceUid”: “-100”,
“model”: {
“conditions”: [
{
“evaluator”: { “params”: [0, 0], “type”: “gt” },
“operator”: { “type”: “and” },
“query”: { “params”: [“B”] },
“reducer”: { “params”: , “type”: “avg” },
“type”: “query”
}
],
“datasource”: {
“name”: “Expression”,
“type”: “expr”,
“uid”: “expr”
},
“expression”: “$B \u003c 1”,
“hide”: false,
“intervalMs”: 1000,
“maxDataPoints”: 43200,
“refId”: “C”,
“type”: “math”
}
}
],
“updated”: “2023-04-07T11:48:38Z”,
“intervalSeconds”: 300,
“version”: 5,
“namespace_uid”: “HO0cNya4z”,
“namespace_id”: 98,
“rule_group”: “No OM Data Alert CU UP”,
“no_data_state”: “Alerting”,
“exec_err_state”: “Alerting”
}
}
]
}
As per the documentation I saw PUT command will overwrite the existing one
curl_output=$(curl -s -X PUT
-H “Authorization: Bearer $GRAFANA_TOKEN”
-H “Content-type: application/json”
“$GRAFANA_URL/api/ruler/grafana/api/v1/rules/$FOLDER_NAME”
-d @“$file” 2>&1)
but it is not updating…
Any leads please?
Thanks in advance.
Thanks & regards,
Bharath Kumar.