Class: NSCA::Check::Base
- Inherits:
-
Object
- Object
- NSCA::Check::Base
- Defined in:
- lib/nsca/check.rb
Class Attribute Summary collapse
-
.hostname ⇒ Object
readonly
Returns the value of attribute hostname.
-
.perfdatas ⇒ Object
readonly
Returns the value of attribute perfdatas.
-
.service ⇒ Object
readonly
Returns the value of attribute service.
Instance Attribute Summary collapse
-
#perfdatas ⇒ Object
readonly
Returns the value of attribute perfdatas.
-
#return_code ⇒ Object
Returns the value of attribute return_code.
-
#status ⇒ Object
Returns the value of attribute status.
-
#timestamp ⇒ Object
Returns the value of attribute timestamp.
Class Method Summary collapse
- .clone(opts = nil) ⇒ Object
- .critical(status = nil, perfdatas = nil) ⇒ Object (also: crit)
- .init(*args) ⇒ Object
- .ok(status = nil, perfdatas = nil) ⇒ Object
- .to_a ⇒ Object
- .to_h ⇒ Object
- .to_sym ⇒ Object
- .unknown(status = nil, perfdatas = nil) ⇒ Object
- .warning(status = nil, perfdatas = nil) ⇒ Object (also: warn)
Instance Method Summary collapse
- #[](perfdata_label) ⇒ Object
- #[]=(perfdata_label, value) ⇒ Object
- #crit ⇒ Object
- #critical(*args) ⇒ Object
- #determine_return_code ⇒ Object
- #hostname ⇒ Object
- #init(return_code = nil, status = nil, perfdatas = nil, timestamp = nil) ⇒ Object
-
#initialize(return_code = nil, status = nil, perfdatas = nil, timestamp = nil) ⇒ Base
constructor
A new instance of Base.
- #measure(perfdata_label, &block) ⇒ Object
- #ok(*args) ⇒ Object
- #perfdata_for(label) ⇒ Object
- #push(*perfdatas) ⇒ Object
- #retcode ⇒ Object
- #send ⇒ Object
- #service ⇒ Object
- #text ⇒ Object
- #to_a ⇒ Object
- #to_h ⇒ Object
- #to_packet(version = nil) ⇒ Object
- #unknown(*args) ⇒ Object
- #warn ⇒ Object
- #warning(*args) ⇒ Object
Constructor Details
#initialize(return_code = nil, status = nil, perfdatas = nil, timestamp = nil) ⇒ Base
Returns a new instance of Base.
86 87 88 89 |
# File 'lib/nsca/check.rb', line 86 def initialize return_code = nil, status = nil, perfdatas = nil, = nil @perfdatas = {} init return_code, status, perfdatas, || Time.now end |
Class Attribute Details
.hostname ⇒ Object (readonly)
Returns the value of attribute hostname.
172 173 174 |
# File 'lib/nsca/check.rb', line 172 def hostname @hostname end |
.perfdatas ⇒ Object (readonly)
Returns the value of attribute perfdatas.
172 173 174 |
# File 'lib/nsca/check.rb', line 172 def perfdatas @perfdatas end |
.service ⇒ Object (readonly)
Returns the value of attribute service.
172 173 174 |
# File 'lib/nsca/check.rb', line 172 def service @service end |
Instance Attribute Details
#perfdatas ⇒ Object (readonly)
Returns the value of attribute perfdatas.
84 85 86 |
# File 'lib/nsca/check.rb', line 84 def perfdatas @perfdatas end |
#return_code ⇒ Object
Returns the value of attribute return_code.
83 84 85 |
# File 'lib/nsca/check.rb', line 83 def return_code @return_code end |
#status ⇒ Object
Returns the value of attribute status.
83 84 85 |
# File 'lib/nsca/check.rb', line 83 def status @status end |
#timestamp ⇒ Object
Returns the value of attribute timestamp.
83 84 85 |
# File 'lib/nsca/check.rb', line 83 def end |
Class Method Details
.clone(opts = nil) ⇒ Object
192 |
# File 'lib/nsca/check.rb', line 192 def clone( opts = nil) ::Class.new( self).init opts ? to_h.merge( opts) : to_h end |
.critical(status = nil, perfdatas = nil) ⇒ Object Also known as: crit
185 |
# File 'lib/nsca/check.rb', line 185 def critical( status = nil, perfdatas = nil) new.warning status, perfdatas end |
.init(*args) ⇒ Object
173 174 175 176 177 178 179 180 |
# File 'lib/nsca/check.rb', line 173 def init *args a, o = args, args.last.is_a?( Hash) ? args.pop : {} service, hostname = nil, perfdatas = nil @service, @hostname, @perfdatas = a[0]||o[:service], a[1]||o[:hostname]||`hostname`.chomp, {} perfdatas = a[2]||o[:perfdatas] perfdatas.each {|pd| @perfdatas[pd.to_sym] = pd } if perfdatas self end |
.ok(status = nil, perfdatas = nil) ⇒ Object
182 |
# File 'lib/nsca/check.rb', line 182 def ok( status = nil, perfdatas = nil) new.ok status, perfdatas end |
.to_a ⇒ Object
189 |
# File 'lib/nsca/check.rb', line 189 def to_a() [service, hostname, perfdatas.dup] end |
.to_h ⇒ Object
190 |
# File 'lib/nsca/check.rb', line 190 def to_h() {service: service, hostname: hostname, perfdatas: perfdatas.values} end |
.to_sym ⇒ Object
191 |
# File 'lib/nsca/check.rb', line 191 def to_sym() "#{hostname}|#{service}".to_sym end |
.unknown(status = nil, perfdatas = nil) ⇒ Object
187 |
# File 'lib/nsca/check.rb', line 187 def unknown( status = nil, perfdatas = nil) new.unknown status, perfdatas end |
.warning(status = nil, perfdatas = nil) ⇒ Object Also known as: warn
183 |
# File 'lib/nsca/check.rb', line 183 def warning( status = nil, perfdatas = nil) new.warning status, perfdatas end |
Instance Method Details
#[](perfdata_label) ⇒ Object
104 105 106 107 |
# File 'lib/nsca/check.rb', line 104 def [] perfdata_label pd = @perfdatas[perfdata_label.to_sym] pd && pd.value end |
#[]=(perfdata_label, value) ⇒ Object
123 124 125 126 127 |
# File 'lib/nsca/check.rb', line 123 def []= perfdata_label, value return push value if value.is_a? PerformanceData::Base perfdata_label = perfdata_label.to_sym @perfdatas[perfdata_label] = perfdata_for( perfdata_label).new value end |
#crit ⇒ Object
144 |
# File 'lib/nsca/check.rb', line 144 def critical( *args) init ReturnCode::CRITICAL, *args end |
#critical(*args) ⇒ Object
143 |
# File 'lib/nsca/check.rb', line 143 def critical( *args) init ReturnCode::CRITICAL, *args end |
#determine_return_code ⇒ Object
147 148 149 150 151 152 |
# File 'lib/nsca/check.rb', line 147 def determine_return_code self.class.perfdatas.map do |label, pdc| pd = @perfdatas[label] pd ? pd.return_code : -1 end.max end |
#hostname ⇒ Object
160 |
# File 'lib/nsca/check.rb', line 160 def hostname() self.class.hostname end |
#init(return_code = nil, status = nil, perfdatas = nil, timestamp = nil) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/nsca/check.rb', line 91 def init return_code = nil, status = nil, perfdatas = nil, = nil @return_code = return_code if return_code @status = status if status case perfdatas when Hash perfdatas.each &method( :[]) when Array push *perfdatas end = if self end |
#measure(perfdata_label, &block) ⇒ Object
135 136 137 |
# File 'lib/nsca/check.rb', line 135 def measure perfdata_label, &block push perfdata_for( perfdata_label).measure( &block) end |
#ok(*args) ⇒ Object
140 |
# File 'lib/nsca/check.rb', line 140 def ok( *args) init ReturnCode::OK, *args end |
#perfdata_for(label) ⇒ Object
114 115 116 117 118 119 120 121 |
# File 'lib/nsca/check.rb', line 114 def perfdata_for label if label.is_a? PerformanceData::Base label else label = label.to_sym self.class.perfdatas[label] || PerformanceData::Base.new( label) end end |
#push(*perfdatas) ⇒ Object
109 110 111 112 |
# File 'lib/nsca/check.rb', line 109 def push *perfdatas perfdatas.each {|perfdata| @perfdatas[perfdata.label.to_sym] = perfdata } @perfdatas end |
#retcode ⇒ Object
154 155 156 157 |
# File 'lib/nsca/check.rb', line 154 def retcode rc = return_code || determine_return_code (0..3).include?(rc) ? rc : 3 end |
#send ⇒ Object
138 |
# File 'lib/nsca/check.rb', line 138 def send() NSCA::send self end |
#service ⇒ Object
159 |
# File 'lib/nsca/check.rb', line 159 def service() self.class.service end |
#text ⇒ Object
129 130 131 132 133 |
# File 'lib/nsca/check.rb', line 129 def text r = "#{status || ReturnCode.find(retcode)}" r += " | #{perfdatas.each_value.map( &:to_s).join ' '}" unless perfdatas.empty? r end |
#to_a ⇒ Object
161 |
# File 'lib/nsca/check.rb', line 161 def to_a() [, retcode, hostname, service, text] end |
#to_h ⇒ Object
162 163 164 |
# File 'lib/nsca/check.rb', line 162 def to_h {timestamp: , return_code: retcode, hostname: hostname, server: service, status: text} end |
#to_packet(version = nil) ⇒ Object
166 167 168 169 |
# File 'lib/nsca/check.rb', line 166 def to_packet version = nil version ||= PacketV3 version.new , retcode, hostname, service, text end |
#unknown(*args) ⇒ Object
145 |
# File 'lib/nsca/check.rb', line 145 def unknown( *args) init ReturnCode::UNKNOWN, *args end |
#warn ⇒ Object
142 |
# File 'lib/nsca/check.rb', line 142 def warning( *args) init ReturnCode::WARNING, *args end |
#warning(*args) ⇒ Object
141 |
# File 'lib/nsca/check.rb', line 141 def warning( *args) init ReturnCode::WARNING, *args end |