Class: Nagios::Splunk::Check

Inherits:
Object
  • Object
show all
Defined in:
lib/nagios/splunk/check.rb

Overview

Nagios::Splunk::Check implements different types of checks of

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Check

Parameters:

  • server_url (String)

    full server url with username and password (RFC 3986)



14
15
16
# File 'lib/nagios/splunk/check.rb', line 14

def initialize(client)
  @rest_client = client
end

Instance Attribute Details

#rest_clientObject (readonly)

Returns the value of attribute rest_client.



10
11
12
# File 'lib/nagios/splunk/check.rb', line 10

def rest_client
  @rest_client
end

Instance Method Details

#cluster_bundle_statusObject



66
67
68
69
70
71
72
# File 'lib/nagios/splunk/check.rb', line 66

def cluster_bundle_status
  splunk = Splunk.new(rest_client)
  info = splunk.cluster_master_info
  errors = info.xpath("//s:key[@name='bundle_validation_errors_on_master']//s:item").map { |n| n.text.chomp }
  code = (errors.empty? ? 0 : 1)
  return [code, "Splunk cluster bundle status is #{STATUS[code]} | #{errors.join("\n")}"]
end

#cluster_replication_factorObject



74
75
76
77
78
79
# File 'lib/nagios/splunk/check.rb', line 74

def cluster_replication_factor
  splunk = Splunk.new(rest_client)
  info = splunk.cluster_master_generation
  code = info.xpath("//s:key[@name='replication_factor_met']").text.to_i
  return [code == 1 ? 0 : 1, "Splunk cluster replication factor is #{code == 1 ? "met" : "not met"}"]
end

#cluster_search_factorObject



81
82
83
84
85
86
# File 'lib/nagios/splunk/check.rb', line 81

def cluster_search_factor
  splunk = Splunk.new(rest_client)
  info = splunk.cluster_master_generation
  code = info.xpath("//s:key[@name='search_factor_met']").text.to_i
  return [code == 1 ? 0 : 1, "Splunk cluster search factor is #{code == 1 ? "met" : "not met"}"]
end

#license_usage(warn, crit, stack_id = "enterprise") ⇒ Array<Integer, String>

license usage check

Parameters:

  • warn (Integer)

    license usage threshhold

  • crit (Integer)

    license usage threshhold

  • stack_id (String) (defaults to: "enterprise")

Returns:

  • (Array<Integer, String>)

    exit code and message



55
56
57
58
59
60
61
62
63
64
# File 'lib/nagios/splunk/check.rb', line 55

def license_usage(warn, crit, stack_id = "enterprise")
  quota = license_quota(stack_id)
  used_quota = pools_in_stack_usage(stack_id)

  code = check_threshold(used_quota, quota, warn, crit)

  message = "License #{STATUS[code]}: #{used_quota * 100 / quota}% of license capacity is used"
  message << " | quota: #{quota} B; used: #{used_quota} B"
  return [code, message]
end

#localslave(warn, crit) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/nagios/splunk/check.rb', line 18

def localslave(warn, crit)
  response = rest_client.get(LICENSE_LOCALSLAVE_URL)
  result = response.code == "200" ? parse_data(response.body) : {}
  last_success_ago = Time.now - result['license']['last_master_contact_success_time'].to_i
  code = case true
         when last_success_ago.to_i > crit.to_i then 2
         when last_success_ago.to_i > warn.to_i then 1
         else 0
         end
  message = "License slave #{result['license']['slave_label']} #{STATUS[code]}"
  message << " | last_master_contact_attempt_time: #{result['license']['last_master_contact_attempt_time']}; last_master_contact_success_time: #{result['license']['last_master_contact_success_time']}"
  return [code, message]
end

#pool_usage(name, warn, crit) ⇒ Array<Integer, String>

pool usage check

Parameters:

  • name (String)

    of the pool

  • warn (Integer)

    license usage threshhold

  • crit (Integer)

    license usage threshhold

  • stack_id (String)

    which pool is assigned to

Returns:

  • (Array<Integer, String>)

    exit code and message



39
40
41
42
43
44
45
46
47
48
# File 'lib/nagios/splunk/check.rb', line 39

def pool_usage(name, warn, crit)
  quota = pool_quota(name)
  used_quota = find_pool_by_name(name)["used_bytes"].to_i

  code = check_threshold(used_quota, quota, warn, crit)

  message = "License pool '#{name}' #{STATUS[code]}: #{used_quota * 100 / quota}% of license pool capacity is used"
  message << " | quota: #{quota} B; used: #{used_quota} B"
  return [code, message]
end