flapjack 0.9.6 → 1.0.0rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.rspec +6 -0
  4. data/.travis.yml +20 -16
  5. data/CHANGELOG.md +11 -25
  6. data/Dockerfile +8 -0
  7. data/Gemfile +2 -5
  8. data/bin/flapjack +24 -213
  9. data/etc/flapjack_config.yaml.example +6 -30
  10. data/features/cli.feature +16 -14
  11. data/features/cli_flapjack-feed-events.feature +12 -13
  12. data/features/cli_flapjack-nagios-receiver.feature +14 -15
  13. data/features/cli_flapjack-populator.feature +16 -15
  14. data/features/cli_flapper.feature +12 -12
  15. data/features/cli_receive-events.feature +6 -5
  16. data/features/cli_simulate-failed-check.feature +7 -6
  17. data/features/steps/cli_steps.rb +2 -2
  18. data/features/support/env.rb +1 -0
  19. data/flapjack.gemspec +1 -0
  20. data/lib/flapjack/cli/flapper.rb +200 -0
  21. data/lib/flapjack/cli/import.rb +102 -0
  22. data/lib/flapjack/cli/receiver.rb +656 -0
  23. data/lib/flapjack/cli/server.rb +256 -0
  24. data/lib/flapjack/cli/simulate.rb +180 -0
  25. data/lib/flapjack/configuration.rb +2 -0
  26. data/lib/flapjack/data/entity_check.rb +5 -22
  27. data/lib/flapjack/data/event.rb +7 -12
  28. data/lib/flapjack/gateways/email.rb +4 -1
  29. data/lib/flapjack/gateways/jabber.rb +12 -36
  30. data/lib/flapjack/gateways/jsonapi/check_presenter.rb +6 -6
  31. data/lib/flapjack/gateways/jsonapi/report_methods.rb +5 -3
  32. data/lib/flapjack/gateways/pagerduty.rb +1 -1
  33. data/lib/flapjack/gateways/web/public/js/backbone.jsonapi.js +1 -1
  34. data/lib/flapjack/gateways/web/public/js/modules/contact.js +2 -2
  35. data/lib/flapjack/gateways/web/public/js/modules/entity.js +2 -2
  36. data/lib/flapjack/gateways/web/public/js/modules/medium.js +4 -4
  37. data/lib/flapjack/gateways/web/public/js/self_stats.js +1 -1
  38. data/lib/flapjack/gateways/web/views/check.html.erb +7 -7
  39. data/lib/flapjack/gateways/web/views/checks.html.erb +2 -3
  40. data/lib/flapjack/gateways/web/views/contact.html.erb +4 -4
  41. data/lib/flapjack/gateways/web/views/contacts.html.erb +2 -2
  42. data/lib/flapjack/gateways/web/views/edit_contacts.html.erb +1 -1
  43. data/lib/flapjack/gateways/web/views/entities.html.erb +1 -1
  44. data/lib/flapjack/gateways/web/views/entity.html.erb +1 -1
  45. data/lib/flapjack/gateways/web/views/index.html.erb +2 -2
  46. data/lib/flapjack/gateways/web/views/layout.erb +10 -10
  47. data/lib/flapjack/gateways/web/views/self_stats.html.erb +1 -1
  48. data/lib/flapjack/gateways/web.rb +36 -7
  49. data/lib/flapjack/pikelet.rb +0 -2
  50. data/lib/flapjack/processor.rb +3 -1
  51. data/lib/flapjack/redis_pool.rb +2 -6
  52. data/lib/flapjack/version.rb +1 -1
  53. data/spec/lib/flapjack/coordinator_spec.rb +3 -3
  54. data/spec/lib/flapjack/data/entity_check_spec.rb +2 -6
  55. data/spec/lib/flapjack/data/event_spec.rb +0 -31
  56. data/spec/lib/flapjack/gateways/email_spec.rb +109 -0
  57. data/spec/lib/flapjack/gateways/jabber_spec.rb +18 -16
  58. data/spec/lib/flapjack/gateways/jsonapi/check_presenter_spec.rb +12 -24
  59. data/spec/lib/flapjack/gateways/pagerduty_spec.rb +1 -1
  60. data/spec/lib/flapjack/gateways/web/views/check.html.erb_spec.rb +2 -0
  61. data/spec/lib/flapjack/gateways/web/views/contact.html.erb_spec.rb +2 -0
  62. data/spec/lib/flapjack/gateways/web/views/index.html.erb_spec.rb +2 -0
  63. data/spec/lib/flapjack/gateways/web_spec.rb +194 -145
  64. data/spec/lib/flapjack/redis_pool_spec.rb +0 -1
  65. data/spec/support/profile_all_formatter.rb +44 -0
  66. data/spec/support/uncolored_doc_formatter.rb +9 -0
  67. data/tasks/benchmarks.rake +0 -4
  68. metadata +28 -38
  69. data/.ruby-version +0 -1
  70. data/Gemfile-ruby1.9 +0 -28
  71. data/Gemfile-ruby1.9.lock +0 -227
  72. data/bin/flapjack-feed-events +0 -124
  73. data/bin/flapjack-nagios-receiver +0 -246
  74. data/bin/flapjack-nsca-receiver +0 -246
  75. data/bin/flapjack-populator +0 -132
  76. data/bin/flapper +0 -152
  77. data/bin/receive-events +0 -179
  78. data/bin/simulate-failed-check +0 -151
  79. data/lib/flapjack/data/migration.rb +0 -36
  80. data/lib/flapjack/gateways/api/contact_methods.rb +0 -369
  81. data/lib/flapjack/gateways/api/entity_check_presenter.rb +0 -218
  82. data/lib/flapjack/gateways/api/entity_methods.rb +0 -361
  83. data/lib/flapjack/gateways/api/entity_presenter.rb +0 -75
  84. data/lib/flapjack/gateways/api/rack/json_params_parser.rb +0 -26
  85. data/lib/flapjack/gateways/api.rb +0 -124
  86. data/spec/lib/flapjack/gateways/api/contact_methods_spec.rb +0 -772
  87. data/spec/lib/flapjack/gateways/api/entity_check_presenter_spec.rb +0 -211
  88. data/spec/lib/flapjack/gateways/api/entity_methods_spec.rb +0 -863
  89. data/spec/lib/flapjack/gateways/api/entity_presenter_spec.rb +0 -108
  90. data/spec/lib/flapjack/gateways/api_spec.rb +0 -30
data/Gemfile-ruby1.9.lock DELETED
@@ -1,227 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- flapjack (0.9.6)
5
- activesupport (~> 3.2.14)
6
- blather (~> 0.8.3)
7
- chronic
8
- chronic_duration
9
- dante
10
- em-http-request
11
- em-resque
12
- em-synchrony (~> 1.0.2)
13
- eventmachine (~> 1.0.0)
14
- hiredis
15
- ice_cube
16
- mail
17
- oj (>= 2.9.0)
18
- rack-fiber_pool
19
- rake
20
- rbtrace
21
- redis (~> 3.0.6)
22
- resque (~> 1.23.0)
23
- sinatra
24
- thin (~> 1.6.1)
25
- tzinfo (~> 1.0.1)
26
- tzinfo-data
27
-
28
- GEM
29
- remote: https://rubygems.org/
30
- specs:
31
- activesupport (3.2.19)
32
- i18n (~> 0.6, >= 0.6.4)
33
- multi_json (~> 1.0)
34
- addressable (2.3.6)
35
- async_rack_test (0.0.5)
36
- blather (0.8.8)
37
- activesupport (>= 2.3.11)
38
- eventmachine (>= 1.0.0)
39
- girl_friday
40
- niceogiri (~> 1.0)
41
- nokogiri (~> 1.5, >= 1.5.6)
42
- builder (3.2.2)
43
- celluloid (0.16.0)
44
- timers (~> 4.0.0)
45
- chronic (0.10.2)
46
- chronic_duration (0.10.6)
47
- numerizer (~> 0.1.1)
48
- coderay (1.1.0)
49
- connection_pool (1.2.0)
50
- cookiejar (0.3.2)
51
- crack (0.4.2)
52
- safe_yaml (~> 1.0.0)
53
- cucumber (1.3.17)
54
- builder (>= 2.1.2)
55
- diff-lcs (>= 1.1.3)
56
- gherkin (~> 2.12)
57
- multi_json (>= 1.7.5, < 2.0)
58
- multi_test (>= 0.1.1)
59
- daemons (1.1.9)
60
- dante (0.2.0)
61
- debugger-ruby_core_source (1.3.5)
62
- delorean (2.1.0)
63
- chronic
64
- diff-lcs (1.2.5)
65
- docile (1.1.5)
66
- em-hiredis (0.1.1)
67
- hiredis (~> 0.4.0)
68
- em-http-request (1.1.2)
69
- addressable (>= 2.3.4)
70
- cookiejar
71
- em-socksify (>= 0.3)
72
- eventmachine (>= 1.0.3)
73
- http_parser.rb (>= 0.6.0)
74
- em-resque (1.1.1)
75
- em-hiredis (~> 0.1.0)
76
- em-synchrony (~> 1.0.0)
77
- resque (~> 1.2)
78
- em-socksify (0.3.0)
79
- eventmachine (>= 1.0.0.beta.4)
80
- em-synchrony (1.0.3)
81
- eventmachine (>= 1.0.0.beta.1)
82
- eventmachine (1.0.3)
83
- ffi (1.9.6)
84
- formatador (0.2.5)
85
- fuubar (2.0.0)
86
- rspec (~> 3.0)
87
- ruby-progressbar (~> 1.4)
88
- gherkin (2.12.2)
89
- multi_json (~> 1.3)
90
- girl_friday (0.11.2)
91
- connection_pool (~> 1.0)
92
- rubinius-actor
93
- guard (2.6.1)
94
- formatador (>= 0.2.4)
95
- listen (~> 2.7)
96
- lumberjack (~> 1.0)
97
- pry (>= 0.9.12)
98
- thor (>= 0.18.1)
99
- guard-cucumber (1.4.1)
100
- cucumber (>= 1.2.0)
101
- guard (>= 1.1.0)
102
- guard-rspec (4.3.1)
103
- guard (~> 2.1)
104
- rspec (>= 2.14, < 4.0)
105
- hiredis (0.4.5)
106
- hitimes (1.2.2)
107
- http_parser.rb (0.6.0)
108
- i18n (0.6.11)
109
- ice_cube (0.12.1)
110
- listen (2.7.11)
111
- celluloid (>= 0.15.2)
112
- rb-fsevent (>= 0.9.3)
113
- rb-inotify (>= 0.9)
114
- lumberjack (1.0.9)
115
- mail (2.6.1)
116
- mime-types (>= 1.16, < 3)
117
- method_source (0.8.2)
118
- mime-types (2.4.2)
119
- mini_portile (0.6.0)
120
- msgpack (0.5.9)
121
- multi_json (1.10.1)
122
- multi_test (0.1.1)
123
- niceogiri (1.1.2)
124
- nokogiri (~> 1.5)
125
- nokogiri (1.6.3.1)
126
- mini_portile (= 0.6.0)
127
- numerizer (0.1.1)
128
- oj (2.10.3)
129
- perftools.rb (2.0.1)
130
- pry (0.10.1)
131
- coderay (~> 1.1.0)
132
- method_source (~> 0.8.1)
133
- slop (~> 3.4)
134
- rack (1.5.2)
135
- rack-fiber_pool (0.9.3)
136
- rack-protection (1.5.3)
137
- rack
138
- rack-test (0.6.2)
139
- rack (>= 1.0)
140
- rake (10.3.2)
141
- rb-fsevent (0.9.4)
142
- rb-inotify (0.9.5)
143
- ffi (>= 0.5.0)
144
- rbtrace (0.4.5)
145
- ffi (>= 1.0.6)
146
- msgpack (>= 0.4.3)
147
- trollop (>= 1.16.2)
148
- redis (3.0.7)
149
- redis-namespace (1.5.1)
150
- redis (~> 3.0, >= 3.0.4)
151
- resque (1.23.1)
152
- multi_json (~> 1.0)
153
- redis-namespace (~> 1.0)
154
- sinatra (>= 0.9.2)
155
- vegas (~> 0.1.2)
156
- resque_spec (0.16.0)
157
- resque (>= 1.19.0)
158
- rspec-core (>= 3.0.0)
159
- rspec-expectations (>= 3.0.0)
160
- rspec-mocks (>= 3.0.0)
161
- rspec (3.0.0)
162
- rspec-core (~> 3.0.0)
163
- rspec-expectations (~> 3.0.0)
164
- rspec-mocks (~> 3.0.0)
165
- rspec-core (3.0.4)
166
- rspec-support (~> 3.0.0)
167
- rspec-expectations (3.0.4)
168
- diff-lcs (>= 1.2.0, < 2.0)
169
- rspec-support (~> 3.0.0)
170
- rspec-mocks (3.0.4)
171
- rspec-support (~> 3.0.0)
172
- rspec-support (3.0.4)
173
- rubinius-actor (0.0.2)
174
- rubinius-core-api
175
- rubinius-core-api (0.0.1)
176
- ruby-prof (0.15.1)
177
- ruby-progressbar (1.6.0)
178
- safe_yaml (1.0.4)
179
- simplecov (0.9.1)
180
- docile (~> 1.1.0)
181
- multi_json (~> 1.0)
182
- simplecov-html (~> 0.8.0)
183
- simplecov-html (0.8.0)
184
- sinatra (1.4.5)
185
- rack (~> 1.4)
186
- rack-protection (~> 1.4)
187
- tilt (~> 1.3, >= 1.3.4)
188
- slop (3.6.0)
189
- thin (1.6.3)
190
- daemons (~> 1.0, >= 1.0.9)
191
- eventmachine (~> 1.0)
192
- rack (~> 1.0)
193
- thor (0.19.1)
194
- tilt (1.4.1)
195
- timers (4.0.1)
196
- hitimes
197
- trollop (2.0)
198
- tzinfo (1.0.1)
199
- tzinfo-data (1.2014.8)
200
- tzinfo (>= 1.0.0)
201
- vegas (0.1.11)
202
- rack (>= 1.0.0)
203
- webmock (1.19.0)
204
- addressable (>= 2.3.6)
205
- crack (>= 0.3.2)
206
-
207
- PLATFORMS
208
- ruby
209
-
210
- DEPENDENCIES
211
- async_rack_test (>= 0.0.5)
212
- cucumber
213
- debugger-ruby_core_source (>= 1.3.4)
214
- delorean
215
- flapjack!
216
- fuubar
217
- guard
218
- guard-cucumber
219
- guard-rspec
220
- perftools.rb
221
- rack-test
222
- rb-fsevent
223
- resque_spec
224
- rspec (~> 3.0.0.beta1)
225
- ruby-prof
226
- simplecov
227
- webmock
@@ -1,124 +0,0 @@
1
- #!/usr/bin/env ruby
2
- unless $:.include?(File.dirname(__FILE__) + '/../lib/')
3
- $: << File.dirname(__FILE__) + '/../lib'
4
- end
5
-
6
- require 'optparse'
7
- require 'ostruct'
8
- require 'redis'
9
- require 'oj'
10
-
11
- require 'flapjack/configuration'
12
- require 'flapjack/data/event'
13
-
14
- exe = File.basename(__FILE__)
15
-
16
- options = OpenStruct.new
17
- options.config = Flapjack::Configuration::DEFAULT_CONFIG_PATH
18
-
19
- optparse = OptionParser.new do |opts|
20
- opts.banner = "Usage: #{exe} [OPTIONS]"
21
-
22
- opts.separator ""
23
- opts.separator "Feed JSON blobs from file or STDIN into the Flapjack event queue."
24
- opts.separator ""
25
- opts.separator "Options"
26
-
27
- opts.on("-c", "--config [PATH]", String, "PATH to the config file to use.") do |c|
28
- options.config = c
29
- end
30
-
31
- opts.on("-f", "--from [FILE]", String, "path to the FILE to process; if not provided, defaults to STDIN.") do |f|
32
- options.from = f
33
- end
34
- end
35
- optparse.parse!(ARGV)
36
-
37
- bail_with_usage = proc do |message|
38
- puts message
39
- puts "\n#{optparse}"
40
- exit(false)
41
- end
42
-
43
- if options.help
44
- puts optparse
45
- exit
46
- elsif options.version
47
- puts Flapjack::VERSION
48
- exit
49
- end
50
-
51
- FLAPJACK_ENV = ENV['FLAPJACK_ENV'] || 'production'
52
- config = Flapjack::Configuration.new
53
- config.load(options.config)
54
- config_env = config.all
55
- if config_env.nil? || config_env.empty?
56
- puts "No config data for environment '#{FLAPJACK_ENV}' found in '#{options.config}'"
57
- exit(false)
58
- end
59
- redis = Redis.new(config.for_redis)
60
-
61
- input = if options.from
62
- File.open(options.from) # Explodes if file does not exist.
63
- else
64
- bail_with_usage.call("No file provided, and STDIN is from terminal! Exiting...") if $stdin.tty?
65
- $stdin
66
- end
67
-
68
- # Sit and churn through the input stream until a valid JSON blob has been assembled.
69
- # This handles both the case of a process sending a single JSON and then exiting
70
- # (eg. cat foo.json | bin/flapjack-feed-event) *and* a longer-running process spitting
71
- # out events (eg. /usr/bin/slow-event-feed | bin/flapjack-feed-event)
72
-
73
- class EventFeedHandler < Oj::ScHandler
74
-
75
- def initialize(&block)
76
- @hash_depth = 0
77
- @callback = block if block_given?
78
- end
79
-
80
- def hash_start
81
- @hash_depth += 1
82
- Hash.new
83
- end
84
-
85
- def hash_end
86
- @hash_depth -= 1
87
- end
88
-
89
- def array_start
90
- Array.new
91
- end
92
-
93
- def array_end
94
- end
95
-
96
- def add_value(value)
97
- @callback.call(value) if @callback
98
- nil
99
- end
100
-
101
- def hash_set(hash, key, value)
102
- hash[key] = value
103
- end
104
-
105
- def array_append(array, value)
106
- array << value
107
- end
108
-
109
- end
110
-
111
- parser = EventFeedHandler.new do |parsed|
112
- # Handle "parsed" (a hash)
113
- errors = Flapjack::Data::Event.validation_errors_for_hash(parsed)
114
- if errors.empty?
115
- Flapjack::Data::Event.add(parsed, :redis => redis)
116
- puts "Enqueued event data, #{parsed.inspect}"
117
- else
118
- puts "Invalid event data received, #{errors.join(', ')} #{parsed.inspect}"
119
- end
120
- end
121
-
122
- Oj.sc_parse(parser, input)
123
-
124
- puts "Done."
@@ -1,246 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- # nagios.cfg must contain the following perfdata templates for host and service data (modified from the default
4
- # to include hoststate / servicestate, and a fake service 'HOST' for hostperfdata, so that the
5
- # fields match up:
6
- #
7
- # host_perfdata_file_template=[HOSTPERFDATA]\t$TIMET$\t$HOSTNAME$\tHOST\t$HOSTSTATE$\t$HOSTEXECUTIONTIME$\t$HOSTLATENCY$\t$HOSTOUTPUT$\t$HOSTPERFDATA$
8
- #
9
- # service_perfdata_file_template=[SERVICEPERFDATA]\t$TIMET$\t$HOSTNAME$\t$SERVICEDESC$\t$SERVICESTATE$\t$SERVICEEXECUTIONTIME$\t$SERVICELATENCY$\t$SERVICEOUTPUT$\t$SERVICEPERFDATA$
10
- #
11
-
12
- unless $:.include?(File.dirname(__FILE__) + '/../lib/')
13
- $: << File.dirname(__FILE__) + '/../lib'
14
- end
15
-
16
- require 'optparse'
17
- require 'ostruct'
18
- require 'redis'
19
-
20
- require 'oj'
21
- Oj.default_options = { :indent => 0, :mode => :strict }
22
-
23
- require 'dante'
24
-
25
- require 'flapjack/configuration'
26
- require 'flapjack/data/event'
27
-
28
- def process_input(opts)
29
- redis = opts[:redis]
30
- fifo = File.new(opts[:fifo])
31
- begin
32
- while line = fifo.gets
33
- skip unless line
34
- split_line = line.split("\t")
35
-
36
- object_type, timestamp, entity, check, state, check_time, check_latency, check_output, check_perfdata, check_long_output = split_line
37
-
38
- case
39
- when ! (split_line.length > 8)
40
- puts "ERROR - rejecting this line as it doesn't split into at least 9 tab separated strings: [#{line}]"
41
- next
42
- when (timestamp !~ /^\d+$/)
43
- puts "ERROR - rejecting this line as second string doesn't look like a timestamp: [#{line}]"
44
- next
45
- when (not ((object_type == '[HOSTPERFDATA]') or (object_type == '[SERVICEPERFDATA]')))
46
- puts "ERROR - rejecting this line as first string is neither '[HOSTPERFDATA]' nor '[SERVICEPERFDATA]': [#{line}]"
47
- next
48
- end
49
-
50
- puts "#{object_type}, #{timestamp}, #{entity}, #{check}, #{state}, #{check_output}, #{check_long_output}"
51
-
52
- state = 'ok' if state.downcase == 'up'
53
- state = 'critical' if state.downcase == 'down'
54
- details = check_long_output ? check_long_output.gsub(/\\n/, "\n") : nil
55
- event = {
56
- 'entity' => entity,
57
- 'check' => check,
58
- 'type' => 'service',
59
- 'state' => state,
60
- 'summary' => check_output,
61
- 'details' => details,
62
- 'perfdata' => check_perfdata,
63
- 'time' => timestamp,
64
- }
65
- Flapjack::Data::Event.add(event, :redis => redis)
66
- end
67
- rescue Redis::CannotConnectError
68
- puts "Error, unable to to connect to the redis server (#{$!})"
69
- end
70
- end
71
-
72
- def main(opts)
73
- fifo = opts[:fifo]
74
- redis = Redis.new(opts[:redis_options])
75
- while true
76
- process_input(:redis => redis, :fifo => fifo)
77
- puts "Whoops with the fifo, restarting main loop in 10 seconds"
78
- sleep 10
79
- end
80
- end
81
-
82
- options = OpenStruct.new
83
- options.config = Flapjack::Configuration::DEFAULT_CONFIG_PATH
84
- options.daemonize = nil
85
-
86
- exe = File.basename(__FILE__)
87
-
88
- optparse = OptionParser.new do |opts|
89
- opts.banner = "Usage: #{exe} COMMAND [OPTIONS]"
90
-
91
- opts.separator ""
92
- opts.separator "Commands"
93
- opts.separator " start #{" " * 25} start #{exe}"
94
- opts.separator " stop #{" " * 26} stop #{exe}"
95
- opts.separator " restart #{" " * 23} (re)start #{exe}"
96
- opts.separator " status #{" " * 24} see if #{exe} is running"
97
- opts.separator ""
98
- opts.separator "Options"
99
-
100
- opts.on("-c", "--config [PATH]", String, "PATH to the config file to use") do |c|
101
- options.config = c
102
- end
103
-
104
- opts.on("-f", "--fifo FIFO", String, "Path to the nagios perfdata named pipe") do |f|
105
- options.fifo = f
106
- end
107
-
108
- opts.on("-d", "--[no-]daemonize", "Daemonize?") do |d|
109
- options.daemonize = d
110
- end
111
-
112
- opts.on("-p", "--pidfile [PATH]", String, "PATH to the pidfile to write to") do |pid|
113
- options.pidfile = pid
114
- end
115
-
116
- opts.on("-l", "--logfile [PATH]", String, "PATH to the logfile to write to") do |l|
117
- options.logfile = l
118
- end
119
-
120
- opts.on_tail("-h", "--help", "Show this usage message") do
121
- puts opts
122
- puts '
123
- Required Nagios Configuration Changes
124
- -------------------------------------
125
-
126
- flapjack-nagios-receiver reads events from a named pipe written to by Nagios. The named pipe needs creating, and Nagios needs to be told to write performance data output to it.
127
-
128
- To create the named pipe:
129
-
130
- mkfifo -m 0666 /var/cache/nagios3/event_stream.fifo
131
-
132
- nagios.cfg changes:
133
-
134
- # modified lines:
135
- enable_notifications=0
136
- host_perfdata_file=/var/cache/nagios3/event_stream.fifo
137
- service_perfdata_file=/var/cache/nagios3/event_stream.fifo
138
- host_perfdata_file_template=[HOSTPERFDATA]\t$TIMET$\t$HOSTNAME$\tHOST\t$HOSTSTATE$\t$HOSTEXECUTIONTIME$\t$HOSTLATENCY$\t$HOSTOUTPUT$\t$HOSTPERFDATA$
139
- service_perfdata_file_template=[SERVICEPERFDATA]\t$TIMET$\t$HOSTNAME$\t$SERVICEDESC$\t$SERVICESTATE$\t$SERVICEEXECUTIONTIME$\t$SERVICELATENCY$\t$SERVICEOUTPUT$\t$SERVICEPERFDATA$
140
- host_perfdata_file_mode=p
141
- service_perfdata_file_mode=p
142
-
143
- Details on the wiki: https://github.com/flapjack/flapjack/wiki/USING#configuring-nagios
144
- '
145
-
146
- exit
147
- end
148
-
149
- end
150
- optparse.parse!(ARGV)
151
-
152
- FLAPJACK_ENV = ENV['FLAPJACK_ENV'] || 'production'
153
-
154
- config = Flapjack::Configuration.new
155
- config.load(options.config)
156
- config_env = config.all
157
- redis_options = config.for_redis
158
-
159
- if config_env.nil? || config_env.empty?
160
- puts "No config data for environment '#{FLAPJACK_ENV}' found in '#{options.config}'"
161
- puts optparse
162
- exit 1
163
- end
164
-
165
- config_nr = config_env['nagios-receiver'] || {}
166
-
167
- pidfile = options.pidfile.nil? ?
168
- (config_nr['pid_file'] || "/var/run/flapjack/#{exe}.pid") :
169
- options.pidfile
170
-
171
- logfile = options.logfile.nil? ?
172
- (config_nr['log_file'] || "/var/log/flapjack/#{exe}.log") :
173
- options.logfile
174
-
175
- fifo = options.fifo.nil? ?
176
- (config_nr['fifo'] || '/var/cache/nagios3/event_stream.fifo') :
177
- options.fifo
178
-
179
- daemonize = options.daemonize.nil? ?
180
- !!config_nr['daemonize'] :
181
- options.daemonize
182
-
183
-
184
- runner = Dante::Runner.new(exe, :pid_path => pidfile, :log_path => logfile)
185
- case ARGV[0]
186
- when "start", "restart"
187
- unless File.exist?(fifo)
188
- raise "No fifo (named pipe) file found at #{fifo}"
189
- end
190
- unless File.pipe?(fifo)
191
- raise "The file at #{fifo} is not a named pipe, try using mkfifo to make one"
192
- end
193
- unless File.readable?(fifo)
194
- raise "The fifo (named pipe) at #{fifo} is unreadable"
195
- end
196
- end
197
-
198
- case ARGV[0]
199
- when "start"
200
- if runner.daemon_running?
201
- puts "#{exe} is already running."
202
- exit 1
203
- else
204
- print "#{exe} starting..."
205
- runner.execute(:daemonize => daemonize) {
206
- main(:redis_options => redis_options, :fifo => fifo)
207
- }
208
- puts " done."
209
- end
210
-
211
- when "stop"
212
- if runner.daemon_running?
213
- print "#{exe} stopping..."
214
- runner.execute(:kill => true)
215
- puts " done."
216
- else
217
- puts "#{exe} is not running."
218
- exit 1
219
- end
220
-
221
- when "restart"
222
- print "#{exe} restarting..."
223
- runner.execute(:daemonize => true, :restart => true) {
224
- main(:redis_options => redis_options, :fifo => fifo)
225
- }
226
- puts " done."
227
-
228
- when "status"
229
- uptime = (runner.daemon_running?) ? Time.now - File.stat(pidfile).ctime : 0
230
- if runner.daemon_running?
231
- puts "#{exe} is running: #{uptime}"
232
- else
233
- puts "#{exe} is not running"
234
- exit 3
235
- end
236
-
237
- else
238
- if ARGV.nil? || ARGV.empty?
239
- puts "No command provided"
240
- else
241
- puts "Unknown command provided: '#{ARGV[0]}'"
242
- end
243
- puts "\n#{optparse}"
244
- exit 1
245
-
246
- end