aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick J Cherry <patrick@bytemark.co.uk>2011-04-19 09:37:53 +0100
committerPatrick J Cherry <patrick@bytemark.co.uk>2011-04-19 09:37:53 +0100
commit326bbd320dbabc075fd7e59e55a715c7d4e9d6b9 (patch)
treeaa637e7287aa7088c31cb0b320241214059a6a7f
parent89a67770e66d11740948e90a41db6cee0482cf8e (diff)
* added sane init script for server
* mauvesend now handles options better * jabber client has stub message receivng method
-rwxr-xr-xbin/mauveclient25
-rwxr-xr-xbin/mauveserver37
-rw-r--r--debian/mauvealert-common.install2
-rw-r--r--debian/mauvealert-server.dirs2
-rw-r--r--debian/mauvealert-server.init159
-rw-r--r--debian/mauvealert-server.install59
-rw-r--r--lib/mauve/notifiers/email.rb15
-rw-r--r--lib/mauve/notifiers/xmpp.rb15
-rw-r--r--lib/mauve/person.rb1
-rw-r--r--mauveserver.conf41
10 files changed, 266 insertions, 90 deletions
diff --git a/bin/mauveclient b/bin/mauveclient
index d513926..1c90741 100755
--- a/bin/mauveclient
+++ b/bin/mauveclient
@@ -101,18 +101,24 @@ message = nil
verbose = 0
help = false
-GetoptLong.new(
- ['-h', '--help', GetoptLong::NO_ARGUMENT],
- ['-o', '--source', GetoptLong::REQUIRED_ARGUMENT],
+opts = GetoptLong.new(
+ ['-h', '--help', GetoptLong::NO_ARGUMENT],
+ ['-o', '--source', GetoptLong::OPTIONAL_ARGUMENT],
['-p', '--replace', GetoptLong::NO_ARGUMENT],
- ['-i', '--id', GetoptLong::REQUIRED_ARGUMENT],
- ['-s', '--summary', GetoptLong::REQUIRED_ARGUMENT],
- ['-u', '--subject', GetoptLong::REQUIRED_ARGUMENT],
- ['-c', '--clear', GetoptLong::REQUIRED_ARGUMENT],
- ['-r', '--raise', GetoptLong::REQUIRED_ARGUMENT],
- ['-d', '--detail', GetoptLong::REQUIRED_ARGUMENT],
+ ['-i', '--id', GetoptLong::OPTIONAL_ARGUMENT],
+ ['-s', '--summary', GetoptLong::OPTIONAL_ARGUMENT],
+ ['-u', '--subject', GetoptLong::OPTIONAL_ARGUMENT],
+ ['-c', '--clear', GetoptLong::OPTIONAL_ARGUMENT],
+ ['-r', '--raise', GetoptLong::OPTIONAL_ARGUMENT],
+ ['-d', '--detail', GetoptLong::OPTIONAL_ARGUMENT],
['-v', '--verbose', GetoptLong::NO_ARGUMENT]
).each do |opt,arg|
+
+ #
+ # Can catch empty arguments better if we set the GetoptLong things to
+ # "optional" rather than "required" and catch the empty arg here.
+ error "#{opt} cannot be empty" if arg.empty? and not %w(-h -p -v).include?(opt)
+
case opt
when '-h'
help = true
@@ -141,7 +147,6 @@ GetoptLong.new(
end
end
-
# CAUTION! Kwality kode.
#
if help
diff --git a/bin/mauveserver b/bin/mauveserver
index c576c85..57a2299 100755
--- a/bin/mauveserver
+++ b/bin/mauveserver
@@ -12,26 +12,18 @@ require 'mauve/configuration'
include Mauve
configuration_file = ARGV[0]
-if configuration_file.nil?
- %w(/etc/mauvealert/mauveserver.conf mauveserver.conf).each do |configuration_file|
- break if File.exists?(configuration_file)
- end
-end
-unless File.exists?(configuration_file)
- if ARGV[0]
- STDERR.print "Configuration file #{configuration_file} not found"
- else
- STDERR.print "Syntax: #{$0} <configuration filename>\n"
- end
- exit 1
+configuration_file = [".", "/etc/mauvealert/"].find{|d| File.file?(File.join(d,"mauveserver.conf")) } if configuration_file.nil?
+
+configuration_file = File.expand_path(configuration_file)
+
+unless File.file?(configuration_file)
+ STDERR.print "Configuration file #{configuration_file} not found"
+ Kernel.exit 1
end
Configuration.current = ConfigurationBuilder.load(configuration_file)
-class RestartSignalReceived < Exception; end
-class TerminateSignalReceived < Exception; end
-
%w(HUP).each do |sig|
trap("HUP") do
# this blows up if you do it twice in quick succession, but don't really
@@ -54,18 +46,5 @@ end
end
end
-#begin
- Mauve::Server.instance.run
-#rescue SystemExit
- # Woo!
-# exit 0
-#rescue Exception => ex
-# [ex.class.to_s, ex.to_s, ex.backtrace.join("\n")].each do |s|
-# Configuration.current.logger.fatal s
-# warn s
-# end
-#
-# exit 1
-#end
-#
+Mauve::Server.instance.run
diff --git a/debian/mauvealert-common.install b/debian/mauvealert-common.install
index 024d922..99771ab 100644
--- a/debian/mauvealert-common.install
+++ b/debian/mauvealert-common.install
@@ -1,3 +1,5 @@
mauve.proto usr/lib/mauvealert/
lib/mauve/proto.rb usr/lib/ruby/1.8/mauve/
+lib/mauve/mauve_time.rb usr/lib/ruby/1.8/mauve/
+
diff --git a/debian/mauvealert-server.dirs b/debian/mauvealert-server.dirs
new file mode 100644
index 0000000..ae8ddd8
--- /dev/null
+++ b/debian/mauvealert-server.dirs
@@ -0,0 +1,2 @@
+var/lib/mauvealert
+var/log/mauvealert
diff --git a/debian/mauvealert-server.init b/debian/mauvealert-server.init
new file mode 100644
index 0000000..1f0e57f
--- /dev/null
+++ b/debian/mauvealert-server.init
@@ -0,0 +1,159 @@
+#! /bin/sh
+### BEGIN INIT INFO
+# Provides: mauvealert
+# Required-Start: $remote_fs $syslog
+# Required-Stop: $remote_fs $syslog
+# Default-Start: 2 3 4 5
+# Default-Stop: 0 1 6
+# Short-Description: Mauve Server
+# Description: Mauve Server
+### END INIT INFO
+
+# Author: Patrick J Cherry <patrick@bytemark.co.uk>
+#
+
+# Do NOT "set -e"
+
+# PATH should only include /usr/* if it runs after the mountnfs.sh script
+PATH=/sbin:/usr/sbin:/bin:/usr/bin
+DESC="Mauve Alert Server"
+NAME=mauveserver
+DAEMON=/usr/sbin/$NAME
+DAEMON_ARGS="/etc/mauvealert/$NAME.conf"
+PIDFILE=/var/run/$NAME.pid
+SCRIPTNAME=/etc/init.d/$NAME
+
+# Exit if the package is not installed
+[ -x "$DAEMON" ] || exit 0
+
+# Read configuration variable file if it is present
+[ -r /etc/default/$NAME ] && . /etc/default/$NAME
+
+# Load the VERBOSE setting and other rcS variables
+. /lib/init/vars.sh
+
+VERBOSE=1
+
+# Define LSB log_* functions.
+# Depend on lsb-base (>= 3.2-14) to ensure that this file is present
+# and status_of_proc is working.
+. /lib/lsb/init-functions
+
+#
+# Function that starts the daemon/service
+#
+do_start()
+{
+ # Return
+ # 0 if daemon has been started
+ # 1 if daemon was already running
+ # 2 if daemon could not be started
+ start-stop-daemon --start --quiet --pidfile $PIDFILE --startas $DAEMON --test > /dev/null \
+ || return 1
+ start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile --background --startas $DAEMON -- \
+ $DAEMON_ARGS \
+ || return 2
+ # Add code here, if necessary, that waits for the process to be ready
+ # to handle requests from services started subsequently which depend
+ # on this one. As a last resort, sleep for some time.
+
+ sleep 5
+}
+
+#
+# Function that stops the daemon/service
+#
+do_stop()
+{
+ # Return
+ # 0 if daemon has been stopped
+ # 1 if daemon was already stopped
+ # 2 if daemon could not be stopped
+ # other if a failure occurred
+ start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
+ RETVAL="$?"
+ [ "$RETVAL" = 2 ] && return 2
+ # Wait for children to finish too if this is a daemon that forks
+ # and if the daemon is only ever run from this initscript.
+ # If the above conditions are not satisfied then add some other code
+ # that waits for the process to drop all resources that could be
+ # needed by services started subsequently. A last resort is to
+ # sleep for some time.
+ start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --pidfile $PIDFILE --name $NAME
+ [ "$?" = 2 ] && return 2
+ # Many daemons don't delete their pidfiles when they exit.
+ rm -f $PIDFILE
+ return "$RETVAL"
+}
+
+#
+# Function that sends a SIGHUP to the daemon/service
+#
+do_reload() {
+ #
+ # If the daemon can reload its configuration without
+ # restarting (for example, when it is sent a SIGHUP),
+ # then implement that here.
+ #
+ start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
+ return 0
+}
+
+case "$1" in
+ start)
+ [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
+ do_start
+ case "$?" in
+ 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
+ 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
+ esac
+ ;;
+ stop)
+ [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
+ do_stop
+ case "$?" in
+ 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
+ 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
+ esac
+ ;;
+ status)
+ status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
+ ;;
+ reload|force-reload)
+ #
+ # If do_reload() is not implemented then leave this commented out
+ # and leave 'force-reload' as an alias for 'restart'.
+ #
+ log_daemon_msg "Reloading $DESC" "$NAME"
+ do_reload
+ log_end_msg $?
+ ;;
+ restart)
+ #
+ # If the "reload" option is implemented then remove the
+ # 'force-reload' alias
+ #
+ log_daemon_msg "Restarting $DESC" "$NAME"
+ do_stop
+ case "$?" in
+ 0|1)
+ do_start
+ case "$?" in
+ 0) log_end_msg 0 ;;
+ 1) log_end_msg 1 ;; # Old process is still running
+ *) log_end_msg 1 ;; # Failed to start
+ esac
+ ;;
+ *)
+ # Failed to stop
+ log_end_msg 1
+ ;;
+ esac
+ ;;
+ *)
+ #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
+ echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
+ exit 3
+ ;;
+esac
+
diff --git a/debian/mauvealert-server.install b/debian/mauvealert-server.install
index 630990d..47a3add 100644
--- a/debian/mauvealert-server.install
+++ b/debian/mauvealert-server.install
@@ -1,31 +1,30 @@
-bin/mauveserver usr/bin/
-lib/mauve/notifiers.rb usr/lib/ruby/1.8/mauve/
-lib/mauve/notification.rb usr/lib/ruby/1.8/mauve/
-lib/mauve/alert.rb usr/lib/ruby/1.8/mauve/
-lib/mauve/time.rb usr/lib/ruby/1.8/mauve/
-lib/mauve/alert_changed.rb usr/lib/ruby/1.8/mauve/
-lib/mauve/source_list.rb usr/lib/ruby/1.8/mauve/
-lib/mauve/alert_group.rb usr/lib/ruby/1.8/mauve/
-lib/mauve/web_sinatra.rb usr/lib/ruby/1.8/mauve/
-lib/mauve/configuration.rb usr/lib/ruby/1.8/mauve/
-lib/mauve/calendar_interface.rb usr/lib/ruby/1.8/mauve/
-lib/mauve/auth_bytemark.rb usr/lib/ruby/1.8/mauve/
-lib/mauve/people_list.rb usr/lib/ruby/1.8/mauve/
-lib/mauve/person.rb usr/lib/ruby/1.8/mauve/
-lib/mauve/web_interface.rb usr/lib/ruby/1.8/mauve/
-lib/mauve/timers.rb usr/lib/ruby/1.8/mauve/
-lib/mauve/server.rb usr/lib/ruby/1.8/mauve/
-lib/mauve/datamapper.rb usr/lib/ruby/1.8/mauve/
-lib/mauve/notifiers/sms_aql.rb usr/lib/ruby/1.8/mauve/notifiers/
-lib/mauve/notifiers/xmpp-smack.rb usr/lib/ruby/1.8/mauve/notifiers/
-lib/mauve/notifiers/debug.rb usr/lib/ruby/1.8/mauve/notifiers/
-lib/mauve/notifiers/email.rb usr/lib/ruby/1.8/mauve/notifiers/
-lib/mauve/notifiers/xmpp.rb usr/lib/ruby/1.8/mauve/notifiers/
-lib/mauve/notifiers/sms_default.rb usr/lib/ruby/1.8/mauve/notifiers/
-lib/dm-sqlite-adapter-with-mutex.rb usr/lib/ruby/1.8/
-lib/sinatra-partials.rb usr/lib/ruby/1.8/
-lib/object_builder.rb usr/lib/ruby/1.8/
-lib/rack-flash.rb usr/lib/ruby/1.8/
-static usr/share/mauvealert
-views usr/share/mauvealert
+bin/mauveserver usr/sbin/
+lib/dm-sqlite-adapter-with-mutex.rb usr/lib/ruby/1.8/
+lib/mauve/alert.rb usr/lib/ruby/1.8/mauve/
+lib/mauve/alert_changed.rb usr/lib/ruby/1.8/mauve/
+lib/mauve/alert_group.rb usr/lib/ruby/1.8/mauve/
+lib/mauve/auth_bytemark.rb usr/lib/ruby/1.8/mauve/
+lib/mauve/calendar_interface.rb usr/lib/ruby/1.8/mauve/
+lib/mauve/configuration.rb usr/lib/ruby/1.8/mauve/
+lib/mauve/datamapper.rb usr/lib/ruby/1.8/mauve/
+lib/mauve/http_server.rb usr/lib/ruby/1.8/mauve/
+lib/mauve/mauve_thread.rb usr/lib/ruby/1.8/mauve/
+lib/mauve/notification.rb usr/lib/ruby/1.8/mauve/
+lib/mauve/notifier.rb usr/lib/ruby/1.8/mauve/
+lib/mauve/notifiers usr/lib/ruby/1.8/mauve/
+lib/mauve/notifiers.rb usr/lib/ruby/1.8/mauve/
+lib/mauve/people_list.rb usr/lib/ruby/1.8/mauve/
+lib/mauve/person.rb usr/lib/ruby/1.8/mauve/
+lib/mauve/processor.rb usr/lib/ruby/1.8/mauve/
+lib/mauve/server.rb usr/lib/ruby/1.8/mauve/
+lib/mauve/source_list.rb usr/lib/ruby/1.8/mauve/
+lib/mauve/timer.rb usr/lib/ruby/1.8/mauve/
+lib/mauve/udp_server.rb usr/lib/ruby/1.8/mauve/
+lib/mauve/web_interface.rb usr/lib/ruby/1.8/mauve/
+lib/object_builder.rb usr/lib/ruby/1.8/
+lib/rack-flash.rb usr/lib/ruby/1.8/
+lib/sinatra-partials.rb usr/lib/ruby/1.8/
+static usr/share/mauvealert
+views usr/share/mauvealert
+mauveserver.conf etc/mauvealert/
diff --git a/lib/mauve/notifiers/email.rb b/lib/mauve/notifiers/email.rb
index c445e09..2c14a54 100644
--- a/lib/mauve/notifiers/email.rb
+++ b/lib/mauve/notifiers/email.rb
@@ -80,8 +80,7 @@ module Mauve
m.header.from = @from
m.header.date = MauveTime.now
- summary_formatted = ""
-# summary_formatted = " * "+alert.summary_two_lines.join("\n ")
+ summary_formatted = " * "+alert.summary_two_lines.join("\n ")
case alert.update_type.to_sym
when :cleared
@@ -99,8 +98,8 @@ module Mauve
# FIXME: include alert.detail as multipart mime
##Thread.abort_on_exception = true
m.body += "\n" + '-'*10 + " This is the detail field " + '-'*44 + "\n\n"
- #m.body += alert.get_details()
- #m.body += alert.get_details_plain_text()
+ m.body += alert.get_details()
+ m.body += alert.get_details_plain_text()
m.body += "\n" + '-'*80 + "\n\n"
if @suppressed_changed == true
@@ -122,12 +121,12 @@ single alert, you must watch the web front-end instead.
"There is currently one other alert outstanding:\n\n" :
"There are currently #{other_alerts.length} other alerts outstanding:\n\n"
-# other_alerts.each do |other|
-# m.body += " * "+other.summary_two_lines.join("\n ")+"\n\n"
-# end
+ other_alerts.each do |other|
+ m.body += " * "+other.summary_two_lines.join("\n ")+"\n\n"
+ end
end
- m.body += @email_suffix
+ m.body += "-- \n"+@signature
m.to_s
end
diff --git a/lib/mauve/notifiers/xmpp.rb b/lib/mauve/notifiers/xmpp.rb
index d216788..18df6b2 100644
--- a/lib/mauve/notifiers/xmpp.rb
+++ b/lib/mauve/notifiers/xmpp.rb
@@ -64,8 +64,6 @@ module Mauve
logger.debug "Jabber starting connection to #{@jid}"
@client = Client.new(JID::new(@jid))
@client.connect
- logger.debug "Jabber authentication"
-
@client.auth_nonsasl(@password, false)
@roster = Roster::Helper.new(@client)
@@ -79,11 +77,16 @@ module Mauve
ensure_roster_and_subscription!(stanza.from)
end.join
end
+
+ @client.add_message_callback do |m|
+ receive_message(m)
+ end
@roster.wait_for_roster
logger.debug "Jabber authenticated, setting presence"
@client.send(Presence.new.set_type(:available))
+
@mucs = {}
logger.debug "Jabber is ready in theory"
@@ -290,6 +293,14 @@ module Mauve
end
end
+
+ #
+ # TODO parse message and ack as needed..? The trick is here to
+ # understand what the person sending the message wants. Could be
+ # difficult.
+ def receive_message(message)
+ @logger.debug "Received message from #{message.from}.. Ignoring for now."
+ end
end
end
end
diff --git a/lib/mauve/person.rb b/lib/mauve/person.rb
index 6e9fcb4..da3aa13 100644
--- a/lib/mauve/person.rb
+++ b/lib/mauve/person.rb
@@ -128,7 +128,6 @@ module Mauve
# being raised.
send_alert(level, alert) if last_change.was_relevant_when_raised?
end
- end
end
def remind(alert, level)
diff --git a/mauveserver.conf b/mauveserver.conf
index 1000283..c17f7f7 100644
--- a/mauveserver.conf
+++ b/mauveserver.conf
@@ -7,26 +7,47 @@
server {
# persistent data store, only sqlite3 supported at the moment
database "sqlite3:///var/lib/mauvealert/alerts.db"
-
- # you probably want to listen on all addresses
- ip "0.0.0.0"
- # UDP port number
- port 32741
-
- # logging options
- log_file "/var/log/mauveserver.log"
- # 0 is debug, 1 is info, 2 is warning
- log_level 1
+ listener {
+ ip "0.0.0.0"
+ port 32741
+ }
+
# default is probably more than enough!
#transmission_id_expire_time 600
# few options for web interface, just the TCP port number
web_interface {
+ ip "0.0.0.0"
port 1288
+ document_root "/usr/share/mauvealert"
}
}
+logger {
+
+ default_format "%d [ %6.6l ] [ %12.12c ] %m"
+
+# outputter("stdout") {
+# level Log4r::DEBUG
+# }
+
+ outputter("file") {
+ filename "/var/log/mauve/mauveserver.log"
+ trunc false
+ level Log4r::DEBUG
+ }
+
+ outputter("email") {
+ server "outgoing.mx.bytemark.co.uk"
+ subject "Mauve logger output"
+ from "#{ENV['USER']}@#{Socket.gethostname}"
+ to "patrick@bytemark.co.uk"
+ domain "test.mauve.bytemark.co.uk"
+ level Log4r::WARN
+ }
+
+}
notification_method("email") {
# email address to send from