class Splunk::Pickaxe::Dashboards

Public Instance Methods

config(file_path) click to toggle source
# 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_dir() click to toggle source
# File lib/splunk/pickaxe/objects/dashboards.rb, line 14
def entity_dir
  DIR
end
entity_file_extensions() click to toggle source
# File lib/splunk/pickaxe/objects/dashboards.rb, line 43
def entity_file_extensions
  ['.xml']
end
entity_file_name(entity) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# 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) click to toggle source
# 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