Sha256: 6b421931d7d324a44b363ca0fbeaf36e6de2a873d3f8fb30410b0694df87b04e

Contents?: true

Size: 1.47 KB

Versions: 4

Compression:

Stored size: 1.47 KB

Contents

class Capacity < CloudstackNagios::Base

  CAPACITY_TYPES = {
    0 => {name: "Memory", method_name: "memory"},
    1 => {name: "CPU", method_name: "cpu"},
    2 => {name: "Storage", method_name: "storage"},
    3 => {name: "Primary Storage", method_name: "primary_storage"},
    4 => {name: "Public IP addresses", method_name: "public_ips"},
    5 => {name: "Private IP addresses", method_name: "private_ips"},
    6 => {name: "Secondary Storage", method_name: "secondary_storage"},
    7 => {name: "VLANs", method_name: "vlans"},
    8 => {name: "Direct Attached Public IP addresses", method_name: "direct_attached_public_ips"},
    9 => {name: "Local Storage", method_name: "local_storage"}
  }

  CAPACITY_TYPES.each do |type, value|
    desc value[:method_name], "check #{value[:name].downcase} on host"
    option :zone, required: true
    define_method(value[:method_name]) {
      capacity_check(options[:zone], type)
    }
  end

  no_commands do
    def capacity_check(zone, type)
      unless res_zone = client.list_zones(name: zone).first
        raise CloudstackNagios::InputError, "zone '#{zone}' not found."
      end
      cap = client.list_capacity(type: type, zoneid: res_zone['id']).first
      data = check_data(cap['capacitytotal'].to_f, cap['capacityused'].to_f, options[:warning], options[:critical])
      puts "#{CAPACITY_TYPES[type][:name]} #{RETURN_CODES[data[0]]} - usage = #{data[1]}% | usage=#{cap['capacityused']} usage_perc=#{data[1]}%"
      exit data[0]
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cloudstack-nagios-0.21.0 lib/cloudstack-nagios/commands/capacity.rb
cloudstack-nagios-0.20.1 lib/cloudstack-nagios/commands/capacity.rb
cloudstack-nagios-0.20.0 lib/cloudstack-nagios/commands/capacity.rb
cloudstack-nagios-0.19.0 lib/cloudstack-nagios/commands/capacity.rb