Class: Splunk::Pickaxe::Dashboards

Inherits:
Objects
  • Object
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?, #save, #skip?, #splunk_config, #splunk_entity_keys, #sync, #update

Constructor Details

This class inherits a constructor from Splunk::Pickaxe::Objects

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)

  # Dashboards don't have many properties just name and source XML
  {
    'name' => File.basename(file_path, '.xml'),
    'config' => {
      'eai:data' => xml_content
    }
  }
end

#entity_dirObject



14
15
16
# File 'lib/splunk/pickaxe/objects/dashboards.rb', line 14

def entity_dir
  DIR
end

#entity_file_extensionsObject



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) ⇒ 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)
  file_path = entity_file_path splunk_entity

  puts "- #{splunk_entity['label']}"
  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

#splunk_resourceObject



10
11
12
# File 'lib/splunk/pickaxe/objects/dashboards.rb', line 10

def splunk_resource
  %w[data ui views]
end