Sha256: 88aba68b8c2210437d2c9ec57ef5276c242cb1d5604d83fbeecac33491bafcfb

Contents?: true

Size: 1.08 KB

Versions: 10

Compression:

Stored size: 1.08 KB

Contents

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
      else
        say "Error: template not found #{template_path}"
        exit 1
      end
    end

    def cs_routers
      routers = client.list_routers(status: 'Running')
      routers += client.list_routers(projectid: -1, status: 'Running')
    end

    def exit_with_failure(exception)
      say 'ERROR: command execution failed!', :red
      say "Message: ", :magenta
      say exception.message
      say "Backtrace:", :magenta
      say exception.backtrace
      exit 3
    end

    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
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
cloudstack-nagios-0.7.8 lib/cloudstack-nagios/helper.rb
cloudstack-nagios-0.7.7 lib/cloudstack-nagios/helper.rb
cloudstack-nagios-0.7.6 lib/cloudstack-nagios/helper.rb
cloudstack-nagios-0.7.5 lib/cloudstack-nagios/helper.rb
cloudstack-nagios-0.7.4 lib/cloudstack-nagios/helper.rb
cloudstack-nagios-0.7.3 lib/cloudstack-nagios/helper.rb
cloudstack-nagios-0.7.2 lib/cloudstack-nagios/helper.rb
cloudstack-nagios-0.7.1 lib/cloudstack-nagios/helper.rb
cloudstack-nagios-0.7.0 lib/cloudstack-nagios/helper.rb
cloudstack-nagios-0.6.2 lib/cloudstack-nagios/helper.rb