deputy 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Readme.md +9 -2
- data/VERSION +1 -1
- data/bin/deputy +3 -0
- data/deputy.gemspec +1 -1
- data/lib/deputy.rb +21 -3
- data/spec/deputy_spec.rb +4 -4
- metadata +2 -2
data/Readme.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
Work in progress do not use.
|
2
2
|
|
3
|
+
Install
|
4
|
+
#######
|
3
5
|
Use with [sheriff](http://github.com/dawanda/sheriff).
|
4
6
|
|
5
7
|
sudo gem install deputy
|
@@ -7,5 +9,10 @@ Use with [sheriff](http://github.com/dawanda/sheriff).
|
|
7
9
|
Put sheriff url into `~/.deputy.yml`
|
8
10
|
sheriff_url: http://sheriff.mydomain.com
|
9
11
|
|
10
|
-
-
|
11
|
-
|
12
|
+
Add deputy to cron with deputy --install-cron (logs to /tmp/deputy.log)
|
13
|
+
|
14
|
+
Usage
|
15
|
+
#####
|
16
|
+
|
17
|
+
### Report something
|
18
|
+
deputy Cronjob.ran 1
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.4
|
data/bin/deputy
CHANGED
@@ -11,11 +11,14 @@ Report to the sheriff
|
|
11
11
|
|
12
12
|
Usage:
|
13
13
|
deputy System.metric value
|
14
|
+
deputy [OPTION]
|
14
15
|
|
15
16
|
Options:
|
16
17
|
BANNER
|
17
18
|
opts.on("-h", "--help","Show this.") { puts opts; exit }
|
18
19
|
opts.on('-v', '--version','Show Version'){ puts Deputy::VERSION; exit}
|
20
|
+
opts.on('--install-cron','Install crontask'){ Deputy.install_cron; exit}
|
21
|
+
opts.on('--run-plugins','Run all plugins for this minute (belongs into crontask)'){ Deputy.run_plugins; exit}
|
19
22
|
end.parse!
|
20
23
|
|
21
24
|
metric, value = ARGV[0..1]
|
data/deputy.gemspec
CHANGED
data/lib/deputy.rb
CHANGED
@@ -19,17 +19,35 @@ class Scout
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def self.plugins(code)
|
22
|
-
|
23
|
-
|
22
|
+
eval_and_fetch_constants(code).map do |container|
|
23
|
+
interval = container.interval
|
24
|
+
next unless plugin = plugin_in_container(container)
|
25
|
+
[interval, plugin]
|
26
|
+
end.compact
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.plugin_in_container(container)
|
30
|
+
constants = container.constants.map{|constant_name| container.const_get(constant_name)}
|
31
|
+
constants.detect do |constant|
|
32
|
+
constant.instance_methods.map{|m| m.to_sym }.include?(:build_report)
|
33
|
+
end
|
24
34
|
end
|
25
35
|
end
|
26
36
|
|
27
37
|
module Deputy
|
38
|
+
START_MINUTE = (Time.now.to_i + 30) / 60 # we could start at 58..02 seconds -> always in middle of minute
|
28
39
|
VERSION = File.read( File.join(File.dirname(__FILE__),'..','VERSION') ).strip
|
29
40
|
|
41
|
+
def self.install_cron
|
42
|
+
`crontab -l | { cat; echo "* * * * * deputy --run-plugins 2>&1 >> /tmp/deputy.log"; } | crontab -`
|
43
|
+
end
|
44
|
+
|
30
45
|
def self.run_plugins
|
31
46
|
content = get("/plugins.rb")
|
32
|
-
Scout.plugins(content).each
|
47
|
+
Scout.plugins(content).each do |interval, plugin|
|
48
|
+
run_every_n_minutes = interval/60
|
49
|
+
plugin.new.build_report if START_MINUTE % run_every_n_minutes == 0
|
50
|
+
end
|
33
51
|
end
|
34
52
|
|
35
53
|
def self.send_report(metric, value)
|
data/spec/deputy_spec.rb
CHANGED
@@ -5,13 +5,13 @@ describe Deputy do
|
|
5
5
|
Deputy::VERSION.should =~ /^\d+\.\d+\.\d+$/
|
6
6
|
end
|
7
7
|
|
8
|
-
def klass(name,
|
9
|
-
"class #{name} < Scout::Plugin; def build_report; #{code}; end; end"
|
8
|
+
def klass(name, options={})
|
9
|
+
"class TEMP_#{options[:rand]||rand(11111)};def self.interval;60;end;class #{name} < Scout::Plugin; def build_report; #{options[:code]}; end; end; end"
|
10
10
|
end
|
11
11
|
|
12
12
|
describe Scout do
|
13
13
|
it "finds plugins" do
|
14
|
-
Scout.plugins(klass('A')).inspect.should == '[A]'
|
14
|
+
Scout.plugins(klass('A', :rand => 1111)).inspect.should == '[[60, TEMP_1111::A]]'
|
15
15
|
end
|
16
16
|
|
17
17
|
it "does not show non-plugins" do
|
@@ -23,7 +23,7 @@ describe Deputy do
|
|
23
23
|
it "executes all plugins" do
|
24
24
|
$notify = 0
|
25
25
|
Deputy.stub!(:sheriff_url).and_return 'http://sheri.ff'
|
26
|
-
FakeWeb.register_uri(:get, "http://sheri.ff/plugins.rb", :body => klass('C', '$notify=1'))
|
26
|
+
FakeWeb.register_uri(:get, "http://sheri.ff/plugins.rb", :body => klass('C', :code => '$notify=1'))
|
27
27
|
Deputy.run_plugins
|
28
28
|
$notify.should == 1
|
29
29
|
end
|