cloudstack-nagios 0.1.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.
- data/.gitignore +6 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +24 -0
- data/LICENSE.txt +21 -0
- data/README.md +57 -0
- data/bin/cs-nagios +6 -0
- data/cloudstack-nagios.gemspec +28 -0
- data/lib/cloudstack-client/client.rb +136 -0
- data/lib/cloudstack-client/commands/account.rb +22 -0
- data/lib/cloudstack-client/commands/capacity.rb +19 -0
- data/lib/cloudstack-client/commands/cluster.rb +19 -0
- data/lib/cloudstack-client/commands/disk_offering.rb +49 -0
- data/lib/cloudstack-client/commands/domain.rb +22 -0
- data/lib/cloudstack-client/commands/host.rb +28 -0
- data/lib/cloudstack-client/commands/ip_address.rb +82 -0
- data/lib/cloudstack-client/commands/iso.rb +64 -0
- data/lib/cloudstack-client/commands/job.rb +29 -0
- data/lib/cloudstack-client/commands/load_balancer_rule.rb +61 -0
- data/lib/cloudstack-client/commands/network.rb +128 -0
- data/lib/cloudstack-client/commands/pod.rb +19 -0
- data/lib/cloudstack-client/commands/port_forwarding_rule.rb +49 -0
- data/lib/cloudstack-client/commands/project.rb +32 -0
- data/lib/cloudstack-client/commands/router.rb +89 -0
- data/lib/cloudstack-client/commands/server.rb +311 -0
- data/lib/cloudstack-client/commands/service_offering.rb +98 -0
- data/lib/cloudstack-client/commands/snapshot.rb +40 -0
- data/lib/cloudstack-client/commands/ssh_key_pair.rb +106 -0
- data/lib/cloudstack-client/commands/template.rb +60 -0
- data/lib/cloudstack-client/commands/user.rb +32 -0
- data/lib/cloudstack-client/commands/volume.rb +20 -0
- data/lib/cloudstack-client/commands/zone.rb +57 -0
- data/lib/cloudstack-client/version.rb +3 -0
- data/lib/cloudstack-nagios/base.rb +69 -0
- data/lib/cloudstack-nagios/cli.rb +100 -0
- data/lib/cloudstack-nagios/commands/nagios_config.rb +13 -0
- data/lib/cloudstack-nagios/helper.rb +17 -0
- data/lib/cloudstack-nagios/templates/cloudstack_routers_hosts.cfg.erb +36 -0
- data/lib/cloudstack-nagios/templates/cloudstack_routers_services.cfg.erb +35 -0
- data/lib/cloudstack-nagios/version.rb +3 -0
- data/lib/cloudstack_client.rb +2 -0
- data/lib/cloudstack_nagios.rb +4 -0
- metadata +155 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
cloudstack-nagios (0.1.0)
|
5
|
+
erubis (~> 2.7.0)
|
6
|
+
thor (~> 0.18.1)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
erubis (2.7.0)
|
12
|
+
json (1.8.1)
|
13
|
+
rake (10.0.4)
|
14
|
+
rdoc (4.0.1)
|
15
|
+
json (~> 1.4)
|
16
|
+
thor (0.18.1)
|
17
|
+
|
18
|
+
PLATFORMS
|
19
|
+
ruby
|
20
|
+
|
21
|
+
DEPENDENCIES
|
22
|
+
cloudstack-nagios!
|
23
|
+
rake (~> 10.0.4)
|
24
|
+
rdoc
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2013 Nik Wolfgramm
|
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,57 @@
|
|
1
|
+
# Cloudstack Nagios
|
2
|
+
|
3
|
+
Cloudstack Nagios helps you monitoring your Cloudstack environment with Nagios.
|
4
|
+
Cloudstack Nagios uses the Cloudsdtack API to collect information about system vm's and cloudstack ressources.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Install the cloudstack-cli gem:
|
9
|
+
|
10
|
+
$ gem install cloudstack-nagios
|
11
|
+
|
12
|
+
## Setup
|
13
|
+
|
14
|
+
Create the initial configuration:
|
15
|
+
|
16
|
+
$ cs setup
|
17
|
+
|
18
|
+
cloudstack-nagios expects to find a configuartion file with the API URL and your CloudStack credentials in your home directory named .cloudstack-cli.yml. If the file is located elsewhere you can specify the loaction using the --config option.
|
19
|
+
|
20
|
+
cloudstack-nagios supports multiple environments using the --environment option.
|
21
|
+
|
22
|
+
Example content of the configuration file:
|
23
|
+
|
24
|
+
:url: "https://my-cloudstack-server/client/api/"
|
25
|
+
:api_key: "cloudstack-api-key"
|
26
|
+
:secret_key: "cloudstack-api-secret"
|
27
|
+
|
28
|
+
test:
|
29
|
+
:url: "http://my-cloudstack-testserver/client/api/"
|
30
|
+
:api_key: "cloudstack-api-key"
|
31
|
+
:secret_key: "cloudstack-api-secret"
|
32
|
+
|
33
|
+
## Usage
|
34
|
+
|
35
|
+
See the help screen:
|
36
|
+
|
37
|
+
$ cs-nagios
|
38
|
+
|
39
|
+
Generate nagios host and services configuration for virtual routers:
|
40
|
+
|
41
|
+
$ cs-nagios config
|
42
|
+
|
43
|
+
## References
|
44
|
+
- [Cloudstack API documentation](http://cloudstack.apache.org/docs/api/apidocs-4.2/TOC_Root_Admin.html)
|
45
|
+
|
46
|
+
|
47
|
+
## Contributing
|
48
|
+
|
49
|
+
1. Fork it
|
50
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
51
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
52
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
53
|
+
5. Create new Pull Request
|
54
|
+
|
55
|
+
## License
|
56
|
+
|
57
|
+
Released under the MIT License. See the [LICENSE](https://bitbucket.org/swisstxt/cloudstack-cli/raw/master/LICENSE.txt) file for further details.
|
data/bin/cs-nagios
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'cloudstack-nagios/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "cloudstack-nagios"
|
8
|
+
gem.version = CloudstackNagios::VERSION
|
9
|
+
gem.authors = ["Nik Wolfgramm"]
|
10
|
+
gem.email = ["nik.wolfgramm@gmail.com"]
|
11
|
+
gem.description = %q{cloudstack-nagios generates nagios configuration and checks for monitoring cloudstack with nagios.}
|
12
|
+
gem.summary = %q{cloudstack-nagios CloudStack monitoring tools for nagios}
|
13
|
+
gem.homepage = "https://bitbucket.org/swisstxt/cloudstack-nagios"
|
14
|
+
gem.license = 'MIT'
|
15
|
+
|
16
|
+
gem.required_ruby_version = '>= 1.9.3'
|
17
|
+
gem.files = `git ls-files`.split($/)
|
18
|
+
gem.executables = ['cs-nagios']
|
19
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
20
|
+
gem.require_paths = ["lib"]
|
21
|
+
gem.rdoc_options = %w[--line-numbers --inline-source]
|
22
|
+
|
23
|
+
gem.add_development_dependency('rdoc')
|
24
|
+
gem.add_development_dependency('rake', '~> 10.0.4')
|
25
|
+
|
26
|
+
gem.add_dependency('thor', '~> 0.18.1')
|
27
|
+
gem.add_dependency('erubis', '~> 2.7.0')
|
28
|
+
end
|
@@ -0,0 +1,136 @@
|
|
1
|
+
require 'base64'
|
2
|
+
require 'openssl'
|
3
|
+
require 'uri'
|
4
|
+
require 'cgi'
|
5
|
+
require 'net/http'
|
6
|
+
require 'net/https'
|
7
|
+
require 'json'
|
8
|
+
require 'yaml'
|
9
|
+
|
10
|
+
module CloudstackClient
|
11
|
+
class Connection
|
12
|
+
|
13
|
+
@@async_poll_interval = 2.0
|
14
|
+
@@async_timeout = 400
|
15
|
+
|
16
|
+
# include all commands
|
17
|
+
Dir.glob(File.dirname(__FILE__) + "/commands/*.rb").each do |file|
|
18
|
+
require file
|
19
|
+
module_name = File.basename(file, '.rb').split('_').map{|f| f.capitalize}.join
|
20
|
+
include Object.const_get("CloudstackClient").const_get(module_name)
|
21
|
+
end
|
22
|
+
|
23
|
+
attr_accessor :verbose
|
24
|
+
|
25
|
+
def initialize(api_url, api_key, secret_key, opts = {})
|
26
|
+
@api_url = api_url
|
27
|
+
@api_key = api_key
|
28
|
+
@secret_key = secret_key
|
29
|
+
@use_ssl = api_url.start_with? "https"
|
30
|
+
@verbose = opts[:quiet] ? false : true
|
31
|
+
@debug = opts[:debug] ? true : false
|
32
|
+
end
|
33
|
+
|
34
|
+
##
|
35
|
+
# Sends a synchronous request to the CloudStack API and returns the response as a Hash.
|
36
|
+
#
|
37
|
+
# The wrapper element of the response (e.g. mycommandresponse) is discarded and the
|
38
|
+
# contents of that element are returned.
|
39
|
+
|
40
|
+
def send_request(params)
|
41
|
+
params['response'] = 'json'
|
42
|
+
params['apiKey'] = @api_key
|
43
|
+
|
44
|
+
params_arr = []
|
45
|
+
params.sort.each { |elem|
|
46
|
+
params_arr << elem[0].to_s + '=' + CGI.escape(elem[1].to_s).gsub('+', '%20').gsub(' ','%20')
|
47
|
+
}
|
48
|
+
|
49
|
+
debug_output JSON.pretty_generate(params) if @debug
|
50
|
+
|
51
|
+
data = params_arr.join('&')
|
52
|
+
signature = OpenSSL::HMAC.digest('sha1', @secret_key, data.downcase)
|
53
|
+
signature = Base64.encode64(signature).chomp
|
54
|
+
signature = CGI.escape(signature)
|
55
|
+
|
56
|
+
url = "#{@api_url}?#{data}&signature=#{signature}"
|
57
|
+
|
58
|
+
uri = URI.parse(url)
|
59
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
60
|
+
http.use_ssl = @use_ssl
|
61
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
62
|
+
|
63
|
+
begin
|
64
|
+
response = http.request(Net::HTTP::Get.new(uri.request_uri))
|
65
|
+
rescue
|
66
|
+
puts "Error connecting to API:"
|
67
|
+
puts "#{@api_url} is not reachable"
|
68
|
+
exit 1
|
69
|
+
end
|
70
|
+
|
71
|
+
if !response.is_a?(Net::HTTPOK)
|
72
|
+
puts "Error #{response.code}: #{response.message}"
|
73
|
+
puts JSON.pretty_generate(JSON.parse(response.body))
|
74
|
+
puts "URL: #{url}"
|
75
|
+
exit 1
|
76
|
+
end
|
77
|
+
|
78
|
+
begin
|
79
|
+
json = JSON.parse(response.body)
|
80
|
+
rescue JSON::ParserError
|
81
|
+
puts "Error parsing response from server."
|
82
|
+
exit 1
|
83
|
+
end
|
84
|
+
json[params['command'].downcase + 'response']
|
85
|
+
end
|
86
|
+
|
87
|
+
##
|
88
|
+
# Sends an asynchronous request and waits for the response.
|
89
|
+
#
|
90
|
+
# The contents of the 'jobresult' element are returned upon completion of the command.
|
91
|
+
|
92
|
+
def send_async_request(params)
|
93
|
+
|
94
|
+
json = send_request(params)
|
95
|
+
|
96
|
+
params = {
|
97
|
+
'command' => 'queryAsyncJobResult',
|
98
|
+
'jobId' => json['jobid']
|
99
|
+
}
|
100
|
+
|
101
|
+
max_tries = (@@async_timeout / @@async_poll_interval).round
|
102
|
+
max_tries.times do
|
103
|
+
json = send_request(params)
|
104
|
+
status = json['jobstatus']
|
105
|
+
|
106
|
+
print "." if @verbose
|
107
|
+
|
108
|
+
if status == 1
|
109
|
+
return json['jobresult']
|
110
|
+
elsif status == 2
|
111
|
+
puts
|
112
|
+
puts "Request failed (#{json['jobresultcode']}): #{json['jobresult']}"
|
113
|
+
exit 1
|
114
|
+
end
|
115
|
+
|
116
|
+
STDOUT.flush
|
117
|
+
sleep @@async_poll_interval
|
118
|
+
end
|
119
|
+
|
120
|
+
print "\n"
|
121
|
+
puts "Error: Asynchronous request timed out"
|
122
|
+
exit 1
|
123
|
+
end
|
124
|
+
|
125
|
+
private
|
126
|
+
|
127
|
+
def debug_output(output, seperator = '-' * 80)
|
128
|
+
puts
|
129
|
+
puts seperator
|
130
|
+
puts output
|
131
|
+
puts seperator
|
132
|
+
puts
|
133
|
+
end
|
134
|
+
|
135
|
+
end # class
|
136
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module CloudstackClient
|
2
|
+
|
3
|
+
module Account
|
4
|
+
|
5
|
+
##
|
6
|
+
# Lists accounts.
|
7
|
+
|
8
|
+
def list_accounts(args = { :name => nil })
|
9
|
+
params = {
|
10
|
+
'command' => 'listAccounts',
|
11
|
+
'listall' => 'true',
|
12
|
+
'isrecursive' => 'true'
|
13
|
+
}
|
14
|
+
params['name'] = args[:name] if args[:name]
|
15
|
+
|
16
|
+
json = send_request(params)
|
17
|
+
json['account'] || []
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module CloudstackClient
|
2
|
+
|
3
|
+
module DiskOffering
|
4
|
+
|
5
|
+
##
|
6
|
+
# Lists all available disk offerings.
|
7
|
+
|
8
|
+
def list_disk_offerings(domain = nil)
|
9
|
+
params = {
|
10
|
+
'command' => 'listDiskOfferings'
|
11
|
+
}
|
12
|
+
|
13
|
+
if domain
|
14
|
+
params['domainid'] = list_domains(domain).first["id"]
|
15
|
+
end
|
16
|
+
|
17
|
+
json = send_request(params)
|
18
|
+
json['diskoffering'] || []
|
19
|
+
end
|
20
|
+
|
21
|
+
##
|
22
|
+
# Get disk offering by name.
|
23
|
+
|
24
|
+
def get_disk_offering(name)
|
25
|
+
|
26
|
+
# TODO: use name parameter
|
27
|
+
# listServiceOfferings in CloudStack 2.2 doesn't seem to work
|
28
|
+
# when the name parameter is specified. When this is fixed,
|
29
|
+
# the name parameter should be added to the request.
|
30
|
+
params = {
|
31
|
+
'command' => 'listDiskOfferings'
|
32
|
+
}
|
33
|
+
json = send_request(params)
|
34
|
+
|
35
|
+
services = json['diskoffering']
|
36
|
+
return nil unless services
|
37
|
+
|
38
|
+
services.each { |s|
|
39
|
+
if s['name'] == name then
|
40
|
+
return s
|
41
|
+
end
|
42
|
+
}
|
43
|
+
nil
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module CloudstackClient
|
2
|
+
|
3
|
+
module Domain
|
4
|
+
|
5
|
+
##
|
6
|
+
# List domains.
|
7
|
+
|
8
|
+
def list_domains(name = nil)
|
9
|
+
params = {
|
10
|
+
'command' => 'listDomains',
|
11
|
+
'listall' => 'true',
|
12
|
+
'isrecursive' => 'true'
|
13
|
+
}
|
14
|
+
params['name'] = name if name
|
15
|
+
|
16
|
+
json = send_request(params)
|
17
|
+
json['domain'] || []
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module CloudstackClient
|
2
|
+
|
3
|
+
module Host
|
4
|
+
|
5
|
+
##
|
6
|
+
# Lists hosts.
|
7
|
+
|
8
|
+
def list_hosts(args = {})
|
9
|
+
params = {
|
10
|
+
'command' => 'listHosts'
|
11
|
+
}
|
12
|
+
|
13
|
+
if args[:zone]
|
14
|
+
zone = get_zone(args[:zone])
|
15
|
+
unless zone
|
16
|
+
puts "Error: zone #{args[:project]} not found."
|
17
|
+
exit 1
|
18
|
+
end
|
19
|
+
params['zoneid'] = zone['id']
|
20
|
+
end
|
21
|
+
|
22
|
+
json = send_request(params)
|
23
|
+
json['host'] || []
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|