cloudstack-nagios 0.3.3 → 0.4.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/Gemfile.lock
CHANGED
@@ -4,167 +4,138 @@ class Check < CloudstackNagios::Base
|
|
4
4
|
|
5
5
|
RETURN_CODES = {0 => 'ok', 1 => 'warning', 2 => 'critical'}
|
6
6
|
|
7
|
-
|
8
|
-
option :host,
|
7
|
+
class_option :host,
|
9
8
|
desc: 'hostname or ipaddress',
|
10
9
|
required: true,
|
11
10
|
aliases: '-H'
|
12
|
-
|
11
|
+
|
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
19
|
desc: 'critical level',
|
19
20
|
type: :numeric,
|
20
21
|
default: 95,
|
21
22
|
aliases: '-c'
|
22
|
-
|
23
|
+
|
24
|
+
class_option :ssh_key,
|
23
25
|
desc: 'ssh private key to use',
|
24
26
|
default: '/var/lib/cloud/management/.ssh/id_rsa'
|
25
|
-
|
27
|
+
|
28
|
+
class_option :port,
|
26
29
|
desc: 'ssh port to use',
|
27
30
|
type: :numeric,
|
28
31
|
default: 3922,
|
29
32
|
aliases: '-p'
|
33
|
+
|
34
|
+
desc "memory HOST", "check memory on host"
|
30
35
|
def memory
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
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)
|
37
51
|
end
|
38
|
-
values = free_output.scan(/\d+/)
|
39
|
-
total = values[0].to_i
|
40
|
-
free = values[2].to_i
|
41
|
-
free_b = values[7].to_i
|
42
|
-
data = check_data(total, free_b, options[:warning], options[:critical])
|
43
|
-
puts "MEMORY #{RETURN_CODES[data[0]]} - usage = #{data[1]}% | usage=#{data[1]}% total=#{total}M, free=#{free}M, free_wo_buffers=#{free_b}M"
|
44
|
-
exit data[0]
|
45
52
|
end
|
46
53
|
|
47
54
|
desc "cpu", "check memory on host"
|
48
|
-
option :host,
|
49
|
-
desc: 'hostname or ipaddress',
|
50
|
-
required: true,
|
51
|
-
aliases: '-H'
|
52
|
-
option :warning,
|
53
|
-
desc: 'warning level',
|
54
|
-
type: :numeric,
|
55
|
-
default: 90,
|
56
|
-
aliases: '-w'
|
57
|
-
option :critical,
|
58
|
-
desc: 'critical level',
|
59
|
-
type: :numeric,
|
60
|
-
default: 95,
|
61
|
-
aliases: '-c'
|
62
|
-
option :ssh_key,
|
63
|
-
desc: 'ssh private key to use',
|
64
|
-
default: '/var/lib/cloud/management/.ssh/id_rsa'
|
65
|
-
option :port,
|
66
|
-
desc: 'ssh port to use',
|
67
|
-
type: :numeric,
|
68
|
-
default: 3922,
|
69
|
-
aliases: '-p'
|
70
55
|
def cpu
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
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)
|
77
69
|
end
|
78
|
-
values = mpstat_output.scan(/\d+/)
|
79
|
-
usage = 100 - values[-1].to_f
|
80
|
-
data = check_data(100, usage, options[:warning], options[:critical])
|
81
|
-
puts "CPU #{RETURN_CODES[data[0]]} - usage = #{data[1]}% | usage=#{data[1]}%"
|
82
|
-
exit data[0]
|
83
70
|
end
|
84
71
|
|
85
72
|
desc "rootfs_rw", "check if the rootfs is read/writeable on host"
|
86
|
-
option :host,
|
87
|
-
desc: 'hostname or ipaddress',
|
88
|
-
required: true,
|
89
|
-
aliases: '-H'
|
90
|
-
option :warning,
|
91
|
-
desc: 'warning level',
|
92
|
-
type: :numeric,
|
93
|
-
default: 90,
|
94
|
-
aliases: '-w'
|
95
|
-
option :critical,
|
96
|
-
desc: 'critical level',
|
97
|
-
type: :numeric,
|
98
|
-
default: 95,
|
99
|
-
aliases: '-c'
|
100
|
-
option :ssh_key,
|
101
|
-
desc: 'ssh private key to use',
|
102
|
-
default: '/var/lib/cloud/management/.ssh/id_rsa'
|
103
|
-
option :port,
|
104
|
-
desc: 'ssh port to use',
|
105
|
-
type: :numeric,
|
106
|
-
default: 3922,
|
107
|
-
aliases: '-p'
|
108
73
|
def rootfs_rw
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
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)
|
115
86
|
end
|
116
|
-
rootfs_rw = proc_out.match(/rootfs\srw\s/)
|
117
|
-
status = rootfs_rw ? 0 : 2
|
118
|
-
puts "ROOTFS_RW #{rootfs_rw ? 'OK - rootfs writeable' : 'CRITICAL - rootfs NOT writeable'}"
|
119
|
-
exit status
|
120
87
|
end
|
121
88
|
|
122
89
|
desc "network", "check network usage on host"
|
123
|
-
option :
|
124
|
-
desc: '
|
125
|
-
|
126
|
-
aliases: '-
|
127
|
-
option :
|
128
|
-
desc: '
|
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',
|
129
96
|
type: :numeric,
|
130
|
-
default:
|
131
|
-
aliases: '-
|
132
|
-
option :critical,
|
133
|
-
desc: 'critical level',
|
134
|
-
type: :numeric,
|
135
|
-
default: 95,
|
136
|
-
aliases: '-c'
|
137
|
-
option :ssh_key,
|
138
|
-
desc: 'ssh private key to use',
|
139
|
-
default: '/var/lib/cloud/management/.ssh/id_rsa'
|
140
|
-
option :port,
|
141
|
-
desc: 'ssh port to use',
|
142
|
-
type: :numeric,
|
143
|
-
default: 3922,
|
144
|
-
aliases: '-p'
|
97
|
+
default: 1000000000,
|
98
|
+
aliases: '-s'
|
145
99
|
def network
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
100
|
+
begin
|
101
|
+
host = systemvm_host
|
102
|
+
raise "arggg"
|
103
|
+
stats_path = "/sys/class/net/#{options[:interface]}/statistics"
|
104
|
+
rx_bytes, tx_bytes = ""
|
105
|
+
on host do |h|
|
106
|
+
rx_bytes = capture("cat #{stats_path}/rx_bytes;sleep 1;cat #{stats_path}/rx_bytes").lines.to_a
|
107
|
+
tx_bytes = capture("cat #{stats_path}/tx_bytes;sleep 1;cat #{stats_path}/tx_bytes").lines.to_a
|
108
|
+
end
|
109
|
+
rbps = (rx_bytes[1].to_i - rx_bytes[0].to_i) * 8
|
110
|
+
tbps = (tx_bytes[1].to_i - tx_bytes[0].to_i) * 8
|
111
|
+
data = check_data(options[:if_speed], rbps, options[:warning], options[:critical])
|
112
|
+
puts "NETWORK #{RETURN_CODES[data[0]]} - usage = #{data[1]}% | usage=#{data[1]}% rxbps=#{rbps.round(0)}, txbps=#{tbps.round(0)}"
|
113
|
+
exit data[0]
|
114
|
+
rescue => e
|
115
|
+
exit_with_failure(e)
|
156
116
|
end
|
157
|
-
rbps = (r2 - r1)
|
158
|
-
tbps = (t2 - t1)
|
159
|
-
data = check_data(1073741824, (1073741824 - rbps), options[:warning], options[:critical])
|
160
|
-
puts "NETWORK #{RETURN_CODES[data[0]]} - usage = #{data[1]}% | rxbps=#{rbps.round(0)}B, txbps=#{tbps.round(0)}B"
|
161
|
-
exit data[0]
|
162
117
|
end
|
163
118
|
|
164
119
|
no_commands do
|
165
120
|
|
121
|
+
def systemvm_host
|
122
|
+
host = SSHKit::Host.new("root@#{options[:host]}")
|
123
|
+
host.ssh_options = sshoptions(options[:ssh_key])
|
124
|
+
host.port = options[:port]
|
125
|
+
host
|
126
|
+
end
|
127
|
+
|
128
|
+
def exit_with_failure(exception)
|
129
|
+
say 'ERROR: command execution failed!', :red
|
130
|
+
say "Message: ", :magenta
|
131
|
+
say exception.message
|
132
|
+
say "Backtrace:", :magenta
|
133
|
+
say exception.backtrace
|
134
|
+
exit 3
|
135
|
+
end
|
136
|
+
|
166
137
|
def check_data(total, usage, warning, critical)
|
167
|
-
usage_percent = 100
|
138
|
+
usage_percent = 100.0 / total.to_f * usage.to_f
|
168
139
|
code = 3
|
169
140
|
if usage_percent < warning
|
170
141
|
code = 0
|
@@ -55,7 +55,7 @@ class SnmpdConfig < CloudstackNagios::Base
|
|
55
55
|
upload! File.join(File.dirname(__FILE__), '..', 'files', 'snmpd.conf'), '/etc/snmp/snmpd.conf'
|
56
56
|
execute 'service', 'snmpd', 'restart'
|
57
57
|
execute 'iptables', '-A INPUT -p tcp -m tcp --dport 161 -j ACCEPT'
|
58
|
-
rescue StandardError => e
|
58
|
+
rescue StandardError => e
|
59
59
|
puts 'configuration failed!'
|
60
60
|
puts e.message
|
61
61
|
puts e.backtrace
|
@@ -16,9 +16,9 @@ define hostgroup {
|
|
16
16
|
alias Cloudstack-SystemVM
|
17
17
|
register 1
|
18
18
|
}
|
19
|
-
|
20
19
|
<% routers.each do |router| -%>
|
21
20
|
<% if router['linklocalip'] -%>
|
21
|
+
|
22
22
|
define host {
|
23
23
|
host_name <%= router['name'] %>
|
24
24
|
display_name <%= router['name'] %> (<%= router['linklocalip'] %>)<%= " - #{router['project']}" if router['project'] %> - <%= router['zonename'] %>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloudstack-nagios
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-11-
|
12
|
+
date: 2013-11-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rdoc
|