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
Instance Method Details
#check_data(total, usage, warning, critical) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/cloudstack-nagios/helper.rb', line 30 def check_data(total, usage, warning, critical) usage_percent = 100.0 / total.to_f * usage.to_f 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
21 22 23 24 25 26 27 28 |
# File 'lib/cloudstack-nagios/helper.rb', line 21 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 not found #{template_path}" exit 1 end end |