This repository has been archived by the owner on Nov 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
357 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
--- | ||
driver: | ||
name: vagrant | ||
customize: | ||
audio: none | ||
|
||
verifier: | ||
name: inspec | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,175 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# Copyright (C) 2012-2017 Icinga Development Team (https://www.icinga.com/) | ||
# | ||
# Copyright (C) 2012-2018 Icinga Development Team (https://www.icinga.com/) | ||
# Except of function urlencode which is Copyright (C) by Brian White ([email protected]) used under MIT license | ||
|
||
# This file is managed by Chef. | ||
# Do NOT modify this file directly. | ||
# | ||
template=$(cat <<TEMPLATE | ||
***** Icinga ***** | ||
|
||
Notification Type: $NOTIFICATIONTYPE | ||
PROG="`basename $0`" | ||
ICINGA2HOST="`hostname`" | ||
MAILBIN="mail" | ||
|
||
if [ -z "`which $MAILBIN`" ] ; then | ||
echo "$MAILBIN not found in \$PATH. Consider installing it." | ||
exit 1 | ||
fi | ||
|
||
## Function helpers | ||
Usage() { | ||
cat << EOF | ||
Required parameters: | ||
-d LONGDATETIME (\$icinga.long_date_time\$) | ||
-e SERVICENAME (\$service.name\$) | ||
-l HOSTNAME (\$host.name\$) | ||
-n HOSTDISPLAYNAME (\$host.display_name\$) | ||
-o SERVICEOUTPUT (\$service.output\$) | ||
-r USEREMAIL (\$user.email\$) | ||
-s SERVICESTATE (\$service.state\$) | ||
-t NOTIFICATIONTYPE (\$notification.type\$) | ||
-u SERVICEDISPLAYNAME (\$service.display_name\$) | ||
Optional parameters: | ||
-4 HOSTADDRESS (\$address\$) | ||
-6 HOSTADDRESS6 (\$address6\$) | ||
-b NOTIFICATIONAUTHORNAME (\$notification.author\$) | ||
-c NOTIFICATIONCOMMENT (\$notification.comment\$) | ||
-i ICINGAWEB2URL (\$notification_icingaweb2url\$, Default: unset) | ||
-f MAILFROM (\$notification_mailfrom\$, requires GNU mailutils (Debian/Ubuntu) or mailx (RHEL/SUSE)) | ||
-v (\$notification_sendtosyslog\$, Default: false) | ||
EOF | ||
} | ||
|
||
Help() { | ||
Usage; | ||
exit 0; | ||
} | ||
|
||
Error() { | ||
if [ "$1" ]; then | ||
echo $1 | ||
fi | ||
Usage; | ||
exit 1; | ||
} | ||
|
||
urlencode() { | ||
local LANG=C i c e='' | ||
for ((i=0;i<${#1};i++)); do | ||
c=${1:$i:1} | ||
[[ "$c" =~ [a-zA-Z0-9\.\~\_\-] ]] || printf -v c '%%%02X' "'$c" | ||
e+="$c" | ||
done | ||
echo "$e" | ||
} | ||
|
||
## Main | ||
while getopts 4:6:b:c:d:e:f:hi:l:n:o:r:s:t:u:v: opt | ||
do | ||
case "$opt" in | ||
4) HOSTADDRESS=$OPTARG ;; | ||
6) HOSTADDRESS6=$OPTARG ;; | ||
b) NOTIFICATIONAUTHORNAME=$OPTARG ;; | ||
c) NOTIFICATIONCOMMENT=$OPTARG ;; | ||
d) LONGDATETIME=$OPTARG ;; # required | ||
e) SERVICENAME=$OPTARG ;; # required | ||
f) MAILFROM=$OPTARG ;; | ||
h) Usage ;; | ||
i) ICINGAWEB2URL=$OPTARG ;; | ||
l) HOSTNAME=$OPTARG ;; # required | ||
n) HOSTDISPLAYNAME=$OPTARG ;; # required | ||
o) SERVICEOUTPUT=$OPTARG ;; # required | ||
r) USEREMAIL=$OPTARG ;; # required | ||
s) SERVICESTATE=$OPTARG ;; # required | ||
t) NOTIFICATIONTYPE=$OPTARG ;; # required | ||
u) SERVICEDISPLAYNAME=$OPTARG ;; # required | ||
v) VERBOSE=$OPTARG ;; | ||
\?) echo "ERROR: Invalid option -$OPTARG" >&2 | ||
Usage ;; | ||
:) echo "Missing option argument for -$OPTARG" >&2 | ||
Usage ;; | ||
*) echo "Unimplemented option: -$OPTARG" >&2 | ||
Usage ;; | ||
esac | ||
done | ||
|
||
shift $((OPTIND - 1)) | ||
|
||
## Keep formatting in sync with mail-host-notification.sh | ||
for P in LONGDATETIME HOSTNAME HOSTDISPLAYNAME SERVICENAME SERVICEDISPLAYNAME SERVICEOUTPUT SERVICESTATE USEREMAIL NOTIFICATIONTYPE ; do | ||
eval "PAR=\$${P}" | ||
|
||
if [ ! "$PAR" ] ; then | ||
Error "Required parameter '$P' is missing." | ||
fi | ||
done | ||
|
||
## Build the message's subject | ||
SUBJECT="[$NOTIFICATIONTYPE] $SERVICEDISPLAYNAME on $HOSTDISPLAYNAME is $SERVICESTATE!" | ||
|
||
## Build the notification message | ||
NOTIFICATION_MESSAGE=`cat << EOF | ||
***** Service Monitoring on $ICINGA2HOST ***** | ||
$SERVICEDISPLAYNAME on $HOSTDISPLAYNAME is $SERVICESTATE! | ||
Info: $SERVICEOUTPUT | ||
When: $LONGDATETIME | ||
Service: $SERVICENAME | ||
Host: $HOSTNAME | ||
EOF | ||
` | ||
|
||
## Check whether IPv4 was specified. | ||
if [ -n "$HOSTADDRESS" ] ; then | ||
NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE | ||
IPv4: $HOSTADDRESS" | ||
fi | ||
|
||
## Check whether IPv6 was specified. | ||
if [ -n "$HOSTADDRESS6" ] ; then | ||
NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE | ||
IPv6: $HOSTADDRESS6" | ||
fi | ||
|
||
## Check whether author and comment was specified. | ||
if [ -n "$NOTIFICATIONCOMMENT" ] ; then | ||
NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE | ||
Comment by $NOTIFICATIONAUTHORNAME: | ||
$NOTIFICATIONCOMMENT" | ||
fi | ||
|
||
## Check whether Icinga Web 2 URL was specified. | ||
if [ -n "$ICINGAWEB2URL" ] ; then | ||
NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE | ||
Host: $HOSTALIAS | ||
Address: $HOSTADDRESS | ||
State: $HOSTSTATE | ||
$ICINGAWEB2URL/monitoring/service/show?host=$(urlencode "$HOSTNAME")&service=$(urlencode "$SERVICENAME")" | ||
fi | ||
|
||
Date/Time: $LONGDATETIME | ||
## Check whether verbose mode was enabled and log to syslog. | ||
if [ "$VERBOSE" == "true" ] ; then | ||
logger "$PROG sends $SUBJECT => $USEREMAIL" | ||
fi | ||
|
||
Additional Info: $HOSTOUTPUT | ||
## Send the mail using the $MAILBIN command. | ||
## If an explicit sender was specified, try to set it. | ||
if [ -n "$MAILFROM" ] ; then | ||
|
||
Comment: [$NOTIFICATIONAUTHORNAME] $NOTIFICATIONCOMMENT | ||
TEMPLATE | ||
) | ||
## Modify this for your own needs! | ||
|
||
/usr/bin/printf "%b" "$template" | mail -s "$NOTIFICATIONTYPE - $HOSTDISPLAYNAME is $HOSTSTATE" $USEREMAIL | ||
## Debian/Ubuntu use mailutils which requires `-a` to append the header | ||
if [ -f /etc/debian_version ]; then | ||
/usr/bin/printf "%b" "$NOTIFICATION_MESSAGE" | $MAILBIN -a "From: $MAILFROM" -s "$SUBJECT" $USEREMAIL | ||
## Other distributions (RHEL/SUSE/etc.) prefer mailx which sets a sender address with `-r` | ||
else | ||
/usr/bin/printf "%b" "$NOTIFICATION_MESSAGE" | $MAILBIN -r "$MAILFROM" -s "$SUBJECT" $USEREMAIL | ||
fi | ||
|
||
else | ||
/usr/bin/printf "%b" "$NOTIFICATION_MESSAGE" \ | ||
| $MAILBIN -s "$SUBJECT" $USEREMAIL | ||
fi |
Oops, something went wrong.