class SystemVm
Public Instance Methods
active_ftp()
click to toggle source
# File lib/cloudstack-nagios/commands/system_vm.rb 208 def active_ftp 209 begin 210 host = systemvm_host 211 active_ftp_enabled = false 212 modules = %w(nf_conntrack_ftp, nf_nat_ftp) 213 on host do |h| 214 lsmod = capture(:lsmod) 215 active_ftp_enabled = lsmod.include?('nf_conntrack_ftp') && 216 lsmod.include?('nf_nat_ftp') 217 unless active_ftp_enabled 218 # load the modules in the kernel 219 execute(:modprobe, 'nf_conntrack_ftp') 220 execute(:modprobe, 'nf_nat_ftp') 221 # load the modules at next server boot 222 execute(:echo, '"nf_conntrack_ftp" >> /etc/modules') 223 execute(:echo, '"nf_nat_ftp" >> /etc/modules') 224 active_ftp_enabled = true 225 end 226 end 227 rescue SSHKit::Command::Failed 228 active_ftp_enabled = false 229 rescue => e 230 exit_with_failure(e) 231 end 232 status = active_ftp_enabled ? 0 : 2 233 puts "ACTIVE_FTP #{active_ftp_enabled ? 'OK - active_ftp enabled' : 'CRITICAL - active_ftp NOT enabled'}" 234 exit status 235 end
conntrack_connections()
click to toggle source
# File lib/cloudstack-nagios/commands/system_vm.rb 160 def conntrack_connections 161 begin 162 host = systemvm_host 163 default_max = 1000000 164 netfilter_path = "/proc/sys/net/netfilter/" 165 current, max = 0 166 on host do |h| 167 max = capture("cat #{netfilter_path}nf_conntrack_max").to_i 168 current = capture("cat #{netfilter_path}nf_conntrack_count").to_i 169 end 170 if max < default_max 171 on host do |h| 172 execute :echo, "#{default_max} > #{netfilter_path}nf_conntrack_max" 173 end 174 end 175 data = check_data(max, current, options[:warning], options[:critical]) 176 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)}" 177 exit data[0] 178 rescue => e 179 exit_with_failure(e) 180 end 181 end
cpu()
click to toggle source
# File lib/cloudstack-nagios/commands/system_vm.rb 33 def cpu 34 begin 35 host = systemvm_host 36 mpstat_output = "" 37 on host do |h| 38 mpstat_output = capture(:mpstat, '-P ALL', '2', '2') 39 end 40 # max takes the min idle value, removes zero values before 41 value = if options[:mode] == "max" 42 values = mpstat_output.each_line.to_a.slice(3..-1).map do |line, index| 43 line.scan(/\d+\.\d+/)[-1].to_f 44 end 45 values.delete(0.0) 46 values.min 47 else 48 mpstat_output.scan(/\d+\.\d+/)[-1].to_f 49 end 50 usage = 100 - value 51 data = check_data(100, usage, options[:warning], options[:critical]) 52 puts "CPU #{RETURN_CODES[data[0]]} - usage = #{data[1]}% | usage=#{data[1]}%" 53 exit data[0] 54 rescue => e 55 exit_with_failure(e) 56 end 57 end
disk_usage()
click to toggle source
# File lib/cloudstack-nagios/commands/system_vm.rb 108 def disk_usage 109 begin 110 host = systemvm_host 111 partition = options[:partition] 112 proc_out = "" 113 on host do |h| 114 proc_out = capture(:df, '-l', partition) 115 end 116 match = proc_out.match(/.*\s(\d+)%\s.*/) 117 if match 118 usage = match[1] 119 data = check_data(100, usage, options[:warning], options[:critical]) 120 puts "DISK_USAGE #{RETURN_CODES[data[0]]} (Partition #{options[:partition]}) - usage = #{data[1]}% | usage=#{data[1]}%" 121 exit data[0] 122 else 123 puts "DISK_USAGE UNKNOWN" 124 end 125 rescue => e 126 exit_with_failure(e) 127 end 128 end
fs_rw()
click to toggle source
# File lib/cloudstack-nagios/commands/system_vm.rb 61 def fs_rw 62 begin 63 host = systemvm_host 64 test_file = File.join(options[:mount_point], 'cs_nagios_diskcheck.txt') 65 fs_rw = false 66 on host do |h| 67 fs_rw = execute(:touch, test_file) 68 execute(:rm, '-f', test_file) 69 end 70 rescue SSHKit::Command::Failed 71 fs_rw = false 72 rescue => e 73 exit_with_failure(e) 74 end 75 status = fs_rw ? 0 : 2 76 puts fs_rw ? 77 "OK - file system (#{options[:mount_point]}) writeable" : 78 "CRITICAL - file system (#{options[:mount_point]}) NOT writeable" 79 exit status 80 end
memory()
click to toggle source
# File lib/cloudstack-nagios/commands/system_vm.rb 7 def memory 8 begin 9 host = systemvm_host 10 free_output = "" 11 on host do |h| 12 free_output = capture(:cat, '/proc/meminfo') 13 end 14 values = free_output.scan(/\d+/) 15 total = values[0].to_i 16 free = values[1].to_i 17 free_b = values[1].to_i + values[3].to_i + values[4].to_i 18 data = check_data(total, total - free_b, options[:warning], options[:critical]) 19 puts "MEMORY #{RETURN_CODES[data[0]]} - usage = #{data[1]}% (#{((total - free_b)/1024.0).round(0)}/#{(total/1024.0).round(0)}MB) | \ 20 usage=#{data[1]}% total=#{total}M free=#{free}M free_wo_buffers=#{free_b}M".gsub(/\s+/, " ") 21 exit data[0] 22 rescue => e 23 exit_with_failure(e) 24 end 25 end
network()
click to toggle source
# File lib/cloudstack-nagios/commands/system_vm.rb 140 def network 141 begin 142 host = systemvm_host 143 stats_path = "/sys/class/net/#{options[:interface]}/statistics" 144 rx_bytes, tx_bytes = "" 145 on host do |h| 146 rx_bytes = capture("cat #{stats_path}/rx_bytes;sleep 1;cat #{stats_path}/rx_bytes").lines.to_a 147 tx_bytes = capture("cat #{stats_path}/tx_bytes;sleep 1;cat #{stats_path}/tx_bytes").lines.to_a 148 end 149 rbps = (rx_bytes[1].to_i - rx_bytes[0].to_i) * 8 150 tbps = (tx_bytes[1].to_i - tx_bytes[0].to_i) * 8 151 data = check_data(options[:if_speed], rbps, options[:warning], options[:critical]) 152 puts "NETWORK #{RETURN_CODES[data[0]]} - usage = #{data[1]}% | usage=#{data[1]}% rxbps=#{rbps.round(0)} txbps=#{tbps.round(0)}" 153 exit data[0] 154 rescue => e 155 exit_with_failure(e) 156 end 157 end
secstor_rw()
click to toggle source
# File lib/cloudstack-nagios/commands/system_vm.rb 83 def secstor_rw 84 host = systemvm_host 85 mounts = {} 86 on host do |h| 87 entries = capture(:mount, '|grep SecStorage') rescue '' 88 entries.each_line do |nfs_mount| 89 mount_point = nfs_mount[/.* on (.*) type .*/, 1] 90 test_file = File.join(mount_point, 'cs_nagios_diskcheck.txt') 91 fs_rw = execute(:touch, test_file) rescue false 92 mounts[mount_point] = fs_rw 93 execute(:rm, '-f', test_file) if fs_rw 94 end 95 end 96 fs_ro = mounts.select {|key,value| value != true} 97 status = fs_ro.size == 0 ? 0 : 2 98 puts status == 0 ? 99 "OK - all sec_stor mounts are writeable" : 100 "CRITICAL - some sec_stor mounts are NOT writeable (#{fs_ro.keys.join(', ')})" 101 exit status 102 rescue => e 103 exit_with_failure(e) 104 end
systemvm_host()
click to toggle source
# File lib/cloudstack-nagios/commands/system_vm.rb 239 def systemvm_host 240 unless options[:host] 241 say "Error: --host/-H option is required for this check.", :red 242 exit 1 243 end 244 # suppress sshkit output to stdout 245 SSHKit.config.output_verbosity = Logger::FATAL 246 host = SSHKit::Host.new("root@#{options[:host]}") 247 host.ssh_options = sshoptions(options[:ssh_key]) 248 host.port = options[:ssh_port] 249 host 250 end
uptime()
click to toggle source
# File lib/cloudstack-nagios/commands/system_vm.rb 184 def uptime 185 begin 186 host = systemvm_host 187 uptime_sec = 0 188 on host do |h| 189 uptime_sec = capture('cat /proc/uptime').split[0].to_f 190 end 191 192 if uptime_sec < options[:critical] 193 code = 2 194 elsif uptime_sec < options[:warning] 195 code = 1 196 else 197 code = 0 198 end 199 200 puts "UPTIME #{RETURN_CODES[code]} #{uptime_sec}s (Critical < #{options[:critical]}s, Warning < #{options[:warning]}s) | uptime=#{uptime_sec}" 201 exit code 202 rescue => e 203 exit_with_failure(e) 204 end 205 end