flapjack 0.9.6 → 1.0.0rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.rspec +6 -0
- data/.travis.yml +20 -16
- data/CHANGELOG.md +11 -25
- data/Dockerfile +8 -0
- data/Gemfile +2 -5
- data/bin/flapjack +24 -213
- data/etc/flapjack_config.yaml.example +6 -30
- data/features/cli.feature +16 -14
- data/features/cli_flapjack-feed-events.feature +12 -13
- data/features/cli_flapjack-nagios-receiver.feature +14 -15
- data/features/cli_flapjack-populator.feature +16 -15
- data/features/cli_flapper.feature +12 -12
- data/features/cli_receive-events.feature +6 -5
- data/features/cli_simulate-failed-check.feature +7 -6
- data/features/steps/cli_steps.rb +2 -2
- data/features/support/env.rb +1 -0
- data/flapjack.gemspec +1 -0
- data/lib/flapjack/cli/flapper.rb +200 -0
- data/lib/flapjack/cli/import.rb +102 -0
- data/lib/flapjack/cli/receiver.rb +656 -0
- data/lib/flapjack/cli/server.rb +256 -0
- data/lib/flapjack/cli/simulate.rb +180 -0
- data/lib/flapjack/configuration.rb +2 -0
- data/lib/flapjack/data/entity_check.rb +5 -22
- data/lib/flapjack/data/event.rb +7 -12
- data/lib/flapjack/gateways/email.rb +4 -1
- data/lib/flapjack/gateways/jabber.rb +12 -36
- data/lib/flapjack/gateways/jsonapi/check_presenter.rb +6 -6
- data/lib/flapjack/gateways/jsonapi/report_methods.rb +5 -3
- data/lib/flapjack/gateways/pagerduty.rb +1 -1
- data/lib/flapjack/gateways/web/public/js/backbone.jsonapi.js +1 -1
- data/lib/flapjack/gateways/web/public/js/modules/contact.js +2 -2
- data/lib/flapjack/gateways/web/public/js/modules/entity.js +2 -2
- data/lib/flapjack/gateways/web/public/js/modules/medium.js +4 -4
- data/lib/flapjack/gateways/web/public/js/self_stats.js +1 -1
- data/lib/flapjack/gateways/web/views/check.html.erb +7 -7
- data/lib/flapjack/gateways/web/views/checks.html.erb +2 -3
- data/lib/flapjack/gateways/web/views/contact.html.erb +4 -4
- data/lib/flapjack/gateways/web/views/contacts.html.erb +2 -2
- data/lib/flapjack/gateways/web/views/edit_contacts.html.erb +1 -1
- data/lib/flapjack/gateways/web/views/entities.html.erb +1 -1
- data/lib/flapjack/gateways/web/views/entity.html.erb +1 -1
- data/lib/flapjack/gateways/web/views/index.html.erb +2 -2
- data/lib/flapjack/gateways/web/views/layout.erb +10 -10
- data/lib/flapjack/gateways/web/views/self_stats.html.erb +1 -1
- data/lib/flapjack/gateways/web.rb +36 -7
- data/lib/flapjack/pikelet.rb +0 -2
- data/lib/flapjack/processor.rb +3 -1
- data/lib/flapjack/redis_pool.rb +2 -6
- data/lib/flapjack/version.rb +1 -1
- data/spec/lib/flapjack/coordinator_spec.rb +3 -3
- data/spec/lib/flapjack/data/entity_check_spec.rb +2 -6
- data/spec/lib/flapjack/data/event_spec.rb +0 -31
- data/spec/lib/flapjack/gateways/email_spec.rb +109 -0
- data/spec/lib/flapjack/gateways/jabber_spec.rb +18 -16
- data/spec/lib/flapjack/gateways/jsonapi/check_presenter_spec.rb +12 -24
- data/spec/lib/flapjack/gateways/pagerduty_spec.rb +1 -1
- data/spec/lib/flapjack/gateways/web/views/check.html.erb_spec.rb +2 -0
- data/spec/lib/flapjack/gateways/web/views/contact.html.erb_spec.rb +2 -0
- data/spec/lib/flapjack/gateways/web/views/index.html.erb_spec.rb +2 -0
- data/spec/lib/flapjack/gateways/web_spec.rb +194 -145
- data/spec/lib/flapjack/redis_pool_spec.rb +0 -1
- data/spec/support/profile_all_formatter.rb +44 -0
- data/spec/support/uncolored_doc_formatter.rb +9 -0
- data/tasks/benchmarks.rake +0 -4
- metadata +28 -38
- data/.ruby-version +0 -1
- data/Gemfile-ruby1.9 +0 -28
- data/Gemfile-ruby1.9.lock +0 -227
- data/bin/flapjack-feed-events +0 -124
- data/bin/flapjack-nagios-receiver +0 -246
- data/bin/flapjack-nsca-receiver +0 -246
- data/bin/flapjack-populator +0 -132
- data/bin/flapper +0 -152
- data/bin/receive-events +0 -179
- data/bin/simulate-failed-check +0 -151
- data/lib/flapjack/data/migration.rb +0 -36
- data/lib/flapjack/gateways/api/contact_methods.rb +0 -369
- data/lib/flapjack/gateways/api/entity_check_presenter.rb +0 -218
- data/lib/flapjack/gateways/api/entity_methods.rb +0 -361
- data/lib/flapjack/gateways/api/entity_presenter.rb +0 -75
- data/lib/flapjack/gateways/api/rack/json_params_parser.rb +0 -26
- data/lib/flapjack/gateways/api.rb +0 -124
- data/spec/lib/flapjack/gateways/api/contact_methods_spec.rb +0 -772
- data/spec/lib/flapjack/gateways/api/entity_check_presenter_spec.rb +0 -211
- data/spec/lib/flapjack/gateways/api/entity_methods_spec.rb +0 -863
- data/spec/lib/flapjack/gateways/api/entity_presenter_spec.rb +0 -108
- data/spec/lib/flapjack/gateways/api_spec.rb +0 -30
@@ -26,42 +26,41 @@ test:
|
|
26
26
|
"""
|
27
27
|
|
28
28
|
Scenario: Running with --help shows usage information
|
29
|
-
When I run `bin/flapjack
|
29
|
+
When I run `bundle exec bin/flapjack receiver nagios --help`
|
30
30
|
Then the exit status should be 0
|
31
|
-
And the output should contain "
|
32
|
-
And the output should contain "
|
33
|
-
And the output should contain "Required Nagios Configuration Changes"
|
31
|
+
And the output should contain "[-f arg|--fifo arg]"
|
32
|
+
And the output should contain "receiver nagios start [-d|--daemonize]"
|
34
33
|
|
35
34
|
Scenario: Starting flapjack-nagios-receiver
|
36
|
-
When I start flapjack-nagios-receiver with `flapjack-
|
35
|
+
When I start flapjack-nagios-receiver (via bundle exec) with `flapjack -n test --config tmp/cucumber_cli/flapjack-nagios-receiver.yaml receiver start --no-daemonize`
|
37
36
|
Then flapjack-nagios-receiver should start within 15 seconds
|
38
37
|
|
39
38
|
Scenario: Stopping flapjack-nagios-receiver via SIGINT
|
40
|
-
When I start flapjack-nagios-receiver with `flapjack-
|
39
|
+
When I start flapjack-nagios-receiver (via bundle exec) with `flapjack -n test --config tmp/cucumber_cli/flapjack-nagios-receiver.yaml receiver nagios start --no-daemonize`
|
41
40
|
Then flapjack-nagios-receiver should start within 15 seconds
|
42
41
|
When I send a SIGINT to the flapjack-nagios-receiver process
|
43
42
|
Then flapjack-nagios-receiver should stop within 15 seconds
|
44
43
|
|
45
44
|
Scenario: Starting, status, and stopping flapjack-nagios-receiver, daemonized
|
46
|
-
When I start flapjack-nagios-receiver (daemonised) with `flapjack-
|
45
|
+
When I start flapjack-nagios-receiver (daemonised) (via bundle exec) with `flapjack -n test --config tmp/cucumber_cli/flapjack-nagios-receiver_d.yaml receiver nagios start -d`
|
47
46
|
Then flapjack-nagios-receiver should start within 15 seconds
|
48
|
-
When I run `bin/flapjack-
|
47
|
+
When I run `bundle exec bin/flapjack -n test --config tmp/cucumber_cli/flapjack-nagios-receiver_d.yaml receiver nagios status`
|
49
48
|
Then the exit status should be 0
|
50
|
-
And the output should contain "
|
51
|
-
When I stop flapjack-nagios-receiver with `flapjack-
|
49
|
+
And the output should contain "nagios-receiver is running"
|
50
|
+
When I stop flapjack-nagios-receiver (via bundle exec) with `flapjack -n test --config tmp/cucumber_cli/flapjack-nagios-receiver_d.yaml receiver nagios stop`
|
52
51
|
Then flapjack-nagios-receiver should stop within 15 seconds
|
53
52
|
|
54
53
|
Scenario: Starting, restarting and stopping flapjack-nagios-receiver, daemonized
|
55
|
-
When I start flapjack-nagios-receiver (daemonised) with `flapjack-
|
54
|
+
When I start flapjack-nagios-receiver (daemonised) (via bundle exec) with `flapjack -n test --config tmp/cucumber_cli/flapjack-nagios-receiver_d.yaml receiver nagios start -d`
|
56
55
|
Then flapjack-nagios-receiver should start within 15 seconds
|
57
|
-
When I restart flapjack-nagios-receiver (daemonised) with `flapjack-
|
56
|
+
When I restart flapjack-nagios-receiver (daemonised) (via bundle exec) with `flapjack -n test --config tmp/cucumber_cli/flapjack-nagios-receiver_d.yaml receiver nagios restart`
|
58
57
|
Then flapjack-nagios-receiver should restart within 15 seconds
|
59
|
-
When I stop flapjack-nagios-receiver with `flapjack-
|
58
|
+
When I stop flapjack-nagios-receiver (via bundle exec) with `flapjack -n test --config tmp/cucumber_cli/flapjack-nagios-receiver_d.yaml receiver nagios stop`
|
60
59
|
Then flapjack-nagios-receiver should stop within 15 seconds
|
61
60
|
|
62
61
|
Scenario: Getting status when stopped
|
63
|
-
When I run `bin/flapjack-
|
62
|
+
When I run `bundle exec bin/flapjack -n test --config tmp/cucumber_cli/flapjack-nagios-receiver_d.yaml receiver nagios status`
|
64
63
|
Then the exit status should not be 0
|
65
|
-
And the output should contain "
|
64
|
+
And the output should contain "nagios-receiver is not running"
|
66
65
|
|
67
66
|
|
@@ -10,6 +10,7 @@ Feature: flapjack-populator command line
|
|
10
10
|
test:
|
11
11
|
redis:
|
12
12
|
db: 14
|
13
|
+
driver: ruby
|
13
14
|
"""
|
14
15
|
And a file named "flapjack-populator-contacts.json" with:
|
15
16
|
"""
|
@@ -58,32 +59,32 @@ test:
|
|
58
59
|
"""
|
59
60
|
|
60
61
|
Scenario: Running with --help shows usage information
|
61
|
-
When I run `bin/flapjack
|
62
|
+
When I run `bundle exec bin/flapjack import --help`
|
62
63
|
Then the exit status should be 0
|
63
|
-
And the output should contain "
|
64
|
-
And the output should contain "import
|
65
|
-
And the output should contain "import
|
66
|
-
And the output should contain "
|
64
|
+
And the output should contain "Bulk import data from an external source"
|
65
|
+
And the output should contain "import contacts"
|
66
|
+
And the output should contain "import entities"
|
67
|
+
And the output should contain "[-f arg|--from arg]"
|
67
68
|
|
68
69
|
Scenario: Running flapjack-populator with no arguments exits uncleanly and shows usage
|
69
|
-
When I run `bin/flapjack
|
70
|
+
When I run `bundle exec bin/flapjack import`
|
70
71
|
Then the exit status should not be 0
|
71
|
-
And the output should contain "
|
72
|
+
And the output should contain "Bulk import data from an external source"
|
72
73
|
|
73
74
|
Scenario: Importing contacts
|
74
|
-
When I run `bin/flapjack
|
75
|
+
When I run `bundle exec bin/flapjack -n test --config tmp/cucumber_cli/flapjack-populator.yaml import contacts --from tmp/cucumber_cli/flapjack-populator-contacts.json`
|
75
76
|
Then the exit status should be 0
|
76
77
|
|
77
78
|
Scenario: Importing entities
|
78
|
-
When I run `bin/flapjack
|
79
|
+
When I run `bundle exec bin/flapjack -n test --config tmp/cucumber_cli/flapjack-populator.yaml import entities --from tmp/cucumber_cli/flapjack-populator-entities.json`
|
79
80
|
Then the exit status should be 0
|
80
81
|
|
81
82
|
Scenario Outline: Running an flapjack-populator import command with a missing '--from' exits uncleanly and shows usage
|
82
|
-
When I run `bin/flapjack-
|
83
|
+
When I run `bundle exec bin/flapjack -n test --config tmp/cucumber_cli/flapjack-populator.yaml import <Type> example.json`
|
83
84
|
Then the exit status should not be 0
|
84
|
-
And the output should contain "
|
85
|
-
And the output should contain "
|
85
|
+
And the output should contain "error: f is required"
|
86
|
+
And the output should contain "Bulk import data from an external source"
|
86
87
|
Examples:
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
88
|
+
| Type |
|
89
|
+
| entities |
|
90
|
+
| contacts |
|
@@ -5,40 +5,40 @@ Feature: Flapper command line
|
|
5
5
|
From the command line
|
6
6
|
|
7
7
|
Scenario: Running with --help shows usage information
|
8
|
-
When I run `bin/flapper --help`
|
8
|
+
When I run `bundle exec bin/flapjack flapper --help`
|
9
9
|
Then the exit status should be 0
|
10
|
-
And the output should contain "
|
11
|
-
And the output should contain "-b
|
10
|
+
And the output should contain "Artificial service that oscillates up and down"
|
11
|
+
And the output should contain "[-b arg|--bind-ip arg]"
|
12
12
|
|
13
13
|
Scenario: Starting flapper
|
14
|
-
When I start flapper with `flapper start --no-daemonize`
|
14
|
+
When I start flapper (via bundle exec) with `flapjack flapper start --no-daemonize`
|
15
15
|
Then flapper should start within 15 seconds
|
16
16
|
|
17
17
|
Scenario: Stopping flapper via SIGINT
|
18
|
-
When I start flapper with `flapper start --no-daemonize`
|
18
|
+
When I start flapper (via bundle exec) with `flapjack flapper start --no-daemonize`
|
19
19
|
Then flapper should start within 15 seconds
|
20
20
|
When I send a SIGINT to the flapper process
|
21
21
|
Then flapper should stop within 15 seconds
|
22
22
|
|
23
23
|
Scenario: Starting, status, and stopping flapper, daemonized
|
24
|
-
When I start flapper (daemonised) with `flapper start -d -p tmp/cucumber_cli/flapper_d.pid -l tmp/cucumber_cli/flapper_d.log`
|
24
|
+
When I start flapper (daemonised) (via bundle exec) with `flapjack flapper start -d -p tmp/cucumber_cli/flapper_d.pid -l tmp/cucumber_cli/flapper_d.log`
|
25
25
|
Then flapper should start within 15 seconds
|
26
|
-
When I run `bin/flapper status -p tmp/cucumber_cli/flapper_d.pid`
|
26
|
+
When I run `bundle exec bin/flapjack flapper status -p tmp/cucumber_cli/flapper_d.pid`
|
27
27
|
Then the exit status should be 0
|
28
28
|
And the output should contain "flapper is running"
|
29
|
-
When I stop flapper with `flapper stop -p tmp/cucumber_cli/flapper_d.pid`
|
29
|
+
When I stop flapper (via bundle exec) with `flapjack flapper stop -p tmp/cucumber_cli/flapper_d.pid`
|
30
30
|
Then flapper should stop within 15 seconds
|
31
31
|
|
32
32
|
Scenario: Starting, restarting and stopping flapper, daemonized
|
33
|
-
When I start flapper (daemonised) with `flapper start -d -p tmp/cucumber_cli/flapper_d.pid -l tmp/cucumber_cli/flapper_d.log`
|
33
|
+
When I start flapper (daemonised) (via bundle exec) with `flapjack flapper start -d -p tmp/cucumber_cli/flapper_d.pid -l tmp/cucumber_cli/flapper_d.log`
|
34
34
|
Then flapper should start within 15 seconds
|
35
|
-
When I restart flapper (daemonised) with `flapper restart -
|
35
|
+
When I restart flapper (daemonised) (via bundle exec) with `flapjack flapper restart -p tmp/cucumber_cli/flapper_d.pid -l tmp/cucumber_cli/flapper_d.log`
|
36
36
|
Then flapper should restart within 15 seconds
|
37
|
-
When I stop flapper with `flapper stop -p tmp/cucumber_cli/flapper_d.pid`
|
37
|
+
When I stop flapper (via bundle exec) with `flapjack flapper stop -p tmp/cucumber_cli/flapper_d.pid`
|
38
38
|
Then flapper should stop within 15 seconds
|
39
39
|
|
40
40
|
Scenario: Getting status when stopped
|
41
|
-
When I run `bin/flapper status -p tmp/cucumber_cli/flapper_d.pid`
|
41
|
+
When I run `bundle exec bin/flapjack flapper status -p tmp/cucumber_cli/flapper_d.pid`
|
42
42
|
Then the exit status should not be 0
|
43
43
|
And the output should contain "flapper is not running"
|
44
44
|
|
@@ -10,18 +10,19 @@ Feature: receive-events command line
|
|
10
10
|
test:
|
11
11
|
redis:
|
12
12
|
db: 14
|
13
|
+
driver: ruby
|
13
14
|
"""
|
14
15
|
|
15
16
|
Scenario: Running with --help shows usage information
|
16
|
-
When I run `bin/
|
17
|
+
When I run `bundle exec bin/flapjack -n test receiver mirror --help`
|
17
18
|
Then the exit status should be 0
|
18
|
-
And the output should contain "
|
19
|
-
And the output should contain "-s, --source
|
19
|
+
And the output should contain "replay the last COUNT events from the source"
|
20
|
+
And the output should contain "-s, --source=arg"
|
20
21
|
|
21
22
|
Scenario: Running receive-events with no arguments exits uncleanly and shows usage
|
22
|
-
When I run `bin/
|
23
|
+
When I run `bundle exec bin/flapjack -n test receiver mirror`
|
23
24
|
Then the exit status should not be 0
|
24
|
-
And the output should contain "
|
25
|
+
And the output should contain "error: s is required"
|
25
26
|
|
26
27
|
#TODO: put some archived events into a separate redis db and then run receive-events to suck them up
|
27
28
|
|
@@ -10,21 +10,22 @@ Feature: simulate-failed-check command line
|
|
10
10
|
test:
|
11
11
|
redis:
|
12
12
|
db: 14
|
13
|
+
driver: ruby
|
13
14
|
"""
|
14
15
|
|
15
16
|
Scenario: Running with --help shows usage information
|
16
|
-
When I run `bin/simulate
|
17
|
+
When I run `bundle exec bin/flapjack simulate --help`
|
17
18
|
Then the exit status should be 0
|
18
|
-
And the output should contain "
|
19
|
-
And the output should contain "-k
|
19
|
+
And the output should contain "Generate streams of events in various states"
|
20
|
+
And the output should contain "-k arg|--check arg"
|
20
21
|
|
21
22
|
Scenario: Running simulate-failed-check with no arguments exits uncleanly and shows usage
|
22
|
-
When I run `bin/simulate
|
23
|
+
When I run `bundle exec bin/flapjack simulate`
|
23
24
|
Then the exit status should not be 0
|
24
|
-
And the output should contain "
|
25
|
+
And the output should contain "Generate streams of events in various states"
|
25
26
|
|
26
27
|
Scenario: Simulate a failed check
|
27
|
-
When I run `bin/
|
28
|
+
When I run `bundle exec bin/flapjack -n test -c tmp/cucumber_cli/simulate-failed-check.yaml simulate fail -t 0 -i 0.1 -e 'test' -k 'PING'`
|
28
29
|
Then the exit status should be 0
|
29
30
|
And the output should contain "sending failure event"
|
30
31
|
And the output should contain "stopping"
|
data/features/steps/cli_steps.rb
CHANGED
@@ -11,12 +11,12 @@ Given /^a fifo named "([^"]*)" exists$/ do |fifo_name|
|
|
11
11
|
create_fifo(fifo_name)
|
12
12
|
end
|
13
13
|
|
14
|
-
When /^I ((?:re)?start|stop) (\S+)( \(daemonised\))? with `(.+)`$/ do |start_stop_restart, exe, daemonise, cmd|
|
14
|
+
When /^I ((?:re)?start|stop) (\S+)( \(daemonised\))?( \(via bundle exec\))? with `(.+)`$/ do |start_stop_restart, exe, daemonise, bundle_exec, cmd|
|
15
15
|
@daemons_output ||= []
|
16
16
|
@daemons_exit_status ||= []
|
17
17
|
|
18
18
|
@root = Pathname.new(File.dirname(__FILE__)).parent.parent.expand_path
|
19
|
-
command = "#{@root.join('bin')}/#{cmd}"
|
19
|
+
command = "#{bundle_exec ? 'bundle exec ' : ''}#{@root.join('bin')}/#{cmd}"
|
20
20
|
|
21
21
|
# enable debugging output from spawn_process etc
|
22
22
|
#@debug = true
|
data/features/support/env.rb
CHANGED
@@ -203,6 +203,7 @@ After('@process') do
|
|
203
203
|
'tmp/cucumber_cli/flapper_d.log',
|
204
204
|
'tmp/cucumber_cli/flapjack-populator.yaml',
|
205
205
|
'tmp/cucumber_cli/flapjack-populator-contacts.json',
|
206
|
+
'tmp/cucumber_cli/flapjack-populator-entities.json',
|
206
207
|
].each do |file|
|
207
208
|
next unless File.exists?(file)
|
208
209
|
File.unlink(file)
|
data/flapjack.gemspec
CHANGED
@@ -0,0 +1,200 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'eventmachine'
|
4
|
+
require 'socket'
|
5
|
+
require 'dante'
|
6
|
+
|
7
|
+
module Flapjack
|
8
|
+
module CLI
|
9
|
+
class Flapper
|
10
|
+
|
11
|
+
def self.local_ip
|
12
|
+
# turn off reverse DNS resolution temporarily
|
13
|
+
orig, Socket.do_not_reverse_lookup = Socket.do_not_reverse_lookup, true
|
14
|
+
|
15
|
+
UDPSocket.open do |s|
|
16
|
+
s.connect '64.233.187.99', 1
|
17
|
+
s.addr.last
|
18
|
+
end
|
19
|
+
ensure
|
20
|
+
Socket.do_not_reverse_lookup = orig
|
21
|
+
end
|
22
|
+
|
23
|
+
def initialize(global_options, options)
|
24
|
+
@global_options = global_options
|
25
|
+
@options = options
|
26
|
+
end
|
27
|
+
|
28
|
+
def start
|
29
|
+
if runner.daemon_running?
|
30
|
+
puts "flapper is already running."
|
31
|
+
exit 1
|
32
|
+
else
|
33
|
+
print "flapper starting..."
|
34
|
+
runner.execute(:daemonize => @options[:daemonize]) do
|
35
|
+
main(@options['bind-ip'], @options['bind-port'].to_i, @options[:frequency])
|
36
|
+
end
|
37
|
+
puts " done."
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def stop
|
42
|
+
if runner.daemon_running?
|
43
|
+
print "flapper stopping..."
|
44
|
+
runner.execute(:kill => true)
|
45
|
+
puts " done."
|
46
|
+
else
|
47
|
+
puts "flapper is not running."
|
48
|
+
exit 1
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def restart
|
53
|
+
print "flapper restarting..."
|
54
|
+
runner.execute(:daemonize => true, :restart => true) do
|
55
|
+
main(@options['bind-ip'], @options['bind-port'].to_i, @options[:frequency])
|
56
|
+
end
|
57
|
+
puts " done."
|
58
|
+
end
|
59
|
+
|
60
|
+
def status
|
61
|
+
uptime = (runner.daemon_running?) ? (Time.now - File.stat(@options[:pidfile]).ctime) : 0
|
62
|
+
if runner.daemon_running?
|
63
|
+
puts "flapper is running: #{uptime}"
|
64
|
+
else
|
65
|
+
puts "flapper is not running"
|
66
|
+
exit 3
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
module Receiver
|
73
|
+
def receive_data(data)
|
74
|
+
send_data ">>>you sent: #{data}"
|
75
|
+
close_connection if data === /quit/i
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def runner
|
80
|
+
return @runner if @runner
|
81
|
+
|
82
|
+
@runner = Dante::Runner.new('flapper', :pid_path => @options[:pidfile],
|
83
|
+
:log_path => @options[:logfile])
|
84
|
+
@runner
|
85
|
+
end
|
86
|
+
|
87
|
+
def main(bind_ip, bind_port, frequency)
|
88
|
+
raise "bind_port must be an integer" unless bind_port.is_a?(Integer) && (bind_port > 0)
|
89
|
+
start_every = frequency
|
90
|
+
stop_after = frequency.to_f / 2
|
91
|
+
|
92
|
+
EM.run do
|
93
|
+
|
94
|
+
puts "#{Time.now}: starting server on #{bind_ip}:#{bind_port}"
|
95
|
+
server_init = EM.start_server bind_ip, bind_port, Flapjack::CLI::Flapper::Receiver
|
96
|
+
EM.add_timer(stop_after) do
|
97
|
+
puts "#{Time.now}: stopping server"
|
98
|
+
EM.stop_server(server_init)
|
99
|
+
end
|
100
|
+
|
101
|
+
EM.add_periodic_timer(start_every) do
|
102
|
+
puts "#{Time.now}: starting server on #{bind_ip}:#{bind_port}"
|
103
|
+
server = EM.start_server bind_ip, bind_port, Flapjack::CLI::Flapper::Receiver
|
104
|
+
EM.add_timer(stop_after) do
|
105
|
+
puts "#{Time.now}: stopping server"
|
106
|
+
EM.stop_server(server)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
|
117
|
+
desc 'Artificial service that oscillates up and down'
|
118
|
+
command :flapper do |flapper|
|
119
|
+
|
120
|
+
flapper.desc 'start flapper'
|
121
|
+
flapper.command :start do |start|
|
122
|
+
|
123
|
+
start.switch [:d, 'daemonize'], :desc => 'Daemonize',
|
124
|
+
:default_value => true
|
125
|
+
|
126
|
+
start.flag [:p, 'pidfile'], :desc => 'PATH of the pidfile to write to',
|
127
|
+
:default_value => "/var/run/flapjack/flapper.pid"
|
128
|
+
|
129
|
+
start.flag [:l, 'logfile'], :desc => 'PATH of the logfile to write to',
|
130
|
+
:default_value => "/var/log/flapjack/flapper.log"
|
131
|
+
|
132
|
+
start.flag [:b, 'bind-ip'], :desc => 'ADDRESS (IPv4 or IPv6) for flapper to bind to',
|
133
|
+
:default_value => Flapjack::CLI::Flapper.local_ip
|
134
|
+
|
135
|
+
start.flag [:P, 'bind-port'], :desc => 'PORT for flapper to bind to (default: 12345)',
|
136
|
+
:default_value => '12345'
|
137
|
+
|
138
|
+
start.flag [:f, 'frequency'], :desc => 'oscillate with a frequency of SECONDS [120]',
|
139
|
+
:default_value => '120.0'
|
140
|
+
|
141
|
+
start.action do |global_options, options, args|
|
142
|
+
cli_flapper = Flapjack::CLI::Flapper.new(global_options, options)
|
143
|
+
cli_flapper.start
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
flapper.desc 'stop flapper'
|
148
|
+
flapper.command :stop do |stop|
|
149
|
+
|
150
|
+
stop.flag [:p, 'pidfile'], :desc => 'PATH of the pidfile to write to',
|
151
|
+
:default_value => "/var/run/flapjack/flapper.pid"
|
152
|
+
|
153
|
+
stop.flag [:l, 'logfile'], :desc => 'PATH of the logfile to write to',
|
154
|
+
:default_value => "/var/log/flapjack/flapper.log"
|
155
|
+
|
156
|
+
stop.action do |global_options, options, args|
|
157
|
+
cli_flapper = Flapjack::CLI::Flapper.new(global_options, options)
|
158
|
+
cli_flapper.stop
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
flapper.desc 'restart flapper'
|
163
|
+
flapper.command :restart do |restart|
|
164
|
+
|
165
|
+
restart.flag [:p, 'pidfile'], :desc => 'PATH of the pidfile to write to',
|
166
|
+
:default_value => "/var/run/flapjack/flapper.pid"
|
167
|
+
|
168
|
+
restart.flag [:l, 'logfile'], :desc => 'PATH of the logfile to write to',
|
169
|
+
:default_value => "/var/log/flapjack/flapper.log"
|
170
|
+
|
171
|
+
restart.flag [:b, 'bind-ip'], :desc => 'ADDRESS (IPv4 or IPv6) for flapper to bind to',
|
172
|
+
:default_value => Flapjack::CLI::Flapper.local_ip
|
173
|
+
|
174
|
+
restart.flag [:P, 'bind-port'], :desc => 'PORT for flapper to bind to (default: 12345)',
|
175
|
+
:default_value => 12345
|
176
|
+
|
177
|
+
restart.flag [:f, 'frequency'], :desc => 'oscillate with a frequency of SECONDS [120]',
|
178
|
+
:default_value => 120.0
|
179
|
+
|
180
|
+
restart.action do |global_options, options, args|
|
181
|
+
cli_flapper = Flapjack::CLI::Flapper.new(global_options, options)
|
182
|
+
cli_flapper.restart
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
flapper.desc 'flapper status'
|
187
|
+
flapper.command :status do |status|
|
188
|
+
|
189
|
+
status.flag [:p, 'pidfile'], :desc => 'PATH of the pidfile to write to',
|
190
|
+
:default_value => "/var/run/flapjack/flapper.pid"
|
191
|
+
|
192
|
+
status.flag [:l, 'logfile'], :desc => 'PATH of the logfile to write to',
|
193
|
+
:default_value => "/var/log/flapjack/flapper.log"
|
194
|
+
|
195
|
+
status.action do |global_options, options, args|
|
196
|
+
cli_flapper = Flapjack::CLI::Flapper.new(global_options, options)
|
197
|
+
cli_flapper.status
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'oj'
|
4
|
+
Oj.default_options = { :indent => 0, :mode => :strict }
|
5
|
+
|
6
|
+
require 'redis'
|
7
|
+
|
8
|
+
require 'flapjack/configuration'
|
9
|
+
require 'flapjack/data/contact'
|
10
|
+
require 'flapjack/data/entity'
|
11
|
+
|
12
|
+
module Flapjack
|
13
|
+
module CLI
|
14
|
+
class Import
|
15
|
+
|
16
|
+
def initialize(global_options, options)
|
17
|
+
@global_options = global_options
|
18
|
+
@options = options
|
19
|
+
|
20
|
+
config = Flapjack::Configuration.new
|
21
|
+
config.load(global_options[:config])
|
22
|
+
@config_env = config.all
|
23
|
+
|
24
|
+
if @config_env.nil? || @config_env.empty?
|
25
|
+
puts "No config data for environment '#{FLAPJACK_ENV}' found in '#{global_options[:config]}'"
|
26
|
+
exit 1
|
27
|
+
end
|
28
|
+
|
29
|
+
@redis_options = config.for_redis
|
30
|
+
end
|
31
|
+
|
32
|
+
# TODO should these be similar to JSONAPI structures? e.g.
|
33
|
+
# {'contacts' => [CONTACT_HASH, ...]}
|
34
|
+
|
35
|
+
def contacts
|
36
|
+
conts = Oj.load(File.new(@options[:from]))
|
37
|
+
|
38
|
+
if conts && conts.is_a?(Enumerable) && conts.any? {|e| !e['id'].nil?}
|
39
|
+
conts.each do |contact|
|
40
|
+
unless contact['id']
|
41
|
+
puts "Contact not imported as it has no id: " + contact.inspect
|
42
|
+
next
|
43
|
+
end
|
44
|
+
Flapjack::Data::Contact.add(contact, :redis => redis)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
def entities
|
51
|
+
ents = Oj.load(File.new(@options[:from]))
|
52
|
+
|
53
|
+
if ents && ents.is_a?(Enumerable) && ents.any? {|e| !e['id'].nil?}
|
54
|
+
ents.each do |entity|
|
55
|
+
unless entity['id']
|
56
|
+
puts "Entity not imported as it has no id: " + entity.inspect
|
57
|
+
next
|
58
|
+
end
|
59
|
+
Flapjack::Data::Entity.add(entity, :redis => redis)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def redis
|
68
|
+
@redis ||= Redis.new(@redis_options)
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
desc 'Bulk import data from an external source'
|
76
|
+
command :import do |import|
|
77
|
+
|
78
|
+
import.desc 'Import contacts'
|
79
|
+
import.command :contacts do |contacts|
|
80
|
+
|
81
|
+
contacts.flag [:f, 'from'], :desc => 'PATH of the contacts JSON file to import',
|
82
|
+
:required => true
|
83
|
+
|
84
|
+
contacts.action do |global_options,options,args|
|
85
|
+
import = Flapjack::CLI::Import.new(global_options, options)
|
86
|
+
import.contacts
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
import.desc 'Import entities'
|
91
|
+
import.command :entities do |entities|
|
92
|
+
|
93
|
+
entities.flag [:f, 'from'], :desc => 'PATH of the entities JSON file to import',
|
94
|
+
:required => true
|
95
|
+
|
96
|
+
entities.action do |global_options,options,args|
|
97
|
+
import = Flapjack::CLI::Import.new(global_options, options)
|
98
|
+
import.entities
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|