-
Notifications
You must be signed in to change notification settings - Fork 2
/
soma_stmt_tree_keeper_startup_checks.go
172 lines (155 loc) · 4.66 KB
/
soma_stmt_tree_keeper_startup_checks.go
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
package main
const tkStmtLoadChecks = `
SELECT check_id,
bucket_id,
source_check_id,
source_object_type,
source_object_id,
configuration_id,
capability_id,
object_id,
object_type
FROM soma.checks
WHERE repository_id = $1::uuid
AND check_id = source_check_id
AND source_object_type = $2::varchar
AND NOT deleted;`
const tkStmtLoadInheritedChecks = `
SELECT check_id,
object_id,
object_type
FROM soma.checks
WHERE repository_id = $1::uuid
AND source_check_id = $2::uuid
AND source_check_id != check_id
AND NOT deleted;`
const tkStmtLoadChecksForType = `
SELECT check_id,
object_id
FROM soma.checks
WHERE repository_id = $1::uuid
AND object_type = $2::varchar
AND NOT deleted;`
const tkStmtLoadCheckConfiguration = `
SELECT bucket_id,
configuration_name,
configuration_object,
configuration_object_type,
configuration_active,
inheritance_enabled,
children_only,
capability_id,
interval,
enabled,
external_id
FROM soma.check_configurations
WHERE configuration_id = $1::uuid
AND repository_id = $2::uuid
AND NOT deleted;`
const tkStmtLoadAllCheckConfigurationsForType = `
SELECT configuration_id,
bucket_id,
configuration_name,
configuration_object,
inheritance_enabled,
children_only,
capability_id,
interval,
enabled,
external_id
FROM soma.check_configurations
WHERE configuration_object_type = $1::varchar
AND repository_id = $2::uuid
AND NOT deleted;`
const tkStmtLoadCheckThresholds = `
SELECT sct.predicate,
sct.threshold,
snl.level_name,
snl.level_shortname,
snl.level_numeric
FROM soma.configuration_thresholds sct
JOIN soma.notification_levels snl
ON sct.notification_level = snl.level_name
WHERE configuration_id = $1::uuid;`
const tkStmtLoadCheckConstraintCustom = `
SELECT sccp.custom_property_id,
scp.custom_property,
sccp.property_value
FROM soma.constraints_custom_property sccp
JOIN soma.custom_properties scp
ON sccp.custom_property_id = scp.custom_property_id
AND sccp.repository_id = scp.repository_id
WHERE configuration_id = $1::uuid;`
// do not get distracted by the squirrels! All constraint
// statements are constructed to use three result variables,
// so they can be loaded in one unified loop.
const tkStmtLoadCheckConstraintNative = `
SELECT native_property,
property_value,
'squirrel'
FROM soma.constraints_native_property
WHERE configuration_id = $1::uuid;`
// return configuration id: every constraint query has 2 columns
const tkStmtLoadCheckConstraintOncall = `
SELECT scop.oncall_duty_id,
oncall_duty_name,
oncall_duty_phone_number
FROM soma.constraints_oncall_property scop
JOIN inventory.oncall_duty_teams iodt
ON scop.oncall_duty_id = iodt.oncall_duty_id
WHERE scop.configuration_id = $1::uuid;`
const tkStmtLoadCheckConstraintAttribute = `
SELECT service_property_attribute,
attribute_value,
'squirrel'
FROM soma.constraints_service_attribute
WHERE configuration_id = $1::uuid;`
const tkStmtLoadCheckConstraintService = `
SELECT organizational_team_id,
service_property,
'squirrel'
FROM soma.constraints_service_property
WHERE configuration_id = $1::uuid;`
const tkStmtLoadCheckConstraintSystem = `
SELECT system_property,
property_value,
'squirrel'
FROM soma.constraints_system_property
WHERE configuration_id = $1::uuid;`
const tkStmtLoadCheckInstances = `
SELECT check_instance_id,
check_configuration_id
FROM soma.check_instances
WHERE check_id = $1::uuid
AND NOT deleted;`
// load the most recent configuration for this instance, which is
// not always the current one, since a newer version could be blocked
// by the current versions rollout
const tkStmtLoadCheckInstanceConfiguration = `
SELECT check_instance_config_id,
version,
monitoring_id,
constraint_hash,
constraint_val_hash,
instance_service,
instance_service_cfg_hash,
instance_service_cfg
FROM soma.check_instance_configurations
WHERE check_instance_id = $1::uuid
ORDER BY created DESC
LIMIT 1;`
const tkStmtLoadCheckGroupState = `
SELECT sg.group_id,
sg.object_state
FROM soma.buckets sb
JOIN soma.groups sg
ON sb.bucket_id = sg.bucket_id
WHERE sb.repository_id = $1::uuid;`
const tkStmtLoadCheckGroupRelations = `
SELECT sgmg.group_id,
sgmg.child_group_id
FROM soma.buckets sb
JOIN soma.group_membership_groups sgmg
ON sb.bucket_id = sgmg.bucket_id
WHERE sb.repository_id = $1::uuid;`
// vim: ts=4 sw=4 sts=4 noet fenc=utf-8 ffs=unix