Class: Check

Inherits:
CloudstackNagios::Base show all
Defined in:
lib/cloudstack-nagios/commands/check.rb

Constant Summary

Constants included from CloudstackNagios::Helper

CloudstackNagios::Helper::RETURN_CODES

Instance Attribute Summary

Attributes inherited from CloudstackNagios::Base

#config

Instance Method Summary collapse

Methods inherited from CloudstackNagios::Base

exit_on_failure?

Methods included from CloudstackNagios::Helper

#check_data, #cs_routers, #cs_system_vms, #exit_with_failure, #load_template, #storage_pools

Instance Method Details

#async_jobsObject



78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/cloudstack-nagios/commands/check.rb', line 78

def async_jobs
   jobs = client.list_async_jobs(listall: true)
   outstanding_jobs = jobs.select {|job| job['jobstatus'] == 0 }
   if outstanding_jobs.size < options[:warning]
     code = 0
   elsif outstanding_jobs.size < options[:critical]
     code = 1
   else
     code = 2
   end
   puts "async_jobs #{RETURN_CODES[code]} - jobs = #{outstanding_jobs.size} | jobs=#{outstanding_jobs.size}"
   exit code
end

#snapshotsObject



103
104
105
106
107
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/check.rb', line 103

def snapshots
  snapshots = client.list_snapshots(listall: true)
  client.list_projects(listall: true).each do |p|
    snapshots = snapshots.concat(client.list_snapshots(listall: true, project_id: p['id']))
  end

  not_backed_up = snapshots.select{|s| s['state'] != 'BackedUp' }
  warnings = []
  critical = []

  not_backed_up.each do |s|
    age = (Time.now - Time.parse(s['created'])) / 3600
    warnings << s if age > options[:warning]
    critical << s if age > options[:critical]
  end

  code = if critical.size > options[:critical]
    2
  elsif warnings.size > options[:warning]
    1
  else
    0
  end
  puts "snapshots #{RETURN_CODES[code]} - warnings = #{warnings.size}, critical = #{critical.size} | warnings=#{warnings.size} critical=#{critical.size}"
  exit code
end

#storage_poolObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/cloudstack-nagios/commands/check.rb', line 48

def storage_pool
   pool = client.list_storage_pools(name: options[:pool_name], zone: options[:zone]).first
   # calculate overprovisioning only for network file systems
   total_size = case pool['type']
   when 'NetworkFilesystem'
      pool['disksizetotal'] * options[:over_provisioning]
   else
      pool['disksizetotal']
   end
   data = check_data(
      total_size,
      pool['disksizeallocated'].to_f,
      options[:warning],
      options[:critical]
   )
   puts "storage_pool #{options[:pool_name]} #{RETURN_CODES[data[0]]} - usage = #{data[1]}% | usage=#{pool['disksizeused']} usage_perc=#{data[1]}%"
   exit data[0]
end