module CloudstackNagios::Helper

Constants

RETURN_CODES

Public Instance Methods

check_data(total, usage, warning, critical) click to toggle source
   # File lib/cloudstack-nagios/helper.rb
40 def check_data(total, usage, warning, critical)
41   usage_percent = 100.0 / total.to_f * usage.to_f
42 
43   if usage_percent.nan?
44     usage_percent = 0.0
45   end
46 
47   if usage_percent < warning
48     code = 0
49   elsif usage_percent < critical
50     code = 1
51   else
52     code = 2
53   end
54   [code, usage_percent.round(0)]
55 end
cs_routers() click to toggle source
   # File lib/cloudstack-nagios/helper.rb
16 def cs_routers
17   routers = client.list_routers(status: 'Running')
18   routers += client.list_routers(projectid: -1, status: 'Running')
19 end
cs_system_vms() click to toggle source
   # File lib/cloudstack-nagios/helper.rb
21 def cs_system_vms
22   vms = client.list_system_vms
23 end
exit_with_failure(exception) click to toggle source
   # File lib/cloudstack-nagios/helper.rb
31 def exit_with_failure(exception)
32   say 'ERROR: command execution failed!', :red
33   say "Message: ", :magenta
34   say exception.message
35   say "Backtrace:", :magenta
36   say exception.backtrace
37   exit 3
38 end
load_template(template_path) click to toggle source
   # File lib/cloudstack-nagios/helper.rb
 5 def load_template(template_path)
 6   if File.file?(template_path)
 7     templ = Erubis::Eruby.new(File.read template_path)
 8     templ.filename = template_path
 9     return templ
10   else
11     say "Error: Template \"#{template_path}\" not found.", :red
12     exit 1
13   end
14 end
storage_pools() click to toggle source
   # File lib/cloudstack-nagios/helper.rb
25 def storage_pools
26   storage_pools = client.list_storage_pools.select do |pool|
27     pool['state'].downcase == 'up'
28   end
29 end