-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpuppet-watch.rb
executable file
·55 lines (39 loc) · 1.26 KB
/
puppet-watch.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/ruby
#http://jetpackweb.com/blog/tags/lib-notify/
#https://github.com/AhmedElGamil/puppet-growl
#gem install eventmachine em-dir-watcher rb-inotify
#apt-get install libnotify-bin
EXPIRATION_IN_SECONDS = 2
ERROR_STOCK_ICON = "gtk-dialog-error"
SUCCESS_STOCK_ICON = "gtk-dialog-info"
require 'rubygems'
require 'em-dir-watcher'
def notify stock_icon, title, message
options = "-t #{EXPIRATION_IN_SECONDS * 1000} -i #{stock_icon}"
system "notify-send #{options} '#{title}' '#{message}'"
end
def puppet_watch dir
puts "Watching #{dir}"
EM.run do
dw = EMDirWatcher.watch File.expand_path(dir), :include_only => ['*.pp'] do |paths|
paths.each do |path|
full_path = File.join(dir, path)
result = `puppet --parseonly #{full_path}`.chomp
if result.any?
notify ERROR_STOCK_ICON, "Puppet", "Syntax Problem, Manifest #{full_path}: #{result}"
else
notify SUCCESS_STOCK_ICON, "Puppet", "Manifest #{full_path}: Syntax OK"
end
end
end
end
end
if __FILE__ == $0
unless ARGV.length == 1
puts " Please specify the directory to watch"
puts " Usage: ruby puppet-watch.rb directory_to_watch"
exit
end
directory=ARGV[0]
puppet_watch "#{directory}"
end