lib/nagiosharder.rb in nagiosharder-0.1.3 vs lib/nagiosharder.rb in nagiosharder-0.2.0
- old
+ new
@@ -291,41 +291,69 @@
host = last_host
end
if columns[1]
service_links = columns[1].css('td a')
+ service_link, other_links = service_links[0], service_links[1..-1]
+ if service_links.size > 1
+ comments_link = other_links.detect do |link|
+ link.attribute('href').to_s =~ /#comments$/
+ end
+ comments_url = comments_link.attribute('href').to_s if comments_link
+
+ flapping = other_links.any? do |link|
+ link.css('img').attribute('src').to_s =~ /flapping\.gif/
+ end
+
+ acknowledged = other_links.any? do |link|
+ link.css('img').attribute('src').to_s =~ /ack\.gif/
+ end
+
+ extra_service_notes_link = other_links.detect do |link|
+ link.css('img').any? do |img|
+ img.attribute('src').to_s =~ /notes\.gif/
+ end
+ end
+ extra_service_notes_url = extra_service_notes_link.attribute('href').to_s if extra_service_notes_link
+ end
+
service = service_links[0].inner_html
- acknowledged = service_links.size == 3 # acknowledged servies have a link to the service, link to comments, and a link to unacknowledge
end
status = columns[2].inner_html if columns[2]
- last_check = columns[3].inner_html if columns[3]
- duration = columns[4].inner_html if columns[4]
+ last_check = if columns[3]
+ datetime = DateTime.strptime(columns[3].inner_html, "%m-%d-%Y %H:%M:%S") rescue nil # nyoo
+ end
+ duration = columns[4].inner_html.squeeze(' ').gsub(/^ /, '') if columns[4]
started_at = if duration && match_data = duration.match(/^\s*(\d+)d\s+(\d+)h\s+(\d+)m\s+(\d+)s\s*$/)
(
match_data[1].to_i.days +
match_data[2].to_i.hours +
match_data[3].to_i.minutes +
match_data[4].to_i.seconds
).ago
-
end
attempts = columns[5].inner_html if columns[5]
status_info = columns[6].inner_html.gsub(' ', '') if columns[6]
if host && service && status && last_check && duration && attempts && started_at && status_info
service_extinfo_url = "#{extinfo_url}?type=2&host=#{host}&service=#{CGI.escape(service)}"
+ host_extinfo_url = "#{extinfo_url}?type=1&host=#{host}"
status = Hashie::Mash.new :host => host,
+ :host_extinfo_url => host_extinfo_url,
:service => service,
:status => status,
:last_check => last_check,
:duration => duration,
:attempts => attempts,
:started_at => started_at,
:extended_info => status_info,
:acknowledged => acknowledged,
- :extinfo_url => service_extinfo_url
+ :service_extinfo_url => service_extinfo_url,
+ :flapping => flapping,
+ :comments_url => comments_url,
+ :extra_service_notes_url => extra_service_notes_url
yield status
end
end
end