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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e55da5bc5897dd51554a5022a5f3e123a721be1f
4
- data.tar.gz: 7a3143d708b70cc5d9cee018b0caecfd40a90e2b
3
+ metadata.gz: e30eda1563101ee3bf15dfaff58b4bcfcccc3d54
4
+ data.tar.gz: 553fcc43e768862110d4acd75dcd596a77db4424
5
5
  SHA512:
6
- metadata.gz: ec70d9d035c320c620c96ab4d00d02d77abc50abed86e2932297861e42446085fcb3a178578e4d8524c5aeb216c8ff64f0743651fea206b98b562e8e8c591dc3
7
- data.tar.gz: 6d9d9dc450bf4c4833dcb9aec225e2f603e04d099119a5c99fa905309e1dc2beff82f163a983004653e27438dfaef2c547b7bd54031a57201c7463f46269d54c
6
+ metadata.gz: c7d145f55702162f5c336c5fea2b63120434249f29f0583351e765cfe1034777051913cdbc792078a647e807955173a2d5ffdf69c193afa8a53a759ea60b59b8
7
+ data.tar.gz: 2982d1bdc9a7c8e8f1933311cd885d2130fd1e841e73dc1a592e2f45493135211e31b2542cb0a63e19d98f5b76fd3be2e4c7e77f2705dfd01c7b66fb772cb512
data/Gemfile CHANGED
@@ -14,5 +14,4 @@ gem 'pry-rails', :group => :development
14
14
 
15
15
  group :release do
16
16
  gem 'octokit'
17
- gem 'rubygems-tasks'
18
17
  end
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
@@ -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, execution_path
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, execution_path
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
- @alerts.save
37
- @dashboards.save
38
- @eventtypes.save
39
- @reports.save
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
@@ -13,7 +13,7 @@ module Splunk
13
13
  },
14
14
  'environments' => {
15
15
  },
16
- 'emails' => []
16
+ 'emails' => [],
17
17
  }.freeze
18
18
 
19
19
  def self.load(execution_path)
@@ -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? file_path
49
- puts ' Already exists'
50
- else
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? file_path
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? file_path
101
- puts ' Already exists'
102
- else
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
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Splunk
4
4
  module Pickaxe
5
- VERSION = '2.1.0'
5
+ VERSION = '2.2.0'
6
6
  end
7
- end
7
+ end
@@ -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, execution_path = Dir.getwd)
11
- config = Config.load execution_path
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.1.0
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-07 00:00:00.000000000 Z
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