Module: Icinga2::Tools
- Included in:
- Client
- Defined in:
- lib/icinga2/tools.rb
Overview
namespache for tools
Instance Method Summary collapse
-
#count_problems(objects, state = nil) ⇒ Integer
return count of handled problems.
-
#object_has_been_checked?(object) ⇒ Bool
returns true for the last check.
-
#parse_version(version) ⇒ String
parse version string and extract version and revision.
Instance Method Details
#count_problems(objects, state = nil) ⇒ Integer
return count of handled problems
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/icinga2/tools.rb', line 67 def count_problems( objects, state = nil ) compare_states = [] unless( state.nil? ) # 0 = "Up" or "OK" # 1 = "Down" or "Warning" # 2 = "Critical" # 3 = "Unknown" compare_states = [1, 2, 3] end compare_states.push(state) if( state.is_a?(Integer) ) objects = JSON.parse(objects) if objects.is_a?(String) f = objects.select do |t| t.dig('attrs','state') == state && \ ( !t.dig('attrs','downtime_depth').nil? && t.dig('attrs','downtime_depth').zero?) && \ ( !t.dig('attrs','acknowledgement').nil? && t.dig('attrs','acknowledgement').zero? ) end f.size end |
#object_has_been_checked?(object) ⇒ Bool
returns true for the last check
16 17 18 |
# File 'lib/icinga2/tools.rb', line 16 def object_has_been_checked?( object ) object.dig('attrs', 'last_check') > 0 end |
#parse_version(version) ⇒ String
parse version string and extract version and revision
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/icinga2/tools.rb', line 26 def parse_version( version ) # version = "v2.4.10-504-gab4ba18" # version = "v2.4.10" version_map = version.split('-', 2) version_str = version_map.first # strip v2.4.10 (default) and r2.4.10 (Debian) version_str = version_str.scan(/^[vr]+(.*)/).last.first revision = if version_map.size > 1 version_map.last else 'release' end [version_str, revision] end |