Class: Carbios::PerfData
- Inherits:
-
Object
- Object
- Carbios::PerfData
- Includes:
- Helpers
- Defined in:
- lib/carbios/perfdata.rb
Constant Summary collapse
- SERVICEKEY =
'SERVICEPERFDATA'
- HOSTKEY =
'HOSTPERFDATA'
Instance Attribute Summary collapse
-
#hostname ⇒ Object
readonly
Returns the value of attribute hostname.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
Instance Method Summary collapse
- #has_perfdata? ⇒ Boolean
-
#initialize(checkstr, options = {}) ⇒ PerfData
constructor
A new instance of PerfData.
- #normalize_perfdata ⇒ Object
- #parse_checkdata(checkstr) ⇒ Object
- #parse_perfdata ⇒ Object
- #to_h ⇒ Object
Methods included from Helpers
Constructor Details
#initialize(checkstr, options = {}) ⇒ PerfData
Returns a new instance of PerfData.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/carbios/perfdata.rb', line 11 def initialize ( checkstr, = {} ) @prefix = [:prefix] parse_checkdata(checkstr) @time = Time.at(@checkdata['TIMET'].to_i) @hostname = Hostname.new( @checkdata['HOSTNAME'], :base_hostname => [:base_hostname] ) @desc = normalize_key(@checkdata['SERVICEDESC']) if @checkdata['SERVICEDESC'] @reverse_hostname = [:reverse_hostname] parse_perfdata end |
Instance Attribute Details
#hostname ⇒ Object (readonly)
Returns the value of attribute hostname.
6 7 8 |
# File 'lib/carbios/perfdata.rb', line 6 def hostname @hostname end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
6 7 8 |
# File 'lib/carbios/perfdata.rb', line 6 def time @time end |
Instance Method Details
#has_perfdata? ⇒ Boolean
41 42 43 |
# File 'lib/carbios/perfdata.rb', line 41 def has_perfdata? !@perfdata.empty? end |
#normalize_perfdata ⇒ Object
37 38 39 |
# File 'lib/carbios/perfdata.rb', line 37 def normalize_perfdata Hash[@perfdata.map { |k,v| [normalize_key(k), v] }] end |
#parse_checkdata(checkstr) ⇒ Object
22 23 24 |
# File 'lib/carbios/perfdata.rb', line 22 def parse_checkdata( checkstr ) @checkdata = Hash[checkstr.scan(/(.*?)::(?:(.*?)(?:\t+|$))/)] end |
#parse_perfdata ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/carbios/perfdata.rb', line 26 def parse_perfdata if @checkdata.has_key? SERVICEKEY @key = SERVICEKEY elsif @checkdata.has_key? HOSTKEY @key = HOSTKEY else raise "Cannot find #{SERVICEKEY} or #{HOSTKEY} keys" end @perfdata = Hash[@checkdata[@key].scan(/(\S+)=(-?\d+(?:\.\d+)?)\S*\s?/)] end |
#to_h ⇒ Object
45 46 47 48 49 |
# File 'lib/carbios/perfdata.rb', line 45 def to_h hostname = @reverse_hostname ? @hostname.reverse : @hostname prefix = [@prefix, hostname, @desc].compact.join('.') normalize_perfdata.prefix_keys("#{prefix}.") end |