/
ons_notification_topic_detail.sp
243 lines (204 loc) · 4.67 KB
/
ons_notification_topic_detail.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
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
dashboard "ons_notification_topic_detail" {
title = "OCI ONS Notification Topic Detail"
tags = merge(local.ons_common_tags, {
type = "Detail"
})
input "topic_id" {
title = "Select a topic:"
query = query.ons_notification_topic_input
width = 4
}
container {
card {
width = 3
query = query.ons_notification_topic_state
args = {
id = self.input.topic_id.value
}
}
}
with "compute_instances_for_ons_notification_topic" {
query = query.compute_instances_for_ons_notification_topic
args = [self.input.topic_id.value]
}
with "ons_subscriptions_for_ons_notification_topic" {
query = query.ons_subscriptions_for_ons_notification_topic
args = [self.input.topic_id.value]
}
container {
graph {
title = "Relationships"
type = "graph"
direction = "TD"
node {
base = node.ons_notification_topic
args = {
ons_notification_topic_ids = [self.input.topic_id.value]
}
}
node {
base = node.compute_instance
args = {
compute_instance_ids = with.compute_instances_for_ons_notification_topic.rows[*].instance_id
}
}
node {
base = node.ons_subscription
args = {
ons_subscription_ids = with.ons_subscriptions_for_ons_notification_topic.rows[*].ons_subscription_id
}
}
edge {
base = edge.compute_instance_to_ons_notification_topic
args = {
compute_instance_ids = with.compute_instances_for_ons_notification_topic.rows[*].instance_id
}
}
edge {
base = edge.ons_notification_topic_to_ons_subscription
args = {
ons_notification_topic_ids = [self.input.topic_id.value]
}
}
}
}
container {
container {
width = 6
table {
title = "Overview"
type = "line"
width = 6
query = query.ons_notification_topic_overview
args = {
id = self.input.topic_id.value
}
}
table {
title = "Tags"
width = 6
query = query.ons_notification_topic_tag
args = {
id = self.input.topic_id.value
}
}
}
container {
width = 6
table {
title = "Subscription Details"
query = query.ons_notification_topic_subscription
args = {
id = self.input.topic_id.value
}
}
}
}
}
query "ons_notification_topic_input" {
sql = <<-EOQ
select
n.name as label,
n.topic_id as value,
json_build_object(
'oci.name', coalesce(oci.title, 'root'),
'n.region', region,
't.name', t.name
) as tags
from
oci_ons_notification_topic as n
left join oci_identity_compartment as oci on n.compartment_id = oci.id
left join oci_identity_tenancy as t on n.tenant_id = t.id
order by
n.name;
EOQ
}
query "ons_notification_topic_state" {
sql = <<-EOQ
select
initcap(lifecycle_state) as "Lifecycle State"
from
oci_ons_notification_topic
where
topic_id = $1;
EOQ
param "id" {}
}
query "ons_notification_topic_overview" {
sql = <<-EOQ
select
name as "Topic Name",
time_created as "Time Created",
api_endpoint as "API Endpoint",
topic_id as "OCID",
compartment_id as "Compartment ID"
from
oci_ons_notification_topic
where
topic_id = $1;
EOQ
param "id" {}
}
query "ons_notification_topic_tag" {
sql = <<-EOQ
with jsondata as (
select
tags::json as tags
from
oci_ons_notification_topic
where
topic_id = $1
)
select
key as "Key",
value as "Value"
from
jsondata,
json_each_text(tags);
EOQ
param "id" {}
}
query "ons_notification_topic_subscription" {
sql = <<-EOQ
select
endpoint as "Endpoint",
s.lifecycle_state as "State",
protocol as "Protocol"
from
oci_ons_notification_topic t
left join oci_ons_subscription as s on s.topic_id = t.topic_id
where
t.topic_id = $1;
EOQ
param "id" {}
}
# With queries
query "ons_subscriptions_for_ons_notification_topic" {
sql = <<-EOQ
select
id as ons_subscription_id
from
oci_ons_subscription
where
topic_id = $1;
EOQ
}
query "compute_instances_for_ons_notification_topic" {
sql = <<-EOQ
with jsondata as (
select
tags::json as tags
from
oci_ons_notification_topic
where
topic_id = $1
)
select
value as instance_id
from
jsondata,
json_each_text(tags)
where
key = 'CTX_NOTIFICATIONS_COMPUTE_ID';
EOQ
}