#!/bin/bash promid=$(curl -s http://admin:admin@localhost:3001/api/datasources/1 | jq -r .uid) if [ "$promid" = "null" ]; then echo "ERROR: Couldn't find prometheus datasource id (datasource 1)"; exit 1; fi folderid=$(curl -X POST -H "Content-Type: application/json" -d '{"title":"alerts"}' http://admin:admin@localhost:3001/api/folders | jq -r .uid) if [ "$folderid" = "null" ]; then echo "ERROR: Couldn't create folder or get folder id"; exit 1; fi curl -X POST -H "X-Disable-Provenance: true" -H "Content-Type: application/json" http://admin:admin@localhost:3001/api/v1/provisioning/alert-rules -d @- << EOF { "title": "NodeStorageUsage>80%", "ruleGroup": "API", "folderUID": "$folderid", "noDataState": "OK", "execErrState": "OK", "for": "5m", "orgId": 1, "uid": "", "condition": "C", "annotations": { "summary": "test_api_1" }, "labels": { "API": "test1" }, "data": [ { "refId": "A", "relativeTimeRange": { "from": 300, "to": 0 }, "datasourceUid": "$promid", "model": { "editorMode": "code", "expr": "100 - ((node_filesystem_avail_bytes{mountpoint=\"/\"} * 100) / node_filesystem_size_bytes{mountpoint=\"/\"})", "intervalMs": 1000, "legendFormat": "__auto", "maxDataPoints": 43200, "range": true, "refId": "A" } }, { "refId": "B", "relativeTimeRange": { "from": 300, "to": 0 }, "datasourceUid": "__expr__", "model": { "conditions": [ { "evaluator": { "params": [], "type": "gt" }, "operator": { "type": "and" }, "query": { "params": [ "B" ] }, "reducer": { "params": [], "type": "last" }, "type": "query" } ], "datasource": { "type": "__expr__", "uid": "__expr__" }, "expression": "A", "intervalMs": 1000, "maxDataPoints": 43200, "reducer": "max", "refId": "B", "type": "reduce" } }, { "refId": "C", "relativeTimeRange": { "from": 300, "to": 0 }, "datasourceUid": "__expr__", "model": { "conditions": [ { "evaluator": { "params": [ 80 ], "type": "gt" }, "operator": { "type": "and" }, "query": { "params": [ "C" ] }, "reducer": { "params": [], "type": "last" }, "type": "query" } ], "datasource": { "type": "__expr__", "uid": "__expr__" }, "expression": "B", "intervalMs": 1000, "maxDataPoints": 43200, "refId": "C", "type": "threshold" } } ] } EOF