From 27d4db67824d5d9be8fa07ee046bb6529069bbaf Mon Sep 17 00:00:00 2001 From: Denis Knauf Date: Tue, 9 Apr 2013 21:02:17 +0200 Subject: [PATCH] perfdata_for label. Perfdata::Base.to_sym --- lib/nsca/check.rb | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/nsca/check.rb b/lib/nsca/check.rb index da57163..b6f7a33 100644 --- a/lib/nsca/check.rb +++ b/lib/nsca/check.rb @@ -24,6 +24,8 @@ module NSCA end new m end + + def to_sym() label.to_sym end end attr_reader :value @@ -94,12 +96,19 @@ module NSCA @perfdatas end + def perfdata_for label + if value.is_a? PerformanceData::Base + label + else + perfdata_label = perfdata_label.to_sym + cl = self.class.perfdatas[perfdata_label] + cl || PerformanceData::Base.new( perfdata_label) + end + end + def []= perfdata_label, value return push value if value.is_a? PerformanceData::Base - perfdata_label = perfdata_label.to_sym - cl = self.class.perfdatas[perfdata_label] - cl ||= PerformanceData::Base.new perfdata_label - @perfdatas[perfdata_label] = cl.new value + @perfdatas[perfdata_label] = perfdata_for( perfdata_label).new value end def text @@ -109,7 +118,7 @@ module NSCA end def measure perfdata_label, &block - @perfdatas[perfdata_label.to_sym].measure &block + push perfdata_for( perfdata_label).measure( &block) end def send() NSCA::send self end