Class: Aspera::Nagios
- Inherits:
-
Object
- Object
- Aspera::Nagios
- Defined in:
- lib/aspera/nagios.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Class Method Summary collapse
-
.process(data) ⇒ Object
process results of a analysis and display status and exit with code.
Instance Method Summary collapse
- #check_product_version(component, product, version) ⇒ Object
-
#check_time_offset(remote_date, component) ⇒ Object
comparte remote time with local time.
-
#initialize ⇒ Nagios
constructor
A new instance of Nagios.
-
#result ⇒ Object
translate for display.
Constructor Details
#initialize ⇒ Nagios
Returns a new instance of Nagios.
20 21 22 |
# File 'lib/aspera/nagios.rb', line 20 def initialize @data=[] end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
19 20 21 |
# File 'lib/aspera/nagios.rb', line 19 def data @data end |
Class Method Details
.process(data) ⇒ Object
process results of a analysis and display status and exit with code
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/aspera/nagios.rb', line 53 def self.process(data) raise "INTERNAL ERROR, result must be list and not empty" unless data.is_a?(Array) and !data.empty? ['status','component','message'].each{|c|raise "INTERNAL ERROR, result must have #{c}" unless data.first.has_key?(c)} res_errors = data.select{|s|!s['status'].eql?('ok')} # keep only errors in case of problem, other ok are assumed so data = res_errors unless res_errors.empty? # first is most critical data.sort!{|a,b|LEVELS.index(a['status'].to_sym)<=>LEVELS.index(b['status'].to_sym)} # build message: if multiple components: concatenate #message = data.map{|i|"#{i['component']}:#{i['message']}"}.join(', ').gsub("\n",' ') = data.map{|i|i['component']}.uniq.map{|comp|comp+':'+data.select{|d|d['component'].eql?(comp)}.map{|d|d['message']}.join(',')}.join(', ').gsub("\n",' ') status=data.first['status'].upcase # display status for nagios puts("#{status} - [#{}]\n") # provide exit code to nagios Process.exit(LEVELS.index(data.first['status'].to_sym)) end |
Instance Method Details
#check_product_version(component, product, version) ⇒ Object
41 42 43 44 |
# File 'lib/aspera/nagios.rb', line 41 def check_product_version( component, product, version ) add_ok(component,"version #{version}") # TODO check on database if latest version end |
#check_time_offset(remote_date, component) ⇒ Object
comparte remote time with local time
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/aspera/nagios.rb', line 25 def check_time_offset( remote_date, component ) # check date if specified : 2015-10-13T07:32:01Z rtime = DateTime.strptime(remote_date) diff_time = (rtime - DateTime.now).abs diff_disp=diff_time.round(-2) Log.log.debug("DATE: #{remote_date} #{rtime} diff=#{diff_disp}") msg="offset #{diff_disp} sec" if diff_time >= DATE_CRIT_OFFSET add_critical(component,msg) elsif diff_time >= DATE_WARN_OFFSET add_warning(component,msg) else add_ok(component,msg) end end |
#result ⇒ Object
translate for display
47 48 49 50 |
# File 'lib/aspera/nagios.rb', line 47 def result raise "missing result" if @data.empty? {:type=>:object_list,:data=>@data.map{|i|{'status'=>LEVELS[i[:code]].to_s,'component'=>i[:comp],'message'=>i[:msg]}}} end |