Created
May 5, 2010 10:05
-
-
Save jsvd/390596 to your computer and use it in GitHub Desktop.
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
Bluepill.define_process_condition(:log_watch) do | |
def initialize(options = {}) | |
@file_name = options.delete(:file) | |
@regexp = options.delete(:regexp) | |
@file_pos = 0 | |
@file_size = 0 | |
end | |
def run(pid) | |
File.open(@file_name, "r") do |file| | |
@file_size = file.stat.size | |
@file_pos = 0 if @file_size < @file_pos # file truncated | |
file.seek @file_pos, IO::SEEK_SET | |
@file_pos = @file_size # grep will seek to end | |
file.grep(@regexp) | |
end | |
end | |
def check(value) | |
value.empty? | |
end | |
end | |
# -------------------- | |
process.checks :log_watch, :file => "file.log", :regexp => /ErrorXPTO/, :every => 60 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment