naginata 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ae0efd9a15d8b81f26114f2543bfda2174d49477
4
- data.tar.gz: 99bb8cb5573bc988e7af37b53205a06eb367733f
3
+ metadata.gz: 32af873ea80b3b5ade9260449bb08f15d45fda41
4
+ data.tar.gz: 232bd48d820d0d500f3a5ac7a26e90564768e8f6
5
5
  SHA512:
6
- metadata.gz: 9302334fe18fd4e010531cecadf009632dd97c54b69f853316ce429a4a36ef64e5ca4daf77e7ecf35b90e00f6e1856992a35b1c22e28bb5a253eadb9d46a8a20
7
- data.tar.gz: b43419293e29760ae3905ecf2d234462dbb64560fdae1a800e2b846c61b01797f7ac4834e29dc8adaa446778badf2b399c3559813f7e4050e75a6e695428c4b8
6
+ metadata.gz: 1c00459ebef2245b3b73d2d97e53a5d5003ff5fd1b0711b5d693d07ddd32fe181288edb76a628265b0ec0473327e11662a8bc60bbe158f93b4132333efadd72a
7
+ data.tar.gz: 9553c604ea5bcfe803e05a8a17ca70ecdec19865dca3caaf1382268107efd7e1a6c8e23db1d357e944d8bd2227dbdd05937b2785aa610c798ceb56cec837b16b
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ### 0.1.1
2
+
3
+ Enhancement:
4
+
5
+ * Introduce `naginata init`
6
+
7
+ Fixes:
8
+
9
+ * --dry-run was broken
10
+
1
11
  ### 0.1.0
2
12
 
3
13
  * First release
data/README.md CHANGED
@@ -33,22 +33,26 @@ And then execute:
33
33
 
34
34
  ## Configuration
35
35
 
36
- Naginatafile
36
+ Next, create a configuration file from the template. The below command creates _Naginatafile_ on the current working directory.
37
+
38
+ $ naginata init
39
+
40
+ And then edit Naginatafile
37
41
 
38
42
  ```
39
43
  # Define nagios servers
40
- nagios 'foo@nagios1.example.com'
41
- nagios 'bar@nagios2.example.com'
42
- nagios 'baz@nagios3.example.com'
44
+ nagios_server 'foo@nagios1.example.com'
45
+ nagios_server 'bar@nagios2.example.com'
46
+ nagios_server 'baz@nagios3.example.com'
43
47
 
44
- # nagios server global options
48
+ # Global nagios server options
45
49
  set :nagios_server_options, {
46
50
  command_file: '/usr/local/nagios/var/rw/nagios.cmd',
47
51
  status_file: '/usr/local/nagios/var/status.cmd',
48
52
  run_command_as: 'nagios',
49
53
  }
50
54
 
51
- # Global options
55
+ # Global SSH options
52
56
  set :ssh_options, {
53
57
  keys: %w(/home/nikushi/.ssh/id_rsa),
54
58
  }
@@ -56,7 +60,6 @@ set :ssh_options, {
56
60
 
57
61
  ## Usage
58
62
 
59
-
60
63
  ### Notification
61
64
 
62
65
  #### Enable(Disable) host and service notifications of server001
data/bin/naginata CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  $:.unshift File.expand_path("../../lib", __FILE__)
4
+ require 'naginata'
4
5
  require 'naginata/cli'
5
6
 
6
7
  Naginata::CLI.start
data/lib/naginata.rb CHANGED
@@ -9,6 +9,9 @@ require "naginata/ui"
9
9
  require "naginata/version"
10
10
 
11
11
  module Naginata
12
+
13
+ class NaginatafileNotFound < StandardError; end
14
+
12
15
  class << self
13
16
  def ui
14
17
  @ui ||= UI::Shell.new
data/lib/naginata/cli.rb CHANGED
@@ -9,27 +9,14 @@ module Naginata
9
9
  class_option :verbose, aliases: "-v", type: :boolean
10
10
  class_option :debug, type: :boolean
11
11
 
12
- def initialize(args = [], opts = [], config = {})
13
- super(args, opts, config)
14
-
15
- Loader.load_configuration
16
-
17
- if options[:debug]
18
- ::Naginata::Configuration.env.set(:log_level, :debug)
19
- elsif options[:verbose]
20
- ::Naginata::Configuration.env.set(:log_level, :info)
21
- end
22
-
23
- # @Note This has a problem, in nap CLI::Base class is initialied multiple
24
- # time, below add same filter every time. This should be fixed but not
25
- # critical.
26
- if options[:nagios]
27
- ::Naginata::Configuration.env.add_filter(:nagios_server, options[:nagios])
28
- end
29
-
30
- configure_backend
31
-
32
- Loader.load_remote_objects
12
+ #def initialize(args = [], opts = [], config = {})
13
+ # super(args, opts, config)
14
+ #end
15
+
16
+ desc 'init', 'Init generates a default Nagipfile into current directory'
17
+ def init
18
+ require 'naginata/cli/init'
19
+ CLI::Init.new(options).execute
33
20
  end
34
21
 
35
22
  desc 'notification [hostpattern ..]', 'Control notification'
@@ -40,25 +27,13 @@ module Naginata
40
27
  method_option :all_hosts, aliases: "-a", desc: "Target all hosts", type: :boolean, default: false
41
28
  def notification(*patterns)
42
29
  require 'naginata/cli/notification'
43
- CLI::Notification.new(options.merge(patterns: patterns)).run
30
+ CLI::Notification.new(options.merge(patterns: patterns)).execute
44
31
  end
45
32
 
46
33
  desc 'fetch', 'Download remote status.dat and create cache on local'
47
34
  def fetch
48
35
  require 'naginata/cli/fetch'
49
- CLI::Fetch.new.run
50
- end
51
-
52
- no_tasks do
53
-
54
- def configure_backend
55
- if options[:dry_run]
56
- require 'sshkit/backends/printer'
57
- ::Naginata::Configuration.env.set(:sshkit_backend, SSHKit::Backend::Printer)
58
- end
59
- ::Naginata::Configuration.env.configure_backend
60
- end
61
-
36
+ CLI::Fetch.new(options).execute
62
37
  end
63
38
 
64
39
  end
@@ -1,13 +1,10 @@
1
+ require 'naginata/cli/remote_abstract'
1
2
  require 'naginata/configuration'
2
3
  require 'naginata/status'
3
4
  require 'naginata/runner'
4
5
 
5
6
  module Naginata
6
- class CLI::Fetch
7
-
8
- def initialize(options = {})
9
- @options = options
10
- end
7
+ class CLI::Fetch < CLI::RemoteAbstract
11
8
 
12
9
  def run
13
10
  Naginata::Runner.run do |backend, nagios_server, services|
@@ -24,6 +21,10 @@ module Naginata
24
21
  end
25
22
 
26
23
  end
24
+
25
+ def load_remote_objects
26
+ end
27
+
27
28
  end
28
29
  end
29
30
 
@@ -0,0 +1,18 @@
1
+ require 'naginata/cli/local_abstract'
2
+
3
+ module Naginata
4
+ class CLI::Init < CLI::LocalAbstract
5
+ def run
6
+ if File.exist?("Naginatafile")
7
+ Naginata.ui.error "Naginatafile already exists at #{Dir.pwd}/Naginatafile"
8
+ exit 1
9
+ end
10
+ Naginata.ui.info "Writing new Naginatafile to #{Dir.pwd}/Naginatafile", true
11
+ FileUtils.cp(File.expand_path('../../templates/Naginatafile', __FILE__), 'Naginatafile')
12
+ end
13
+
14
+ def load_configuration
15
+ # Skip loading configuration because Nagipfile does not exist yet.
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,12 @@
1
+ require 'naginata/cli/remote_abstract'
2
+
3
+ module Naginata
4
+ class CLI::LocalAbstract < CLI::RemoteAbstract
5
+
6
+ def configure_backend; end
7
+ def load_remote_objects; end
8
+
9
+ end
10
+ end
11
+
12
+
@@ -1,14 +1,11 @@
1
1
  require 'naginata'
2
+ require 'naginata/cli/remote_abstract'
2
3
  require 'naginata/command/external_command'
3
4
  require 'naginata/configuration'
4
5
  require 'naginata/runner'
5
6
 
6
7
  module Naginata
7
- class CLI::Notification
8
-
9
- def initialize(options)
10
- @options = options
11
- end
8
+ class CLI::Notification < CLI::RemoteAbstract
12
9
 
13
10
  def run
14
11
  if !@options[:enable] and !@options[:disable]
@@ -0,0 +1,56 @@
1
+ require 'naginata/configuration'
2
+ require 'naginata/loader'
3
+
4
+ module Naginata
5
+ class CLI::RemoteAbstract
6
+
7
+ def initialize(options = {})
8
+ @options = options
9
+ end
10
+
11
+ def execute
12
+ load_configuration
13
+ set_log_level
14
+ set_nagios_filter
15
+ configure_backend
16
+ load_remote_objects
17
+ run
18
+ end
19
+
20
+ def set_log_level
21
+ if @options[:debug]
22
+ ::Naginata::Configuration.env.set(:log_level, :debug)
23
+ elsif @options[:verbose]
24
+ ::Naginata::Configuration.env.set(:log_level, :info)
25
+ end
26
+ end
27
+
28
+ def set_nagios_filter
29
+ if @options[:nagios]
30
+ ::Naginata::Configuration.env.add_filter(:nagios_server, @options[:nagios])
31
+ end
32
+ end
33
+
34
+ def load_configuration
35
+ Loader.load_configuration
36
+ end
37
+
38
+ def configure_backend
39
+ if @options[:dry_run]
40
+ require 'sshkit/backends/printer'
41
+ ::Naginata::Configuration.env.set(:sshkit_backend, SSHKit::Backend::Printer)
42
+ end
43
+ ::Naginata::Configuration.env.configure_backend
44
+ end
45
+
46
+ def load_remote_objects
47
+ Loader.load_remote_objects(@options)
48
+ end
49
+
50
+ def run
51
+ raise NotImplementedError, 'Called abstract method'
52
+ end
53
+ end
54
+ end
55
+
56
+
@@ -9,13 +9,14 @@ module Naginata
9
9
 
10
10
  def load_configuration
11
11
  instance_eval File.read(File.join(File.dirname(__FILE__), 'defaults.rb'))
12
- instance_eval File.read 'Naginatafile'
12
+ naginatafile_path = find_naginatafile
13
+ instance_eval File.read naginatafile_path
13
14
  end
14
15
 
15
- def load_remote_objects
16
+ def load_remote_objects(fetch_options = {})
16
17
  require 'naginata/cli/fetch'
17
18
  # Refresh cached status.dat
18
- CLI::Fetch.new.run
19
+ CLI::Fetch.new(fetch_options).run
19
20
 
20
21
  # Load status.dat
21
22
  #
@@ -33,6 +34,17 @@ module Naginata
33
34
 
34
35
  end
35
36
 
37
+ private
38
+
39
+ def find_naginatafile
40
+ naginatafile_path = File.expand_path('Naginatafile')
41
+ if File.file?(naginatafile_path)
42
+ return naginatafile_path
43
+ else
44
+ raise NaginatafileNotFound, 'Could not locate Naginatafile'
45
+ end
46
+ end
47
+
36
48
  end
37
49
  end
38
50
  end
@@ -0,0 +1,37 @@
1
+ # Nagios server definition
2
+ # ========================
3
+ # Defines nagios servers with multiple properties.
4
+
5
+ # nagios_server 'nagios.tokyo.example.com', user: 'nagios'
6
+ # nagios_server 'nagios.ny.example.com', user: 'nagios', port: '10022'
7
+ # nagios_server 'admin@nagios.sf.example.com'
8
+ # nagios_server 'admin@nagios.sha.example.com:10022'
9
+ # nagios_server 'nagios.uk.example.com', keys: %w(/path/to/private_key)
10
+
11
+ # Global Nagios Server Options
12
+ # ============================
13
+ # You can set global properties for all nagios servers here.
14
+ # `run_command_as` is a user who execute external commands on a remote nagios
15
+ # server. By default external commands are as the same user who is log-in.
16
+ # This means naginata executes sudo -u `run_command_as sh -c ...` on remote
17
+ # servers if `run_command_as` is set.
18
+
19
+ # set :nagios_server_options, {
20
+ # command_file: '/var/spool/nagios/cmd/nagios.cmd',
21
+ # status_file: '/var/log/nagios/status.dat',
22
+ # run_command_as: 'nagios',
23
+ # }
24
+
25
+ #
26
+ # Custom SSH Options
27
+ # ==================
28
+ # You may pass any option but keep in mind that net/ssh understands a
29
+ # limited set of options, consult the Net::SSH documentation.
30
+ # http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start
31
+ #
32
+ # Global options
33
+ # --------------
34
+ # set :ssh_options, {
35
+ # user: 'admin',
36
+ # keys: %w(/path/to/private_key),
37
+ # }
@@ -1,3 +1,3 @@
1
1
  module Naginata
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: naginata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nobuhiro Nikushi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-02 00:00:00.000000000 Z
11
+ date: 2015-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sshkit
@@ -117,7 +117,10 @@ files:
117
117
  - lib/naginata.rb
118
118
  - lib/naginata/cli.rb
119
119
  - lib/naginata/cli/fetch.rb
120
+ - lib/naginata/cli/init.rb
121
+ - lib/naginata/cli/local_abstract.rb
120
122
  - lib/naginata/cli/notification.rb
123
+ - lib/naginata/cli/remote_abstract.rb
121
124
  - lib/naginata/command/external_command.rb
122
125
  - lib/naginata/configuration.rb
123
126
  - lib/naginata/configuration/filter.rb
@@ -128,6 +131,7 @@ files:
128
131
  - lib/naginata/loader.rb
129
132
  - lib/naginata/runner.rb
130
133
  - lib/naginata/status.rb
134
+ - lib/naginata/templates/Naginatafile
131
135
  - lib/naginata/ui.rb
132
136
  - lib/naginata/ui/shell.rb
133
137
  - lib/naginata/version.rb