From fde75277e68eb3cf74187554c2920f3be605b95d Mon Sep 17 00:00:00 2001 From: Will Foster Date: Tue, 22 Nov 2016 15:03:36 +0000 Subject: [PATCH] Expand upon notifications for QUADS. * Add optional IRC notifications for when new systems are provisioned and available. * Add optional email notifications for when new systems are provisioned and available * Rename alert-expiration to quads-notify patchset #2: whitespace patchset #3: fix mistake in IRC notification adding channel option patchset #4: typo in IRC channel variable fixes https://github.com/redhat-performance/quads/issues/2 Change-Id: Ib49b5d5d92081b7bbfc1f23179f7096acaf79f8e --- bin/{alert-expiration.sh => quads-notify.sh} | 56 ++++++++++++++++++-- conf/quads.yml | 18 +++++-- cron/quads | 2 +- 3 files changed, 67 insertions(+), 9 deletions(-) rename bin/{alert-expiration.sh => quads-notify.sh} (54%) diff --git a/bin/alert-expiration.sh b/bin/quads-notify.sh similarity index 54% rename from bin/alert-expiration.sh rename to bin/quads-notify.sh index b51b4be69..ef801e91d 100755 --- a/bin/alert-expiration.sh +++ b/bin/quads-notify.sh @@ -1,7 +1,6 @@ #!/bin/sh -# -# Send notifications when hosts are expiring. -# +# Send email and IRC notifications when hosts are assigned +# Send email notifications when hosts are expiring. ####### if [ ! -e $(dirname $0)/load-config.sh ]; then @@ -9,6 +8,7 @@ if [ ! -e $(dirname $0)/load-config.sh ]; then exit 1 fi +# load the ../conf/quads.yml values as associative array source $(dirname $0)/load-config.sh quads=${quads["install_dir"]}/bin/quads.py @@ -19,6 +19,49 @@ days="1 3 5 7" # only worry about environments with active hosts env_list=$($quads --summary | awk '{ print $1 }') +function craft_initial_message() { + msg_file=$(mktemp /tmp/msgXXXXXXXXXX) + owner=$1 + env_to_report=$2 + ircbot_ipaddr=${quads["ircbot_ipaddr"]} + ircbot_port=${quads["ircbot_port"]} + irc_channel=${quads["ircbot_channel"]} + report_file=${env_to_report}-${owner}-initial-$($quads --ls-ticket --cloud-only ${env_to_report}) + if [ ! -f ${data_dir}/report/${report_file} ]; then + touch ${data_dir}/report/${report_file} + if ${quads["email_notify"]} ; then + cat > $msg_file < +Reply-To: dev-null@${quads["domain"]} + +Greetings Citizen, + +You've been allocated a new environment! + + $env_to_report + +(Details) +http://${quads["wp_wiki"]}/assignments/#$env_to_report + +You can view your machine list, duration and other +details above. + +DevOps Team + +EOF + /usr/sbin/sendmail -t < $msg_file 1>/dev/null 2>&1 + fi + if ${quads["irc_notify"]} ; then + # send IRC notification + printf "$ircbot_channel QUADS: $env_to_report is now active, choo choo! - http://${quads["wp_wiki"]}/assignments/#$env_to_report" | nc -w 1 $ircbot_ipaddr $ircbot_port + fi + fi + rm -f $msg_file +} + function craft_message() { msg_file=$(mktemp /tmp/msgXXXXXXXXXX) @@ -30,7 +73,8 @@ function craft_message() { report_file=${env_to_report}-${owner}-${days_to_report}-$($quads --ls-ticket --cloud-only ${env_to_report}) if [ ! -f ${data_dir}/report/${report_file} ]; then touch ${data_dir}/report/${report_file} - cat > $msg_file < $msg_file </dev/null 2>&1 + /usr/sbin/sendmail -t < $msg_file 1>/dev/null 2>&1 + fi fi rm -f $msg_file } for e in $env_list ; do + craft_initial_message $($quads --cloud-only $e --ls-owner) $e alerted=false for d in $days ; do # if "nobody" is the owner you can skip it... diff --git a/conf/quads.yml b/conf/quads.yml index c98b34d5e..0d2597a97 100644 --- a/conf/quads.yml +++ b/conf/quads.yml @@ -8,6 +8,19 @@ domain: example.com # used for reporting report_cc: someuser@example.com, someuser@example.com, someuser@example.com, someuser@example.com +# notification options +# set to true to receive notifications when: +# 1) upon systems assignment +# 2) 1,3,5,7 days out from when assignment ends +email_notify: true +# set to true to receive notifications when: +# 1) upon systems assignment +# * Note* you'll need Supybot with the notify plugin +irc_notify: true +ircbot_ipaddr: 192.168.0.100 +ircbot_port: 5050 +ircbot_channel: #yourchannel + # wordpress wiki wp_wiki: wiki.example.com wp_username: wikiadmin @@ -37,9 +50,8 @@ racks: b09 b10 c01 c02 c03 c04 c05 c06 c07 c08 c09 c10 # this is where we place the generated instackenv.json files json_web_path: /var/www/html/cloud -# untouchable_hosts is used for paranoid people that worry that quads -# might in some way effect changes on critical infrastructure. Use this -# to define hosts quads should never move. +# untouchable_hosts are hosts that should be avoided by QUADS in any way. +# use this to define hosts QUADS should never move. untouchable_hosts: foreman.example.com c08-h30-r630.example.com # phpical diff --git a/cron/quads b/cron/quads index 0ce68a515..392d94131 100644 --- a/cron/quads +++ b/cron/quads @@ -3,6 +3,6 @@ # example: # * * * * * /ops/quads/bin/schedule.py --move-hosts --move-command /opt/quads/bin/move-and-rebuild-host.sh 1>>/dev/null 2>&1 # 0 * * * * /opt/quads/bin/regenerate-wiki.sh 1>/dev/null 2>&1 -# 0 0 * * * /opt/quads/bin/alert-expiration.sh 1>/dev/null 2>&1 +# 0 0 * * * /opt/quads/bin/quads-notify.sh 1>/dev/null 2>&1 # 0 * * * * /opt/quads/bin/ical-generate-cron.sh 1>/dev/null 2>&1 # 0 0 * * * /opt/quads/bin/simple-table-web.sh 1>/dev/null 2>&1