Skip to content

Instantly share code, notes, and snippets.

@kplawver
Created December 7, 2010 15:00
Show Gist options
  • Save kplawver/731861 to your computer and use it in GitHub Desktop.
Save kplawver/731861 to your computer and use it in GitHub Desktop.
A super simple Scout plugin to monitor just the existence of a file. We're using it to alert us when an NFS share goes down (if it times out, it's down).
class FileCheckPlugin < Scout::Plugin
OPTIONS=<<-EOS
file:
default: ~
name: File
notes: The file to check to make sure it exists.
EOS
def build_report
timed_out = false
exists = false
file = option(:file) || "/tmp"
begin
timeout(5) do
exists = File.exists?(file)
end
rescue Exception => e
timed_out = true
alert('File Check Failed With Timeout!','Checking for file existance timed out. That may mean indicate a problem with the filesystem.')
else
if !exists
alert("File Does Not Exist!", "File #{file} does not exist. That's a bad thing, right?")
end
end
report(:exists => exists.to_s, :timed_out => timed_out.to_s)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment