Class: Splunk::Pickaxe::FieldExtractions
- Inherits:
-
Objects
- Object
- Objects
- Splunk::Pickaxe::FieldExtractions
show all
- Defined in:
- lib/splunk/pickaxe/objects/field_extractions.rb
Instance Attribute Summary
Attributes inherited from Objects
#environment, #pickaxe_config, #service
Instance Method Summary
collapse
Methods inherited from Objects
#config, #create, #entity_file_extensions, #initialize, #name, #remove_pickaxe_config, #save, #skip?, #splunk_config, #sync
Instance Method Details
#entity_dir ⇒ Object
15
16
17
|
# File 'lib/splunk/pickaxe/objects/field_extractions.rb', line 15
def entity_dir
DIR
end
|
#entity_file_name(splunk_entity) ⇒ Object
19
20
21
22
|
# File 'lib/splunk/pickaxe/objects/field_extractions.rb', line 19
def entity_file_name(splunk_entity)
"#{splunk_entity['stanza']}-#{splunk_entity['type']}-#{splunk_entity['attribute']}.yml"
.gsub(/[^a-z0-9_\-. ]/i, '')
end
|
#entity_file_path(splunk_entity) ⇒ Object
24
25
26
27
28
29
|
# File 'lib/splunk/pickaxe/objects/field_extractions.rb', line 24
def entity_file_path(splunk_entity)
File.join(
pickaxe_config.execution_path, entity_dir,
entity_file_name(splunk_entity)
)
end
|
#find(entity) ⇒ Object
31
32
33
34
35
36
37
38
|
# File 'lib/splunk/pickaxe/objects/field_extractions.rb', line 31
def find(entity)
find_entity = Hash.new(entity)
find_entity['name'] = "#{entity['config']['stanza']} : #{entity['config']['type']}-#{entity['name']}"
super(find_entity)
end
|
#needs_update?(splunk_entity, entity) ⇒ Boolean
45
46
47
48
|
# File 'lib/splunk/pickaxe/objects/field_extractions.rb', line 45
def needs_update?(splunk_entity, entity)
splunk_entity['value'] != splunk_config(entity)['value']
end
|
#save_config(splunk_entity, overwrite, local_save) ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/splunk/pickaxe/objects/field_extractions.rb', line 50
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.name}"
write_to_file(file_path, overwrite, splunk_entity)
end
else
puts "- #{splunk_entity.name}"
write_to_file(file_path, overwrite, splunk_entity)
end
end
|
#splunk_entity_keys ⇒ Object
#splunk_resource ⇒ Object
11
12
13
|
# File 'lib/splunk/pickaxe/objects/field_extractions.rb', line 11
def splunk_resource
%w[data props extractions]
end
|
#update(splunk_entity, entity) ⇒ Object
40
41
42
43
|
# File 'lib/splunk/pickaxe/objects/field_extractions.rb', line 40
def update(splunk_entity, entity)
splunk_entity.update('value' => splunk_config(entity)['value'])
end
|
#write_to_file(file_path, overwrite, splunk_entity) ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/splunk/pickaxe/objects/field_extractions.rb', line 64
def write_to_file(file_path, overwrite, splunk_entity)
if overwrite || !File.exist?(file_path)
config = splunk_entity_keys
.map { |k| { k => splunk_entity.fetch(k) } }
.reduce({}) { |memo, setting| memo.update(setting) }
config['type'] = splunk_entity.fetch('attribute').split('-').first
config['value'].gsub!(/, /, ',')
overwritten = overwrite && File.exist?(file_path)
File.write(file_path, {
'name' => splunk_entity.name,
'config' => config
}.to_yaml)
puts overwritten ? ' Overwritten' : ' Created'
else
puts ' Already exists'
end
end
|