Module: CloudstackNagios::Helper
- Included in:
- Base
- Defined in:
- lib/cloudstack-nagios/helper.rb
Constant Summary collapse
- RETURN_CODES =
{0 => 'ok', 1 => 'warning', 2 => 'critical'}
Instance Method Summary collapse
- #check_data(total, usage, warning, critical) ⇒ Object
- #cs_routers ⇒ Object
- #exit_with_failure(exception) ⇒ Object
- #load_template(template_path) ⇒ Object
- #storage_pools ⇒ Object
Instance Method Details
#check_data(total, usage, warning, critical) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/cloudstack-nagios/helper.rb', line 36 def check_data(total, usage, warning, critical) 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 code = 2 end [code, usage_percent.round(0)] end |
#cs_routers ⇒ Object
16 17 18 19 |
# File 'lib/cloudstack-nagios/helper.rb', line 16 def cs_routers routers = client.list_routers(status: 'Running') routers += client.list_routers(projectid: -1, status: 'Running') end |
#exit_with_failure(exception) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/cloudstack-nagios/helper.rb', line 27 def exit_with_failure(exception) say 'ERROR: command execution failed!', :red say "Message: ", :magenta say exception. say "Backtrace:", :magenta say exception.backtrace exit 3 end |
#load_template(template_path) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/cloudstack-nagios/helper.rb', line 5 def load_template(template_path) if File.file?(template_path) templ = Erubis::Eruby.new(File.read template_path) templ.filename = template_path return templ else say "Error: Template \"#{template_path}\" not found.", :red exit 1 end end |
#storage_pools ⇒ Object
21 22 23 24 25 |
# File 'lib/cloudstack-nagios/helper.rb', line 21 def storage_pools storage_pools = client.list_storage_pools.select do |pool| pool['state'].downcase == 'up' end end |