aboutsummaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
Diffstat (limited to 'utils')
-rwxr-xr-xutils/buffer_size.sh32
-rw-r--r--utils/clear_wrong_reminder.sql4
-rwxr-xr-xutils/get_last_test_db.sh3
-rwxr-xr-xutils/get_last_test_log.sh3
-rwxr-xr-xutils/get_live_db.sh3
-rwxr-xr-xutils/init_jmauve.sh80
-rwxr-xr-xutils/init_mauve.sh83
-rwxr-xr-xutils/packet_processing.sh32
-rwxr-xr-xutils/run_android.sh2
-rwxr-xr-xutils/supportbot-mauve73
-rwxr-xr-xutils/test-smack.rb101
11 files changed, 416 insertions, 0 deletions
diff --git a/utils/buffer_size.sh b/utils/buffer_size.sh
new file mode 100755
index 0000000..02984b2
--- /dev/null
+++ b/utils/buffer_size.sh
@@ -0,0 +1,32 @@
+#!/bin/sh
+
+NO_ARGS=0
+OPTERROR=65
+if [ $# -eq "$NO_ARGS" ] # Script invoked with no command-line args?
+then
+ echo "Usage: `basename $0` File.log"
+ exit $OPTERROR # Exit and explain usage, if no argument(s) given.
+fi
+logFile=$1
+
+egrep 'Buffer has [0-9]* packets left' $logFile |\
+ awk 'BEGIN {print " date sz"} {print s++ " " $1 "::" $2 " " $10}' > data
+
+R --vanilla --no-save --slave <<RSCRIPT
+lst <- read.table("data")
+attach(lst)
+summary(sz)
+png(filename="buffer.png", width=1024)
+dates <- strptime(as.character(date), "%Y-%m-%d::%H:%M:%S")
+plot(dates, sz, type='l',
+ main="Mauve server: Maximum buffer size per second",
+ xlab="Time",
+ ylab="Maximum number of packets waiting to be processed")
+abline(h=1.05, col="red")
+abline(h=mean(sz), col="blue")
+RSCRIPT
+img=`which qiv`
+if [ $? != 0 ]
+then echo "Cannot display image here"
+else $img buffer.png
+fi
diff --git a/utils/clear_wrong_reminder.sql b/utils/clear_wrong_reminder.sql
new file mode 100644
index 0000000..fde0504
--- /dev/null
+++ b/utils/clear_wrong_reminder.sql
@@ -0,0 +1,4 @@
+select * from 'mauve_alerts' where update_type='cleared' and will_unacknowledge_at != 0;
+
+update 'mauve_alerts' set will_unacknowledge_at=NULL where update_type='cleared' and will_unacknowledge_at != 0;
+
diff --git a/utils/get_last_test_db.sh b/utils/get_last_test_db.sh
new file mode 100755
index 0000000..71ce4f1
--- /dev/null
+++ b/utils/get_last_test_db.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+test=`echo $1 | sed s/://`
+sqlitebrowser `/bin/ls -dtr /tmp/mauve_test/* | tail -1`/$test\(ZTestCases\)/mauve_test.db
diff --git a/utils/get_last_test_log.sh b/utils/get_last_test_log.sh
new file mode 100755
index 0000000..26597d0
--- /dev/null
+++ b/utils/get_last_test_log.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+test=`echo $1 | sed s/://`
+less `/bin/ls -dtr /tmp/mauve_test/* | tail -1`/$test\(ZTestCases\)/log000001
diff --git a/utils/get_live_db.sh b/utils/get_live_db.sh
new file mode 100755
index 0000000..35c5aea
--- /dev/null
+++ b/utils/get_live_db.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+scp one-eyed-jack:/var/lib/mauveserver/alerts.db . && \
+ sqlitebrowser alerts.db
diff --git a/utils/init_jmauve.sh b/utils/init_jmauve.sh
new file mode 100755
index 0000000..3011d62
--- /dev/null
+++ b/utils/init_jmauve.sh
@@ -0,0 +1,80 @@
+#!/bin/sh
+### BEGIN INIT INFO
+# Provides: mauveserver
+# Required-Start: $remote_fs $syslog
+# Required-Stop: $remote_fs $syslog
+# Default-Start: 2 3 4 5
+# Default-Stop: 0 1 6
+# Short-Description: Start the mauve alerting daemon at boot time
+# Description: Start the mauve alerting daemon at boot time
+### END INIT INFO
+
+PATH=/bin:/sbin:/usr/bin:/usr/local/bin
+DAEMON=/usr/bin/jmauveserver
+DAEMON_OPTS=/etc/mauvealert/mauveserver.conf
+DESC="mauvealert server"
+PIDFILE=/var/run/jmauveserver.pid
+LOG=/var/log/mauve
+
+test -x $DAEMON || exit 0
+
+. /lib/lsb/init-functions
+
+case "$1" in
+ start)
+ log_begin_msg "Starting $DESC:" "$NAME"
+ if [ ! -d $LOG ]; then mkdir $LOG; fi
+ chown mauveserver $LOG /var/lib/mauveserver
+ $DAEMON $DAEMON_OPTS &
+ echo $! > $PIDFILE
+ for i in `seq 0 1 11`;do sleep 1; echo -n '.'; done
+ kill -0 $(cat $PIDFILE)
+ if [ $? != 0 ] ; then echo -n "failed"; else echo -n "success"; fi
+
+ # Email on start.
+ address="yann@bytemark.co.uk"
+ lastLog=`/bin/ls -tr $LOG/*.log | tail -1`
+ logLastLines=`tail -101 $lastLog`
+ echo $logLastLines | mail -s "Mauve was started at `date`" $address
+
+ log_end_msg $?
+ ;;
+ stop)
+ log_begin_msg "Stopping $DESC:" "$NAME"
+ if [ -f $PIDFILE ] ; then
+ kill `cat $PIDFILE`
+ rm $PIDFILE
+
+ # Email on stop.
+ address="yann@bytemark.co.uk"
+ lastLog=`/bin/ls -tr $LOG/*.log | tail -1`
+ logLastLines=`tail -101 $lastLog`
+ echo $logLastLines | mail -s "Mauve was stopped at `date`" $address
+
+ else
+ echo Not running to stop
+ exit 1
+ fi
+ log_end_msg $?
+ ;;
+ reload)
+ if [ -f $PIDFILE ] ; then
+ echo Sending restart signal to mauveserver
+ kill -HUP `cat $PIDFILE`
+ else
+ echo Not running to reload
+ fi
+ ;;
+ restart|reload|force-reload)
+ $0 stop
+ sleep 1
+ $0 start
+ ;;
+ *)
+ N=/etc/init.d/$NAME
+ echo "Usage: $N {start|stop|restart}" >&2
+ exit 1
+ ;;
+esac
+
+exit 0
diff --git a/utils/init_mauve.sh b/utils/init_mauve.sh
new file mode 100755
index 0000000..309562c
--- /dev/null
+++ b/utils/init_mauve.sh
@@ -0,0 +1,83 @@
+#!/bin/sh
+### BEGIN INIT INFO
+# Provides: mauveserver
+# Required-Start: $remote_fs $syslog
+# Required-Stop: $remote_fs $syslog
+# Default-Start: 2 3 4 5
+# Default-Stop: 0 1 6
+# Short-Description: Start the mauve alerting daemon at boot time
+# Description: Start the mauve alerting daemon at boot time
+### END INIT INFO
+
+PATH=/bin:/sbin:/usr/bin:/usr/local/bin
+DAEMON=/usr/bin/mauveserver
+DAEMON_OPTS=/etc/mauvealert/mauveserver.conf
+DESC="mauvealert server"
+PIDFILE=/var/run/mauveserver.pid
+LOG=/var/log/mauve
+
+test -x $DAEMON || exit 0
+
+. /lib/lsb/init-functions
+
+case "$1" in
+ start)
+ log_begin_msg "Starting $DESC:" "$NAME"
+ if [ ! -d $LOG ]; then mkdir $LOG; fi
+ chown mauveserver $LOG /var/lib/mauveserver
+ $DAEMON $DAEMON_OPTS &
+ echo $! > $PIDFILE
+ #start-stop-daemon --background --make-pidfile --pidfile $PIDFILE \
+ # --start --quiet --chuid mauveserver \
+ # --exec "$DAEMON" --oknodo -- $DAEMON_OPTS
+ sleep 3
+ #kill -0 $(cat $PIDFILE)
+ #if [ $? != 0 ] ; then echo -n "failed"; else echo -n "success"; fi
+
+ # Email on start.
+ address="yann@bytemark.co.uk"
+ lastLog=`/bin/ls -tr $LOG/*.log | tail -1`
+ logLastLines=`tail -101 $lastLog`
+ echo $logLastLines | mail -s "Mauve was started at `date`" $address
+
+ log_end_msg $?
+ ;;
+ stop)
+ log_begin_msg "Stopping $DESC:" "$NAME"
+ if [ -f $PIDFILE ] ; then
+ kill `cat $PIDFILE`
+ rm $PIDFILE
+
+ # Email on stop.
+ address="yann@bytemark.co.uk"
+ lastLog=`/bin/ls -tr $LOG/*.log | tail -1`
+ logLastLines=`tail -101 $lastLog`
+ echo $logLastLines | mail -s "Mauve was stopped at `date`" $address
+
+ else
+ echo Not running to stop
+ exit 1
+ fi
+ log_end_msg $?
+ ;;
+ reload)
+ if [ -f $PIDFILE ] ; then
+ echo Sending restart signal to mauveserver
+ kill -HUP `cat $PIDFILE`
+ else
+ echo Not running to reload
+ fi
+ ;;
+ restart|reload|force-reload)
+ $0 stop
+ sleep 1
+ $0 start
+ ;;
+ *)
+ N=/etc/init.d/$NAME
+ echo "Usage: $N {start|stop|restart}" >&2
+ exit 1
+ ;;
+esac
+
+exit 0
diff --git a/utils/packet_processing.sh b/utils/packet_processing.sh
new file mode 100755
index 0000000..d78a916
--- /dev/null
+++ b/utils/packet_processing.sh
@@ -0,0 +1,32 @@
+#!/bin/sh
+
+NO_ARGS=0
+OPTERROR=65
+if [ $# -eq "$NO_ARGS" ] # Script invoked with no command-line args?
+then
+ echo "Usage: `basename $0` File.log"
+ exit $OPTERROR # Exit and explain usage, if no argument(s) given.
+fi
+logFile=$1
+
+egrep 'Packet processed in [\.0-9]* seconds' $logFile |\
+ awk 'BEGIN {print " date sz"} {print s++ " " $1 "::" $2 " " $11}' > data
+
+R --vanilla --no-save --slave <<RSCRIPT
+lst <- read.table("data")
+attach(lst)
+summary(sz)
+png(filename="packets.png", width=1024)
+dates <- strptime(as.character(date), "%Y-%m-%d::%H:%M:%S")
+plot(dates, sz, type='l',
+ main="Mauve server: maximum processing time of a packet per second.",
+ xlab="Time",
+ ylab="Maximum processing time of one packet")
+abline(h=1.05, col="red")
+abline(h=mean(sz), col="blue")
+RSCRIPT
+img=`which qiv`
+if [ $? != 0 ]
+then echo "Cannot display image here"
+else $img packets.png
+fi
diff --git a/utils/run_android.sh b/utils/run_android.sh
new file mode 100755
index 0000000..e932257
--- /dev/null
+++ b/utils/run_android.sh
@@ -0,0 +1,2 @@
+#!/bin/sh
+/usr/local/android-sdk-linux_x86/tools/android&
diff --git a/utils/supportbot-mauve b/utils/supportbot-mauve
new file mode 100755
index 0000000..614c5f5
--- /dev/null
+++ b/utils/supportbot-mauve
@@ -0,0 +1,73 @@
+#!/usr/bin/ruby
+require 'fileutils'
+require 'yaml'
+require 'timeout'
+require 'rubygems'
+require 'cgi'
+
+class RT
+ class Ticket < Struct.new(:id, :subject, :content)
+ end
+
+ def initialize(cli, ticket_query)
+ @cli = cli
+ @ticket_query = ticket_query
+ end
+
+ def query(args)
+ IO.popen("#{@cli} #{args}", "r") do |io|
+ io.read
+ end
+ end
+
+ def tickets
+ query(@ticket_query).split("\n").map do |line|
+ if /^(\d+): (.*)$/.match(line)
+ t = Ticket.new($1.to_i, $2, "")
+ query("show ticket/#{t.id}/attachments").split("\n")[-5..-1].each do |line2|
+ next unless /\s(\d+):\s+\(text\/(plain|html)/.match(line2)
+ is_html = $2 == "html"
+
+ attachment = query("show -f Content ticket/#{t.id}/attachments/#{$1}").
+ split("Content: ")[1].
+ split("\n").
+ map { |line3| line3.gsub(/^\s+/,"") }.
+ join("\n")
+ next unless attachment.match(/Action=Take/)
+ if is_html
+ t.content += attachment + "<hr/>"
+ else
+ t.content += "<pre>"+attachment+"</pre><hr/>"
+ end
+ end
+ t
+ else
+ nil
+ end
+ end.compact
+ end
+end
+
+class String; def escape; gsub(/[^A-Za-z0-9]/) { |x| "\\#{x}" }; end end
+
+config = File.open("supportbot.config") { |fh|
+ YAML::parse(fh.read).transform }
+
+system("mauvesend -o supportbot -i heartbeat -r +10m -c now -s \"heartbeat not received\" -d \"Headtbeat send from supportbot-mauve code. It maybe down.\"")
+
+rt = RT.new(config['rt']['bin'], config['rt']['ticket_query2'])
+
+if 0 < rt.tickets.size
+ args = %w( mauvesend alert.bytemark.co.uk -o supportbot )
+ args += rt.tickets.map do |ticket|
+ ["-i", ticket.id.to_s,
+ "-u", ticket.id.to_s,
+ "-s", ticket.subject,
+ "-d", ticket.content
+ ]
+ end.flatten
+ exec(*args)
+else
+ args = %w( mauvesend alert.bytemark.co.uk --id supportbot -o supportbot -p -c now )
+ exec(*args)
+end
diff --git a/utils/test-smack.rb b/utils/test-smack.rb
new file mode 100755
index 0000000..022f9d0
--- /dev/null
+++ b/utils/test-smack.rb
@@ -0,0 +1,101 @@
+#!/usr/bin/jruby
+# CLASSPATH="$CLASSPATH:/home/yann/projects/mauvealert/jars/smack.jar:/home/yann/projects/mauvealert/jars/smackx.jar
+# ./test-smack
+
+require 'java'
+require '../jars/smack.jar'
+require '../jars/smackx.jar'
+require 'rubygems'
+require 'rainbow'
+require 'pp'
+
+include_class "org.jivesoftware.smack.XMPPConnection"
+include_class "org.jivesoftware.smackx.muc.MultiUserChat"
+
+user_jid='mauvealert'
+password='WojIsEv8ScaufOm1'
+msg = "What fresh hell is this? -- Dorothy Parker."
+begin
+
+ print "XMPP object instanciated.\n".color(:green)
+ xmpp = XMPPConnection.new("chat.bytemark.co.uk")
+
+
+ print "Connection done.\n".color(:green)
+ xmpp.connect
+ if true != xmpp.isConnected
+ print "Failed to connect".color(:red)
+ return -1
+ end
+
+
+ print "Login.\n".color(:green)
+ xmpp.login(user_jid, password, "Testing_smack")
+ if true != xmpp.isAuthenticated()
+ print "Failed to authenticate\n".color(:red)
+ return -1
+ end
+ if true == xmpp.isSecureConnection()
+ print "Connection is secure\n".color(:green)
+ else
+ print "Connection is NOT secure.\n".color(:yellow)
+ end
+
+
+ print "Get chat manager.\n".color(:green)
+ chat = xmpp.getChatManager.createChat(
+ "yann@chat.bytemark.co.uk", nil)
+
+ print "Sending message to #{chat.getParticipant}.\n".color(:green)
+ chat.sendMessage(msg)
+
+
+ print "Joining, sending a message and leaving a room.\n".color(:green)
+ #muc = MultiUserChat.new(xmpp, "office@conference.chat.bytemark.co.uk")
+ muc = MultiUserChat.new(xmpp, "test@conference.chat.bytemark.co.uk")
+ muc.join("Mauve alert bot")
+ muc.sendMessage(msg)
+ sleep 1
+ #muc.leave()
+
+
+ print "Adieu monde cruel!\n".color(:green)
+ xmpp.disconnect
+
+
+ print "all done.\n".color(:green)
+rescue => ex
+ print "EPIC FAIL: Raised #{ex.class} because #{ex.message}\n\n".color(:red)
+ raise ex
+end
+
+=begin
+require 'java'
+require './jars/smack.jar'
+require './jars/smackx.jar'
+include_class "org.jivesoftware.smack.XMPPConnection"
+include_class "org.jivesoftware.smackx.muc.MultiUserChat"
+user_jid='mauvealert'
+password='WojIsEv8ScaufOm1'
+msg = "What fresh hell is this? -- Dorothy Parker."
+xmpp = XMPPConnection.new("chat.bytemark.co.uk")
+xmpp.connect
+xmpp.login(user_jid, password, "mauve_test")
+
+jid="yann@chat.bytemark.co.uk"
+chat = xmpp.getChatManager.createChat(jid, nil)
+chat.sendMessage(msg)
+
+xmpp.getRoster().reload()
+xmpp.getRoster().getPresence(jid).isAvailable()
+xmpp.getRoster().getPresence(jid).getStatus()
+
+muc = MultiUserChat.new(xmpp, 'office@conference.chat.bytemark.co.uk/mauvealert')
+muc.join("Mauve alert bot")
+muc.sendMessage(msg)
+
+muc2 = MultiUserChat.new(xmpp, "test@conference.chat.bytemark.co.uk")
+muc2.join("Mauve alert bot")
+muc2.sendMessage(msg)
+
+=end