cloudstack-nagios 0.5.1 → 0.6.0

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: 4462047d3995a0bc4a2e347fd3638fff6bf43340
4
- data.tar.gz: 6c6b7a70f376373605b2e981e178dc09ee1e9efd
3
+ metadata.gz: 3c0b8e37946dcb6dd032418c6d73ab56d1c40bd0
4
+ data.tar.gz: 5f60019260f8410034d62a284ff007d5c08a0529
5
5
  SHA512:
6
- metadata.gz: 7429635d543cdc83cf13eedda9ccf2e95ef0f3d1419e5e4594d293ac5ef109f249078f846d97fc90e611ca8e6d4cd0a42c36db7b3613933ac6209eb81c2ff0e6
7
- data.tar.gz: 9847ab9a65ab09a93225a06c9b41a14cf27f49a2c14b5c6cfde69f1c77e22f56b6ccfca7e1ffce97fa781ff5cdc7f48b3c73a95afd4dc39096e583a7186de064
6
+ metadata.gz: e0db95dbfa0c23130e7c0783713df8d97fcfd1a4f4ecaaacc3dc91e88b5b7605b660d8740430fec5d8cd3660a7dd809dfa936bd1b828d783b101051d58b31484
7
+ data.tar.gz: a32712202e84a342102b256e552c0abe9dd68ed879f185e16d757a0c5b3a108e2df5de89055d125454a7399c3819eb2e7eb33c2fccf80246663be8cd9dcd4064
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cloudstack-nagios (0.5.0)
5
- cloudstack_client (~> 0.2.10)
4
+ cloudstack-nagios (0.6.0)
5
+ cloudstack_client (~> 0.4, >= 0.4.4)
6
6
  erubis (~> 2.7.0)
7
7
  highline (~> 1.6.20)
8
8
  sshkit (~> 1.1.0)
@@ -11,24 +11,24 @@ PATH
11
11
  GEM
12
12
  remote: https://rubygems.org/
13
13
  specs:
14
- cloudstack_client (0.2.10)
14
+ cloudstack_client (0.4.4)
15
15
  erubis (2.7.0)
16
16
  highline (1.6.20)
17
17
  json (1.8.1)
18
18
  net-scp (1.1.2)
19
19
  net-ssh (>= 2.6.5)
20
- net-ssh (2.7.0)
20
+ net-ssh (2.8.0)
21
21
  rake (10.0.4)
22
- rdoc (4.0.1)
22
+ rdoc (4.1.1)
23
23
  json (~> 1.4)
24
24
  sshkit (1.1.0)
25
25
  net-scp
26
26
  net-ssh
27
27
  term-ansicolor
28
- term-ansicolor (1.2.2)
29
- tins (~> 0.8)
28
+ term-ansicolor (1.3.0)
29
+ tins (~> 1.0)
30
30
  thor (0.18.1)
31
- tins (0.13.0)
31
+ tins (1.0.0)
32
32
 
33
33
  PLATFORMS
34
34
  ruby
data/README.md CHANGED
@@ -1,26 +1,34 @@
1
1
  # Cloudstack Nagios
2
2
 
3
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.
4
+ Cloudstack Nagios uses the Cloudstack API to collect information about system vm's and ressources.
5
+
6
+ The following checks are supported:
7
+ * system and network checks for virtual routers
8
+ * storage pool capacity checks
9
+ * global zone capacities
5
10
 
6
11
  ## Prerequisites
7
12
 
8
- * Cloudstack Root Admin keys must be used.
9
- * In order to connect to system vms the private ssh key found on the Cloudstack management server under /var/lib/cloud/management/.ssh/id_rsa must be used.
10
- * The system vms must be reachable over SSH (default port 3922) from the nagios server executing the checks.
11
- * check with 'ssh -i /var/lib/cloud/management/.ssh/id_rsa -p 3922 <router_mgmt_ip>'
13
+ * Cloudstack Root Admin keys have to be used.
14
+ * In order to connect to system VMs the private ssh key found on the Cloudstack management server under /var/lib/cloud/management/.ssh/id_rsa are required.
15
+ * The system vms must be reachable over SSH (default port 3922) from the nagios server executing the checks (check with 'ssh -i /var/lib/cloud/management/.ssh/id_rsa -p 3922 <router_mgmt_ip>').
12
16
 
13
17
  ## Installation
14
18
 
15
19
  Install the cloudstack-cli gem:
16
20
 
17
- $ gem install cloudstack-nagios
21
+ ```bash
22
+ $ gem install cloudstack-nagios
23
+ ```
18
24
 
19
25
  ## Setup
20
26
 
21
27
  Create the initial configuration:
22
28
 
23
- $ cs setup
29
+ ```bash
30
+ $ cs setup
31
+ ```
24
32
 
25
33
  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.
26
34
 
@@ -28,14 +36,16 @@ cloudstack-nagios supports multiple environments using the --environment option.
28
36
 
29
37
  Example content of the configuration file:
30
38
 
31
- :url: "https://my-cloudstack-server/client/api/"
32
- :api_key: "cloudstack-api-key"
33
- :secret_key: "cloudstack-api-secret"
39
+ ```yaml
40
+ :url: "https://my-cloudstack-server/client/api/"
41
+ :api_key: "cloudstack-api-key"
42
+ :secret_key: "cloudstack-api-secret"
34
43
 
35
- test:
36
- :url: "http://my-cloudstack-testserver/client/api/"
37
- :api_key: "cloudstack-api-key"
38
- :secret_key: "cloudstack-api-secret"
44
+ test:
45
+ :url: "http://my-cloudstack-testserver/client/api/"
46
+ :api_key: "cloudstack-api-key"
47
+ :secret_key: "cloudstack-api-secret"
48
+ ```
39
49
 
40
50
  ## Usage
41
51
 
@@ -43,21 +53,49 @@ Example content of the configuration file:
43
53
 
44
54
  See the help screen:
45
55
 
46
- $ cs-nagios
56
+ ```bash
57
+ $ cs-nagios
58
+ ```
47
59
 
48
60
  ### Generate Nagios configuration files
49
61
 
62
+ Note that you can also use your own ERB templates using the '--template' option to generate the nagios confifuration files.
63
+
50
64
  Generate nagios host configuration for virtual routers:
51
65
 
52
- $ cs-nagios nagios_config host
66
+ ```bash
67
+ $ cs-nagios nagios_config router_hosts
68
+ ```
53
69
 
54
70
  Generate nagios host configuration for virtual routers:
55
71
 
56
- $ cs-nagios nagios_config service
72
+ ```bash
73
+ $ cs-nagios nagios_config router_services
74
+ ```
57
75
 
58
- Note that you can also use your own ERB templates using the '--template' option to generate the nagios confifuration files.
76
+ Generate nagios host configuration api hosts (one pseudo host per Cloudstack zone):
77
+
78
+ ```bash
79
+ $ cs-nagios nagios_config api_hosts
80
+ ```
81
+
82
+ Generate nagios service configuration for storage pool checks:
83
+
84
+ ```bash
85
+ $ cs-nagios nagios_config storage_pool_services
86
+ ```
87
+
88
+ Generate nagios service configuration for capacity checks:
89
+
90
+ ```bash
91
+ $ cs-nagios nagios_config capacity_services
92
+ ```
93
+
94
+ ### System VM checks
95
+
96
+ For all vm checks access to the cloudstack management network is required in order to run the ckecks via ssh or snmp.
59
97
 
60
- ### Check system vms over ssh
98
+ #### Check system vms over ssh
61
99
 
62
100
  The following checks are available:
63
101
 
@@ -66,17 +104,44 @@ The following checks are available:
66
104
  * network - measure network usage
67
105
  * rootfs_rw - check if the root file system is writeable
68
106
 
69
- ### Enabling snmpd checks
107
+ Example:
70
108
 
71
- If you want to check your system vms with standard snmp checks instead of checking over SSH, there are commands to configure snmpd on the machines and open the firewall.
109
+ ```bash
110
+ $ cs-nagios check system_vm network --host 10.100.9.161
111
+ ```
112
+
113
+ #### Enabling snmpd checks for system vms
114
+
115
+ If you want to check your system vms with standard Nagios snmp checks instead of checking over SSH, there are commands to configure snmpd on the machines and open the firewall.
72
116
 
73
117
  * snmpd_config enable - goes to all the routers and configure snmpd
74
118
  * snmpd_config check - test if port TCP 161 is reachable on routers
75
119
 
76
120
  Note: If you want to use snmp checks, you have to adapt the nagios configuration files accordingly.
77
121
 
122
+ ### Capacity checks
123
+
124
+ Checks various global capacity values.
125
+
126
+ Example:
127
+
128
+ ```bash
129
+ $ cs-nagios check capacity memory --zone ZUERICH_IX
130
+ ```
131
+
132
+ ### Storage Pool checks
133
+
134
+ Checks the available disk space on Cloudstack storage pools.
135
+
136
+ Example:
137
+
138
+ ```bash
139
+ $ cs-nagios check storage_pool --pool_name fs_cs_zone01_pod01
140
+ ```
141
+
78
142
  ## References
79
- - [Cloudstack API documentation](http://cloudstack.apache.org/docs/api/apidocs-4.2/TOC_Root_Admin.html)
143
+
144
+ * [Cloudstack API documentation](http://cloudstack.apache.org/docs/api/apidocs-4.2/TOC_Root_Admin.html)
80
145
 
81
146
  ## Contributing
82
147
 
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ require 'bundler'
2
+
3
+ Bundler::GemHelper.install_tasks
@@ -23,7 +23,7 @@ Gem::Specification.new do |gem|
23
23
  gem.add_development_dependency('rdoc')
24
24
  gem.add_development_dependency('rake', '~> 10.0.4')
25
25
 
26
- gem.add_dependency('cloudstack_client', '~> 0.2.10')
26
+ gem.add_dependency('cloudstack_client', '~> 0.4', '>= 0.4.4')
27
27
  gem.add_dependency('thor', '~> 0.18.1')
28
28
  gem.add_dependency('erubis', '~> 2.7.0')
29
29
  gem.add_dependency('sshkit', '~> 1.1.0')
@@ -0,0 +1,32 @@
1
+ class Capacity < CloudstackNagios::Base
2
+
3
+ CAPACITY_TYPES = {
4
+ 0 => {name: "Memory", method_name: "memory"},
5
+ 1 => {name: "CPU", method_name: "cpu"},
6
+ 2 => {name: "Storage", method_name: "storage"},
7
+ 3 => {name: "Primary Storage", method_name: "primary_storage"},
8
+ 4 => {name: "Public IP's", method_name: "public_ips"},
9
+ 5 => {name: "Private IP's", method_name: "private_ips"},
10
+ 6 => {name: "Secondary Storage", method_name: "secondary_storage"},
11
+ 7 => {name: "VLANs", method_name: "vlans"},
12
+ 8 => {name: "Direct Attached Public IP's", method_name: "direct_attached_public_ips"},
13
+ 9 => {name: "Local Storage", method_name: "local_storage"}
14
+ }
15
+
16
+ CAPACITY_TYPES.each do |type, value|
17
+ desc value[:method_name], "check #{value[:name].downcase} on host"
18
+ option :zone, required: true
19
+ define_method(value[:method_name]) {
20
+ capacity_check(options[:zone], type)
21
+ }
22
+ end
23
+
24
+ no_commands do
25
+ def capacity_check(zone, type)
26
+ cap = client.list_capacity(type: type, zone: zone).first
27
+ data = check_data(cap['capacitytotal'].to_f, cap['capacityused'].to_f, options[:warning], options[:critical])
28
+ puts "#{CAPACITY_TYPES[type][:name]} #{RETURN_CODES[data[0]]} - usage = #{data[1]}% | usage=#{cap['capacityused']}"
29
+ exit data[0]
30
+ end
31
+ end
32
+ end
@@ -1,151 +1,53 @@
1
- require 'sshkit/dsl'
1
+ require "cloudstack-nagios/commands/router"
2
+ require "cloudstack-nagios/commands/capacity"
2
3
 
3
4
  class Check < CloudstackNagios::Base
5
+ default_task :help
4
6
 
5
- RETURN_CODES = {0 => 'ok', 1 => 'warning', 2 => 'critical'}
6
-
7
- class_option :host,
7
+ class_option :host,
8
8
  desc: 'hostname or ipaddress',
9
- required: true,
9
+ default: '127.0.0.1',
10
10
  aliases: '-H'
11
11
 
12
- class_option :warning,
12
+ class_option :warning,
13
13
  desc: 'warning level',
14
14
  type: :numeric,
15
15
  default: 90,
16
16
  aliases: '-w'
17
17
 
18
- class_option :critical,
18
+ class_option :critical,
19
19
  desc: 'critical level',
20
20
  type: :numeric,
21
21
  default: 95,
22
22
  aliases: '-c'
23
23
 
24
- class_option :ssh_key,
24
+ class_option :ssh_key,
25
25
  desc: 'ssh private key to use',
26
26
  default: '/var/lib/cloud/management/.ssh/id_rsa'
27
27
 
28
- class_option :port,
28
+ class_option :port,
29
29
  desc: 'ssh port to use',
30
30
  type: :numeric,
31
31
  default: 3922,
32
32
  aliases: '-p'
33
33
 
34
- desc "memory HOST", "check memory on host"
35
- def memory
36
- begin
37
- host = systemvm_host
38
- free_output = ""
39
- on host do |h|
40
- free_output = capture(:free)
41
- end
42
- values = free_output.scan(/\d+/)
43
- total = values[0].to_i
44
- free = values[2].to_i
45
- free_b = values[7].to_i
46
- data = check_data(total, total - free_b, options[:warning], options[:critical])
47
- puts "MEMORY #{RETURN_CODES[data[0]]} - usage = #{data[1]}% | usage=#{data[1]}% total=#{total}M free=#{free}M free_wo_buffers=#{free_b}M"
48
- exit data[0]
49
- rescue => e
50
- exit_with_failure(e)
51
- end
52
- end
34
+ desc "router SUBCOMMAND ...ARGS", "router checks"
35
+ subcommand :router, Router
53
36
 
54
- desc "cpu", "check memory on host"
55
- def cpu
56
- begin
57
- host = systemvm_host
58
- mpstat_output = ""
59
- on host do |h|
60
- mpstat_output = capture(:mpstat)
61
- end
62
- values = mpstat_output.scan(/\d+\.\d+/)
63
- usage = 100 - values[-1].to_f
64
- data = check_data(100, usage, options[:warning], options[:critical])
65
- puts "CPU #{RETURN_CODES[data[0]]} - usage = #{data[1]}% | usage=#{data[1]}%"
66
- exit data[0]
67
- rescue => e
68
- exit_with_failure(e)
69
- end
70
- end
37
+ desc "capacity SUBCOMMAND ...ARGS", "capacity checks"
38
+ subcommand :capacity, Capacity
71
39
 
72
- desc "rootfs_rw", "check if the rootfs is read/writeable on host"
73
- def rootfs_rw
74
- begin
75
- host = systemvm_host
76
- proc_out = ""
77
- on host do |h|
78
- proc_out = capture(:cat, '/proc/mounts')
79
- end
80
- rootfs_rw = proc_out.match(/rootfs\srw\s/)
81
- status = rootfs_rw ? 0 : 2
82
- puts "ROOTFS_RW #{rootfs_rw ? 'OK - rootfs writeable' : 'CRITICAL - rootfs NOT writeable'}"
83
- exit status
84
- rescue => e
85
- exit_with_failure(e)
86
- end
87
- end
40
+ desc "stoarge_pool SUBCOMMAND ...ARGS", "storage_pool checks"
41
+ subcommand :capacity, Capacity
88
42
 
89
- desc "network", "check network usage on host"
90
- option :interface,
91
- desc: 'network interface to probe',
92
- default: 'eth0',
93
- aliases: '-i'
94
- option :if_speed,
95
- desc: 'network interface speed in bits per second',
96
- type: :numeric,
97
- default: 1000000000,
98
- aliases: '-s'
99
- def network
100
- begin
101
- host = systemvm_host
102
- stats_path = "/sys/class/net/#{options[:interface]}/statistics"
103
- rx_bytes, tx_bytes = ""
104
- on host do |h|
105
- rx_bytes = capture("cat #{stats_path}/rx_bytes;sleep 1;cat #{stats_path}/rx_bytes").lines.to_a
106
- tx_bytes = capture("cat #{stats_path}/tx_bytes;sleep 1;cat #{stats_path}/tx_bytes").lines.to_a
107
- end
108
- rbps = (rx_bytes[1].to_i - rx_bytes[0].to_i) * 8
109
- tbps = (tx_bytes[1].to_i - tx_bytes[0].to_i) * 8
110
- data = check_data(options[:if_speed], rbps, options[:warning], options[:critical])
111
- puts "NETWORK #{RETURN_CODES[data[0]]} - usage = #{data[1]}% | usage=#{data[1]}% rxbps=#{rbps.round(0)} txbps=#{tbps.round(0)}"
43
+ desc "storage_pool", "check capacity of storage_pool"
44
+ option :pool_name, required: true
45
+ option :zone
46
+ def storage_pool
47
+ pool = client.list_storage_pools(name: options[:pool_name], zone: options[:zone]).first
48
+ data = check_data(pool['disksizetotal'].to_f, pool['disksizeused'].to_f, options[:warning], options[:critical])
49
+ puts "storage_pool #{options[:pool_name]} #{RETURN_CODES[data[0]]} - usage = #{data[1]}% | usage=#{pool['disksizeused']}"
112
50
  exit data[0]
113
- rescue => e
114
- exit_with_failure(e)
115
- end
116
- end
117
-
118
- no_commands do
119
-
120
- def systemvm_host
121
- host = SSHKit::Host.new("root@#{options[:host]}")
122
- host.ssh_options = sshoptions(options[:ssh_key])
123
- host.port = options[:port]
124
- host
125
- end
126
-
127
- def exit_with_failure(exception)
128
- say 'ERROR: command execution failed!', :red
129
- say "Message: ", :magenta
130
- say exception.message
131
- say "Backtrace:", :magenta
132
- say exception.backtrace
133
- exit 3
134
- end
135
-
136
- def check_data(total, usage, warning, critical)
137
- usage_percent = 100.0 / total.to_f * usage.to_f
138
- code = 3
139
- if usage_percent < warning
140
- code = 0
141
- elsif usage_percent < critical
142
- code = 1
143
- else
144
- code = 2
145
- end
146
- [code, usage_percent.round(0)]
147
- end
148
-
149
- end
51
+ end
150
52
 
151
- end
53
+ end
@@ -1,11 +1,11 @@
1
1
  class NagiosConfig < CloudstackNagios::Base
2
2
 
3
- desc "hosts", "generate nagios hosts configuration for virtual routers"
3
+ desc "router_hosts", "generate nagios hosts configuration for virtual routers"
4
4
  option :template,
5
5
  desc: "path of ERB template to use",
6
- default: File.join(File.dirname(__FILE__), '..', 'templates', 'cloudstack_routers_hosts.cfg.erb'),
6
+ default: File.join(File.dirname(__FILE__), '..', 'templates', 'cloudstack_router_hosts.cfg.erb'),
7
7
  aliases: '-t'
8
- def hosts
8
+ def router_hosts
9
9
  host_template = load_template(options[:template])
10
10
  puts host_template.result(
11
11
  routers: cs_routers,
@@ -13,19 +13,65 @@ class NagiosConfig < CloudstackNagios::Base
13
13
  )
14
14
  end
15
15
 
16
- desc "services", "generate nagios services configuration for virtual routers"
16
+ desc "router_services", "generate nagios services configuration for system vms"
17
17
  option :template,
18
18
  desc: "path of ERB template to use",
19
- default: File.join(File.dirname(__FILE__), '..', 'templates', 'cloudstack_routers_services.cfg.erb'),
19
+ default: File.join(File.dirname(__FILE__), '..', 'templates', 'cloudstack_router_services.cfg.erb'),
20
20
  aliases: '-t'
21
- def services
22
- bin_path = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'bin'))
23
- config_file = options[:config]
21
+ def router_services
24
22
  service_template = load_template(options[:template])
25
23
  puts service_template.result(
26
24
  routers: cs_routers,
27
25
  bin_path: bin_path,
28
- config_file: config_file,
26
+ config_file: options[:config],
27
+ date: date_string
28
+ )
29
+ end
30
+
31
+ desc "api_hosts", "generate nagios api host configuration"
32
+ option :template,
33
+ desc: "path of ERB template to use",
34
+ default: File.join(File.dirname(__FILE__), '..', 'templates', 'cloudstack_api_hosts.cfg.erb'),
35
+ aliases: '-t'
36
+ def api_hosts
37
+ service_template = load_template(options[:template])
38
+ puts service_template.result(
39
+ zones: client.list_zones,
40
+ bin_path: bin_path,
41
+ config_file: options[:config],
42
+ date: date_string
43
+ )
44
+ end
45
+
46
+ desc "storage_pool_services", "generate nagios storage pool services configuration"
47
+ option :template,
48
+ desc: "path of ERB template to use",
49
+ default: File.join(File.dirname(__FILE__), '..', 'templates', 'cloudstack_storage_pool_services.cfg.erb'),
50
+ aliases: '-t'
51
+ def storage_pool_services
52
+ service_template = load_template(options[:template])
53
+ storage_pools = client.list_storage_pools.select do |pool|
54
+ pool['state'].downcase == 'up'
55
+ end
56
+ puts service_template.result(
57
+ storage_pools: storage_pools,
58
+ bin_path: bin_path,
59
+ config_file: options[:config],
60
+ date: date_string
61
+ )
62
+ end
63
+
64
+ desc "capacity_services", "generate nagios capacity services configuration"
65
+ option :template,
66
+ desc: "path of ERB template to use",
67
+ default: File.join(File.dirname(__FILE__), '..', 'templates', 'cloudstack_capacity_services.cfg.erb'),
68
+ aliases: '-t'
69
+ def capacity_services
70
+ service_template = load_template(options[:template])
71
+ puts service_template.result(
72
+ capacity_types: Capacity::CAPACITY_TYPES,
73
+ bin_path: bin_path,
74
+ config_file: options[:config],
29
75
  date: date_string
30
76
  )
31
77
  end
@@ -34,6 +80,10 @@ class NagiosConfig < CloudstackNagios::Base
34
80
  def date_string
35
81
  Time.new.strftime("%d.%m.%Y - %H:%M:%S")
36
82
  end
83
+
84
+ def bin_path
85
+ File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'bin'))
86
+ end
37
87
  end
38
88
 
39
- end
89
+ end
@@ -0,0 +1,100 @@
1
+ require 'sshkit/dsl'
2
+
3
+ class Router < CloudstackNagios::Base
4
+
5
+ desc "memory HOST", "check memory on host"
6
+ def memory
7
+ begin
8
+ host = systemvm_host
9
+ free_output = ""
10
+ on host do |h|
11
+ free_output = capture(:free)
12
+ end
13
+ values = free_output.scan(/\d+/)
14
+ total = values[0].to_i
15
+ free = values[2].to_i
16
+ free_b = values[7].to_i
17
+ data = check_data(total, total - free_b, options[:warning], options[:critical])
18
+ puts "MEMORY #{RETURN_CODES[data[0]]} - usage = #{data[1]}% | usage=#{data[1]}% total=#{total}M free=#{free}M free_wo_buffers=#{free_b}M"
19
+ exit data[0]
20
+ rescue => e
21
+ exit_with_failure(e)
22
+ end
23
+ end
24
+
25
+ desc "cpu", "check memory on host"
26
+ def cpu
27
+ begin
28
+ host = systemvm_host
29
+ mpstat_output = ""
30
+ on host do |h|
31
+ mpstat_output = capture(:mpstat)
32
+ end
33
+ values = mpstat_output.scan(/\d+\.\d+/)
34
+ usage = 100 - values[-1].to_f
35
+ data = check_data(100, usage, options[:warning], options[:critical])
36
+ puts "CPU #{RETURN_CODES[data[0]]} - usage = #{data[1]}% | usage=#{data[1]}%"
37
+ exit data[0]
38
+ rescue => e
39
+ exit_with_failure(e)
40
+ end
41
+ end
42
+
43
+ desc "rootfs_rw", "check if the rootfs is read/writeable on host"
44
+ def rootfs_rw
45
+ begin
46
+ host = systemvm_host
47
+ proc_out = ""
48
+ on host do |h|
49
+ proc_out = capture(:cat, '/proc/mounts')
50
+ end
51
+ rootfs_rw = proc_out.match(/rootfs\srw\s/)
52
+ status = rootfs_rw ? 0 : 2
53
+ puts "ROOTFS_RW #{rootfs_rw ? 'OK - rootfs writeable' : 'CRITICAL - rootfs NOT writeable'}"
54
+ exit status
55
+ rescue => e
56
+ exit_with_failure(e)
57
+ end
58
+ end
59
+
60
+ desc "network", "check network usage on host"
61
+ option :interface,
62
+ desc: 'network interface to probe',
63
+ default: 'eth0',
64
+ aliases: '-i'
65
+ option :if_speed,
66
+ desc: 'network interface speed in bits per second',
67
+ type: :numeric,
68
+ default: 1000000,
69
+ aliases: '-s'
70
+ def network
71
+ begin
72
+ host = systemvm_host
73
+ stats_path = "/sys/class/net/#{options[:interface]}/statistics"
74
+ rx_bytes, tx_bytes = ""
75
+ on host do |h|
76
+ rx_bytes = capture("cat #{stats_path}/rx_bytes;sleep 1;cat #{stats_path}/rx_bytes").lines.to_a
77
+ tx_bytes = capture("cat #{stats_path}/tx_bytes;sleep 1;cat #{stats_path}/tx_bytes").lines.to_a
78
+ end
79
+ rbps = (rx_bytes[1].to_i - rx_bytes[0].to_i) * 8
80
+ tbps = (tx_bytes[1].to_i - tx_bytes[0].to_i) * 8
81
+ data = check_data(options[:if_speed], rbps, options[:warning], options[:critical])
82
+ puts "NETWORK #{RETURN_CODES[data[0]]} - usage = #{data[1]}% | usage=#{data[1]}% rxbps=#{rbps.round(0)} txbps=#{tbps.round(0)}"
83
+ exit data[0]
84
+ rescue => e
85
+ exit_with_failure(e)
86
+ end
87
+ end
88
+
89
+ no_commands do
90
+
91
+ def systemvm_host
92
+ host = SSHKit::Host.new("root@#{options[:host]}")
93
+ host.ssh_options = sshoptions(options[:ssh_key])
94
+ host.port = options[:port]
95
+ host
96
+ end
97
+
98
+ end
99
+
100
+ end
@@ -1,5 +1,7 @@
1
1
  module CloudstackNagios
2
2
  module Helper
3
+ RETURN_CODES = {0 => 'ok', 1 => 'warning', 2 => 'critical'}
4
+
3
5
  def load_template(template_path)
4
6
  if File.file?(template_path)
5
7
  templ = Erubis::Eruby.new(File.read template_path)
@@ -15,5 +17,28 @@ module CloudstackNagios
15
17
  routers = client.list_routers(status: 'Running')
16
18
  routers += client.list_routers(projectid: -1, status: 'Running')
17
19
  end
20
+
21
+ def exit_with_failure(exception)
22
+ say 'ERROR: command execution failed!', :red
23
+ say "Message: ", :magenta
24
+ say exception.message
25
+ say "Backtrace:", :magenta
26
+ say exception.backtrace
27
+ exit 3
28
+ end
29
+
30
+ def check_data(total, usage, warning, critical)
31
+ usage_percent = 100.0 / total.to_f * usage.to_f
32
+ code = 3
33
+ if usage_percent < warning
34
+ code = 0
35
+ elsif usage_percent < critical
36
+ code = 1
37
+ else
38
+ code = 2
39
+ usage_percent = 0
40
+ end
41
+ [code, usage_percent.round(0)]
42
+ end
18
43
  end
19
44
  end
@@ -0,0 +1,39 @@
1
+ ###############################################################################
2
+ #
3
+ # Cloudstack API Host configuration file
4
+ #
5
+ # Created by: cloudstack-nagios
6
+ # Date: <%= date %>
7
+ # Version: Nagios 3.x config file
8
+ #
9
+ # --- DO NOT EDIT THIS FILE BY HAND ---
10
+ # cloudstack-nagios will overwite all manual settings during the next update
11
+ #
12
+ ###############################################################################
13
+
14
+ define hostgroup {
15
+ hostgroup_name Cloudstack-SystemVM
16
+ alias Cloudstack-SystemVM
17
+ register 1
18
+ }
19
+
20
+ <% zones.each do |zone| -%>
21
+ define host {
22
+ host_name Cloudstack_<%= zone['name'] %>
23
+ display_name Cloudstack_<%= zone['name'] %>
24
+ address localhost
25
+ use Linux-Host,host-pnp
26
+ hostgroups Cloudstack-Base
27
+ check_command check-host-alive
28
+ register 1
29
+ }
30
+
31
+ <% end -%>
32
+
33
+ ###############################################################################
34
+ #
35
+ # Host configuration file
36
+ #
37
+ # END OF FILE
38
+ #
39
+ ###############################################################################
@@ -0,0 +1,41 @@
1
+
2
+ ###############################################################################
3
+ #
4
+ # Cloudstack capcity services configuration file
5
+ #
6
+ # Created by: cloudstack-nagios
7
+ # Date: <%= date %>
8
+ # Version: Nagios 3.x config file
9
+ #
10
+ # --- DO NOT EDIT THIS FILE BY HAND ---
11
+ # cloudstack-nagios will overwite all manual settings during the next update
12
+ #
13
+ ###############################################################################
14
+
15
+ <% capacity_types.each do |cap_type, cap_values| -%>
16
+ define command {
17
+ command_name cs-nagios_check-capacity_<%= cap_values[:method_name] %>
18
+ command_line <%= bin_path -%>/cs-nagios check capacity <%= cap_values[:method_name] %> -w $ARG1$ -c $ARG2$ --config <%= config_file %>
19
+ register 1
20
+ }
21
+
22
+ <% end -%>
23
+
24
+ <% capacity_types.each do |cap_type, cap_values| -%>
25
+ define service {
26
+ hostgroup_name Cloudstack-SystemVM
27
+ service_description <%= cap_values[:name] %>
28
+ display_name <%= cap_values[:method_name] %>
29
+ use Generic-Service,service-pnp
30
+ check_command cs-nagios_check-capacity_<%= cap_values[:method_name] -%>!80!90
31
+ register 1
32
+ }
33
+
34
+ <% end -%>
35
+ ###############################################################################
36
+ #
37
+ # Service configuration file
38
+ #
39
+ # END OF FILE
40
+ #
41
+ ###############################################################################
@@ -12,21 +12,21 @@
12
12
  ###############################################################################
13
13
 
14
14
  define hostgroup {
15
- hostgroup_name Cloudstack-SystemVM
16
- alias Cloudstack-SystemVM
17
- register 1
15
+ hostgroup_name Cloudstack-SystemVM
16
+ alias Cloudstack-SystemVM
17
+ register 1
18
18
  }
19
+
19
20
  <% routers.each do |router| -%>
20
21
  <% if router['linklocalip'] -%>
21
-
22
22
  define host {
23
- host_name <%= router['name'] %>
24
- display_name <%= router['name'] %> (<%= router['linklocalip'] %>)<%= " - #{router['project']}" if router['project'] %> - <%= router['zonename'] %>
25
- address <%= router['linklocalip'] %>
26
- use Linux-Host,host-pnp
27
- hostgroups Cloudstack-SystemVM
28
- check_command check-host-alive
29
- register 1
23
+ host_name <%= router['name'] %>
24
+ display_name <%= router['name'] %> (<%= router['linklocalip'] %>)<%= " - #{router['project']}" if router['project'] %> - <%= router['zonename'] %>
25
+ address <%= router['linklocalip'] %>
26
+ use Linux-Host,host-pnp
27
+ hostgroups Cloudstack-SystemVM
28
+ check_command check-host-alive
29
+ register 1
30
30
  }
31
31
  <% end -%>
32
32
  <% end -%>
@@ -14,25 +14,25 @@
14
14
 
15
15
  define command {
16
16
  command_name cs-nagios_check-memory
17
- command_line <%= bin_path -%>/cs-nagios check memory -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$ --config <%= config_file %>
17
+ command_line <%= bin_path -%>/cs-nagios check router memory -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$ --config <%= config_file %>
18
18
  register 1
19
19
  }
20
20
 
21
21
  define command {
22
22
  command_name cs-nagios_check-cpu
23
- command_line <%= bin_path -%>/cs-nagios check cpu -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$ --config <%= config_file %>
23
+ command_line <%= bin_path -%>/cs-nagios check router cpu -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$ --config <%= config_file %>
24
24
  register 1
25
25
  }
26
26
 
27
27
  define command {
28
28
  command_name cs-nagios_check-network
29
- command_line <%= bin_path -%>/cs-nagios check network -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$ --config <%= config_file %>
29
+ command_line <%= bin_path -%>/cs-nagios check router network -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$ --config <%= config_file %>
30
30
  register 1
31
31
  }
32
32
 
33
33
  define command {
34
34
  command_name cs-nagios_check-rootfsrw
35
- command_line <%= bin_path -%>/cs-nagios check rootfs_rw -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$ --config <%= config_file %>
35
+ command_line <%= bin_path -%>/cs-nagios check router rootfs_rw -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$ --config <%= config_file %>
36
36
  register 1
37
37
  }
38
38
 
@@ -0,0 +1,39 @@
1
+
2
+ ###############################################################################
3
+ #
4
+ # Cloudstack storage_pool services configuration file
5
+ #
6
+ # Created by: cloudstack-nagios
7
+ # Date: <%= date %>
8
+ # Version: Nagios 3.x config file
9
+ #
10
+ # --- DO NOT EDIT THIS FILE BY HAND ---
11
+ # cloudstack-nagios will overwite all manual settings during the next update
12
+ #
13
+ ###############################################################################
14
+
15
+ <% storage_pools.each do |storage_pool| -%>
16
+ define command {
17
+ command_name cs-nagios_check-storage_pool
18
+ command_line <%= bin_path -%>/cs-nagios check storage_pool --name <%= storage_pool['name'] -%> --zone <%= storage_pool['zonename'] -%> -w $ARG1$ -c $ARG2$ --config <%= config_file %>
19
+ register 1
20
+ }
21
+
22
+ <% end -%>
23
+
24
+ define service {
25
+ hostgroup_name Cloudstack-SystemVM
26
+ service_description Cloudstack Storage Pool
27
+ display_name Cloudstack Storage Pool
28
+ use Generic-Service,service-pnp
29
+ check_command cs-nagios_check-storage_pool!80!90
30
+ register 1
31
+ }
32
+
33
+ ###############################################################################
34
+ #
35
+ # Service configuration file
36
+ #
37
+ # END OF FILE
38
+ #
39
+ ###############################################################################
@@ -1,3 +1,3 @@
1
1
  module CloudstackNagios
2
- VERSION = "0.5.1"
2
+ VERSION = "0.6.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudstack-nagios
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nik Wolfgramm
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-08 00:00:00.000000000 Z
11
+ date: 2014-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rdoc
@@ -44,14 +44,20 @@ dependencies:
44
44
  requirements:
45
45
  - - ~>
46
46
  - !ruby/object:Gem::Version
47
- version: 0.2.10
47
+ version: '0.4'
48
+ - - '>='
49
+ - !ruby/object:Gem::Version
50
+ version: 0.4.4
48
51
  type: :runtime
49
52
  prerelease: false
50
53
  version_requirements: !ruby/object:Gem::Requirement
51
54
  requirements:
52
55
  - - ~>
53
56
  - !ruby/object:Gem::Version
54
- version: 0.2.10
57
+ version: '0.4'
58
+ - - '>='
59
+ - !ruby/object:Gem::Version
60
+ version: 0.4.4
55
61
  - !ruby/object:Gem::Dependency
56
62
  name: thor
57
63
  requirement: !ruby/object:Gem::Requirement
@@ -122,17 +128,23 @@ files:
122
128
  - Gemfile.lock
123
129
  - LICENSE.txt
124
130
  - README.md
131
+ - Rakefile
125
132
  - bin/cs-nagios
126
133
  - cloudstack-nagios.gemspec
127
134
  - lib/cloudstack-nagios/base.rb
128
135
  - lib/cloudstack-nagios/cli.rb
136
+ - lib/cloudstack-nagios/commands/capacity.rb
129
137
  - lib/cloudstack-nagios/commands/check.rb
130
138
  - lib/cloudstack-nagios/commands/nagios_config.rb
139
+ - lib/cloudstack-nagios/commands/router.rb
131
140
  - lib/cloudstack-nagios/commands/snmpd_config.rb
132
141
  - lib/cloudstack-nagios/files/snmpd.conf
133
142
  - lib/cloudstack-nagios/helper.rb
134
- - lib/cloudstack-nagios/templates/cloudstack_routers_hosts.cfg.erb
135
- - lib/cloudstack-nagios/templates/cloudstack_routers_services.cfg.erb
143
+ - lib/cloudstack-nagios/templates/cloudstack_api_hosts.cfg.erb
144
+ - lib/cloudstack-nagios/templates/cloudstack_capacity_services.cfg.erb
145
+ - lib/cloudstack-nagios/templates/cloudstack_router_hosts.cfg.erb
146
+ - lib/cloudstack-nagios/templates/cloudstack_router_services.cfg.erb
147
+ - lib/cloudstack-nagios/templates/cloudstack_storage_pool_services.cfg.erb
136
148
  - lib/cloudstack-nagios/version.rb
137
149
  - lib/cloudstack_nagios.rb
138
150
  homepage: https://bitbucket.org/swisstxt/cloudstack-nagios