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

Instance Method Details

#check_data(total, usage, warning, critical) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/cloudstack-nagios/helper.rb', line 40

def check_data(total, usage, warning, critical)
  usage_percent = 100.0 / total.to_f * usage.to_f

  if usage_percent.nan?
    usage_percent = 0.0
  end

  if usage_percent < warning
    code = 0
  elsif usage_percent < critical
    code = 1
  else
    code = 2
  end
  [code, usage_percent.round(0)]
end

#cs_routersObject



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

#cs_system_vmsObject



21
22
23
# File 'lib/cloudstack-nagios/helper.rb', line 21

def cs_system_vms
  vms = client.list_system_vms
end

#exit_with_failure(exception) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/cloudstack-nagios/helper.rb', line 31

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

#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_poolsObject



25
26
27
28
29
# File 'lib/cloudstack-nagios/helper.rb', line 25

def storage_pools
  storage_pools = client.list_storage_pools.select do |pool|
    pool['state'].downcase == 'up'
  end
end