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
readonly
Returns the value of attribute return_code.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
Class Method Summary collapse
- .critical(status = nil, perfdatas = nil) ⇒ Object (also: crit)
- .init(service, hostname = nil, perfdatas = nil) ⇒ Object
- .ok(status = nil, perfdatas = nil) ⇒ 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(status = nil, perfdatas = nil) ⇒ 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) ⇒ Base
constructor
A new instance of Base.
- #measure(perfdata_label, &block) ⇒ Object
- #ok(status = nil, perfdatas = nil) ⇒ Object
- #push(*perfdatas) ⇒ Object
- #retcode ⇒ Object
- #send ⇒ Object
- #service ⇒ Object
- #text ⇒ Object
- #unknown(status = nil, perfdatas = nil) ⇒ Object
- #warn ⇒ Object
- #warning(status = nil, perfdatas = nil) ⇒ Object
Constructor Details
#initialize(return_code = nil, status = nil, perfdatas = nil) ⇒ Base
Returns a new instance of Base.
67 68 69 70 |
# File 'lib/nsca/check.rb', line 67 def initialize return_code = nil, status = nil, perfdatas = nil @perfdatas = {} init return_code, status, perfdatas, || Time.now end |
Class Attribute Details
.hostname ⇒ Object (readonly)
Returns the value of attribute hostname.
156 157 158 |
# File 'lib/nsca/check.rb', line 156 def hostname @hostname end |
.perfdatas ⇒ Object (readonly)
Returns the value of attribute perfdatas.
156 157 158 |
# File 'lib/nsca/check.rb', line 156 def perfdatas @perfdatas end |
.service ⇒ Object (readonly)
Returns the value of attribute service.
156 157 158 |
# File 'lib/nsca/check.rb', line 156 def service @service end |
Instance Attribute Details
#perfdatas ⇒ Object (readonly)
Returns the value of attribute perfdatas.
66 67 68 |
# File 'lib/nsca/check.rb', line 66 def perfdatas @perfdatas end |
#return_code ⇒ Object (readonly)
Returns the value of attribute return_code.
66 67 68 |
# File 'lib/nsca/check.rb', line 66 def return_code @return_code end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
66 67 68 |
# File 'lib/nsca/check.rb', line 66 def status @status end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
66 67 68 |
# File 'lib/nsca/check.rb', line 66 def @timestamp end |
Class Method Details
.critical(status = nil, perfdatas = nil) ⇒ Object Also known as: crit
166 |
# File 'lib/nsca/check.rb', line 166 def critical( status = nil, perfdatas = nil) new.warning status, perfdatas end |
.init(service, hostname = nil, perfdatas = nil) ⇒ Object
157 158 159 160 161 |
# File 'lib/nsca/check.rb', line 157 def init service, hostname = nil, perfdatas = nil @service, @hostname, @perfdatas = service, hostname || `hostname -f`, {} perfdatas.each {|pd| @perfdatas[pd.label.to_sym] = pd } self end |
.ok(status = nil, perfdatas = nil) ⇒ Object
163 |
# File 'lib/nsca/check.rb', line 163 def ok( status = nil, perfdatas = nil) new.ok status, perfdatas end |
.unknown(status = nil, perfdatas = nil) ⇒ Object
168 |
# File 'lib/nsca/check.rb', line 168 def unknown( status = nil, perfdatas = nil) new.unknown status, perfdatas end |
.warning(status = nil, perfdatas = nil) ⇒ Object Also known as: warn
164 |
# File 'lib/nsca/check.rb', line 164 def warning( status = nil, perfdatas = nil) new.warning status, perfdatas end |
Instance Method Details
#[](perfdata_label) ⇒ Object
85 86 87 88 |
# File 'lib/nsca/check.rb', line 85 def [] perfdata_label pd = @perfdatas[perfdata_label.to_sym] pd && pd.value end |
#[]=(perfdata_label, value) ⇒ Object
95 96 97 98 99 100 101 |
# File 'lib/nsca/check.rb', line 95 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 end |
#crit ⇒ Object
129 130 131 132 |
# File 'lib/nsca/check.rb', line 129 def critical status = nil, perfdatas = nil init ReturnCode::CRITICAL, status, perfdatas send end |
#critical(status = nil, perfdatas = nil) ⇒ Object
125 126 127 128 |
# File 'lib/nsca/check.rb', line 125 def critical status = nil, perfdatas = nil init ReturnCode::CRITICAL, status, perfdatas send end |
#determine_return_code ⇒ Object
136 137 138 139 140 141 142 143 144 145 |
# File 'lib/nsca/check.rb', line 136 def determine_return_code self.class.perfdatas.map do |label, pdc| pd = @perfdatas[label] if pd pd.return_code else -1 end end.max end |
#hostname ⇒ Object
153 |
# File 'lib/nsca/check.rb', line 153 def hostname() self.class.hostname end |
#init(return_code = nil, status = nil, perfdatas = nil, timestamp = nil) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/nsca/check.rb', line 72 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 @timestamp = if self end |
#measure(perfdata_label, &block) ⇒ Object
109 110 111 |
# File 'lib/nsca/check.rb', line 109 def measure perfdata_label, &block @perfdatas[perfdata_label.to_sym].measure &block end |
#ok(status = nil, perfdatas = nil) ⇒ Object
114 115 116 117 |
# File 'lib/nsca/check.rb', line 114 def ok status = nil, perfdatas = nil init ReturnCode::OK, status, perfdatas send end |
#push(*perfdatas) ⇒ Object
90 91 92 93 |
# File 'lib/nsca/check.rb', line 90 def push *perfdatas perfdatas.each {|perfdata| @perfdatas[perfdata.label] = perfdata } @perfdatas end |
#retcode ⇒ Object
147 148 149 150 |
# File 'lib/nsca/check.rb', line 147 def retcode rc = return_code || determine_return_code (0..3).include?(rc) ? rc : 3 end |
#service ⇒ Object
152 |
# File 'lib/nsca/check.rb', line 152 def service() self.class.service end |
#text ⇒ Object
103 104 105 106 107 |
# File 'lib/nsca/check.rb', line 103 def text r = "#{status || ReturnCode.find(return_code)}" r += " | #{perfdatas.each_value.map( &:to_s).join ' '}" unless perfdatas.empty? r end |
#unknown(status = nil, perfdatas = nil) ⇒ Object
131 132 133 134 |
# File 'lib/nsca/check.rb', line 131 def unknown status = nil, perfdatas = nil init ReturnCode::UNKNOWN, status, perfdatas send end |
#warn ⇒ Object
123 124 125 126 |
# File 'lib/nsca/check.rb', line 123 def warning status = nil, perfdatas = nil init ReturnCode::WARNING, status, perfdatas send end |
#warning(status = nil, perfdatas = nil) ⇒ Object
119 120 121 122 |
# File 'lib/nsca/check.rb', line 119 def warning status = nil, perfdatas = nil init ReturnCode::WARNING, status, perfdatas send end |