Class: Splunk::Pickaxe::Tags
- Inherits:
-
Objects
- Object
- Objects
- Splunk::Pickaxe::Tags
show all
- Defined in:
- lib/splunk/pickaxe/objects/tags.rb
Instance Attribute Summary
Attributes inherited from Objects
#environment, #pickaxe_config, #service
Instance Method Summary
collapse
Methods inherited from Objects
#config, #entity_file_extensions, #entity_file_name, #initialize, #name, #remove_pickaxe_config, #save, #save_config, #skip?, #sync, #write_to_file
Instance Method Details
#create(entity) ⇒ Object
43
44
45
46
|
# File 'lib/splunk/pickaxe/objects/tags.rb', line 43
def create(entity)
update [], entity
end
|
#entity_dir ⇒ Object
15
16
17
|
# File 'lib/splunk/pickaxe/objects/tags.rb', line 15
def entity_dir
DIR
end
|
#entity_file_path(splunk_entity) ⇒ Object
19
20
21
22
23
24
|
# File 'lib/splunk/pickaxe/objects/tags.rb', line 19
def entity_file_path(splunk_entity)
File.join(
pickaxe_config.execution_path, entity_dir,
entity_file_name(splunk_entity)
)
end
|
#find(entity) ⇒ Object
Tags do not follow the typical conventions that other splunk resources do so we have to change the find/create/update methods
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/splunk/pickaxe/objects/tags.rb', line 28
def find(entity)
response = service.request(method: :GET, resource: splunk_resource + [name(entity)])
atom_feed = Splunk::AtomFeed.new(response.body)
atom_feed.entries.map { |e| e['title'] }
rescue Splunk::SplunkHTTPError => e
if e.code == 404
nil
else
raise e
end
end
|
#needs_update?(splunk_entity, entity) ⇒ Boolean
66
67
68
69
|
# File 'lib/splunk/pickaxe/objects/tags.rb', line 66
def needs_update?(splunk_entity, entity)
splunk_config(entity).uniq.sort != splunk_entity.uniq.sort
end
|
#splunk_config(entity) ⇒ Object
62
63
64
|
# File 'lib/splunk/pickaxe/objects/tags.rb', line 62
def splunk_config(entity)
entity['fields']
end
|
#splunk_entity_keys ⇒ Object
71
72
73
|
# File 'lib/splunk/pickaxe/objects/tags.rb', line 71
def splunk_entity_keys
Splunk::Pickaxe::TAGS_KEYS
end
|
#splunk_resource ⇒ Object
11
12
13
|
# File 'lib/splunk/pickaxe/objects/tags.rb', line 11
def splunk_resource
%w[search tags]
end
|
#update(splunk_entity, entity) ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/splunk/pickaxe/objects/tags.rb', line 48
def update(splunk_entity, entity)
(splunk_config(entity) - splunk_entity).each do |field|
response = service.request(method: :POST, resource: splunk_resource + [name(entity)], body: { add: field })
raise "Failed to add field to tag [#{response.code}] - [#{response.body}]" unless response.is_a? Net::HTTPSuccess
end
(splunk_entity - splunk_config(entity)).each do |field|
response = service.request(method: :POST, resource: splunk_resource + [name(entity)], body: { delete: field })
raise "Failed to delete field from tag [#{response.code}] - [#{response.body}]" unless response.is_a? Net::HTTPSuccess
end
end
|