Created
February 27, 2013 03:13
-
-
Save mikehale/5044681 to your computer and use it in GitHub Desktop.
parse nagios.debug log and print start and finished times for host and service checks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'time' | |
STDOUT.sync = true | |
def time(stuff) | |
Time.at(stuff.to_f).strftime("%H:%M:%S") | |
end | |
while line = $stdin.readline | |
if line =~ /\A\[(.*?)\] \[.*?\] \[.*?\] Attempting to run scheduled check of service '([^']+)' on host '([^']+)'/ | |
puts "scheduled_at=#{time($1)} host=#{$3} service='#{$2}'" | |
elsif line =~ /\A\[(.*?)\] \[.*?\] \[.*?\] Attempting to run scheduled check of host '([^']+)'/ | |
puts "scheduled_at=#{time($1)} host=#{$2}" | |
end | |
if line =~ /\A\[(.*?)\] \[.*?\] \[.*?\]\s+HOST: (.*?), SERVICE: (.*?),.*RETURN CODE: (\d)/ | |
puts "finished_at=#{time($1)} host=#{$2} service=#{$3} return_code=#{$4}" | |
elsif line =~ /\A\[(.*?)\] \[.*?\] \[.*?\]\s+HOST: (.*?), ATTEMPT=(.*?),.*?, NEW STATE=(\d)/ | |
puts "finished_at=#{time($1)} host=#{$2} attempt=#{$3} new_state=#{$4}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment