-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdailyalarms.sp
124 lines (103 loc) · 2.52 KB
/
dailyalarms.sp
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
dashboard "turbot_recent_alarms_report" {
title = "Turbot Recent Alarms Report"
tags = {
service = "Turbot Recent Alarms Report"
}
text {
value = "Recent Turbot Controls that are in an Alarm State"
}
container {
card {
sql = query.turbot_alarms_24_hours_count.sql
width = 2
}
card {
sql = query.turbot_alarms_48_hours_count.sql
width = 2
}
card {
sql = query.turbot_alarms_1_week_count.sql
width = 2
}
card {
sql = query.turbot_alarms_total_count.sql
width = 2
}
}
text {
value = "List of Alarms in the last 24 hours"
}
table {
sql = query.turbot_alarms_24_hours.sql
}
}
query "turbot_alarms_24_hours_count" {
sql = <<-EOQ
select
count(*) as "value",
'Alarms within 24 hours' as label,
case count(*) when 0 then 'ok' else 'alert' end as "type"
from
turbot_control
where
filter = 'state:alarm stateChangeTimestamp:>=T-1d';
EOQ
}
query "turbot_alarms_48_hours_count" {
sql = <<-EOQ
select
count(*) as "value",
'Alarms within 48 hours' as label,
case count(*) when 0 then 'ok' else 'alert' end as "type"
from
turbot_control
where
filter = 'state:alarm stateChangeTimestamp:>=T-2d';
EOQ
}
query "turbot_alarms_1_week_count" {
sql = <<-EOQ
select
count(*) as "value",
'Alarms within 1 week' as label,
case count(*) when 0 then 'ok' else 'alert' end as "type"
from
turbot_control
where
filter = 'state:alarm stateChangeTimestamp:>=T-1w';
EOQ
}
query "turbot_alarms_total_count" {
sql = <<-EOQ
select
count(*) as "value",
'Total Alarms' as label,
case count(*) when 0 then 'ok' else 'alert' end as "type"
from
turbot_control
where
filter = 'state:alarm';
EOQ
}
query "turbot_alarms_24_hours" {
sql = <<-EOQ
select
control_type_trunk_title as "control_name",
TO_CHAR(DATE_TRUNC('minute', timestamp), 'YYYY-MM-DD HH24:MI') as "last_updated",
state,
reason,
resource_trunk_title as "resource_name",
CASE
WHEN control_type_uri LIKE 'tmod:@turbot/aws-%' THEN 'AWS'
WHEN control_type_uri LIKE 'tmod:@turbot/azure-%' THEN 'Azure'
WHEN control_type_uri LIKE 'tmod:@turbot/gcp-%' THEN 'GCP'
ELSE 'Other'
END as "cloud_provider"
from
turbot_control
where
filter = 'state:alarm stateChangeTimestamp:>=T-1d'
order by
"control_name" asc;
EOQ
}