Hello, I'm trying to explain the example of creating a rule via API that is in the documentation, but I've been getting this error:
{"statusCode":400,"error":"Bad Request","message":"Error creating rule: could not create API key - Unsupported scheme \"ApiKey\" for granting API Key"}
My code:
import requests
header = {
'Content-Type': 'application/json;charset=UTF-8',
'kbn-xsrf': 'true',
'Authorization': 'ApiKey XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
}
data = {
"params":{
"aggType":"avg",
"termSize":6,
"thresholdComparator":">",
"timeWindowSize":5,
"timeWindowUnit":"m",
"groupBy":"top",
"threshold":[
1000
],
"index":[
".test-index"
],
"timeField":"@timestamp",
"aggField":"sheet.version",
"termField":"name.keyword"
},
"consumer":"alerts",
"rule_type_id":".index-threshold",
"schedule":{
"interval":"1m"
},
"actions":[
{
"id":"dceeb5d0-6b41-11eb-802b-85b0c1bc8ba2",
"group":"threshold met",
"params":{
"level":"info",
"message":"alert '{{alertName}}' is active for group '{{context.group}}':\n\n- Value: {{context.value}}\n- Conditions Met: {{context.conditions}} over {{params.timeWindowSize}}{{params.timeWindowUnit}}\n- Timestamp: {{context.date}}"
}
}
],
"tags":[
"cpu"
],
"notify_when":"onActionGroupChange",
"name":"my alert"
}
resp = requests.post('http://XXX.XXX.XXX.XXX:5601/api/alerting/rule', headers=header, json=data)
print(resp.text)
The rule json was copied from the documentation: