Module: Gzr::Dashboard
- Includes:
- Alert
- Included in:
- Commands::Dashboard::Cat, Commands::Dashboard::Import, Commands::Dashboard::ImportLookml, Commands::Dashboard::Mv, Commands::Dashboard::Rm, Commands::Dashboard::SyncLookml, Commands::Folder::Export
- Defined in:
- lib/gzr/modules/dashboard.rb
Instance Method Summary collapse
- #cat_dashboard(dashboard_id) ⇒ Object
- #create_dashboard(dash) ⇒ Object
- #create_dashboard_element(dash_elem) ⇒ Object
- #create_dashboard_filter(dash_filter) ⇒ Object
- #create_dashboard_layout(dash_layout) ⇒ Object
- #delete_dashboard(dash) ⇒ Object
- #delete_dashboard_element(id) ⇒ Object
- #delete_dashboard_filter(id) ⇒ Object
- #delete_dashboard_layout(id) ⇒ Object
- #get_all_dashboard_layout_components(id) ⇒ Object
- #get_dashboard_layout(id) ⇒ Object
- #import_lookml_dashboard(id, folder) ⇒ Object
- #query_dashboard(dashboard_id) ⇒ Object
- #search_dashboards_by_slug(slug, folder_id = nil) ⇒ Object
- #search_dashboards_by_title(title, folder_id = nil) ⇒ Object
- #sync_lookml_dashboard(id) ⇒ Object
- #trim_dashboard(data) ⇒ Object
- #update_dashboard(dash_id, dash) ⇒ Object
- #update_dashboard_element(id, dash_elem) ⇒ Object
- #update_dashboard_filter(id, dash_filter) ⇒ Object
- #update_dashboard_layout(id, dash_layout) ⇒ Object
- #update_dashboard_layout_component(id, component) ⇒ Object
Methods included from Alert
#alert_notifications, #create_alert, #delete_alert, #follow_alert, #get_alert, #read_alert_notification, #search_alerts, #unfollow_alert, #update_alert, #update_alert_field
Instance Method Details
#cat_dashboard(dashboard_id) ⇒ Object
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 |
# File 'lib/gzr/modules/dashboard.rb', line 281 def cat_dashboard(dashboard_id) data = query_dashboard(dashboard_id) data[:dashboard_elements].each_index do |i| element = data[:dashboard_elements][i] find_vis_config_reference(element) do |vis_config| find_color_palette_reference(vis_config) do |o,default_colors| rewrite_color_palette!(o,default_colors) end end alerts = [] begin alerts = search_alerts(fields: 'id,dashboard_element_id', group_by: 'dashboard', all_owners: true) rescue LookerSDK::Forbidden => e say_warning "Must be an admin user to look up all alerts" begin alerts = search_alerts(fields: 'id,dashboard_element_id', group_by: 'dashboard') rescue LookerSDK::Error => e say_warning "Error looking up alerts owned by user." end end say_warning alerts if @options[:debug] data[:dashboard_elements].each do |e| alerts_found = alerts.select { |a| a[:dashboard_element_id] == e[:id]} say_warning "Found alerts #{alerts_found}" if @options[:debug] alerts_entries = alerts_found.map { |a| get_alert(a[:id]) } say_warning "Looked up alerts entries #{alerts_entries}" if @options[:debug] e[:alerts] = alerts_entries end merge_result = merge_query(element[:merge_result_id])&.to_attrs if element[:merge_result_id] if merge_result merge_result[:source_queries].each_index do |j| source_query = merge_result[:source_queries][j] merge_result[:source_queries][j][:query] = query(source_query[:query_slug] || source_query[:query_id]).to_attrs end find_vis_config_reference(merge_result) do |vis_config| find_color_palette_reference(vis_config) do |o,default_colors| rewrite_color_palette!(o,default_colors) end end data[:dashboard_elements][i][:merge_result] = merge_result end end data[:scheduled_plans] = query_scheduled_plans_for_dashboard(@dashboard_id,"all") if @options[:plans] data end |
#create_dashboard(dash) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/gzr/modules/dashboard.rb', line 93 def create_dashboard(dash) data = nil begin data = @sdk.create_dashboard(dash).to_attrs say_error data.inspect if data.respond_to?(:message) data[:dashboard_filters]&.sort! { |a,b| a[:row] <=> b[:row] } data[:dashboard_layouts]&.sort_by! { |v| (v[:active] ? 0 : 1) } rescue LookerSDK::Error => e say_error "Error creating dashboard(#{JSON.pretty_generate(dash)})" say_error e raise end data end |
#create_dashboard_element(dash_elem) ⇒ Object
125 126 127 128 129 130 131 132 133 |
# File 'lib/gzr/modules/dashboard.rb', line 125 def create_dashboard_element(dash_elem) begin @sdk.create_dashboard_element(dash_elem).to_attrs rescue LookerSDK::Error => e say_error "Error creating dashboard_element(#{JSON.pretty_generate(dash_elem)})" say_error e raise end end |
#create_dashboard_filter(dash_filter) ⇒ Object
243 244 245 246 247 248 249 250 251 |
# File 'lib/gzr/modules/dashboard.rb', line 243 def create_dashboard_filter(dash_filter) begin @sdk.create_dashboard_filter(dash_filter).to_attrs rescue LookerSDK::Error => e say_error "Error creating dashboard_filter(#{JSON.pretty_generate(dash_filter)})" say_error e raise end end |
#create_dashboard_layout(dash_layout) ⇒ Object
177 178 179 180 181 182 183 184 185 |
# File 'lib/gzr/modules/dashboard.rb', line 177 def create_dashboard_layout(dash_layout) begin @sdk.create_dashboard_layout(dash_layout).to_attrs rescue LookerSDK::Error => e say_error "Error creating dashboard_layout(#{JSON.pretty_generate(dash_layout)})" say_error e raise end end |
#delete_dashboard(dash) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/gzr/modules/dashboard.rb', line 47 def delete_dashboard(dash) begin @sdk.delete_dashboard(dash) rescue LookerSDK::Error => e say_error "dashboard #{dash} not found" say_error e raise rescue LookerSDK::Error => e say_error "Error deleting dashboard(#{dash})" say_error e raise end end |
#delete_dashboard_element(id) ⇒ Object
149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/gzr/modules/dashboard.rb', line 149 def delete_dashboard_element(id) begin @sdk.delete_dashboard_element(id) rescue LookerSDK::NotFound => e say_error "dashboard_element #{id} not found" say_error e raise rescue LookerSDK::Error => e say_error "Error deleting dashboard_element(#{id})})" say_error e raise end end |
#delete_dashboard_filter(id) ⇒ Object
267 268 269 270 271 272 273 274 275 276 277 278 279 |
# File 'lib/gzr/modules/dashboard.rb', line 267 def delete_dashboard_filter(id) begin @sdk.delete_dashboard_filter(id) rescue LookerSDK::NotFound => e say_error "dashboard_filter #{id} not found" say_error e raise rescue LookerSDK::Error => e say_error "Error deleting dashboard_filter(#{id})})" say_error e raise end end |
#delete_dashboard_layout(id) ⇒ Object
201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/gzr/modules/dashboard.rb', line 201 def delete_dashboard_layout(id) begin @sdk.delete_dashboard_layout(id) rescue LookerSDK::NotFound => e say_error "dashboard_layout #{id} not found" say_error e raise rescue LookerSDK::Error => e say_error "Error deleting dashboard_layout(#{id})" say_error e raise end end |
#get_all_dashboard_layout_components(id) ⇒ Object
215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/gzr/modules/dashboard.rb', line 215 def get_all_dashboard_layout_components(id) begin @sdk.dashboard_layout_dashboard_layout_components(id).collect { |e| e.to_attrs } rescue LookerSDK::NotFound => e say_error "dashboard_layout #{id} not found" say_error e raise rescue LookerSDK::Error => e say_error "Error getting dashboard_layout_dashboard_layout_components(#{id})" say_error e raise end end |
#get_dashboard_layout(id) ⇒ Object
163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/gzr/modules/dashboard.rb', line 163 def get_dashboard_layout(id) begin @sdk.dashboard_layout(id).to_attrs rescue LookerSDK::NotFound => e say_error "dashboard_layout #{id} not found" say_error e raise rescue LookerSDK::Error => e say_error "Error getting dashboard_layout(#{id})" say_error e raise end end |
#import_lookml_dashboard(id, folder) ⇒ Object
402 403 404 405 406 407 408 409 410 411 412 413 414 |
# File 'lib/gzr/modules/dashboard.rb', line 402 def import_lookml_dashboard(id,folder) begin return @sdk.import_lookml_dashboard(id,folder).to_attrs rescue LookerSDK::NotFound => e say_error "lookml_dashboard #{id} not found" say_error e raise rescue LookerSDK::Error => e say_error "Error import_lookml_dashboard(#{id},#{folder})" say_error e raise end end |
#query_dashboard(dashboard_id) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/gzr/modules/dashboard.rb', line 29 def query_dashboard(dashboard_id) data = nil begin data = @sdk.dashboard(dashboard_id).to_attrs data[:dashboard_filters]&.sort! { |a,b| a[:row] <=> b[:row] } data[:dashboard_layouts]&.sort_by! { |v| (v[:active] ? 0 : 1) } rescue LookerSDK::Error => e say_error "dashboard #{dashboard_id} not found" say_error e raise rescue LookerSDK::Error => e say_error "Error querying dashboard(#{dashboard_id})" say_error e raise end data end |
#search_dashboards_by_slug(slug, folder_id = nil) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/gzr/modules/dashboard.rb', line 61 def search_dashboards_by_slug(slug, folder_id=nil) data = [] begin req = { :slug => slug } req[:folder_id] = folder_id if folder_id data = @sdk.search_dashboards(req).collect { |e| e.to_attrs } req[:deleted] = true data = @sdk.search_dashboards(req).collect { |e| e.to_attrs } if data.empty? rescue LookerSDK::Error => e say_error "Error search_dashboards_by_slug(#{JSON.pretty_generate(req)})" say_error e raise end data end |
#search_dashboards_by_title(title, folder_id = nil) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/gzr/modules/dashboard.rb', line 77 def search_dashboards_by_title(title, folder_id=nil) data = [] begin req = { :title => title } req[:folder_id] = folder_id if folder_id data = @sdk.search_dashboards(req).collect { |e| e.to_attrs } req[:deleted] = true data = @sdk.search_dashboards(req).collect { |e| e.to_attrs } if data.empty? rescue LookerSDK::Error => e say_error "Error search_dashboards_by_title(#{JSON.pretty_generate(req)})" say_error e raise end data end |
#sync_lookml_dashboard(id) ⇒ Object
416 417 418 419 420 421 422 423 424 425 426 427 428 |
# File 'lib/gzr/modules/dashboard.rb', line 416 def sync_lookml_dashboard(id) begin return @sdk.sync_lookml_dashboard(id, {}) rescue LookerSDK::NotFound => e say_error "lookml_dashboard #{id} not found" say_error e raise rescue LookerSDK::Error => e say_error "Error sync_lookml_dashboard(#{id})" say_error e raise end end |
#trim_dashboard(data) ⇒ Object
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 |
# File 'lib/gzr/modules/dashboard.rb', line 328 def trim_dashboard(data) trimmed = data.select do |k,v| (keys_to_keep('update_dashboard') + [:id,:dashboard_elements,:dashboard_filters,:dashboard_layouts,:scheduled_plans]).include? k end trimmed[:dashboard_elements] = data[:dashboard_elements].map do |de| new_de = de.select do |k,v| (keys_to_keep('update_dashboard_element') + [:id,:look,:query,:merge_result,:alerts]).include? k end if de[:look] new_de[:look] = de[:look].select do |k,v| (keys_to_keep('update_look') + [:id,:query]).include? k end if de[:look][:query] new_de[:look][:query] = de[:look][:query].select do |k,v| (keys_to_keep('create_query') + [:id]).include? k end end end if de[:query] new_de[:query] = de[:query].select do |k,v| (keys_to_keep('create_query') + [:id]).include? k end end if de[:merge_result] new_de[:merge_result] = de[:merge_result].select do |k,v| (keys_to_keep('update_merge_query') + [:id]).include? k end new_de[:merge_result][:source_queries] = de[:merge_result][:source_queries].map do |sq| sq.select do |k,v| (keys_to_keep('create_query') + [:id]).include? k end end end if de[:alerts] new_de[:alerts] = de[:alerts].map do |a| a.select do |k,v| (keys_to_keep('update_alert') + [:id,:owner]).include? k end end end new_de end trimmed[:dashboard_filters] = data[:dashboard_filters].map do |df| new_df = df.select do |k,v| keys_to_keep('update_dashboard_filter').include? k end new_df end trimmed[:dashboard_layouts] = data[:dashboard_layouts].map do |dl| new_dl = dl.select do |k,v| (keys_to_keep('update_dashboard_layout') + [:id]).include? k end if dl[:dashboard_layout_components] new_dl[:dashboard_layout_components] = dl[:dashboard_layout_components].map do |dlc| dlc.select do |k,v| (keys_to_keep('update_dashboard_layout_component') + [:id]).include? k end end end new_dl end trimmed[:scheduled_plans] = data[:scheduled_plans].map do |sp| sp.select do |k,v| (keys_to_keep('create_scheduled_plan') + [:id]).include? k end end if data[:scheduled_plans] trimmed end |
#update_dashboard(dash_id, dash) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/gzr/modules/dashboard.rb', line 108 def update_dashboard(dash_id,dash) data = nil begin data = @sdk.update_dashboard(dash_id,dash).to_attrs data[:dashboard_filters]&.sort! { |a,b| a[:row] <=> b[:row] } rescue LookerSDK::NotFound => e say_error "dashboard #{dash_id} not found" say_error e raise rescue LookerSDK::Error => e say_error "Error updating dashboard(#{dash_id},#{JSON.pretty_generate(dash)})" say_error e raise end data end |
#update_dashboard_element(id, dash_elem) ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/gzr/modules/dashboard.rb', line 135 def update_dashboard_element(id,dash_elem) begin @sdk.update_dashboard_element(id,dash_elem).to_attrs rescue LookerSDK::NotFound => e say_error "dashboard_element #{id} not found" say_error e raise rescue LookerSDK::Error => e say_error "Error updating dashboard_element(#{id},#{JSON.pretty_generate(dash_elem)})" say_error e raise end end |
#update_dashboard_filter(id, dash_filter) ⇒ Object
253 254 255 256 257 258 259 260 261 262 263 264 265 |
# File 'lib/gzr/modules/dashboard.rb', line 253 def update_dashboard_filter(id,dash_filter) begin @sdk.update_dashboard_filter(id,dash_filter).to_attrs rescue LookerSDK::NotFound => e say_error "dashboard_filter #{id} not found" say_error e raise rescue LookerSDK::Error => e say_error "Error updating dashboard_filter(#{id},#{JSON.pretty_generate(dash_filter)})" say_error e raise end end |
#update_dashboard_layout(id, dash_layout) ⇒ Object
187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/gzr/modules/dashboard.rb', line 187 def update_dashboard_layout(id,dash_layout) begin @sdk.update_dashboard_layout(id,dash_layout).to_attrs rescue LookerSDK::NotFound => e say_error "dashboard_layout #{id} not found" say_error e raise rescue LookerSDK::Error => e say_error "Error updating dashboard_layout(#{id},#{JSON.pretty_generate(dash_layout)})" say_error e raise end end |
#update_dashboard_layout_component(id, component) ⇒ Object
229 230 231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/gzr/modules/dashboard.rb', line 229 def update_dashboard_layout_component(id,component) begin @sdk.update_dashboard_layout_component(id,component).to_attrs rescue LookerSDK::NotFound => e say_error "dashboard_layout #{id} not found" say_error e raise rescue LookerSDK::Error => e say_error "Error updating dashboard_layout_component(#{id},#{JSON.pretty_generate(component)})" say_error e raise end end |