influxdata / influxdb-client-go

InfluxDB 2 Go Client
MIT License
607 stars 116 forks source link

Create Alerts (Checks, Notification Endpoint, Notification Rule) via influxdb-client-go in Influxdb2 #385

Open yockgen opened 1 year ago

yockgen commented 1 year ago

Specifications

Steps to reproduce

Is it any way to create Alerts (Checks, Notification Endpoint, Notification Rule) via influxdb-client-go in Influxdb2?

Expected behavior

influxdb-client-go/v2 allowed Alerts to be create via Library

Actual behavior

influxdb-client-go/v2 not allowed Alerts to be create via Library

Additional info

No response

powersj commented 1 year ago

hi @yockgen,

Can you point to the API endpoint for alerts you are trying to use? There is support for creating tasks.

yockgen commented 1 year ago

hi @yockgen,

Can you point to the API endpoint for alerts you are trying to use? There is support for creating tasks.

Hi @powersj, Thanks for the info! I'm trying to find information on how to use "influx-client-go" to do something like below (to create CHECKS/Endpoint/Rules for Alert):

curl -X POST "http://10.49.76.106:32701/api/v2/checks" \
-H "Authorization: Token  xxxxxxx" \
-H "Content-Type: application/json" \
-d '{
  "name": "Testing 01",
  "type": "threshold",  
  "query": {
    "text": "from(bucket: \"intel\")\n  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n  |> filter(fn: (r) => r[\"_measurement\"] == \"mem_available_percent\")\n  |> filter(fn: (r) => r[\"_field\"] == \"gauge\")\n  |> filter(fn: (r) => r[\"host\"] == \"node01\")\n  |> aggregateWindow(every: 1m, fn: last, createEmpty: false)\n  |> yield(name: \"last\")",
    "editMode": "builder",
    "name": "",
    "builderConfig": {
      "buckets": ["company"],
      "tags": [
        {
          "key": "_measurement",
          "values": ["mem_available_percent"],
          "aggregateFunctionType": "filter"
        },
        {
          "key": "_field",
          "values": ["gauge"],
          "aggregateFunctionType": "filter"
        },
        {
          "key": "host",
          "values": ["3214261f-3ee2-1169-841c-1c697aa4038c"],
          "aggregateFunctionType": "filter"
        }
      ],
      "functions": [
        {
          "name": "last"
        }
      ],
      "aggregateWindow": {
        "period": "1m",
        "fillValues": false
      }
    }
  },
  "every": "5m",
  "offset": "30s",  
  "status": "active",
  "description": "My check description",
  "labels": ["label1", "label2"],
  "message": "Check triggered",
  "orgID": "xxxxxxx"
}'

Thanks of your guidance!

powersj commented 1 year ago

@bednar does this library expose anything for the /api/v2/checks endpoint? Quick search doesn't seem to show it.