%PDF- %PDF-
Server IP : 79.170.40.229 / Your IP : 3.138.122.118 Web Server : Apache System : Linux web231.extendcp.co.uk 4.18.0-513.24.1.el8_9.x86_64 #1 SMP Mon Apr 8 11:23:13 EDT 2024 x86_64 User : 1stforcarhirealicante.com ( 296923) PHP Version : 5.6.40 Disable Function : NONE MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /proc/thread-self/root/opt/icinga2-hardware-checks/checks/ |
Upload File : |
#!/usr/bin/env ruby require 'rubygems' if RUBY_VERSION < '1.9.0' require 'sensu-plugin/check/cli' require_relative 'CheckHelper' require_relative 'Plugincommands' require 'socket' class ControllerCheck < Sensu::Plugin::Check::CLI def run # if this is a virtul machine, we dont want to proceed if CheckHelper.is_virtual() ok end vendor = CheckHelper.get_manufacturer() if vendor == '' warning = 'Vendor couldnt be determined' ok warning end # parse the hw config file to figure out what tools to use for the hw checks @settings = CheckHelper.settings() hwmap = @settings['tools'] @hwmatch = 0 @hwtype = '' hwmap.each do |name,info| if vendor.include?(info["vendor"]) # found a match in the config file @hwmatch = 1 @hwtype = name break end end # if this is a vendor not found in the config file, lets run the default check if @hwmatch == 0 @hwtype = 'default' end tools_to_run = hwmap[@hwtype]['raid_match'] run_status = {} tool_found = false tools_to_run.each do |tool| # lets run a test against every tool by the order they are configured and if the results are inconclusive, go on to the next if tool == 'default' path = '' else path = Plugincommands.send('which', tool) end if path != nil tool_found = true # go ahead and run the test case when tool.downcase().include?('omreport') run_status = perform_omreport_check() when tool.downcase().include?('sas3') run_status = perform_sas3ircu_check() else run_status = perform_default_check() end end if tool_found if run_status['exit_code'] == 0 # if the tool is valid, but the results are not concrete, we want to try other configured tools unless run_status['msg'].include?('Warning') ok end elsif run_status['exit_code'] == 2 critical run_status['msg'] end end end if tool_found == false # run the default test begin run_status = perform_default_check() rescue => exception warning 'No tools found to run the RAID tests. Tools checked: omreport, sas3ircu' end end case run_status['exit_code'] when 0 ok when 1 warning run_status['msg'] when 2 critical run_status['msg'] else unknown end end def perform_megacli_check # use megacli/megacli64 to determine controller status mcbin = '' retstat = 0 errcount = 0 retmsg = '' mccmd = Plugincommands.send('which', 'megacli') if !mccmd.nil? mcbin = mccmd elsif File.exist?('/opt/MegaRAID/MegaCli/MegaCli64') mcbin = '/opt/MegaRAID/MegaCli/MegaCli64' elsif File.exist?('/opt/MegaRAID/MegaCli/MegaCli') mcbin = '/opt/MegaRAID/MegaCli/MegaCli' else mcbin = '/opt/icinga2-hardware-checks/bin/MegaCli64' end if !mcbin.nil? and File.exist?(mcbin) raidstat = `sudo #{mcbin} -LDInfo -Lall -aAll | grep ^State` raidstat = raidstat.split(/\r?\n/) if raidstat.length > 0 raidstat.each do |line| if !line.include? 'Optimal' retstat = 2 errcount += 1 end end else retstat = 1 retmsg = mcbin + " could not determine raid status" end end if !retstat.zero? if retmsg == '' retmsg = mcbin + " found " + errcount.to_s + " raid problems" end end out = {'exit_code' => retstat, 'msg' => retmsg} return out end def perform_omreport_check() # uses omreport for the raid check; mainly for dell servers # get the application path omreport = Plugincommands.send('which', 'omreport') # Sample output: # Status : Ok begin # on c-series, omreport is known not to work for this # where we find omreport doesn't work and megacli does, # we should use megacli instead unless CheckHelper.validate_omreport if CheckHelper.validate_megacli disk_status = perform_megacli_check return disk_status end end # If MegaCli is installed and working, check for punctures if CheckHelper.validate_megacli exit_code = 0 msg = '' puncout = `sudo #{Plugincommands.megacli} -AdpAllInfo -aALL -NoLog` if puncout.include? 'FATAL:Punctur' msg = 'RAID Puncture detected:' + line exit_code = 2 end unless exit_code.zero? out = {'exit_code' => exit_code, 'msg' => msg} return out end end # Check OMSA for failures out = `#{omreport} storage controller | grep -i status` cmdout = out.split(/\r?\n/) if cmdout.length == 0 msg = 'Warning: Couldnt perform the check with this tool' end for line in cmdout status = line.split(':')[1].strip().downcase() # if status anything other than ok/okay/online, error out unless ['ok','okay','online'].any? { |word| status.include?(word) } msg = "omreport raid check failed with status #{status}" out = {'exit_code' => 2, 'msg' => msg} return out end end rescue => exception msg = exception.backtrace out = {'exit_code' => 2, 'msg' => msg} return out end out = {'exit_code' => 0, 'msg' => 'Tests passed'} return out end def perform_sas3ircu_check() # as with any tool, this only works for certain models (ceph/hadoop models) path = Plugincommands.send('which', 'sas3ircu') exit_code = 0 msg = "All checks passed" begin ok_list = ['okay','online'] # checking for 'status of volume' in the sas3 output will help us determine the controller status # Sample output: # Status of volume : Okay (OKY) out = `sudo #{path} 0 display | grep -i 'status of volume'` cmdout = out.split(/\r?\n/) if cmdout.length == 0 msg = 'Warning: Couldnt perform the check with this tool' end for line in cmdout status = line.split(':')[1].strip().downcase() # anything other than okay/online, exit with error unless ok_list.any? { |word| status.include?(word) } msg = "sas3 raid checks failed with status: #{status}" exit_code = 2 end end rescue => exception msg = exception.backtrace exit_code = 2 ensure out = {'exit_code' => exit_code, 'msg' => msg} return out end end def perform_default_check() # default when nothing else 'works'. The op will display an error in case there is one cmd = "grep -E 'U_|_U' /proc/mdstat" overall_raid_status = true op = `#{cmd}` if op.length > 0 overall_raid_status = false end if overall_raid_status == false out = {'exit_code' => 2, 'msg' => 'RAID Check failed based on /proc/mdstat'} return out else out = {'exit_code' => 0, 'msg' => 'Tests passed'} return out end end end