From 89a67770e66d11740948e90a41db6cee0482cf8e Mon Sep 17 00:00:00 2001 From: Patrick J Cherry Date: Wed, 13 Apr 2011 17:03:16 +0100 Subject: new version. --- bin/jconsole | 23 ++++++++ bin/jmauveserver | 65 +++++++++++++++++++++ bin/mauveclient | 172 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ bin/mauveconsole | 23 ++++++++ bin/mauveserver | 71 +++++++++++++++++++++++ 5 files changed, 354 insertions(+) create mode 100755 bin/jconsole create mode 100755 bin/jmauveserver create mode 100755 bin/mauveclient create mode 100755 bin/mauveconsole create mode 100755 bin/mauveserver (limited to 'bin') diff --git a/bin/jconsole b/bin/jconsole new file mode 100755 index 0000000..6e638ad --- /dev/null +++ b/bin/jconsole @@ -0,0 +1,23 @@ +#!/usr/bin/env jruby + +require 'pp' +pp $: + +Thread.abort_on_exception = true +require 'irb' +require 'thread' + +# hack for delving into test-generated configurations +class AlertAndNotificationLogic; Alerts = Queue.new; end + +require 'mauve/configuration' +include Mauve +#raise "must specify config file" unless ARGV.length > 0 +unless ARGV.length > 0 + STDERR.print("You must specify a configuration file as $arg[1]\n") + STDERR.print(" eg: ./mauve_starter ./bin/console ./test/local.conf\n") + exit 1 +end +Configuration.current = ConfigurationBuilder.load(ARGV.shift) +IRB.start + diff --git a/bin/jmauveserver b/bin/jmauveserver new file mode 100755 index 0000000..9cdd26f --- /dev/null +++ b/bin/jmauveserver @@ -0,0 +1,65 @@ +#!/usr/bin/env jruby + +begin + eval "Proc.new { |a,&b| }" +rescue SyntaxError => no_blocks_with_procs + STDERR.print "mauveserver must have Ruby 1.8.7 or later, sorry (if you "+ + "try, you'll get a SyntaxError trying to load one of its libraries)\n" + exit 1 +end + +require 'mauve/configuration' +include Mauve + +configuration_file = ARGV[0] +if !configuration_file + if File.exists?("/etc/mauvealert/mauveserver.conf") + configuration_file = "/etc/mauvealert/mauveserver.conf" + else + STDERR.print "Syntax: #{$0} \n" + exit 1 + end +end +Configuration.current = ConfigurationBuilder.load(configuration_file) + +class RestartSignalReceived < Exception; end +trap("HUP") do + # this blows up if you do it twice in quick succession, but don't really + # care about that case as it's only for log rotation. + Thread.main.raise(RestartSignalReceived.new) +end + +# Start canary thread. +#require 'canary' +#Canary.start(1, Log) + +# Main loop +@logger = Log4r::Logger.new "mauve::server<#{Process.pid}>" +loop do + begin + Configuration.current.server.run + rescue Interrupt + @logger.info "Interrupted by user, exiting" + Configuration.current.close + exit 0 + rescue RestartSignalReceived => ex + @logger.info "Restart signal received, reloading the configuration" + begin + new_configuration = ConfigurationBuilder.load(configuration_file) + rescue Exception => ex + @logger.error "Error reloading configuration, reusing old one: #{ex}" + @logger.debug ex.backtrace.join("\n") + end + + Configuration.current.close + Configuration.current = new_configuration + rescue Exception => ex + @logger.fatal("Uncaught #{ex.class} exception, will try to log") + @logger.fatal("Class: #{ex.class} "+ + "Message: #{ex.message} "+ + "Backtrace: #{ex.backtrace.join("\n")}") + exit 9 + end +end + + diff --git a/bin/mauveclient b/bin/mauveclient new file mode 100755 index 0000000..d513926 --- /dev/null +++ b/bin/mauveclient @@ -0,0 +1,172 @@ +#! /usr/bin/ruby1.8 +# == Synopsis +# +# mauvesend: send alert(s) to a given alert station +# +# == Usage +# +# mauvesend [destination] +# [--source | -o ] [--replace | -p] [--verbose | -v] +# [--id [alert options] ... ] +# +# : +# where the alert should go, can be one of: +# SRV record from DNS (we add _mauvealert._udp to record name) +# normal hostname (i.e. A record) +# IP address:port number +# +# if no destination is supplied, reads parameter from file +# /etc/mauvealert/mauvesend.destination (otherwise throws an error). +# +# --source | -o : +# identify the source of the alert (defaults to hostname, but you might +# want to name your monitoring systems more explicitly). +# +# --replace | -p: +# Send an update replacing all other alerts for this source - any previous +# alerts not specified in this update are assumed to be cleared. If you +# specify this option, you don't have to supply *any* alerts to raise or +# clear (in which case all alerts from that source will be cleared). +# +# --verbose | -v: +# If you specify this option once, it will print the transmission ID +# of the packet for debugging. If you specify it twice, it will print +# the entire data structure. +# +# You can specify any number of alerts in an update - every time you specify +# --id starts a new alert. +# +# --id | -i : +# alert ID; unique specified for each alert raised. +# +# --summary | -s : +# text for humans describing the nature of the alert, first 100 characters +# are only ones guaranteed to make it to pagers, twitter, SMS etc. +# +# --detail | -d : +# HTML fragment describing the alert in more detail, no limit on length. +# +# --subject | -u : +# set the subject of the alert (i.e. the server/entity that this alert +# concerns). +# +# --clear | -c