Class: SystemVm
Direct Known Subclasses
Router
Constant Summary
CloudstackNagios::Helper::RETURN_CODES
Instance Attribute Summary
#config
Instance Method Summary
collapse
exit_on_failure?
#check_data, #cs_routers, #cs_system_vms, #exit_with_failure, #load_template, #storage_pools
Instance Method Details
#active_ftp ⇒ Object
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
# File 'lib/cloudstack-nagios/commands/system_vm.rb', line 184
def active_ftp
begin
host = systemvm_host
active_ftp_enabled = false
modules = %w(nf_conntrack_ftp, nf_nat_ftp)
on host do |h|
lsmod = capture(:lsmod)
active_ftp_enabled = lsmod.include?('nf_conntrack_ftp') &&
lsmod.include?('nf_nat_ftp')
unless active_ftp_enabled
execute(:modprobe, 'nf_conntrack_ftp')
execute(:modprobe, 'nf_nat_ftp')
execute(:echo, '"nf_conntrack_ftp" >> /etc/modules')
execute(:echo, '"nf_nat_ftp" >> /etc/modules')
active_ftp_enabled = true
end
end
rescue SSHKit::Command::Failed
active_ftp_enabled = false
rescue => e
exit_with_failure(e)
end
status = active_ftp_enabled ? 0 : 2
puts "ACTIVE_FTP #{active_ftp_enabled ? 'OK - active_ftp enabled' : 'CRITICAL - active_ftp NOT enabled'}"
exit status
end
|
#conntrack_connections ⇒ Object
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
# File 'lib/cloudstack-nagios/commands/system_vm.rb', line 160
def conntrack_connections
begin
host = systemvm_host
default_max = 1000000
netfilter_path = "/proc/sys/net/netfilter/"
current, max = 0
on host do |h|
max = capture("cat #{netfilter_path}nf_conntrack_max").to_i
current = capture("cat #{netfilter_path}nf_conntrack_count").to_i
end
if max < default_max
on host do |h|
execute :echo, "#{default_max} > #{netfilter_path}nf_conntrack_max"
end
end
data = check_data(max, current, options[:warning], options[:critical])
puts "CONNTRACK_CONNECTIONS #{RETURN_CODES[data[0]]} - usage = #{data[1]}% (#{current.round(0)}/#{max.round(0)}) | usage=#{data[1]}% current=#{current.round(0)} max=#{max.round(0)}"
exit data[0]
rescue => e
exit_with_failure(e)
end
end
|
#cpu ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/cloudstack-nagios/commands/system_vm.rb', line 33
def cpu
begin
host = systemvm_host
mpstat_output = ""
on host do |h|
mpstat_output = capture(:mpstat, '-P ALL', '2', '2')
end
value = if options[:mode] == "max"
values = mpstat_output.each_line.to_a.slice(3..-1).map do |line, index|
line.scan(/\d+\.\d+/)[-1].to_f
end
values.delete(0.0)
values.min
else
mpstat_output.scan(/\d+\.\d+/)[-1].to_f
end
usage = 100 - value
data = check_data(100, usage, options[:warning], options[:critical])
puts "CPU #{RETURN_CODES[data[0]]} - usage = #{data[1]}% | usage=#{data[1]}%"
exit data[0]
rescue => e
exit_with_failure(e)
end
end
|
#disk_usage ⇒ Object
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/cloudstack-nagios/commands/system_vm.rb', line 108
def disk_usage
begin
host = systemvm_host
partition = options[:partition]
proc_out = ""
on host do |h|
proc_out = capture(:df, '-l', partition)
end
match = proc_out.match(/.*\s(\d+)%\s.*/)
if match
usage = match[1]
data = check_data(100, usage, options[:warning], options[:critical])
puts "DISK_USAGE #{RETURN_CODES[data[0]]} (Partition #{options[:partition]}) - usage = #{data[1]}% | usage=#{data[1]}%"
exit data[0]
else
puts "DISK_USAGE UNKNOWN"
end
rescue => e
exit_with_failure(e)
end
end
|
#fs_rw ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/cloudstack-nagios/commands/system_vm.rb', line 61
def fs_rw
begin
host = systemvm_host
test_file = File.join(options[:mount_point], 'cs_nagios_diskcheck.txt')
fs_rw = false
on host do |h|
fs_rw = execute(:touch, test_file)
execute(:rm, '-f', test_file)
end
rescue SSHKit::Command::Failed
fs_rw = false
rescue => e
exit_with_failure(e)
end
status = fs_rw ? 0 : 2
puts fs_rw ?
"OK - file system (#{options[:mount_point]}) writeable" :
"CRITICAL - file system (#{options[:mount_point]}) NOT writeable"
exit status
end
|
#memory ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/cloudstack-nagios/commands/system_vm.rb', line 7
def memory
begin
host = systemvm_host
free_output = ""
on host do |h|
free_output = capture(:free)
end
values = free_output.scan(/\d+/)
total = values[0].to_i
free = values[2].to_i
free_b = values[7].to_i
data = check_data(total, total - free_b, options[:warning], options[:critical])
puts "MEMORY #{RETURN_CODES[data[0]]} - usage = #{data[1]}% (#{((total - free_b)/1024.0).round(0)}/#{(total/1024.0).round(0)}MB) | \
usage=#{data[1]}% total=#{total}M free=#{free}M free_wo_buffers=#{free_b}M".gsub(/\s+/, " ")
exit data[0]
rescue => e
exit_with_failure(e)
end
end
|
#network ⇒ Object
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
# File 'lib/cloudstack-nagios/commands/system_vm.rb', line 140
def network
begin
host = systemvm_host
stats_path = "/sys/class/net/#{options[:interface]}/statistics"
rx_bytes, tx_bytes = ""
on host do |h|
rx_bytes = capture("cat #{stats_path}/rx_bytes;sleep 1;cat #{stats_path}/rx_bytes").lines.to_a
tx_bytes = capture("cat #{stats_path}/tx_bytes;sleep 1;cat #{stats_path}/tx_bytes").lines.to_a
end
rbps = (rx_bytes[1].to_i - rx_bytes[0].to_i) * 8
tbps = (tx_bytes[1].to_i - tx_bytes[0].to_i) * 8
data = check_data(options[:if_speed], rbps, options[:warning], options[:critical])
puts "NETWORK #{RETURN_CODES[data[0]]} - usage = #{data[1]}% | usage=#{data[1]}% rxbps=#{rbps.round(0)} txbps=#{tbps.round(0)}"
exit data[0]
rescue => e
exit_with_failure(e)
end
end
|
#secstor_rw ⇒ Object
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
# File 'lib/cloudstack-nagios/commands/system_vm.rb', line 83
def secstor_rw
host = systemvm_host
mounts = {}
on host do |h|
entries = capture(:mount, '|grep SecStorage') rescue ''
entries.each_line do |nfs_mount|
mount_point = nfs_mount[/.* on (.*) type .*/, 1]
test_file = File.join(mount_point, 'cs_nagios_diskcheck.txt')
fs_rw = execute(:touch, test_file) rescue false
mounts[mount_point] = fs_rw
execute(:rm, '-f', test_file) if fs_rw
end
end
fs_ro = mounts.select {|key,value| value != true}
status = fs_ro.size == 0 ? 0 : 2
puts status == 0 ?
"OK - all sec_stor mounts are writeable" :
"CRITICAL - some sec_stor mounts are NOT writeable (#{fs_ro.keys.join(', ')})"
exit status
rescue => e
exit_with_failure(e)
end
|