flapjack 0.4.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $: << File.dirname(__FILE__) + '/../lib' unless $:.include?(File.dirname(__FILE__) + '/../lib/')
4
+
5
+ require 'rubygems'
6
+ require 'log4r'
7
+ require 'log4r/outputter/syslogoutputter'
8
+ require 'flapjack/cli/worker'
9
+
10
+ at_exit do
11
+ puts "Shutting down"
12
+ end
13
+
14
+ trap("INT") do
15
+ puts "Caught shutdown signal, cleaning up."
16
+ exit
17
+ end
18
+
19
+ @options = Flapjack::WorkerOptions.parse(ARGV)
20
+ @worker = Flapjack::Worker.new(:host => @options.host,
21
+ :port => @options.port,
22
+ :checks_directory => @options.check_directory)
23
+
24
+ begin
25
+ @worker.process_loop
26
+ rescue Beanstalk::NotConnected
27
+ puts "Couldn't connect to the beanstalk!"
28
+
29
+ timeout = 5
30
+ puts "Retrying in #{timeout} seconds"
31
+ sleep timeout
32
+
33
+ puts "Retrying..."
34
+ retry
35
+ end
36
+
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $: << File.dirname(__FILE__) + '/../lib' unless $:.include?(File.dirname(__FILE__) + '/../lib/')
4
+
5
+ require 'rubygems'
6
+ require 'daemons'
7
+ require 'fileutils'
8
+ require 'flapjack/cli/worker_manager'
9
+ require 'flapjack/patches' # for Daemons
10
+
11
+ # reassign ARGV so we don't mess with it directly
12
+ args = ARGV
13
+ args << '--help' if args.size == 0
14
+ options = WorkerManagerOptions.parse(args)
15
+
16
+ worker_path = File.join(File.dirname(__FILE__), 'flapjack-worker')
17
+
18
+ # set up pid dir
19
+ pid_dir = "/var/run/flapjack"
20
+ FileUtils.mkdir_p(pid_dir)
21
+
22
+ # spin up a number of workers (5 is the default).
23
+ options.workers.times do |n|
24
+ # we fork for each worker, as Daemons.run backgrounds this script.
25
+ fork do
26
+ Daemons.run(worker_path,
27
+ :ARGV => (args + %w(-- -b localhost)),
28
+ :multiple => true,
29
+ :dir_mode => :normal,
30
+ :dir => pid_dir)
31
+ end
32
+ # so we don't try and stop the daemon multiple times
33
+ break if ARGV[0] == "stop"
34
+ end
35
+
@@ -0,0 +1,58 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # 28 05 2009
4
+ # Lindsay Holmwood <lindsay@holmwood.id.au>
5
+ #
6
+ # Copies various scripts to appropriate places so Flapjack can be
7
+ # started as a daemon.
8
+ #
9
+ # I abhor these sort of scripts. It's only a stopgap until Flapjack
10
+ # gets packaged properly.
11
+ #
12
+ # If you would like to package, please let me know! Patches welcome.
13
+ #
14
+
15
+ unless ENV["USERNAME"] == "root"
16
+ puts 'You need to be root to run this script'
17
+ exit 1
18
+ end
19
+
20
+ # prompt/warn the user what is about to happen
21
+ puts "This script sets up Flapjack to run as a daemon. Specifically it: "
22
+ puts
23
+ puts " * installs init scripts and configs into /etc"
24
+ puts " * sets up /var/run/flapjack "
25
+ puts " * sets Flapjack to run on boot"
26
+ puts
27
+ puts "It will prompt you if it wants to overwrite an existing file."
28
+ puts
29
+ print "Do you want to continue? [y/n] "
30
+ continue = gets.strip
31
+ puts
32
+
33
+ unless continue == "y"
34
+ puts "Exiting."
35
+ exit
36
+ end
37
+
38
+ # setup
39
+ system("mkdir -p /var/run/flapjack")
40
+ system("chmod a+rw /var/run/flapjack")
41
+
42
+ etc_path=`gem contents auxesis-flapjack |grep etc`.split.first.gsub(/etc\/.+/, 'etc').strip
43
+ system("cp -aiv #{etc_path}/* /etc")
44
+
45
+ # set sequence number to 50 so beanstalkd has a chance to boot
46
+ system("update-rc.d flapjack-workers defaults 50")
47
+ system("update-rc.d flapjack-notifier defaults 50")
48
+
49
+ puts
50
+ puts "Setup complete!"
51
+ puts
52
+ puts "You will want to customise:"
53
+ puts " * /etc/flapjack/recipients.yaml"
54
+ puts " * /etc/flapjack/flapjack-notifier.yaml"
55
+ puts
56
+ puts ".examples of these files exist in /etc/flapjack/'
57
+
58
+
@@ -0,0 +1,38 @@
1
+ ### Configuring ###
2
+
3
+ You can configure who receives notifications from `flapjack-notifier`
4
+ in `/etc/flapjack/recipients.yaml`:
5
+
6
+ ---
7
+ - :name: Jane Doe
8
+ :email: "jane@doe.com"
9
+ :phone: "+61 444 222 111"
10
+ :pager: "61444222111"
11
+ :jid: "jane@doe.com"
12
+
13
+ Then you can configure how people are notified in `/etc/flapjack/flapjack-notifier.yaml`:
14
+
15
+ ---
16
+ :notifiers:
17
+ :mailer:
18
+ :from_address: notifications@my-domain.com
19
+ :xmpp:
20
+ :jid: notifications@my-domain.com
21
+ :password: foo
22
+ :database_uri: "sqlite3:///var/lib/flapjack/flapjack.db"
23
+
24
+ Currently there are email and XMPP notifiers.
25
+
26
+ The `database_uri` setting must point to the database `flapjack-admin` backs
27
+ onto. This can be SQLite3, MySQL, or PostgreSQL:
28
+
29
+ :database_uri: "mysql://user:password@localhost/flapjack_production"
30
+ # or
31
+ :database_uri: "postgres://me:spoons@db.mydomain.com/flapjack_production"
32
+
33
+ Now you need to restart the notifier:
34
+
35
+ flapjack-notifier-manager restart --recipients /etc/flapjack/recipients.yaml \
36
+ --config /etc/flapjack/flapjack-notifier.yaml
37
+
38
+
data/doc/DEVELOPING.md ADDED
@@ -0,0 +1,35 @@
1
+ Developing
2
+ ----------
3
+
4
+ You can write your own notifiers and place them in `lib/flapjack/notifiers/`.
5
+
6
+ Your notifier just needs to implement the `notify` method, and take in a hash:
7
+
8
+ class Sms
9
+ def initialize(opts={})
10
+ # you may want to set from address here
11
+ @from = (opts[:from] || "0431 112 233")
12
+ end
13
+
14
+ def notify(opts={})
15
+ who = opts[:who]
16
+ result = opts[:result]
17
+ # sms to your hearts content
18
+ end
19
+ end
20
+
21
+
22
+ Testing
23
+ -------
24
+
25
+ Flapjack is, and will continue to be, well tested. Monitoring is like continuous
26
+ integration for production apps, so why shouldn't your monitoring system have tests?
27
+
28
+ Testing is done with rspec, and tests live in `spec/`.
29
+
30
+ To run the tests, check out the code and run:
31
+
32
+ $ rake spec
33
+
34
+
35
+
data/doc/INSTALL.md ADDED
@@ -0,0 +1,64 @@
1
+ Dependencies
2
+ ------------
3
+
4
+ Before installing Flapjack you will need to setup some dependencies.
5
+
6
+ ### Setup dependencies (Ubuntu Hardy) ###
7
+
8
+ Add the following lines to `/etc/apt/sources.list`
9
+
10
+ deb http://ppa.launchpad.net/ubuntu-ruby-backports/ubuntu hardy main
11
+ deb http://ppa.launchpad.net/auxesis/ppa/ubuntu hardy main
12
+
13
+ Add GPG keys for the repos:
14
+
15
+ sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 288BA53BCB7DA731
16
+
17
+ Update your package list:
18
+
19
+ sudo apt-get update
20
+
21
+ Install Ruby dependencies:
22
+
23
+ sudo apt-get install build-essential libsqlite3-dev
24
+
25
+ Install rubygems + beanstalkd:
26
+
27
+ sudo apt-get install rubygems beanstalkd
28
+
29
+ Set `ENABLED=1` in `/etc/default/beanstalkd`.
30
+
31
+ Start beanstalkd:
32
+
33
+ sudo /etc/init.d/beanstalkd start
34
+
35
+
36
+ ### Setup dependencies (everyone else) ###
37
+
38
+ Install the following software through your package manager or from source:
39
+
40
+ - beanstalkd (from [http://xph.us/software/beanstalkd/](http://xph.us/software/beanstalkd/))
41
+ - libevent (from [http://monkey.org/~provos/libevent/](http://monkey.org/~provos/libevent/))
42
+ - latest RubyGems (from [http://rubyforge.org/projects/rubygems/](http://rubyforge.org/projects/rubygems/))
43
+
44
+
45
+ ## Installation ##
46
+
47
+ Add GitHub's RubyGems server to your Gem sources:
48
+
49
+ sudo gem sources -a http://gems.github.com
50
+
51
+ Install the Flapjack gem:
52
+
53
+ sudo gem install auxesis-flapjack
54
+
55
+ Then run the magic configuration script to set up init scripts:
56
+
57
+ sudo install-flapjack-systemwide
58
+
59
+ The script will prompt you if it wants to do anything destructive.
60
+
61
+ ## Packages ##
62
+
63
+ We want to provide native packages for Flapjack (`.deb`, `.rpm`, `.ebuild`). If
64
+ you'd like to contribute please let us know!
@@ -0,0 +1,15 @@
1
+ # Defaults for flapjack-notifier initscript
2
+ # sourced by /etc/init.d/flapjack-notifier
3
+
4
+ # set enabled to 1 if you want the init script to start flapjack-notifier
5
+ ENABLED=1
6
+
7
+ # recipients file
8
+ RECIPIENTS=/etc/flapjack/recipients.yaml
9
+
10
+ # address beanstalkd is bound to
11
+ BEANSTALKD_ADDR=localhost
12
+
13
+ # port beanstalk is listening on
14
+ BEANSTALKD_PORT=11300
15
+
@@ -0,0 +1,17 @@
1
+ # Defaults for flapjack-workers initscript
2
+ # sourced by /etc/init.d/flapjack-workers
3
+
4
+ # set enabled to 1 if you want the init script to start flapjack-workers
5
+ ENABLED=1
6
+
7
+ # address beanstalkd is bound to
8
+ BEANSTALKD_ADDR=localhost
9
+
10
+ # port beanstalk is listening on
11
+ BEANSTALKD_PORT=11300
12
+
13
+ # number of workers to spin up
14
+ WORKERS=5
15
+
16
+ # location of the checks
17
+ CHECKS_DIRECTORY=/usr/lib/flapjack/checks
@@ -0,0 +1,8 @@
1
+ ---
2
+ :notifiers:
3
+ :mailer:
4
+ :from_address: notifications@my-domain.com
5
+ :xmpp:
6
+ :jid: notifications@my-domain.com
7
+ :password: foo
8
+ :database_uri: "sqlite3:///var/lib/flapjack/flapjack.db"
@@ -0,0 +1,10 @@
1
+ - :name: Jane Doe
2
+ :email: "jane@doe.com"
3
+ :phone: "+1 444 333 888"
4
+ :pager: "1444333888"
5
+ :jid: "jane@doe.com"
6
+ - :name: John Doe
7
+ :email: "john@doe.com"
8
+ :phone: "+1 483 401 501"
9
+ :pager: "1888777333"
10
+ :jid: "john@doe.com"
@@ -0,0 +1,47 @@
1
+ #!/bin/bash
2
+ #
3
+ # Copyright (c) 2009 Lindsay Holmwood <lindsay@holmwood.id.au>
4
+ #
5
+ # flapjack-notifier
6
+ # Boots flapjack-notifier, check executors for Flapjack.
7
+ #
8
+
9
+ PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local:/usr/local/sbin:/usr/local/bin
10
+
11
+ if [ -f /etc/default/flapjack-notifier ]; then
12
+ . /etc/default/flapjack-notifier
13
+ fi
14
+
15
+ # Default return value
16
+ RETVAL=0
17
+
18
+ if [ ! $(which flapjack-notifier-manager) ]; then
19
+ echo "Error: flapjack-notifier-manager isn't on your path."
20
+ echo "Refusing to start!"
21
+ exit 1
22
+ fi
23
+
24
+ # Evaluate command
25
+ case "$1" in
26
+ start)
27
+ flapjack-notifier-manager start --recipients $RECIPIENTS \
28
+ --port $BEANSTALKD_PORT --beanstalk $BEANSTALKD_ADDR
29
+ RETVAL=$?
30
+ ;;
31
+ stop)
32
+ flapjack-notifier-manager stop --recipients $RECIPIENTS \
33
+ --port $BEANSTALKD_PORT --beanstalk $BEANSTALKD_ADDR
34
+ RETVAL=$?
35
+ ;;
36
+ restart)
37
+ flapjack-notifier-manager restart --recipients $RECIPIENTS \
38
+ --port $BEANSTALKD_PORT --beanstalk $BEANSTALKD_ADDR
39
+ RETVAL=$?
40
+ ;;
41
+ *)
42
+ echo "Usage: flapjack-notifier {start|stop|restart}"
43
+ exit 1
44
+ ;;
45
+ esac
46
+
47
+ exit $RETVAL
@@ -0,0 +1,44 @@
1
+ #!/bin/bash
2
+ #
3
+ # Copyright (c) 2009 Lindsay Holmwood <lindsay@holmwood.id.au>
4
+ #
5
+ # flapjack-workers
6
+ # Boots flapjack-workers, check executors for Flapjack.
7
+ #
8
+
9
+ PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local:/usr/local/sbin:/usr/local/bin
10
+
11
+ if [ -f /etc/default/flapjack-workers ]; then
12
+ . /etc/default/flapjack-workers
13
+ fi
14
+
15
+ # Default return value
16
+ RETVAL=0
17
+
18
+ if [ ! $(which flapjack-worker-manager) ]; then
19
+ echo "flapjack-worker-manager isn't on your path."
20
+ echo "Refusing to start."
21
+ exit 1
22
+ fi
23
+
24
+ # Evaluate command
25
+ case "$1" in
26
+ start)
27
+ flapjack-worker-manager start --workers $WORKERS --checks-directory $CHECKS_DIRECTORY
28
+ RETVAL=$?
29
+ ;;
30
+ stop)
31
+ flapjack-worker-manager stop
32
+ RETVAL=$?
33
+ ;;
34
+ restart)
35
+ flapjack-worker-manager restart --workers $WORKERS
36
+ RETVAL=$?
37
+ ;;
38
+ *)
39
+ echo "Usage: flapjack-workers {start|stop|restart}"
40
+ exit 1
41
+ ;;
42
+ esac
43
+
44
+ exit $RETVAL
data/flapjack.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'flapjack'
3
+ s.version = '0.4.10'
4
+ s.date = '2009-07-16'
5
+
6
+ s.summary = "a scalable and distributed monitoring system"
7
+ s.description = "Flapjack is highly scalable and distributed monitoring system. It understands the Nagios plugin format, and can easily be scaled from 1 server to 1000."
8
+
9
+ s.authors = ['Lindsay Holmwood']
10
+ s.email = 'lindsay@holmwood.id.au'
11
+ s.homepage = 'http://flapjack-project.com'
12
+ s.has_rdoc = false
13
+
14
+ s.add_dependency('daemons', '>= 1.0.10')
15
+ s.add_dependency('beanstalk-client', '>= 1.0.2')
16
+ s.add_dependency('log4r', '>= 1.0.5')
17
+ s.add_dependency('xmpp4r-simple', '>= 0.8.8')
18
+ s.add_dependency('mailfactory', '>= 1.4.0')
19
+ s.add_dependency('dm-core', '>= 0.9.11')
20
+ s.add_dependency('dm-timestamps', '>= 0.9.11')
21
+ s.add_dependency('dm-types', '>= 0.9.11')
22
+ s.add_dependency('dm-validations', '>= 0.9.11')
23
+ s.add_dependency('data_objects', '>= 0.9.12')
24
+ s.add_dependency('do_sqlite3', '>= 0.9.12')
25
+
26
+ s.bindir = "bin"
27
+ s.executables = ["flapjack-notifier", "flapjack-notifier-manager", "flapjack-stats", "flapjack-worker", "flapjack-worker-manager", "install-flapjack-systemwide"]
28
+ s.files = ["LICENCE", "README.md", "Rakefile", "TODO.md", "bin/flapjack-notifier", "bin/flapjack-notifier-manager", "bin/flapjack-stats", "bin/flapjack-worker", "bin/flapjack-worker-manager", "bin/install-flapjack-systemwide", "doc/CONFIGURING.md", "doc/DEVELOPING.md", "doc/INSTALL.md", "etc/default/flapjack-notifier", "etc/default/flapjack-workers", "etc/flapjack/flapjack-notifier.yaml.example", "etc/flapjack/recipients.yaml.example", "etc/init.d/flapjack-notifier", "etc/init.d/flapjack-workers", "flapjack.gemspec", "lib/flapjack/checks/http_content", "lib/flapjack/cli/notifier.rb", "lib/flapjack/cli/notifier_manager.rb", "lib/flapjack/cli/worker.rb", "lib/flapjack/cli/worker_manager.rb", "lib/flapjack/database.rb", "lib/flapjack/models/check.rb", "lib/flapjack/models/check_template.rb", "lib/flapjack/models/node.rb", "lib/flapjack/models/related_check.rb", "lib/flapjack/notifier.rb", "lib/flapjack/notifiers/mailer/init.rb", "lib/flapjack/notifiers/mailer/mailer.rb", "lib/flapjack/notifiers/xmpp/init.rb", "lib/flapjack/notifiers/xmpp/xmpp.rb", "lib/flapjack/patches.rb", "lib/flapjack/result.rb"]
29
+ end
30
+
31
+