naginata 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/README.md +17 -1
- data/integration-test/Vagrantfile +1 -1
- data/lib/naginata/cli.rb +24 -0
- data/lib/naginata/cli/active_check.rb +61 -0
- data/lib/naginata/loader.rb +2 -7
- data/lib/naginata/runner.rb +3 -1
- data/lib/naginata/templates/Naginatafile +4 -2
- data/lib/naginata/version.rb +1 -1
- 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: 4a8ceb909d5af735d4415f2a4b2b510b3ef9cc96
|
4
|
+
data.tar.gz: 137468f15fcd645b7a4b114b69845ccfb3fab30b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf65f48fb8b918f22e9eac4051605a2e039b1acbd35b656d919a1ff5965a09b77dde38f59672892f15dfde595866ae5359d132d933763a6ab681d54020ef2897
|
7
|
+
data.tar.gz: 631c3ac537362cbd5ac31be6ea675921905fa7547480f810b7eea19fe2da7658cfd607afe84d463db25168f9d0b36041e5cddcef092bbf2bca3071a9851a8d14
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -12,7 +12,8 @@ If you already have nagios servers, it's easy to try out Naginata! It does not r
|
|
12
12
|
|
13
13
|
## Requirements
|
14
14
|
|
15
|
-
|
15
|
+
* Ruby 1.9.3, 2.0.0, 2.1.x, 2.2.x
|
16
|
+
* Nagios 3.x, 4.x
|
16
17
|
|
17
18
|
## Installation
|
18
19
|
|
@@ -49,11 +50,16 @@ nagios_server 'baz@nagios3.example.com'
|
|
49
50
|
set :nagios_server_options, {
|
50
51
|
command_file: '/usr/local/nagios/var/rw/nagios.cmd',
|
51
52
|
status_file: '/usr/local/nagios/var/status.cmd',
|
53
|
+
# If you want to change run user for external commands execution after login
|
54
|
+
# to nagios servers, uncomment below and set a proper user name. This is
|
55
|
+
# usefull if a login user does not have write or read permission to
|
56
|
+
# command_file or status_file.
|
52
57
|
run_command_as: 'nagios',
|
53
58
|
}
|
54
59
|
|
55
60
|
# Global SSH options
|
56
61
|
set :ssh_options, {
|
62
|
+
# Currently Naginata only supports remote login with no passphrase.
|
57
63
|
keys: %w(/home/nikushi/.ssh/id_rsa),
|
58
64
|
}
|
59
65
|
```
|
@@ -98,6 +104,16 @@ $ naginata notification -a -s cpu -[e|d]
|
|
98
104
|
$ naginata notification -a -[e|d] -s 'disk.+' -s 'https?'
|
99
105
|
```
|
100
106
|
|
107
|
+
### Active Checks Control
|
108
|
+
|
109
|
+
You can enable or disable active checks of hosts and services.
|
110
|
+
|
111
|
+
```
|
112
|
+
$ naginata activecheck [hostpattern...] [OPTIONS]
|
113
|
+
```
|
114
|
+
|
115
|
+
Optinos are same as `naginata notification`. See above examples.
|
116
|
+
|
101
117
|
### View service status (Experimental)
|
102
118
|
|
103
119
|
#### View service status for all hosts
|
@@ -6,6 +6,7 @@ ScriptAlias /nagios/cgi-bin/ "/usr/lib64/nagios/cgi-bin/"
|
|
6
6
|
AllowOverride None
|
7
7
|
Order allow,deny
|
8
8
|
Allow from all
|
9
|
+
SetEnv REMOTE_USER nagiosadmin
|
9
10
|
</Directory>
|
10
11
|
|
11
12
|
Alias /nagios "/usr/share/nagios/html"
|
@@ -91,7 +92,6 @@ Vagrant.configure("2") do |config|
|
|
91
92
|
" > /etc/nagios/conf.d/servers.cfg
|
92
93
|
|
93
94
|
|
94
|
-
sed -i 's/use_authentication=1/use_authentication=0/' /etc/nagios/cgi.cfg
|
95
95
|
service httpd start && service nagios start
|
96
96
|
INLINE
|
97
97
|
|
data/lib/naginata/cli.rb
CHANGED
@@ -11,6 +11,13 @@ module Naginata
|
|
11
11
|
# super(args, opts, config)
|
12
12
|
#end
|
13
13
|
|
14
|
+
desc "version", "Prints the naginata's version information"
|
15
|
+
def version
|
16
|
+
require 'naginata/version'
|
17
|
+
Naginata.ui.info "Naginata version #{Naginata::VERSION}"
|
18
|
+
end
|
19
|
+
map %w(--version) => :version
|
20
|
+
|
14
21
|
desc 'init', 'Init generates a default Nagipfile into current directory'
|
15
22
|
def init
|
16
23
|
require 'naginata/cli/init'
|
@@ -34,6 +41,23 @@ module Naginata
|
|
34
41
|
CLI::Notification.new(options.merge(patterns: patterns)).execute
|
35
42
|
end
|
36
43
|
|
44
|
+
desc 'activecheck [hostpattern ..]', 'Control active checks'
|
45
|
+
method_option :enable, aliases: "-e", desc: "Enable active checks", type: :boolean
|
46
|
+
method_option :disable, aliases: "-d", desc: "Disable active checks", type: :boolean
|
47
|
+
method_option :dry_run, aliases: "-n", type: :boolean
|
48
|
+
method_option :force, aliases: "-f", desc: "Run without prompting for confirmation", type: :boolean
|
49
|
+
method_option :nagios, aliases: "-N", desc: "Filter targeted nagios servers by their hostname", type: :array
|
50
|
+
method_option :services, aliases: "-s", desc: "Services to be enabled|disabled", type: :array
|
51
|
+
method_option :all_hosts, aliases: "-a", desc: "Target all hosts", type: :boolean
|
52
|
+
def activecheck(*patterns)
|
53
|
+
if patterns.empty? and options.empty?
|
54
|
+
help(:activecheck)
|
55
|
+
exit(1)
|
56
|
+
end
|
57
|
+
require 'naginata/cli/active_check'
|
58
|
+
CLI::ActiveCheck.new(options.merge(patterns: patterns)).execute
|
59
|
+
end
|
60
|
+
|
37
61
|
method_option :nagios, aliases: "-N", desc: "Filter targeted nagios servers by their hostname", type: :array
|
38
62
|
desc 'fetch', 'Download remote status.dat and create cache on local'
|
39
63
|
def fetch
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'naginata'
|
2
|
+
require 'naginata/cli/remote_abstract'
|
3
|
+
require 'naginata/command/external_command'
|
4
|
+
require 'naginata/configuration'
|
5
|
+
require 'naginata/runner'
|
6
|
+
|
7
|
+
module Naginata
|
8
|
+
class CLI::ActiveCheck < CLI::RemoteAbstract
|
9
|
+
|
10
|
+
def run
|
11
|
+
if !@options[:enable] and !@options[:disable]
|
12
|
+
abort "Either --enable or --disable options is required"
|
13
|
+
end
|
14
|
+
if @options[:enable] and @options[:disable]
|
15
|
+
abort "Both --enable and --disable options can not be given"
|
16
|
+
end
|
17
|
+
|
18
|
+
if @options[:all_hosts]
|
19
|
+
::Naginata::Configuration.env.add_filter(:host, :all)
|
20
|
+
elsif @options[:patterns].empty?
|
21
|
+
abort "At least one hostpattern must be given or use --all-hosts option"
|
22
|
+
else
|
23
|
+
::Naginata::Configuration.env.add_filter(:host, @options[:patterns])
|
24
|
+
end
|
25
|
+
if @options[:services]
|
26
|
+
::Naginata::Configuration.env.add_filter(:service, @options[:services])
|
27
|
+
end
|
28
|
+
|
29
|
+
command_file = ::Naginata::Configuration.env.fetch(:nagios_server_options)[:command_file]
|
30
|
+
|
31
|
+
if !@options[:force]
|
32
|
+
Naginata.ui.info "Following active checks will be #{@options[:enable] ? 'enabled' : 'disabled'}"
|
33
|
+
Naginata::Runner.run_locally do |nagios_server, services|
|
34
|
+
services.group_by{ |s| s.hostname }.each do |hostname, svcs|
|
35
|
+
Naginata.ui.info hostname
|
36
|
+
svcs.each do |service|
|
37
|
+
Naginata.ui.info " - #{service.description}"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
abort unless Naginata.ui.yes?("Are you sure? [y|N]")
|
42
|
+
end
|
43
|
+
|
44
|
+
Naginata::Runner.run do |backend, nagios_server, services|
|
45
|
+
path = nagios_server.fetch(:command_file) || command_file
|
46
|
+
|
47
|
+
services.each do |service|
|
48
|
+
opts = {path: (nagios_server.fetch(:command_file) || command_file), host_name: service.hostname}
|
49
|
+
opts.merge!(service_description: service.description) if service.description != :ping
|
50
|
+
action = @options[:enable] ? 'enable' : 'disable'
|
51
|
+
host_or_svc = service.description == :ping ? 'host' : 'svc'
|
52
|
+
command_arg = Naginata::Command::ExternalCommand.send("#{action}_#{host_or_svc}_check".to_sym, opts).split(/\s+/, 2)
|
53
|
+
command = command_arg.shift.to_sym
|
54
|
+
backend.execute command, command_arg
|
55
|
+
end
|
56
|
+
end
|
57
|
+
Naginata.ui.info "Done"
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
data/lib/naginata/loader.rb
CHANGED
@@ -18,13 +18,8 @@ module Naginata
|
|
18
18
|
# Refresh cached status.dat
|
19
19
|
CLI::Fetch.new(fetch_options).run
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
# @Note currently here reads all nagios servers' cache files. This
|
24
|
-
# means that users can not reduce nagios servers by --nagios= CLI
|
25
|
-
# option. Below loop may be moved into initialization phase of CLI
|
26
|
-
# class.
|
27
|
-
Configuration.env.nagios_servers.each do |nagios_server|
|
21
|
+
nagios_servers = Configuration.env.filter(Configuration.env.nagios_servers)
|
22
|
+
nagios_servers.each do |nagios_server|
|
28
23
|
status = ::Naginata::Status.find(nagios_server.hostname)
|
29
24
|
status.service_items.group_by{ |section| section.host_name }.each do |host, sections|
|
30
25
|
services = sections.map { |s| s.service_description }
|
data/lib/naginata/runner.rb
CHANGED
@@ -11,7 +11,9 @@ module Naginata
|
|
11
11
|
|
12
12
|
run_backend(nagios_servers) do |nagios_server|
|
13
13
|
svcs = Configuration::Filter.new(:nagios_server, nagios_server).filter_service(services)
|
14
|
-
|
14
|
+
if user
|
15
|
+
as(user) { yield self, nagios_server, svcs }
|
16
|
+
else
|
15
17
|
yield self, nagios_server, svcs
|
16
18
|
end
|
17
19
|
end
|
@@ -11,10 +11,12 @@
|
|
11
11
|
# Global Nagios Server Options
|
12
12
|
# ============================
|
13
13
|
# You can set global properties for all nagios servers here.
|
14
|
+
#
|
14
15
|
# `run_command_as` is a user who execute external commands on a remote nagios
|
15
16
|
# server. By default external commands are as the same user who is log-in.
|
16
|
-
#
|
17
|
-
# servers
|
17
|
+
# If you want to change run user for external commands execution after login
|
18
|
+
# to nagios servers, set a proper user name . This is usefull if a login user
|
19
|
+
# does not have write or read permission to command_file or status_file.
|
18
20
|
|
19
21
|
# set :nagios_server_options, {
|
20
22
|
# command_file: '/var/spool/nagios/cmd/nagios.cmd',
|
data/lib/naginata/version.rb
CHANGED
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.
|
4
|
+
version: 0.1.5
|
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-
|
11
|
+
date: 2015-06-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sshkit
|
@@ -116,6 +116,7 @@ files:
|
|
116
116
|
- integration-test/Vagrantfile
|
117
117
|
- lib/naginata.rb
|
118
118
|
- lib/naginata/cli.rb
|
119
|
+
- lib/naginata/cli/active_check.rb
|
119
120
|
- lib/naginata/cli/fetch.rb
|
120
121
|
- lib/naginata/cli/hosts.rb
|
121
122
|
- lib/naginata/cli/init.rb
|