flapjack 0.6.38 → 0.6.39

Sign up to get free protection for your applications and to get access to all the features.
data/.gitmodules ADDED
@@ -0,0 +1,3 @@
1
+ [submodule "doc"]
2
+ path = doc
3
+ url = https://github.com/flpjck/flapjack.wiki.git
data/.travis.yml CHANGED
@@ -7,4 +7,6 @@ services:
7
7
  - redis-server
8
8
  before_script:
9
9
  - mkdir -p ./log
10
+ before_install:
11
+ - git submodule update --init --recursive
10
12
  script: bundle exec rspec spec && bundle exec cucumber features
data/README.md CHANGED
@@ -1,5 +1,4 @@
1
- Flapjack
2
- ========
1
+ # Flapjack
3
2
 
4
3
  [![Travis CI Status][id_travis_img]][id_travis_link]
5
4
 
@@ -10,203 +9,33 @@ Flapjack is a highly scalable and distributed monitoring notification system.
10
9
 
11
10
  Flapjack provides a scalable method for dealing with events representing changes in system state (OK -> WARNING -> CRITICAL transitions) and alerting appropriate people as necessary.
12
11
 
13
- At its core, flapjack process events received from external check execution engines, such as Nagios. Nagios provides a 'perfdata' event output channel, which writes to a named pipe. `flapjack-nagios-receiver` then reads from this named pipe, converts each line to JSON and adds them to the events queue. `executive` picks up the events and processes them - deciding when and who to notifify about problems, recoveries, acknowledgements etc. Additional check engines can be supported by adding additional receiver processes similar to the nagios receiver.
12
+ At its core, flapjack process events received from external check execution engines, such as Nagios. Nagios provides a 'perfdata' event output channel, which writes to a named pipe. `flapjack-nagios-receiver` then reads from this named pipe, converts each line to JSON and adds them to the events queue. Flapjack's `executive` component picks up the events and processes them -- deciding when and who to notifify about problems, recoveries, acknowledgements etc. Additional check engines can be supported by adding additional receiver processes similar to the nagios receiver.
14
13
 
15
14
 
16
- What things do
17
- --------------
15
+ ## Using Flapjack
18
16
 
19
- Executables:
17
+ ### Quickstart
20
18
 
21
- * `flapjack` => starts multiple components ('pikelets') within the one ruby process as specified in the configuration file.
22
- * `flapjack-nagios-receiver` => reads nagios check output on standard input and places them on the events queue in redis as JSON blobs. Currently unable to be run in-process with `flapjack`
19
+ TODO numbered list for simplest possible Flapjack run
23
20
 
24
- There are more fun executables in the bin directory.
21
+ For more information, including full specification of the configuration file and the data import formats, please refer to the [Flapjack Wiki](https://github.com/ali-graham/flapjack/wiki/USING).
25
22
 
26
- Pikelets:
23
+ ## Developing Flapjack
27
24
 
28
- * `executive` => processes events off a queue (a redis list) and decides what actions to take (alert, record state changes, etc)
29
- * `email_notifier` => generates email notifications (resque, mail)
30
- * `sms_notifier` => generates sms notifications (resque)
31
- * `jabber_gateway` => connects to an XMPP (jabber) server, sends notifications (to rooms and individuals), handles acknowledgements from jabber users and other commands (blather)
32
- * `web` => web UI (sinatra, thin)
33
- * `api` => HTTP API server (sinatra, thin)
25
+ Information on developing more Flapjack components or contributing to core Flapjack development can be found in the [Flapjack Wiki](https://github.com/ali-graham/flapjack/wiki/DEVELOPING).
34
26
 
35
- Pikelets are flapjack components which can be run within the same ruby process, or as separate processes.
27
+ ## Documentation Submodule
36
28
 
37
- The simplest configuration will have one `flapjack` process running executive, web, and some notification gateways, and one `flapjack-nagios-receiver` process receiving events from Nagios and placing them on the events queue for processing by executive.
38
-
39
-
40
- Developing
41
- ----------
42
-
43
- Clone the repository:
44
-
45
- git clone https://auxesis@github.com/auxesis/flapjack.git
46
-
47
- Install development dependencies:
48
-
49
- gem install bundler
50
- bundle install
51
-
52
- Run the tests:
53
-
54
- cucumber features/
55
- rspec spec
56
-
57
- Testing
58
- -------
59
-
60
- Feature tests live in `features/`.
61
-
62
- To run feature tests:
63
-
64
- $ cucumber features
65
-
66
- There's some rspec unit tests as well, run these like so:
67
-
68
- $ rspec spec
69
-
70
- NB, if the cucumber tests fail with a [spurious lexing error](https://github.com/cucumber/gherkin/issues/182) on line 2 of events.feature, then try this:
71
-
72
- $ cucumber -f fuubar features
73
-
74
-
75
-
76
- Releasing
77
- ---------
78
-
79
- Gem releases are handled with [Bundler](http://gembundler.com/rubygems.html).
80
-
81
- To build the gem, run:
82
-
83
- gem build flapjack.gemspec
84
-
85
- Configuring
86
- ===========
29
+ We have the documentation for this project on a github wiki and also referenced as a submodule at /doc in this project. Run the following commands to populate the local doc/ directory:
87
30
 
88
31
  ```
89
- cp etc/flapjack-config.yaml.example etc/flapjack-config.yaml
32
+ git submodule init
33
+ git submodule update
90
34
  ```
91
35
 
92
- Edit the configuration to suit (redis connection, smtp server, jabber server, sms gateway, etc)
93
-
94
- The default FLAPJACK_ENV is "development" if there is no environment variable set.
95
-
96
- Nagios config
97
- -------------
98
-
99
- You need a Nagios prior to version 3.3 as this breaks perfdata output for checks which don't generate performance data (stuff after a | in the check output). We are developing and running against Nagios version 3.2.3 with success.
100
-
101
- nagios.cfg config file changes:
102
-
103
- ```
104
- # modified lines:
105
- enable_notifications=0
106
- host_perfdata_file=/var/cache/nagios3/event_stream.fifo
107
- service_perfdata_file=/var/cache/nagios3/event_stream.fifo
108
- host_perfdata_file_template=[HOSTPERFDATA]\t$TIMET$\t$HOSTNAME$\tHOST\t$HOSTSTATE$\t$HOSTEXECUTIONTIME$\t$HOSTLATENCY$\t$HOSTOUTPUT$\t$HOSTPERFDATA$
109
- service_perfdata_file_template=[SERVICEPERFDATA]\t$TIMET$\t$HOSTNAME$\t$SERVICEDESC$\t$SERVICESTATE$\t$SERVICEEXECUTIONTIME$\t$SERVICELATENCY$\t$SERVICEOUTPUT$\t$SERVICEPERFDATA$
110
- host_perfdata_file_mode=p
111
- service_perfdata_file_mode=p
112
- ```
113
-
114
- What we're doing here is telling Nagios to generate a line of output for every host and service check into a named pipe. The template lines must be as above so that `flapjack-nagios-receiver` knows what to expect.
115
-
116
- All hosts and services (or templates that they use) will need to have process_perf_data enabled on them. (This is a real misnomer, it doesn't mean the performance data will be processed, just that it will be fed to the perfdata output channel, a named pipe in our case.)
117
-
118
- Create the named pipe if it doesn't already exist:
119
-
120
- mkfifo -m 0666 /var/cache/nagios3/event_stream.fifo
121
-
122
-
123
- Running
124
- =======
125
-
126
- bin/flapjack [options]
127
-
128
- $ flapjack --help
129
- Usage: flapjack [options]
130
- -c, --config [PATH] PATH to the config file to use
131
- -d, --[no-]daemonize Daemonize?
132
-
133
- The command line option for daemonize overrides whatever is set in the config file.
134
-
135
- flapjack-nagios-receiver
136
- ------------------------
137
-
138
- There is a control script that uses [Daemons](http://daemons.rubyforge.org/) to start, stop, restart, show status etc of the flapjack-nagios-receiver process. Options after -- are passed through to flapjack-nagios-receiver. Run it like so:
139
-
140
- flapjack-nagios-receiver-control start -- --config /etc/flapjack/flapjack-config.yaml --fifo /path/to/nagios/perfdata.fifo
141
- flapjack-nagios-receiver-control status
142
- flapjack-nagios-receiver-control restart -- --config /etc/flapjack/flapjack-config.yaml --fifo /path/to/nagios/perfdata.fifo
143
- flapjack-nagios-receiver-control stop
144
-
145
- * Bypassing daemons control script: *
146
-
147
- Specify the path to the nagios named pipe (fifo):
148
-
149
- flapjack-nagios-receiver --fifo /var/cache/nagios3/event_stream.fifo
150
-
151
- Now as nagios feeds check execution results into the perfdata named pipe, flapjack-nagios-receiver will convert them to JSON encoded ruby objects and insert them into the *events* queue.
152
-
153
- Importing contacts and entities
154
- -------------------------------
155
-
156
- The `flapjack-populator` script provides a mechanism for importing contacts and entities from JSON formatted import files.
157
-
158
- bin/flapjack-populator import-contacts --from tmp/dummy_contacts.json --config /etc/flapjack/flapjack-config.yml
159
- bin/flapjack-populator import-entities --from tmp/dummy_entities.json --config /etc/flapjack/flapjack-config.yml
160
-
161
- TODO: convert the format documentation into markdown and include in the project
162
-
163
- In lieu of actual documentation of the formats there are example files, and example ruby code which generated them, in the tmp directory.
164
-
165
- executive
166
- ---------
167
-
168
- Flapjack executive processes events from the 'events' list in redis. It does a blocking read on redis so new events are picked off the events list and processed as soon as they created.
169
-
170
- When executive decides somebody ought to be notified (for a problem, recovery, or acknowledgement or what-have-you) it looks up contact information and then creates a notification job on one of the notification queues (eg sms_notifications) in rescue, or via the jabber_notifications redis list which is processed by the jabber_gateway.
171
-
172
- Resque Workers
173
- --------------
174
-
175
- We're using [Resque](https://github.com/defunkt/resque) to queue email and sms notifications generated by flapjack-executive. The queues are named as follows:
176
- - email_notifications
177
- - sms_notifications
178
-
179
- There'll be more of these as we add more notification mediums.
180
-
181
- Note that using the flapjack-config.yaml file you can have flapjack start the resque workers in-process. Or you can run them standalone with the `rake resque:work` command as follows.
182
-
183
- One resque worker that processes both queues (but prioritises SMS above email) can be started as follows:
184
-
185
- QUEUE=sms_notifications,email_notifications VERBOSE=1 be rake resque:work
186
-
187
- resque sets the command name so grep'ing ps output for `rake` or `ruby` will NOT find resque processes. Search instead for `resque`. (and remember the 'q').
188
-
189
- To background it you can add `BACKGROUND=yes`. Excellent documentation is available in [Resque's README](https://github.com/defunkt/resque/blob/master/README.markdown)
190
-
191
- Redis Database Instances
192
- ------------------------
193
-
194
- We use the following redis database numbers by convention:
195
-
196
- * 0 => production
197
- * 13 => development
198
- * 14 => testing
199
-
200
- Architecture
201
- ------------
202
-
203
- TODO: insert architecture diagram and notes here
204
-
205
- Dependencies
206
- ------------
36
+ If you make changes to the documentation locally, here's how to publish them:
207
37
 
208
- Apart from a bundle of gems (see flapjack.gemspec for runtime gems, and Gemfile for additional gems required for testing):
209
- - Ruby >= 1.9
210
- - Redis >= 2.4.15
38
+ * git add, commit and push from inside the doc subdir
39
+ * add, commit and push the doc dir from the root (this updates the pointer in the main git repo to the correct ref in the doc repo, we think...)
211
40
 
212
41
 
data/Rakefile CHANGED
@@ -13,15 +13,14 @@ Dir['tasks/**/*.rake'].each { |t| load t }
13
13
 
14
14
  require 'cucumber'
15
15
  require 'cucumber/rake/task'
16
- require 'colorize'
17
16
  require 'rake/clean'
18
17
  require 'bundler'
19
18
  Bundler::GemHelper.install_tasks
20
19
 
21
20
  Cucumber::Rake::Task.new(:features) do |t|
22
- #t.cucumber_opts = "features --format pretty"
23
- #t.cucumber_opts = "--format progress"
24
- t.cucumber_opts = "--format fuubar"
21
+ #t.cucumber_opts = 'features --format pretty'
22
+ #t.cucumber_opts = '--format progress'
23
+ t.cucumber_opts = '--format fuubar'
25
24
  end
26
25
 
27
26
  require 'rspec/core/rake_task'
@@ -30,12 +29,18 @@ RSpec::Core::RakeTask.new(:spec)
30
29
  task :default => :tests
31
30
 
32
31
  namespace :verify do
32
+
33
33
  task :uncommitted do
34
+
35
+ def red(text)
36
+ "\e[0;31;49m#{text}\e[0m"
37
+ end
38
+
34
39
  uncommitted = `git ls-files -m`.split("\n")
35
40
  if uncommitted.size > 0
36
- puts "The following files are uncommitted:".red
41
+ puts red('The following files are uncommitted:')
37
42
  uncommitted.each do |filename|
38
- puts " - #{filename}".red
43
+ puts red(" - #{filename}")
39
44
  end
40
45
  exit 1
41
46
  end
@@ -44,6 +49,5 @@ namespace :verify do
44
49
  task :all => [ :uncommitted ]
45
50
  end
46
51
 
47
- # FIXME: getting that intermittent gherken lexing error so removing :features from verify list
48
52
  task :verify => [ 'verify:all', :spec, :features]
49
53
  task :tests => [ :spec, :features]
data/bin/flapjack CHANGED
@@ -1,9 +1,15 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'yaml'
4
3
  require 'optparse'
5
4
  require 'ostruct'
6
5
 
6
+ # add lib to the default include path
7
+ unless $:.include?(File.dirname(__FILE__) + '/../lib/')
8
+ $: << File.dirname(__FILE__) + '/../lib'
9
+ end
10
+
11
+ require 'flapjack/configuration'
12
+
7
13
  options = OpenStruct.new
8
14
  options.config = File.join('etc', 'flapjack_config.yaml')
9
15
  options.daemonize = nil
@@ -27,16 +33,7 @@ end.parse!(ARGV)
27
33
 
28
34
  FLAPJACK_ENV = ENV['FLAPJACK_ENV'] || 'development'
29
35
 
30
- # load the config hash for the current environment
31
-
32
- if File.file?(options.config)
33
- config = YAML::load_file(options.config)
34
- else
35
- puts "Could not find config file at '#{options.config}', you may want to specify one with the --config option"
36
- exit(false)
37
- end
38
-
39
- config_env = config[FLAPJACK_ENV]
36
+ config_env = Flapjack::Configuration.new.load(options.config)
40
37
 
41
38
  if config_env.nil? || config_env.empty?
42
39
  puts "No config data for environment '#{FLAPJACK_ENV}' found in '#{options.config}'"
@@ -49,11 +46,6 @@ else
49
46
  pid_file = options.pidfile
50
47
  end
51
48
 
52
- # add lib to the default include path
53
- unless $:.include?(File.dirname(__FILE__) + '/../lib/')
54
- $: << File.dirname(__FILE__) + '/../lib'
55
- end
56
-
57
49
  # TODO Flapjack falls over when Redis restarted -- trap errors and attempt reconnect
58
50
 
59
51
  require 'flapjack/coordinator'
@@ -69,4 +61,4 @@ else
69
61
  end
70
62
 
71
63
  puts "Daemonising ... " if daemonize
72
- coordinator.start(:daemonize => daemonize)
64
+ coordinator.start(:daemonize => daemonize, :signals => true)
@@ -1,11 +1,16 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'redis'
4
- require 'json'
5
- require 'yaml'
6
3
  require 'optparse'
7
4
  require 'ostruct'
8
- require 'flapjack/data/entity_check'
5
+ require 'redis'
6
+ require 'yajl/json_gem'
7
+
8
+ # add lib to the default include path
9
+ unless $:.include?(File.dirname(__FILE__) + '/../lib/')
10
+ $: << File.dirname(__FILE__) + '/../lib'
11
+ end
12
+
13
+ require 'flapjack/configuration'
9
14
 
10
15
  options = OpenStruct.new
11
16
  options.config = File.join('etc', 'flapjack_config.yaml')
@@ -26,18 +31,9 @@ end.parse!(ARGV)
26
31
 
27
32
  FLAPJACK_ENV = ENV['FLAPJACK_ENV'] || 'development'
28
33
 
29
- # load the config hash for the current environment
30
-
31
- if File.file?(options.config)
32
- config = YAML::load(File.open(options.config))
33
- else
34
- puts "Could not find config file at '#{options.config}', you may want to specify one with the --config option"
35
- exit(false)
36
- end
34
+ @config_env = Flapjack::Configuration.new.load(options.config)
37
35
 
38
- config_env = config[FLAPJACK_ENV]
39
-
40
- if config_env.nil? || config_env.empty?
36
+ if @config_env.nil? || @config_env.empty?
41
37
  puts "No config data for environment '#{FLAPJACK_ENV}' found in '#{options.config}'"
42
38
  exit(false)
43
39
  end
@@ -55,24 +51,13 @@ end
55
51
  # host_perfdata_file_template=[HOSTPERFDATA]\t$TIMET$\t$HOSTNAME$\tHOST\t$HOSTSTATE$\t$HOSTEXECUTIONTIME$\t$HOSTLATENCY$\t$HOSTOUTPUT$\t$HOSTPERFDATA$
56
52
  # service_perfdata_file_template=[SERVICEPERFDATA]\t$TIMET$\t$HOSTNAME$\t$SERVICEDESC$\t$SERVICESTATE$\t$SERVICEEXECUTIONTIME$\t$SERVICELATENCY$\t$SERVICEOUTPUT$\t$SERVICEPERFDATA$
57
53
 
58
- @redis_host = config_env['redis']['host'] || 'localhost'
59
- @redis_port = config_env['redis']['port'] || '6379'
60
- @redis_path = config_env['redis']['path'] || nil
61
- @redis_db = config_env['redis']['db'] || 0
62
-
63
- if config_env.nil? || config_env.empty?
64
- puts "No config data for environment '#{FLAPJACK_ENV}'"
65
- exit(false)
54
+ def get_redis_connection(cfg)
55
+ opts = cfg['path'] ? {:path => cfg['path']} :
56
+ {:host => cfg['host'], :port => cfg['port']}
57
+ Redis.new(opts.merge(:db => cfg['db']))
66
58
  end
67
59
 
68
- def process_input
69
-
70
- if @redis_path
71
- redis = Redis.new(:db => @redis_db, :path => @redis_path)
72
- else
73
- redis = Redis.new(:db => @redis_db, :host => @redis_host, :port => @redis_port)
74
- end
75
-
60
+ def process_input(redis)
76
61
  begin
77
62
  while line = @fifo.gets
78
63
  skip unless line
@@ -112,8 +97,10 @@ def process_input
112
97
  end
113
98
 
114
99
  def main
100
+ redis = get_redis_connection(@config_env['redis'])
101
+
115
102
  while true
116
- process_input
103
+ process_input(redis)
117
104
  puts "Whoops, restarting main loop in 10 seconds"
118
105
  sleep 10
119
106
  end
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'yajl/json_gem'
4
- require 'redis'
5
3
  require 'optparse'
6
4
  require 'ostruct'
5
+ require 'yajl/json_gem'
6
+ require 'redis'
7
7
 
8
8
  # add lib to the default include path
9
9
  unless $:.include?(File.dirname(__FILE__) + '/../lib/')
@@ -45,6 +45,11 @@ FLAPJACK_ENV = ENV['FLAPJACK_ENV'] || 'development'
45
45
 
46
46
  config_env = Flapjack::Configuration.new.load(options.config)
47
47
 
48
+ if config_env.nil? || config_env.empty?
49
+ puts "No config data for environment '#{FLAPJACK_ENV}' found in '#{options.config}'"
50
+ exit(false)
51
+ end
52
+
48
53
  if options.from
49
54
  filename = options.from
50
55
  file = File.new(filename)
@@ -1,5 +1,25 @@
1
1
  ---
2
2
 
3
+ quickstart:
4
+ redis:
5
+ host: 127.0.0.1
6
+ port: 6379
7
+ db: 6
8
+ executive:
9
+ enabled: yes
10
+ email_queue: email_notifications
11
+ notification_log_file: log/flapjack-notification.log
12
+ email_notifier:
13
+ enabled: yes
14
+ queue: email_notifications
15
+ smtp_config:
16
+ address: "localhost"
17
+ domain: 'localhost.localdomain'
18
+ port: 25
19
+ web:
20
+ enabled: yes
21
+ port: 5080
22
+
3
23
  development:
4
24
  pid_file: tmp/pids/flapjack.pid
5
25
  log_file: log/flapjack.log