lib/cloudstack-nagios/helper.rb in cloudstack-nagios-0.14.1 vs lib/cloudstack-nagios/helper.rb in cloudstack-nagios-0.14.2

- old
+ new

@@ -1,9 +1,9 @@ module CloudstackNagios module Helper RETURN_CODES = {0 => 'ok', 1 => 'warning', 2 => 'critical'} - + def load_template(template_path) if File.file?(template_path) templ = Erubis::Eruby.new(File.read template_path) templ.filename = template_path return templ @@ -17,11 +17,11 @@ routers = client.list_routers(status: 'Running') routers += client.list_routers(projectid: -1, status: 'Running') end def storage_pools - storage_pools = client.list_storage_pools.select do |pool| + storage_pools = client.list_storage_pools.select do |pool| pool['state'].downcase == 'up' end end def exit_with_failure(exception) @@ -32,16 +32,16 @@ say exception.backtrace exit 3 end def check_data(total, usage, warning, critical) - usage_percent = 100.0 / total.to_f * usage.to_f + usage_percent = (100.0 / total.to_f * usage.to_f) || 0.0 code = 3 if usage_percent < warning code = 0 elsif usage_percent < critical code = 1 - else + else code = 2 end [code, usage_percent.round(0)] end end