Class: Splunk::Pickaxe::Dashboards
- Inherits:
-
Objects
- Object
- Objects
- Splunk::Pickaxe::Dashboards
show all
- Defined in:
- lib/splunk/pickaxe/objects/dashboards.rb
Instance Attribute Summary
Attributes inherited from Objects
#environment, #pickaxe_config, #service
Instance Method Summary
collapse
Methods inherited from Objects
#create, #find, #initialize, #name, #needs_update?, #remove_pickaxe_config, #save, #skip?, #splunk_config, #splunk_entity_keys, #sync, #update
Instance Method Details
#config(file_path) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/splunk/pickaxe/objects/dashboards.rb', line 30
def config(file_path)
template = IO.read(file_path)
xml_content = ERBWithBinding::render_from_hash(template, pickaxe_config.env_config)
{
'name' => File.basename(file_path, '.xml'),
'config' => {
'eai:data' => xml_content
}
}
end
|
#entity_dir ⇒ Object
14
15
16
|
# File 'lib/splunk/pickaxe/objects/dashboards.rb', line 14
def entity_dir
DIR
end
|
#entity_file_extensions ⇒ Object
43
44
45
|
# File 'lib/splunk/pickaxe/objects/dashboards.rb', line 43
def entity_file_extensions
['.xml']
end
|
#entity_file_name(entity) ⇒ Object
18
19
20
21
|
# File 'lib/splunk/pickaxe/objects/dashboards.rb', line 18
def entity_file_name(entity)
"#{entity['label']}.xml".gsub(/[^a-z0-9_\-. ]/i, '')
.tr(' ', '_')
end
|
#entity_file_path(splunk_entity) ⇒ Object
23
24
25
26
27
28
|
# File 'lib/splunk/pickaxe/objects/dashboards.rb', line 23
def entity_file_path(splunk_entity)
File.join(
pickaxe_config.execution_path, entity_dir,
entity_file_name(splunk_entity)
)
end
|
#save_config(splunk_entity, overwrite, local_save) ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/splunk/pickaxe/objects/dashboards.rb', line 47
def save_config(splunk_entity, overwrite, local_save)
file_path = entity_file_path splunk_entity
if local_save
if File.exist?(file_path)
puts "- #{splunk_entity['label']}"
write_to_file(file_path, overwrite, splunk_entity)
end
else
puts "- #{splunk_entity['label']}"
write_to_file(file_path, overwrite, splunk_entity)
end
end
|
#splunk_resource ⇒ Object
10
11
12
|
# File 'lib/splunk/pickaxe/objects/dashboards.rb', line 10
def splunk_resource
%w[data ui views]
end
|
#write_to_file(file_path, overwrite, splunk_entity) ⇒ Object
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/splunk/pickaxe/objects/dashboards.rb', line 61
def write_to_file(file_path, overwrite, splunk_entity)
if overwrite || !File.exist?(file_path)
overwritten = overwrite && File.exist?(file_path)
File.write(file_path, splunk_entity['eai:data'])
puts overwritten ? ' Overwritten' : ' Created'
else
puts ' Already exists'
end
end
|