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, #initialize, #name, #skip?, #sync
Instance Method Details
#create(entity) ⇒ Object
36
37
38
39
|
# File 'lib/splunk/pickaxe/objects/tags.rb', line 36
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
|
#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
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/splunk/pickaxe/objects/tags.rb', line 21
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
59
60
61
62
|
# File 'lib/splunk/pickaxe/objects/tags.rb', line 59
def needs_update?(splunk_entity, entity)
splunk_config(entity).uniq.sort != splunk_entity.uniq.sort
end
|
#splunk_config(entity) ⇒ Object
55
56
57
|
# File 'lib/splunk/pickaxe/objects/tags.rb', line 55
def splunk_config(entity)
entity['fields']
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
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/splunk/pickaxe/objects/tags.rb', line 41
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
|