splunk-pickaxe 2.1.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +0 -1
- data/README.md +2 -0
- data/Rakefile +12 -0
- data/lib/splunk/pickaxe/cli.rb +3 -4
- data/lib/splunk/pickaxe/client.rb +9 -6
- data/lib/splunk/pickaxe/config.rb +1 -1
- data/lib/splunk/pickaxe/cookie_proxy.rb +21 -0
- data/lib/splunk/pickaxe/objects/dashboards.rb +7 -5
- data/lib/splunk/pickaxe/objects/field_extractions.rb +6 -5
- data/lib/splunk/pickaxe/objects.rb +12 -7
- data/lib/splunk/pickaxe/version.rb +2 -2
- data/lib/splunk/pickaxe.rb +5 -3
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e30eda1563101ee3bf15dfaff58b4bcfcccc3d54
|
4
|
+
data.tar.gz: 553fcc43e768862110d4acd75dcd596a77db4424
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c7d145f55702162f5c336c5fea2b63120434249f29f0583351e765cfe1034777051913cdbc792078a647e807955173a2d5ffdf69c193afa8a53a759ea60b59b8
|
7
|
+
data.tar.gz: 2982d1bdc9a7c8e8f1933311cd885d2130fd1e841e73dc1a592e2f45493135211e31b2542cb0a63e19d98f5b76fd3be2e4c7e77f2705dfd01c7b66fb772cb512
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -8,6 +8,8 @@ A tool for serializing and syncing your repo of Splunk objects across Splunk ins
|
|
8
8
|
This provides a development workflow for Splunk components (e.g., dashboards,
|
9
9
|
alerts, reports, etc) and an easy way to apply them consistently.
|
10
10
|
|
11
|
+
Check the [changelog](CHANGELOG.md) to see what has changed.
|
12
|
+
|
11
13
|
Getting Started
|
12
14
|
---------------
|
13
15
|
|
data/Rakefile
CHANGED
@@ -22,10 +22,22 @@ task :release do
|
|
22
22
|
update_change_log version
|
23
23
|
puts "Change log updated!"
|
24
24
|
|
25
|
+
puts "Publishing the gem ..."
|
25
26
|
run_command 'gem build splunk-pickaxe.gemspec'
|
26
27
|
run_command "gem push splunk-pickaxe-#{version}.gem"
|
28
|
+
run_command "rm -f splunk-pickaxe-#{version}.gem"
|
29
|
+
puts "Gem published!"
|
27
30
|
|
31
|
+
puts "Creating git tag ..."
|
32
|
+
run_command "git tag #{version}"
|
33
|
+
run_command "git push origin #{version}"
|
34
|
+
puts "Git tag created!"
|
35
|
+
|
36
|
+
puts "Updating to next version ..."
|
28
37
|
update_version version
|
38
|
+
puts "Version updated!"
|
39
|
+
|
40
|
+
puts "Gem released!"
|
29
41
|
end
|
30
42
|
|
31
43
|
task :build_change_log do
|
data/lib/splunk/pickaxe/cli.rb
CHANGED
@@ -49,9 +49,8 @@ module Splunk
|
|
49
49
|
|
50
50
|
user = options[:user] || Etc.getlogin
|
51
51
|
password = options[:password] || cli.ask('Password: ') { |o| o.echo = '*' }
|
52
|
-
execution_path = options[:repo_path] || Dir.getwd
|
53
52
|
|
54
|
-
pickaxe = Pickaxe.configure environment, user, password,
|
53
|
+
pickaxe = Pickaxe.configure environment, user, password, options
|
55
54
|
pickaxe.sync_all
|
56
55
|
end
|
57
56
|
|
@@ -59,14 +58,14 @@ module Splunk
|
|
59
58
|
option :user, type: :string, desc: 'The user to login to splunk with. If this is not provide it will use the current user'
|
60
59
|
option :password, type: :string, desc: 'The password to login to splunk with. If this is not provided it will ask for a password'
|
61
60
|
option :repo_path, type: :string, desc: 'The path to the repo. If this is not specified it is assumed you are executing from within the repo'
|
61
|
+
option :overwrite, type: :boolean, desc: 'Overwrite any local Splunk objects which differ from remote objects with the same name.'
|
62
62
|
def save(environment)
|
63
63
|
cli = HighLine.new
|
64
64
|
|
65
65
|
user = options[:user] || Etc.getlogin
|
66
66
|
password = options[:password] || cli.ask('Password: ') { |o| o.echo = '*' }
|
67
|
-
execution_path = options[:repo_path] || Dir.getwd
|
68
67
|
|
69
|
-
pickaxe = Pickaxe.configure environment, user, password,
|
68
|
+
pickaxe = Pickaxe.configure environment, user, password, options
|
70
69
|
pickaxe.save_all
|
71
70
|
end
|
72
71
|
end
|
@@ -12,8 +12,9 @@ module Splunk
|
|
12
12
|
class Client
|
13
13
|
attr_reader :service, :alerts, :dashboards, :eventypes, :reports, :tags, :field_extractions
|
14
14
|
|
15
|
-
def initialize(service, environment, config)
|
15
|
+
def initialize(service, environment, config, args)
|
16
16
|
@service = service
|
17
|
+
@args = args
|
17
18
|
|
18
19
|
@alerts = Alerts.new service, environment, config
|
19
20
|
@dashboards = Dashboards.new service, environment, config
|
@@ -33,12 +34,14 @@ module Splunk
|
|
33
34
|
end
|
34
35
|
|
35
36
|
def save_all
|
36
|
-
@
|
37
|
-
|
38
|
-
@
|
39
|
-
@
|
37
|
+
overwrite = @args.fetch(:overwrite, false)
|
38
|
+
|
39
|
+
@alerts.save overwrite
|
40
|
+
@dashboards.save overwrite
|
41
|
+
@eventtypes.save overwrite
|
42
|
+
@reports.save overwrite
|
40
43
|
# splunk-sdk doesn't seem to support iterating tags
|
41
|
-
@field_extractions.save
|
44
|
+
@field_extractions.save overwrite
|
42
45
|
end
|
43
46
|
end
|
44
47
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Splunk
|
4
|
+
module Pickaxe
|
5
|
+
class CookieProxy < Net::HTTP
|
6
|
+
@@cookies ||= nil
|
7
|
+
|
8
|
+
def request(req, body = nil, &block) # :yield: +response+
|
9
|
+
if @@cookies
|
10
|
+
req['Cookie'] = @@cookies
|
11
|
+
end
|
12
|
+
r = super(req,body,&block)
|
13
|
+
c = r.to_hash['set-cookie']
|
14
|
+
if c
|
15
|
+
@@cookies = c.collect{|ea|ea[/^.*?;/]}.join
|
16
|
+
end
|
17
|
+
return r
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -41,15 +41,17 @@ module Splunk
|
|
41
41
|
['.xml']
|
42
42
|
end
|
43
43
|
|
44
|
-
def save_config(splunk_entity)
|
44
|
+
def save_config(splunk_entity, overwrite)
|
45
45
|
file_path = entity_file_path splunk_entity
|
46
46
|
|
47
47
|
puts "- #{splunk_entity['label']}"
|
48
|
-
if File.exist?
|
49
|
-
|
50
|
-
|
48
|
+
if overwrite || !File.exist?(file_path)
|
49
|
+
overwritten = overwrite && File.exist?(file_path)
|
50
|
+
|
51
51
|
File.write(file_path, splunk_entity['eai:data'])
|
52
|
-
puts ' Created'
|
52
|
+
puts overwritten ? ' Overwritten' : ' Created'
|
53
|
+
else
|
54
|
+
puts ' Already exists'
|
53
55
|
end
|
54
56
|
end
|
55
57
|
end
|
@@ -47,13 +47,11 @@ module Splunk
|
|
47
47
|
splunk_entity['value'] != splunk_config(entity)['value']
|
48
48
|
end
|
49
49
|
|
50
|
-
def save_config(splunk_entity)
|
50
|
+
def save_config(splunk_entity, overwrite)
|
51
51
|
file_path = entity_file_path splunk_entity
|
52
52
|
|
53
53
|
puts "- #{splunk_entity.name}"
|
54
|
-
if File.exist?
|
55
|
-
puts ' Already exists'
|
56
|
-
else
|
54
|
+
if overwrite || !File.exist?(file_path)
|
57
55
|
config = splunk_entity_keys
|
58
56
|
.map { |k| { k => splunk_entity.fetch(k) } }
|
59
57
|
.reduce({}) { |memo, setting| memo.update(setting) }
|
@@ -64,11 +62,14 @@ module Splunk
|
|
64
62
|
config['type'] = splunk_entity.fetch('attribute').split('-').first
|
65
63
|
config['value'].gsub!(/, /, ',')
|
66
64
|
|
65
|
+
overwritten = overwrite && File.exist?(file_path)
|
67
66
|
File.write(file_path, {
|
68
67
|
'name' => splunk_entity.name,
|
69
68
|
'config' => config
|
70
69
|
}.to_yaml)
|
71
|
-
puts ' Created'
|
70
|
+
puts overwritten ? ' Overwritten' : ' Created'
|
71
|
+
else
|
72
|
+
puts ' Already exists'
|
72
73
|
end
|
73
74
|
end
|
74
75
|
|
@@ -86,27 +86,32 @@ module Splunk
|
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
89
|
-
def save
|
89
|
+
def save(overwrite)
|
90
90
|
puts "Saving all #{entity_dir.capitalize}"
|
91
91
|
|
92
|
+
dir = File.join(pickaxe_config.execution_path, entity_dir)
|
93
|
+
Dir.mkdir dir unless Dir.exist? dir
|
94
|
+
|
92
95
|
Splunk::Collection.new(service, splunk_resource)
|
93
|
-
.map { |e| save_config e }
|
96
|
+
.map { |e| save_config e, overwrite }
|
94
97
|
end
|
95
98
|
|
96
|
-
def save_config(splunk_entity)
|
99
|
+
def save_config(splunk_entity, overwrite)
|
97
100
|
file_path = entity_file_path splunk_entity
|
98
101
|
|
99
102
|
puts "- #{splunk_entity.name}"
|
100
|
-
if File.exist?
|
101
|
-
|
102
|
-
|
103
|
+
if overwrite || !File.exist?(file_path)
|
104
|
+
overwritten = overwrite && File.exist?(file_path)
|
105
|
+
|
103
106
|
File.write(file_path, {
|
104
107
|
'name' => splunk_entity.name,
|
105
108
|
'config' => splunk_entity_keys
|
106
109
|
.map { |k| { k => splunk_entity.fetch(k) } }
|
107
110
|
.reduce({}) { |memo, setting| memo.update(setting) }
|
108
111
|
}.to_yaml)
|
109
|
-
puts ' Created'
|
112
|
+
puts overwritten ? ' Overwritten' : ' Created'
|
113
|
+
else
|
114
|
+
puts ' Already exists'
|
110
115
|
end
|
111
116
|
end
|
112
117
|
|
data/lib/splunk/pickaxe.rb
CHANGED
@@ -4,11 +4,12 @@ require 'splunk-sdk-ruby'
|
|
4
4
|
require 'uri'
|
5
5
|
require 'splunk/pickaxe/config'
|
6
6
|
require 'splunk/pickaxe/client'
|
7
|
+
require 'splunk/pickaxe/cookie_proxy'
|
7
8
|
|
8
9
|
module Splunk
|
9
10
|
module Pickaxe
|
10
|
-
def self.configure(environment, username, password,
|
11
|
-
config = Config.load
|
11
|
+
def self.configure(environment, username, password, args)
|
12
|
+
config = Config.load(args.fetch(:repo_path, Dir.getwd))
|
12
13
|
|
13
14
|
raise "Unknown environment [#{environment}]. Expected #{config.environments.keys}" unless config.environments.key?(environment)
|
14
15
|
|
@@ -16,6 +17,7 @@ module Splunk
|
|
16
17
|
|
17
18
|
puts "Connecting to splunk [#{uri}]"
|
18
19
|
service = Splunk.connect(
|
20
|
+
proxy: CookieProxy,
|
19
21
|
scheme: uri.scheme.to_sym,
|
20
22
|
host: uri.host,
|
21
23
|
port: uri.port,
|
@@ -24,7 +26,7 @@ module Splunk
|
|
24
26
|
namespace: config.namespace
|
25
27
|
)
|
26
28
|
|
27
|
-
Client.new service, environment.downcase, config
|
29
|
+
Client.new service, environment.downcase, config, args
|
28
30
|
end
|
29
31
|
end
|
30
32
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: splunk-pickaxe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryan Baugher
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-12-
|
11
|
+
date: 2017-12-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: splunk-sdk-ruby
|
@@ -96,6 +96,7 @@ files:
|
|
96
96
|
- lib/splunk/pickaxe/cli.rb
|
97
97
|
- lib/splunk/pickaxe/client.rb
|
98
98
|
- lib/splunk/pickaxe/config.rb
|
99
|
+
- lib/splunk/pickaxe/cookie_proxy.rb
|
99
100
|
- lib/splunk/pickaxe/objects.rb
|
100
101
|
- lib/splunk/pickaxe/objects/alerts.rb
|
101
102
|
- lib/splunk/pickaxe/objects/dashboards.rb
|