Hello, I'm trying to use custom variable inside mail notification script. I would like to add documentation url to the notification, so it should be clear for the administrator what to fix.
I've done few things i thought would get it to work:
- I added the -k parameter to mail-service-notification
NotificationCommand in /etc/icinga2/conf.d/commands.conf:
object NotificationCommand "mail-service-notification" {
command = [ SysconfDir + "/icinga2/scripts/mail-service-notification.sh" ]
arguments += {
"-4" = "$notification_address$"
"-6" = "$notification_address6$"
"-b" = "$notification_author$"
"-c" = "$notification_comment$"
"-d" = {
required = true
value = "$notification_date$"
}
"-e" = {
required = true
value = "$notification_servicename$"
}
"-f" = {
value = "$notification_from$"
description = "Set from address. Requires GNU mailutils
(Debian/Ubuntu) or mailx (RHEL/SUSE)"
}
"-i" = "$notification_icingaweb2url$"
"-k" = "$notification_docurl$"
"-l" = {
required = true
value = "$notification_hostname$"
}
"-n" = {
required = true
value = "$notification_hostdisplayname$"
}
"-o" = {
required = true
value = "$notification_serviceoutput$"
}
"-r" = {
required = true
value = "$notification_useremail$"
}
"-s" = {
required = true
value = "$notification_servicestate$"
}
"-t" = {
required = true
value = "$notification_type$"
}
"-u" = {
required = true
value = "$notification_servicedisplayname$"
}
"-v" = "$notification_logtosyslog$"
}
vars += {
//notification_address = "$address$"
notification_address6 = "$address6$"
notification_author = "$notification.author$"
notification_comment = "$notification.comment$"
notification_type = "$notification.type$"
notification_date = "$icinga.long_date_time$"
notification_hostname = "$host.name$"
notification_hostdisplayname = "$host.display_name$"
notification_servicename = "$service.name$"
notification_serviceoutput = "$service.output$"
notification_servicestate = "$service.state$"
notification_useremail = "$user.email$"
notification_servicedisplayname = "$service.display_name$"
notification_icingaweb2url = "https://" + NodeName
notification_docurl = "$service.doc_url$"
notification_from = "nagios@" + NodeName
}
}
- I've modified the script which creates notifications:
(added -k to getopts)
## Main
while getopts 4:6:b:c:d:e:f:hi:k: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 ;;
k) DOCURL=$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
....
(added parameter to mail body)
## Check whether documentation URL was specified
if [ -n "$DOCURL" ] ; then
NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE
Documentation: $DOCURL"
fi
I thought it would work after these changes, but it doesn't.
I've tried some debug:
- The service dump is:
Object 'charon.dopskopl.cz!BIG-PACKET' of type 'Service':
* __name = "charon.dopskopl.cz!BIG-PACKET"
* action_url = ""
* check_command = "check_rad_eap"
* check_interval = 86400
* check_period = ""
* check_timeout = null
* command_endpoint = ""
* display_name = "BIG-PACKET"
* enable_active_checks = true
* enable_event_handler = true
* enable_flapping = true
* enable_notifications = true
* enable_passive_checks = true
* enable_perfdata = true
* event_command = ""
* flapping_threshold = 0
* flapping_threshold_high = 30
* flapping_threshold_low = 25
* groups = [ "BIG-PACKET" ]
* host_name = "charon.dopskopl.cz"
* icon_image = ""
* icon_image_alt = ""
* max_check_attempts = 3
* name = "BIG-PACKET"
* notes = ""
* notes_url = ""
* package = "director"
* retry_interval = 43200
* source_location
* first_column = 5
* first_line = 247
* last_column = 69
* last_line = 247
* path =
"/var/lib/icinga2/api/packages/director/a9e6712b-1b14-4f51-8f66-8ed778569478/zones.d/director-global/service_apply_rules/static_config.conf"
* templates = [ "BIG-PACKET", "big packet template" ]
* type = "Service"
* vars
* doc_url = "https://www.eduroam.cz/cs/spravce/monitoring
* info = "ermon.cesnet.cz is testing UDP fragmentation at server
charon.dopskopl.cz"
* mac_address = "70:6f:6c:69:4f:3f"
* testing_id = "[email protected]"
* testing_password = "ika6Ojohneifeileuh2x"
* volatile = false
* zone = "ermon2.cesnet.cz"
So the variable doc_url is present.
- mail script arguments are:
-6 -b -c -d 2018-08-03 21:21:47 +0200 -e BIG-PACKET -f
[email protected] -i https://ermon2.cesnet.cz -l
charon.dopskopl.cz -n charon.dopskopl.cz -o timeout; 50 sec -r
my_address -s CRITICAL -t PROBLEM -u BIG-PACKET
It seems that the variable just doesn't get to the script. I'm not sure
why. Can someone help me with this?
Thanks for help.
--
Václav Mach
tel: +420 234 680 206
CESNET, z.s.p.o.
www.cesnet.cz
smime.p7s
Description: S/MIME Cryptographic Signature
_______________________________________________ icinga-users mailing list [email protected] https://lists.icinga.org/mailman/listinfo/icinga-users
