Sha256: f80a04dd53609f040abef52045fb7de312110dfdd3a6d1f81363a107dd05dc51

Contents?: true

Size: 1.24 KB

Versions: 21

Compression:

Stored size: 1.24 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 \"#{template_path}\" not found.", :red
        exit 1
      end
    end

    def cs_routers
      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| 
        pool['state'].downcase == 'up'
      end
    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

21 entries across 21 versions & 1 rubygems

Version Path
cloudstack-nagios-0.14.1 lib/cloudstack-nagios/helper.rb
cloudstack-nagios-0.14.0 lib/cloudstack-nagios/helper.rb
cloudstack-nagios-0.13.0 lib/cloudstack-nagios/helper.rb
cloudstack-nagios-0.12.3 lib/cloudstack-nagios/helper.rb
cloudstack-nagios-0.12.2 lib/cloudstack-nagios/helper.rb
cloudstack-nagios-0.12.1 lib/cloudstack-nagios/helper.rb
cloudstack-nagios-0.12.0 lib/cloudstack-nagios/helper.rb
cloudstack-nagios-0.11.4 lib/cloudstack-nagios/helper.rb
cloudstack-nagios-0.11.3 lib/cloudstack-nagios/helper.rb
cloudstack-nagios-0.11.2 lib/cloudstack-nagios/helper.rb
cloudstack-nagios-0.11.1 lib/cloudstack-nagios/helper.rb
cloudstack-nagios-0.11.0 lib/cloudstack-nagios/helper.rb
cloudstack-nagios-0.10.3 lib/cloudstack-nagios/helper.rb
cloudstack-nagios-0.10.2 lib/cloudstack-nagios/helper.rb
cloudstack-nagios-0.10.1 lib/cloudstack-nagios/helper.rb
cloudstack-nagios-0.10.0 lib/cloudstack-nagios/helper.rb
cloudstack-nagios-0.9.1 lib/cloudstack-nagios/helper.rb
cloudstack-nagios-0.9.0 lib/cloudstack-nagios/helper.rb
cloudstack-nagios-0.8.2 lib/cloudstack-nagios/helper.rb
cloudstack-nagios-0.8.1 lib/cloudstack-nagios/helper.rb