naginata 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +142 -0
- data/Rakefile +11 -0
- data/bin/naginata +6 -0
- data/integration-test/.gitignore +1 -0
- data/integration-test/Naginatafile +22 -0
- data/integration-test/Vagrantfile +100 -0
- data/lib/naginata.rb +17 -0
- data/lib/naginata/cli.rb +66 -0
- data/lib/naginata/cli/fetch.rb +29 -0
- data/lib/naginata/cli/notification.rb +64 -0
- data/lib/naginata/command/external_command.rb +198 -0
- data/lib/naginata/configuration.rb +100 -0
- data/lib/naginata/configuration/filter.rb +78 -0
- data/lib/naginata/configuration/nagios_server.rb +83 -0
- data/lib/naginata/configuration/service.rb +35 -0
- data/lib/naginata/defaults.rb +8 -0
- data/lib/naginata/dsl.rb +28 -0
- data/lib/naginata/loader.rb +39 -0
- data/lib/naginata/runner.rb +36 -0
- data/lib/naginata/status.rb +82 -0
- data/lib/naginata/ui.rb +6 -0
- data/lib/naginata/ui/shell.rb +39 -0
- data/lib/naginata/version.rb +3 -0
- data/naginata.gemspec +28 -0
- metadata +159 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ae0efd9a15d8b81f26114f2543bfda2174d49477
|
4
|
+
data.tar.gz: 99bb8cb5573bc988e7af37b53205a06eb367733f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9302334fe18fd4e010531cecadf009632dd97c54b69f853316ce429a4a36ef64e5ca4daf77e7ecf35b90e00f6e1856992a35b1c22e28bb5a253eadb9d46a8a20
|
7
|
+
data.tar.gz: b43419293e29760ae3905ecf2d234462dbb64560fdae1a800e2b846c61b01797f7ac4834e29dc8adaa446778badf2b399c3559813f7e4050e75a6e695428c4b8
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Nobuhiro Nikushi
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
# Naginata
|
2
|
+
|
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
|
+
|
5
|
+
Naginata includes `naginata` command executable. `naginata` command can be done by just single command execution from workstation host.
|
6
|
+
|
7
|
+
* Enable/Disable notifications of hosts and services.
|
8
|
+
* Display current host and service status. (will be added)
|
9
|
+
* and more
|
10
|
+
|
11
|
+
If you already have nagios servers, it's easy to try out Naginata! It does not require to install ruby and Naginata on remote nagio servers.
|
12
|
+
|
13
|
+
## Requirements
|
14
|
+
|
15
|
+
Set up a workstation host which can connect to nagios servers over ssh connection. Currently supports only no passphrase remote login.
|
16
|
+
|
17
|
+
## Installation
|
18
|
+
|
19
|
+
Install naginata on workstation host.
|
20
|
+
|
21
|
+
$ gem install naginata
|
22
|
+
|
23
|
+
Or if you use bundler, add this line to your application's Gemfile:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
gem 'naginata'
|
27
|
+
```
|
28
|
+
|
29
|
+
And then execute:
|
30
|
+
|
31
|
+
$ bundle
|
32
|
+
|
33
|
+
|
34
|
+
## Configuration
|
35
|
+
|
36
|
+
Naginatafile
|
37
|
+
|
38
|
+
```
|
39
|
+
# Define nagios servers
|
40
|
+
nagios 'foo@nagios1.example.com'
|
41
|
+
nagios 'bar@nagios2.example.com'
|
42
|
+
nagios 'baz@nagios3.example.com'
|
43
|
+
|
44
|
+
# nagios server global options
|
45
|
+
set :nagios_server_options, {
|
46
|
+
command_file: '/usr/local/nagios/var/rw/nagios.cmd',
|
47
|
+
status_file: '/usr/local/nagios/var/status.cmd',
|
48
|
+
run_command_as: 'nagios',
|
49
|
+
}
|
50
|
+
|
51
|
+
# Global options
|
52
|
+
set :ssh_options, {
|
53
|
+
keys: %w(/home/nikushi/.ssh/id_rsa),
|
54
|
+
}
|
55
|
+
```
|
56
|
+
|
57
|
+
## Usage
|
58
|
+
|
59
|
+
|
60
|
+
### Notification
|
61
|
+
|
62
|
+
#### Enable(Disable) host and service notifications of server001
|
63
|
+
|
64
|
+
```
|
65
|
+
$ naginata notification server001 -[e|d]
|
66
|
+
```
|
67
|
+
|
68
|
+
#### Enable(Disable) host and specific service notifications of server001
|
69
|
+
|
70
|
+
```
|
71
|
+
$ naginata notification server001 -s cpu -[e|d]
|
72
|
+
```
|
73
|
+
|
74
|
+
#### Enable(Disable) host and service notifications of all hosts
|
75
|
+
|
76
|
+
```
|
77
|
+
$ naginata notification -a -[e|d]
|
78
|
+
```
|
79
|
+
|
80
|
+
#### Enable(Disable) specific service notifications of all hosts
|
81
|
+
|
82
|
+
```
|
83
|
+
$ naginata notification -a -s cpu -[e|d]
|
84
|
+
```
|
85
|
+
|
86
|
+
### Display status (will be added)
|
87
|
+
|
88
|
+
#### Show server001's status
|
89
|
+
|
90
|
+
```
|
91
|
+
$ naginata status server001
|
92
|
+
```
|
93
|
+
|
94
|
+
#### Show all hosts' status
|
95
|
+
|
96
|
+
```
|
97
|
+
$ naginata status -a
|
98
|
+
```
|
99
|
+
|
100
|
+
#### Show all hosts' specific service status
|
101
|
+
|
102
|
+
```
|
103
|
+
$ naginata status -a -s cpu
|
104
|
+
```
|
105
|
+
|
106
|
+
|
107
|
+
### Global Options
|
108
|
+
|
109
|
+
#### Filter by nagios servers
|
110
|
+
|
111
|
+
You can filter target host and servers scope with `--nagios=server1,..` option.
|
112
|
+
|
113
|
+
```
|
114
|
+
$ naginata --nagios=nagios1.example.com,nagios2.example.com notification -e --all-hosts
|
115
|
+
```
|
116
|
+
|
117
|
+
#### Dry run mode
|
118
|
+
|
119
|
+
naginata command with `-n` or `--dry-run` runs as dry run mode.
|
120
|
+
|
121
|
+
#### Verbose output
|
122
|
+
|
123
|
+
naginata command with `-v`
|
124
|
+
|
125
|
+
#### Debug output
|
126
|
+
|
127
|
+
naginata command with `--debug`
|
128
|
+
|
129
|
+
|
130
|
+
## Development
|
131
|
+
|
132
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
133
|
+
|
134
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
135
|
+
|
136
|
+
## Contributing
|
137
|
+
|
138
|
+
1. Fork it ( https://github.com/[my-github-username]/naginata/fork )
|
139
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
140
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
141
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
142
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/naginata
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
.vagrant
|
@@ -0,0 +1,22 @@
|
|
1
|
+
nagios_server 'nagios0:2220'
|
2
|
+
nagios_server 'nagios1:2221'
|
3
|
+
|
4
|
+
set :nagios_server_options, {
|
5
|
+
command_file: '/var/spool/nagios/cmd/nagios.cmd',
|
6
|
+
status_file: '/var/log/nagios/status.dat',
|
7
|
+
run_command_as: 'nagios',
|
8
|
+
}
|
9
|
+
|
10
|
+
#
|
11
|
+
# Custom SSH Options
|
12
|
+
# ==================
|
13
|
+
# You may pass any option but keep in mind that net/ssh understands a
|
14
|
+
# limited set of options, consult the Net::SSH documentation.
|
15
|
+
# http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start
|
16
|
+
#
|
17
|
+
# Global options
|
18
|
+
# --------------
|
19
|
+
set :ssh_options, {
|
20
|
+
user: 'vagrant',
|
21
|
+
keys: %w(~/.vagrant.d/insecure_private_key),
|
22
|
+
}
|
@@ -0,0 +1,100 @@
|
|
1
|
+
$httpd_config = <<-EOS
|
2
|
+
ScriptAlias /nagios/cgi-bin/ "/usr/lib64/nagios/cgi-bin/"
|
3
|
+
|
4
|
+
<Directory "/usr/lib64/nagios/cgi-bin/">
|
5
|
+
Options ExecCGI
|
6
|
+
AllowOverride None
|
7
|
+
Order allow,deny
|
8
|
+
Allow from all
|
9
|
+
</Directory>
|
10
|
+
|
11
|
+
Alias /nagios "/usr/share/nagios/html"
|
12
|
+
|
13
|
+
<Directory "/usr/share/nagios/html">
|
14
|
+
Options None
|
15
|
+
AllowOverride None
|
16
|
+
Order allow,deny
|
17
|
+
Allow from all
|
18
|
+
</Directory>
|
19
|
+
EOS
|
20
|
+
|
21
|
+
def nagios_config_for(h)
|
22
|
+
out = <<-EOS
|
23
|
+
#
|
24
|
+
# #{h}
|
25
|
+
#
|
26
|
+
define host {
|
27
|
+
use linux-server
|
28
|
+
host_name #{h}
|
29
|
+
alias #{h}
|
30
|
+
address 127.0.0.1
|
31
|
+
}
|
32
|
+
|
33
|
+
define service {
|
34
|
+
use generic-service
|
35
|
+
host_name #{h}
|
36
|
+
service_description PING
|
37
|
+
check_command check_ping!100.0,20%!500.0,60%
|
38
|
+
}
|
39
|
+
|
40
|
+
define service {
|
41
|
+
use generic-service
|
42
|
+
host_name #{h}
|
43
|
+
service_description SSH
|
44
|
+
check_command check_ssh
|
45
|
+
notifications_enabled 0
|
46
|
+
}
|
47
|
+
|
48
|
+
define service {
|
49
|
+
use generic-service
|
50
|
+
host_name #{h}
|
51
|
+
service_description Load
|
52
|
+
check_command check_local_load!5.0,4.0,3.0!10.0,6.0,4.0
|
53
|
+
}
|
54
|
+
|
55
|
+
EOS
|
56
|
+
end
|
57
|
+
|
58
|
+
Vagrant.configure("2") do |config|
|
59
|
+
|
60
|
+
hosts = {
|
61
|
+
:nagios0 => %w(web01.tokyo.local redis01.tokyo.local),
|
62
|
+
:nagios1 => %w(web01.osaka.local redis01.osaka.local),
|
63
|
+
}
|
64
|
+
|
65
|
+
hosts.keys.each_with_index do |hostname, i|
|
66
|
+
config.vm.define(hostname, primary: true) do |config|
|
67
|
+
config.vm.define hostname
|
68
|
+
config.vm.box = "chef/centos-6.5"
|
69
|
+
config.vm.network "forwarded_port", guest: 22, host: "222#{i}".to_i, id: "ssh"
|
70
|
+
config.ssh.guest_port = "222#{i}".to_i
|
71
|
+
config.vm.network "forwarded_port", guest: 80, host: "888#{i}".to_i
|
72
|
+
|
73
|
+
nagios_config = hosts[hostname].inject("") { |a, b| a + nagios_config_for(b)}
|
74
|
+
|
75
|
+
config.vm.provision :shell,
|
76
|
+
inline: <<-INLINE
|
77
|
+
|
78
|
+
echo SELINUX=disabled > /etc/selinux/config
|
79
|
+
setenforce 0
|
80
|
+
|
81
|
+
yum -y -q install epel-release
|
82
|
+
yum -y -q install nagios nagios-plugins-all php httpd
|
83
|
+
chkconfig httpd on && chkconfig nagios on
|
84
|
+
|
85
|
+
echo "
|
86
|
+
#{$httpd_config}
|
87
|
+
" > /etc/httpd/conf.d/nagios.conf
|
88
|
+
|
89
|
+
echo "
|
90
|
+
#{nagios_config}
|
91
|
+
" > /etc/nagios/conf.d/servers.cfg
|
92
|
+
|
93
|
+
|
94
|
+
sed -i 's/use_authentication=1/use_authentication=0/' /etc/nagios/cgi.cfg
|
95
|
+
service httpd start && service nagios start
|
96
|
+
INLINE
|
97
|
+
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
data/lib/naginata.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require "naginata/command/external_command"
|
2
|
+
require "naginata/configuration"
|
3
|
+
require "naginata/configuration/filter"
|
4
|
+
require "naginata/configuration/nagios_server"
|
5
|
+
require "naginata/configuration/service"
|
6
|
+
require "naginata/runner"
|
7
|
+
require "naginata/status"
|
8
|
+
require "naginata/ui"
|
9
|
+
require "naginata/version"
|
10
|
+
|
11
|
+
module Naginata
|
12
|
+
class << self
|
13
|
+
def ui
|
14
|
+
@ui ||= UI::Shell.new
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/naginata/cli.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'naginata/configuration'
|
3
|
+
require 'naginata/loader'
|
4
|
+
|
5
|
+
module Naginata
|
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
|
+
class_option :verbose, aliases: "-v", type: :boolean
|
10
|
+
class_option :debug, type: :boolean
|
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
|
33
|
+
end
|
34
|
+
|
35
|
+
desc 'notification [hostpattern ..]', 'Control notification'
|
36
|
+
method_option :enable, aliases: "-e", desc: "Enable notification", type: :boolean, default: false
|
37
|
+
method_option :disable, aliases: "-d", desc: "Disable notification", type: :boolean, default: false
|
38
|
+
method_option :force, aliases: "-f", desc: "Run without prompting for confirmation", type: :boolean, default: false
|
39
|
+
method_option :services, aliases: "-s", desc: "Services to be enabled|disabled", type: :array
|
40
|
+
method_option :all_hosts, aliases: "-a", desc: "Target all hosts", type: :boolean, default: false
|
41
|
+
def notification(*patterns)
|
42
|
+
require 'naginata/cli/notification'
|
43
|
+
CLI::Notification.new(options.merge(patterns: patterns)).run
|
44
|
+
end
|
45
|
+
|
46
|
+
desc 'fetch', 'Download remote status.dat and create cache on local'
|
47
|
+
def fetch
|
48
|
+
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
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'naginata/configuration'
|
2
|
+
require 'naginata/status'
|
3
|
+
require 'naginata/runner'
|
4
|
+
|
5
|
+
module Naginata
|
6
|
+
class CLI::Fetch
|
7
|
+
|
8
|
+
def initialize(options = {})
|
9
|
+
@options = options
|
10
|
+
end
|
11
|
+
|
12
|
+
def run
|
13
|
+
Naginata::Runner.run do |backend, nagios_server, services|
|
14
|
+
status_file = (nagios_server.fetch(:status_file) || ::Naginata::Configuration.env.fetch(:nagios_server_options)[:status_file])
|
15
|
+
if !@options[:dry_run]
|
16
|
+
str = backend.capture(:cat, status_file)
|
17
|
+
st = ::Naginata::Status.build(str, nagios_server.hostname)
|
18
|
+
st.save
|
19
|
+
else
|
20
|
+
st = ::Naginata::Status.new
|
21
|
+
st.hostname = nagios_server.hostname
|
22
|
+
end
|
23
|
+
puts "Saved into #{st.path}" if @options[:verbose]
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|