Skip to content

Commit

Permalink
Expand upon notifications for QUADS.
Browse files Browse the repository at this point in the history
* 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 #2

Change-Id: Ib49b5d5d92081b7bbfc1f23179f7096acaf79f8e
  • Loading branch information
sadsfae committed Nov 22, 2016
1 parent 2400e55 commit fde7527
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 9 deletions.
56 changes: 51 additions & 5 deletions bin/alert-expiration.sh → bin/quads-notify.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#!/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
echo "$(basename $0): could not find load-config.sh"
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
Expand All @@ -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 <<EOF
To: $owner@${quads["domain"]}
Cc: ${quads["report_cc"]}
Subject: New QUADS Assignment Allocated
From: QUADS <quads@${quads["domain"]}>
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)
Expand All @@ -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 <<EOF
if ${quads["email_notify"]} ; then
cat > $msg_file <<EOF
To: $owner@${quads["domain"]}
Cc: ${quads["report_cc"]}
Subject: QUADS upcoming expiration notification
Expand All @@ -54,12 +98,14 @@ Thank you for your attention.
DevOps Team
EOF
/usr/sbin/sendmail -t < $msg_file 1>/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...
Expand Down
18 changes: 15 additions & 3 deletions conf/quads.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@ domain: example.com
# used for reporting
report_cc: [email protected], [email protected], [email protected], [email protected]

# 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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cron/quads
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit fde7527

Please sign in to comment.