forked from influxdata/community-templates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
monitoring_task.yml
46 lines (44 loc) · 1.51 KB
/
monitoring_task.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
apiVersion: influxdata.com/v2alpha1
kind: Task
metadata:
name: failed-tasks-check-1m
spec:
every: 1m
name: 00. Failed Tasks Check
query: |-
import "strings"
import "regexp"
import "influxdata/influxdb/monitor"
import "influxdata/influxdb/v1"
task_data = from(bucket: "_tasks")
|> range(start: -1m, stop: now())
|> filter(fn: (r) =>
(r["_measurement"] == "runs"))
|> filter(fn: (r) =>
(r["_field"] == "logs"))
|> map(fn: (r) => ({ r with name: strings.split(v: regexp.findString(r: /option task = \{([^\}]+)/, v: r._value), t: "\\\\\\\"")[1] }))
|> drop(columns: ["_value", "_start", "_stop"])
|> group(columns: ["name", "taskID", "status", "_measurement"])
|> map(fn: (r) =>
({r with _value: if r.status == "failed" then 1 else 0}))
|> last()
check = {
_check_id: "00000000ba5eba11",
_check_name: "Failed Tasks Check",
_type: "threshold",
tags: {},
}
ok = (r) =>
(r["logs"] == 0)
crit = (r) =>
(r["logs"] == 1)
messageFn = (r) =>
("The task: ${r.taskID} - ${r.name} has a status of ${r.status}")
task_data
|> v1["fieldsAsCols"]()
|> monitor["check"](
data: check,
messageFn: messageFn,
ok: ok,
crit: crit,
)