diff options
author | Holger Levsen <holger@layer-acht.org> | 2012-12-10 11:23:37 +0100 |
---|---|---|
committer | Holger Levsen <holger@layer-acht.org> | 2012-12-10 11:23:37 +0100 |
commit | 3d1b9640710f6b10feaa89ce95d4c9527030daef (patch) | |
tree | d0ec90daa62e5e3392412f0174f8b67f8fba6a70 | |
parent | de4abb5fa84b21cdc48c78fe60efa013fc81fddc (diff) | |
download | jenkins.debian.net-3d1b9640710f6b10feaa89ce95d4c9527030daef.tar.xz |
explain what email2irc.sh is doing
-rwxr-xr-x | bin/email2irc.sh | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/bin/email2irc.sh b/bin/email2irc.sh index 7ea47ce1..1c8b38de 100755 --- a/bin/email2irc.sh +++ b/bin/email2irc.sh @@ -4,52 +4,69 @@ # released under the GPLv=2 # -# FIXME: email2irc still needs cleanup / documentation +# called by ~jenkins/.procmailrc +# to turn jenkins email notifications into irc announcements with kgb +# see http://kgb.alioth.debian.org/ # LOGFILE=/var/lib/jenkins/email_log +# +# parse email headers to check if they come from jenkins +# HEADER=true VALID_MAIL=false FIRST_LINE="" while read line ; do if [ "$HEADER" == "true" ] ; then + # check if email header ends if [[ $line =~ ^$ ]] ; then HEADER=false fi + # valid From: line? if [[ $line =~ ^(From: jenkins@jenkins.debian.net) ]] ; then VALID_MAIL=true fi + # catch Subject (to send to IRC later) if [[ $line =~ ^(Subject: .*) ]] ; then SUBJECT=${line:9} fi + # determine the channel to send notifications to + # by parsing the To: line if [[ $line =~ ^(To: .*) ]] ; then echo $line >> $LOGFILE CHANNEL=$(echo $line | cut -d "+" -f2| cut -d "@" -f1) echo "CHANNEL = $CHANNEL" >> $LOGFILE fi + # check if it's a valid jenkins job if [[ $line =~ ^(X-Jenkins-Job: .*) ]] ; then JENKINS_JOB=${line:15} fi fi + # catch first line of email body (to send to IRC later) if [ "$HEADER" == "false" ] && [ -z "$FIRST_LINE" ] ; then FIRST_LINE=$line fi done +# check that it's a valid job if [ -z $JENKINS_JOB ] ; then VALID_MAIL=false fi +# only send notifications for valid emails if [ "$VALID_MAIL" == "true" ] ; then echo -e "----------\nvalid email\n-----------" >> $LOGFILE echo $JENKINS_JOB | cut -d ":" -f1 >> $LOGFILE SUBJECT=$(echo $SUBJECT | cut -d ":" -f1) echo $SUBJECT >> $LOGFILE echo $FIRST_LINE >> $LOGFILE + # only notify if there is a channel to notify if [ ! -z $CHANNEL ] ; then + # log message echo "#$CHANNEL: $SUBJECT. $FIRST_LINE" >> $LOGFILE #MESSAGE=$(echo "$SUBJECT. $FIRST_LINE" | colorit -c /etc/colorit.conf ) MESSAGE="$JENKINS_JOB: $SUBJECT. $FIRST_LINE" + # notify kgb kgb-client --conf /srv/jenkins/kgb/$CHANNEL.conf --relay-msg "$MESSAGE" && echo "kgb informed successfully." >> $LOGFILE echo >> $LOGFILE else |