naginata 0.1.1 → 0.1.2

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: 32af873ea80b3b5ade9260449bb08f15d45fda41
4
- data.tar.gz: 232bd48d820d0d500f3a5ac7a26e90564768e8f6
3
+ metadata.gz: 74e188ef978a45024f7f18d461322f65e679ed9a
4
+ data.tar.gz: f7c51a3a8467dc3c9ad685ee78cb7990f0c29c3e
5
5
  SHA512:
6
- metadata.gz: 1c00459ebef2245b3b73d2d97e53a5d5003ff5fd1b0711b5d693d07ddd32fe181288edb76a628265b0ec0473327e11662a8bc60bbe158f93b4132333efadd72a
7
- data.tar.gz: 9553c604ea5bcfe803e05a8a17ca70ecdec19865dca3caaf1382268107efd7e1a6c8e23db1d357e944d8bd2227dbdd05937b2785aa610c798ceb56cec837b16b
6
+ metadata.gz: c9ccf821b8df0b705608cb4021434eddf422470c08f822130204e4a0d5012d8d0fd9d02dc84691e2d4f8e85b280739f93b1351be804b0dcabd2ef4f00c8c3650
7
+ data.tar.gz: 2ef51b650b5e11b58e6c284686f62af96c3c03a9b1d808a48e17d53b9aae881ae59d746244e2329dd00dbd706a91337162c35a41d1f771b44d68d18052eaa922
data/.travis.yml CHANGED
@@ -1,5 +1,9 @@
1
1
  language: ruby
2
2
  rvm:
3
+ - 1.9.3
3
4
  - 2.0.0
4
5
  - 2.1
5
6
  - 2.2
7
+ - ruby-head
8
+ before_install:
9
+ - "gem install bundler -v '~> 1.9'"
data/CHANGELOG.md CHANGED
@@ -1,4 +1,11 @@
1
- ### 0.1.1
1
+ ### 0.1.2 - 2015/04/06
2
+
3
+ Enhancement:
4
+
5
+ * Add tests to evaluate command execution output and behavior
6
+ * List hosts and their services and status
7
+
8
+ ### 0.1.1 - 2015/04/03
2
9
 
3
10
  Enhancement:
4
11
 
@@ -8,6 +15,6 @@ Fixes:
8
15
 
9
16
  * --dry-run was broken
10
17
 
11
- ### 0.1.0
18
+ ### 0.1.0 - 2015/04/02
12
19
 
13
20
  * First release
data/Gemfile CHANGED
@@ -2,3 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in naginata.gemspec
4
4
  gemspec
5
+
6
+ group :development, :test do
7
+ gem 'coveralls', :require => false
8
+ end
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Naginata
1
+ # Naginata [![Build Status](https://travis-ci.org/niku4i/naginata.svg?branch=master)](https://travis-ci.org/niku4i/naginata) [![Coverage Status](https://coveralls.io/repos/niku4i/naginata/badge.svg)](https://coveralls.io/r/niku4i/naginata) [![Gem Version](https://badge.fury.io/rb/naginata.svg)](http://badge.fury.io/rb/naginata)
2
2
 
3
3
  Naginata is multi nagios server control tool. If you have multiple nagios servers and want to control them from single workstation host by CLI over ssh connection, Naginata is good for you.
4
4
 
@@ -86,26 +86,73 @@ $ naginata notification -a -[e|d]
86
86
  $ naginata notification -a -s cpu -[e|d]
87
87
  ```
88
88
 
89
- ### Display status (will be added)
89
+ ### View service status (Experimental)
90
90
 
91
- #### Show server001's status
91
+ #### View service status for all hosts
92
92
 
93
93
  ```
94
- $ naginata status server001
94
+ $ naginata services -a
95
95
  ```
96
96
 
97
- #### Show all hosts' status
97
+ Output example:
98
98
 
99
99
  ```
100
- $ naginata status -a
100
+ $ naginata services -a
101
+ NAGIOS HOST SERVICE STATUS FLAGS OUTPUT
102
+ nagios0 localhost HTTP WARNING AC,nt HTTP WARNING: HTTP/1.1 403 Forbidden - 5152 bytes in 0.001 second response time
103
+ nagios0 localhost Current Load OK AC,NT OK - load average: 0.00, 0.00, 0.00
104
+ nagios0 localhost PING OK AC,NT PING OK - Packet loss = 0%, RTA = 0.04 ms
105
+ nagios0 redis01.tokyo.local Load CRITICAL AC,NT Too high load average 15
106
+ nagios0 redis01.tokyo.local PING OK ac,NT PING OK - Packet loss = 0%, RTA = 0.04 ms
107
+ nagios0 redis01.tokyo.local SSH OK AC,NT SSH OK - OpenSSH_5.3 (protocol 2.0)
108
+ nagios0 web01.tokyo.local Load OK AC,NT OK - load average: 0.01, 0.00, 0.00
109
+ nagios0 web01.tokyo.local PING OK AC,NT PING OK - Packet loss = 0%, RTA = 0.04 ms
110
+ nagios0 web01.tokyo.local SSH OK AC,NT SSH OK - OpenSSH_5.3 (protocol 2.0)
111
+ nagios1 redis01.osaka.local Load OK AC,NT OK - load average: 0.00, 0.00, 0.00
112
+ nagios1 redis01.osaka.local PING OK AC,NT PING OK - Packet loss = 0%, RTA = 0.04 ms
113
+ nagios1 redis01.osaka.local SSH OK AC,NT SSH OK - OpenSSH_5.3 (protocol 2.0)
114
+ ...
101
115
  ```
102
116
 
103
- #### Show all hosts' specific service status
117
+
118
+ #### View service status for specific hosts
119
+
120
+ ```
121
+ $ naginata services web01.example.com db01.example.com
122
+ ```
123
+
124
+ #### View service status filtering by services
104
125
 
105
126
  ```
106
- $ naginata status -a -s cpu
127
+ $ naginata services -a -s PING,SWAP
107
128
  ```
108
129
 
130
+ ### View host status (Experimental)
131
+
132
+ #### View all host status
133
+
134
+ ```
135
+ $ naginata hosts -a
136
+ ```
137
+
138
+ Output example:
139
+
140
+ ```
141
+ $ naginata hosts -a
142
+ NAGIOS HOST STATUS FLAGS OUTPUT
143
+ nagios0 localhost OK AC,NT PING OK - Packet loss = 0%, RTA = 0.01 ms
144
+ nagios0 redis01.tokyo.local OK AC,NT PING OK - Packet loss = 0%, RTA = 0.03 ms
145
+ nagios0 web01.tokyo.local OK AC,NT PING OK - Packet loss = 0%, RTA = 0.04 ms
146
+ nagios1 localhost OK AC,NT PING OK - Packet loss = 0%, RTA = 0.04 ms
147
+ nagios1 redis01.osaka.local OK AC,NT PING OK - Packet loss = 0%, RTA = 0.05 ms
148
+ nagios1 web01.osaka.local OK AC,NT PING OK - Packet loss = 0%, RTA = 0.04 ms
149
+ ```
150
+
151
+ #### View host status for specific hosts
152
+
153
+ ```
154
+ $ naginata hosts web01.example.com db01.example.com
155
+ ```
109
156
 
110
157
  ### Global Options
111
158
 
data/Rakefile CHANGED
@@ -1,5 +1,12 @@
1
1
  require "bundler/gem_tasks"
2
2
 
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new(:spec) do |t|
5
+ t.rspec_opts = ["-c", "-f documentation"]
6
+ end
7
+ task :test => :spec
8
+ task :default => :spec
9
+
3
10
  desc 'Open an irb session preloaded with the gem library'
4
11
  task :console do
5
12
  require "bundler/setup"
data/lib/naginata.rb CHANGED
@@ -8,6 +8,8 @@ require "naginata/status"
8
8
  require "naginata/ui"
9
9
  require "naginata/version"
10
10
 
11
+ require "nagios_analyzer/section_decorator"
12
+
11
13
  module Naginata
12
14
 
13
15
  class NaginatafileNotFound < StandardError; end
data/lib/naginata/cli.rb CHANGED
@@ -4,8 +4,6 @@ require 'naginata/loader'
4
4
 
5
5
  module Naginata
6
6
  class CLI < Thor
7
- class_option :nagios, desc: "Filter hosts by nagios server names", type: :array
8
- class_option :dry_run, aliases: "-n", type: :boolean
9
7
  class_option :verbose, aliases: "-v", type: :boolean
10
8
  class_option :debug, type: :boolean
11
9
 
@@ -20,22 +18,53 @@ module Naginata
20
18
  end
21
19
 
22
20
  desc 'notification [hostpattern ..]', 'Control notification'
23
- method_option :enable, aliases: "-e", desc: "Enable notification", type: :boolean, default: false
24
- method_option :disable, aliases: "-d", desc: "Disable notification", type: :boolean, default: false
25
- method_option :force, aliases: "-f", desc: "Run without prompting for confirmation", type: :boolean, default: false
21
+ method_option :enable, aliases: "-e", desc: "Enable notification", type: :boolean
22
+ method_option :disable, aliases: "-d", desc: "Disable notification", type: :boolean
23
+ method_option :dry_run, aliases: "-n", type: :boolean
24
+ method_option :force, aliases: "-f", desc: "Run without prompting for confirmation", type: :boolean
25
+ method_option :nagios, desc: "Filter hosts by nagios server names", type: :array
26
26
  method_option :services, aliases: "-s", desc: "Services to be enabled|disabled", type: :array
27
- method_option :all_hosts, aliases: "-a", desc: "Target all hosts", type: :boolean, default: false
27
+ method_option :all_hosts, aliases: "-a", desc: "Target all hosts", type: :boolean
28
28
  def notification(*patterns)
29
+ if patterns.empty? and options.empty?
30
+ help(:notification)
31
+ exit(1)
32
+ end
29
33
  require 'naginata/cli/notification'
30
34
  CLI::Notification.new(options.merge(patterns: patterns)).execute
31
35
  end
32
36
 
37
+ method_option :nagios, desc: "Filter hosts by nagios server names", type: :array
33
38
  desc 'fetch', 'Download remote status.dat and create cache on local'
34
39
  def fetch
35
40
  require 'naginata/cli/fetch'
36
41
  CLI::Fetch.new(options).execute
37
42
  end
38
43
 
44
+ desc 'hosts [hostpattern ..]', 'View host status'
45
+ method_option :nagios, desc: "Filter hosts by nagios server names", type: :array
46
+ method_option :all_hosts, aliases: "-a", desc: "Target all hosts", type: :boolean
47
+ def hosts(*patterns)
48
+ if patterns.empty? and !options[:all_hosts]
49
+ help(:hosts)
50
+ exit(1)
51
+ end
52
+ require 'naginata/cli/hosts'
53
+ CLI::Hosts.new(options.merge(patterns: patterns)).execute
54
+ end
55
+
56
+ desc 'services [hostpattern ..]', 'View service status'
57
+ method_option :nagios, desc: "Filter hosts by nagios server names", type: :array
58
+ method_option :services, aliases: "-s", desc: "Filter by service description", type: :array
59
+ method_option :all_hosts, aliases: "-a", desc: "Target all hosts", type: :boolean
60
+ def services(*patterns)
61
+ if patterns.empty? and !options[:all_hosts]
62
+ help(:services)
63
+ exit(1)
64
+ end
65
+ require 'naginata/cli/services'
66
+ CLI::Services.new(options.merge(patterns: patterns)).execute
67
+ end
39
68
  end
40
69
  end
41
70
 
@@ -0,0 +1,32 @@
1
+ require 'naginata'
2
+ require 'naginata/cli/remote_abstract'
3
+ require 'naginata/configuration'
4
+ require 'naginata/status'
5
+ require 'naginata/runner'
6
+
7
+ module Naginata
8
+ class CLI::Hosts < CLI::RemoteAbstract
9
+
10
+ def run
11
+ if @options[:all_hosts]
12
+ ::Naginata::Configuration.env.add_filter(:host, :all)
13
+ else
14
+ ::Naginata::Configuration.env.add_filter(:host, @options[:patterns])
15
+ end
16
+
17
+ table = []
18
+ table << %w(NAGIOS HOST STATUS FLAGS OUTPUT)
19
+ Naginata::Runner.run_locally do |nagios_server, services|
20
+ targets = services.map{ |s| s.hostname }.uniq
21
+ status = Status.find(nagios_server.hostname)
22
+ status.scopes << lambda { |s|
23
+ targets.any? {|host| s.include?("host_name=#{host}") }
24
+ }
25
+ table.concat(status.decorate.hosts_table)
26
+ end
27
+ Naginata.ui.print_table table
28
+ end
29
+
30
+ end
31
+ end
32
+
@@ -7,7 +7,7 @@ module Naginata
7
7
  Naginata.ui.error "Naginatafile already exists at #{Dir.pwd}/Naginatafile"
8
8
  exit 1
9
9
  end
10
- Naginata.ui.info "Writing new Naginatafile to #{Dir.pwd}/Naginatafile", true
10
+ Naginata.ui.info "Writing new Naginatafile to #{Dir.pwd}/Naginatafile"
11
11
  FileUtils.cp(File.expand_path('../../templates/Naginatafile', __FILE__), 'Naginatafile')
12
12
  end
13
13
 
@@ -29,12 +29,12 @@ module Naginata
29
29
  command_file = ::Naginata::Configuration.env.fetch(:nagios_server_options)[:command_file]
30
30
 
31
31
  if !@options[:force]
32
- Naginata.ui.info "Following notifications will be #{@options[:enable] ? 'enabled' : 'disabled'}", true
32
+ Naginata.ui.info "Following notifications will be #{@options[:enable] ? 'enabled' : 'disabled'}"
33
33
  Naginata::Runner.run_locally do |nagios_server, services|
34
34
  services.group_by{ |s| s.hostname }.each do |hostname, svcs|
35
35
  puts hostname
36
36
  svcs.each do |service|
37
- Naginata.ui.info " - #{service.description}", true
37
+ Naginata.ui.info " - #{service.description}"
38
38
  end
39
39
  end
40
40
  end
@@ -54,7 +54,7 @@ module Naginata
54
54
  backend.execute command, command_arg
55
55
  end
56
56
  end
57
- Naginata.ui.info "Done", true
57
+ Naginata.ui.info "Done"
58
58
  end
59
59
 
60
60
  end
@@ -0,0 +1,39 @@
1
+ require 'naginata'
2
+ require 'naginata/cli/remote_abstract'
3
+ require 'naginata/configuration'
4
+ require 'naginata/status'
5
+ require 'naginata/runner'
6
+
7
+ module Naginata
8
+ class CLI::Services < CLI::RemoteAbstract
9
+
10
+ def run
11
+ if @options[:all_hosts]
12
+ ::Naginata::Configuration.env.add_filter(:host, :all)
13
+ else
14
+ ::Naginata::Configuration.env.add_filter(:host, @options[:patterns])
15
+ end
16
+ if @options[:services]
17
+ ::Naginata::Configuration.env.add_filter(:service, @options[:services])
18
+ end
19
+
20
+ table = []
21
+ table << %w(NAGIOS HOST SERVICE STATUS FLAGS OUTPUT)
22
+ Naginata::Runner.run_locally do |nagios_server, services|
23
+ target_hosts = services.map{|s| s.hostname }.uniq
24
+ target_services = services.reject{|s| s.description == :ping}.map{|s| s.description }.uniq
25
+ status = Status.find(nagios_server.hostname)
26
+ status.scopes << lambda { |s|
27
+ target_hosts.any? {|host| s.include?("host_name=#{host}") }
28
+ }
29
+ status.scopes << lambda { |s|
30
+ target_services.any? {|desc| s.include?("service_description=#{desc}") }
31
+ }
32
+ table.concat(status.decorate.services_table)
33
+ end
34
+ Naginata.ui.print_table table
35
+ end
36
+
37
+ end
38
+ end
39
+
@@ -1,12 +1,14 @@
1
1
  require 'nagios_analyzer'
2
2
  require 'forwardable'
3
3
  require 'tempfile'
4
+ require 'naginata/status_decorator'
4
5
 
5
6
  module Naginata
6
7
  class Status
7
8
  extend Forwardable
8
9
  def_delegators :@status, :service_items, :host_items, :items, :service_problems, :host_problems, :scopes
9
10
  attr_accessor :status, :hostname
11
+ alias :nagios :hostname
10
12
 
11
13
  # Write status.dat into local disk
12
14
  #
@@ -35,6 +37,13 @@ module Naginata
35
37
  @path ||= File.join(self.class.cache_dir, "#{hostname}.status.dat")
36
38
  end
37
39
 
40
+ # Returns decorator instance
41
+ #
42
+ # @return [StatusDecorator]
43
+ def decorate
44
+ StatusDecorator.new(self)
45
+ end
46
+
38
47
  # Create a new instance from raw status.dat string
39
48
  #
40
49
  # @param [String] string raw status.dat text
@@ -0,0 +1,26 @@
1
+ require 'naginata'
2
+
3
+ module Naginata
4
+ class StatusDecorator
5
+
6
+ attr_reader :object
7
+
8
+ def initialize(status)
9
+ @object = status
10
+ end
11
+
12
+ def hosts_table
13
+ object.host_items.sort.map do |section|
14
+ [object.nagios, section.host_name, section.decorate.current_state, section.decorate.flags_short, section.plugin_output]
15
+ end
16
+ end
17
+
18
+ def services_table
19
+ object.service_items.sort.map do |section|
20
+ [object.nagios, section.host_name, section.service_description, section.decorate.current_state, section.decorate.flags_short, section.plugin_output]
21
+ end
22
+ end
23
+
24
+ end
25
+ end
26
+
@@ -11,19 +11,19 @@ module Naginata
11
11
  end
12
12
 
13
13
  def info(msg, newline = nil)
14
- @shell.say(msg, nil, newline) if level("info")
14
+ tell_me(msg, nil, newline) if level("info")
15
15
  end
16
16
 
17
17
  def warn(msg, newline = nil)
18
- @shell.say(msg, :yellow, newline) if level("warn")
18
+ tell_me(msg, :yellow, newline) if level("warn")
19
19
  end
20
20
 
21
21
  def error(msg, newline = nil)
22
- @shell.say(msg, :red, newline) if level("error")
22
+ tell_me(msg, :red, newline) if level("error")
23
23
  end
24
24
 
25
25
  def debug(msg, newline = nil)
26
- @shell.say(msg, nil, newline) if level("debug")
26
+ tell_me(msg, nil, newline) if level("debug")
27
27
  end
28
28
 
29
29
  def level(name = nil)
@@ -34,6 +34,20 @@ module Naginata
34
34
  @shell.yes?(msg)
35
35
  end
36
36
 
37
+ def print_table(array, options = {})
38
+ @shell.print_table(array, options)
39
+ end
40
+
41
+ private
42
+
43
+ def tell_me(msg, color = nil, newline = nil)
44
+ if newline.nil?
45
+ @shell.say(msg, color)
46
+ else
47
+ @shell.say(msg, color, newline)
48
+ end
49
+ end
50
+
37
51
  end
38
52
  end
39
53
  end
@@ -1,3 +1,3 @@
1
1
  module Naginata
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -0,0 +1,37 @@
1
+ require 'nagios_analyzer'
2
+
3
+ module NagiosAnalyzer
4
+ class Section
5
+
6
+ def decorate
7
+ SectionDecorator.new(self)
8
+ end
9
+
10
+ end
11
+ end
12
+
13
+ module NagiosAnalyzer
14
+ class SectionDecorator
15
+
16
+ attr_reader :object
17
+
18
+ def initialize(section)
19
+ @object = section
20
+ end
21
+
22
+ def current_state
23
+ if object.current_state
24
+ Status::STATES[object.current_state]
25
+ end
26
+ end
27
+
28
+ def flags_short
29
+ ret = []
30
+ ret.push (object.active_checks_enabled == 1) ? "AC": "ac"
31
+ ret.push (object.notifications_enabled == 1) ? "NT": "nt"
32
+ ret.join(",")
33
+ end
34
+
35
+ end
36
+ end
37
+
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.1
4
+ version: 0.1.2
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-03 00:00:00.000000000 Z
11
+ date: 2015-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sshkit
@@ -117,10 +117,12 @@ files:
117
117
  - lib/naginata.rb
118
118
  - lib/naginata/cli.rb
119
119
  - lib/naginata/cli/fetch.rb
120
+ - lib/naginata/cli/hosts.rb
120
121
  - lib/naginata/cli/init.rb
121
122
  - lib/naginata/cli/local_abstract.rb
122
123
  - lib/naginata/cli/notification.rb
123
124
  - lib/naginata/cli/remote_abstract.rb
125
+ - lib/naginata/cli/services.rb
124
126
  - lib/naginata/command/external_command.rb
125
127
  - lib/naginata/configuration.rb
126
128
  - lib/naginata/configuration/filter.rb
@@ -131,10 +133,12 @@ files:
131
133
  - lib/naginata/loader.rb
132
134
  - lib/naginata/runner.rb
133
135
  - lib/naginata/status.rb
136
+ - lib/naginata/status_decorator.rb
134
137
  - lib/naginata/templates/Naginatafile
135
138
  - lib/naginata/ui.rb
136
139
  - lib/naginata/ui/shell.rb
137
140
  - lib/naginata/version.rb
141
+ - lib/nagios_analyzer/section_decorator.rb
138
142
  - naginata.gemspec
139
143
  homepage: https://github.com/niku4i/naginata
140
144
  licenses: