Class: Nagios::Splunk::Check
- Inherits:
-
Object
- Object
- Nagios::Splunk::Check
- Defined in:
- lib/nagios/splunk/check.rb
Overview
Nagios::Splunk::Check implements different types of checks of
Instance Attribute Summary collapse
-
#rest_client ⇒ Object
readonly
Returns the value of attribute rest_client.
Instance Method Summary collapse
- #cluster_bundle_status ⇒ Object
- #cluster_replication_factor ⇒ Object
- #cluster_search_factor ⇒ Object
-
#initialize(client) ⇒ Check
constructor
example: user:pass@localhost:8089/.
-
#license_usage(warn, crit, stack_id = "enterprise") ⇒ Array<Integer, String>
license usage check.
- #localslave(warn, crit) ⇒ Object
-
#pool_usage(name, warn, crit) ⇒ Array<Integer, String>
pool usage check.
Constructor Details
#initialize(client) ⇒ Check
example: user:pass@localhost:8089/
14 15 16 |
# File 'lib/nagios/splunk/check.rb', line 14 def initialize(client) @rest_client = client end |
Instance Attribute Details
#rest_client ⇒ Object (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_status ⇒ Object
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_factor ⇒ Object
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_factor ⇒ Object
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
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) = "License #{STATUS[code]}: #{used_quota * 100 / quota}% of license capacity is used" << " | quota: #{quota} B; used: #{used_quota} B" return [code, ] 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 = "License slave #{result['license']['slave_label']} #{STATUS[code]}" << " | 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, ] end |
#pool_usage(name, warn, crit) ⇒ Array<Integer, String>
pool usage check
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) = "License pool '#{name}' #{STATUS[code]}: #{used_quota * 100 / quota}% of license pool capacity is used" << " | quota: #{quota} B; used: #{used_quota} B" return [code, ] end |