I’m trying to use the pushbullet notification plugin which calls mail-host plugins and for some reason Icinga2 is complaining about errors in mail-host-notification.sh
I’m running Icinga2 on a RaspberryPi 4, and everything else works fine, I can execute the scripts manually as root and my user, and it doesn’t give me any errors, it just displays the help text since I didn’t supply any of the mandatory arguments.
root@raspberrypi:/etc/icinga2/scripts # bash -x mail-host-notification.sh
++ basename /etc/icinga2/scripts/mail-host-notification.sh
+ PROG=mail-host-notification.sh
++ hostname
+ ICINGA2HOST=pi.mydomain.us
+ MAILBIN=mail
++ command -v mail
+ '[' -z /usr/bin/mail ']'
+ getopts 4:6::b:c:d:f:hi:l:n:o:r:s:t:v: opt
+ shift 0
+ for P in LONGDATETIME HOSTNAME HOSTDISPLAYNAME HOSTOUTPUT HOSTSTATE USEREMAIL NOTIFICATIONTYPE
+ eval 'PAR=$LONGDATETIME'
++ PAR=
+ '[' '!' '' ']'
+ Error 'Required parameter '\''LONGDATETIME'\'' is missing.'
+ '[' 'Required parameter '\''LONGDATETIME'\'' is missing.' ']'
+ echo 'Required parameter '\''LONGDATETIME'\'' is missing.'
Required parameter 'LONGDATETIME' is missing.
+ Usage
+ cat
Required parameters:
-d LONGDATETIME ($icinga.long_date_time$)
-l HOSTNAME ($host.name$)
-n HOSTDISPLAYNAME ($host.display_name$)
-o HOSTOUTPUT ($host.output$)
-r USEREMAIL ($user.email$)
-s HOSTSTATE ($host.state$)
-t NOTIFICATIONTYPE ($notification.type$)
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)
+ exit 1
When I followed the directions for the pushbullet plugin and then deploy the changes via Director it complains of the following errors, which the Icinga daemon also complains about as well when I execute icinga2 daemon -C
[2019-11-03 21:41:57 -0500] information/cli: Icinga application loader (version: r2.11.2-1)
[2019-11-03 21:41:57 -0500] information/cli: Loading configuration file(s).
[2019-11-03 21:41:57 -0500] critical/config: Error: syntax error, unexpected $undefined, expecting $end
Location: in /etc/icinga2/scripts/mail-host-notification.sh: 5:19-5:19
/etc/icinga2/scripts/mail-host-notification.sh(3): # Except of function urlencode which is Copyright (C) by Brian White (brian@aljex.com) used under MIT license
/etc/icinga2/scripts/mail-host-notification.sh(4):
/etc/icinga2/scripts/mail-host-notification.sh(5): PROG="$(basename "$0")"
^
/etc/icinga2/scripts/mail-host-notification.sh(6): ICINGA2HOST="$(hostname)"
/etc/icinga2/scripts/mail-host-notification.sh(7): MAILBIN="mail"
[2019-11-03 21:41:57 -0500] critical/cli: Config validation failed. Re-run with 'icinga2 daemon -C' after fixing the config.
When I comment out that variable assignment I then get this error
[2019-11-03 21:43:32 -0500] information/cli: Icinga application loader (version: r2.11.2-1)
[2019-11-03 21:43:32 -0500] information/cli: Loading configuration file(s).
[2019-11-03 21:43:32 -0500] critical/config: Error: syntax error, unexpected '[', expecting '('
Location: in /etc/icinga2/scripts/mail-host-notification.sh: 9:4-9:4
/etc/icinga2/scripts/mail-host-notification.sh(7): MAILBIN="mail"
/etc/icinga2/scripts/mail-host-notification.sh(8):
/etc/icinga2/scripts/mail-host-notification.sh(9): if [ -z "$(command -v $MAILBIN)" ] ; then
^
/etc/icinga2/scripts/mail-host-notification.sh(10): echo "$MAILBIN not found in \$PATH. Consider installing it."
/etc/icinga2/scripts/mail-host-notification.sh(11): exit 1
[2019-11-03 21:43:32 -0500] critical/cli: Config validation failed. Re-run with 'icinga2 daemon -C' after fixing the config.
I’ve run it though shellcheck and it updated the script to use current features (?) of bash (like $() instead of backticks) and replacing which with command -v, I also had to change the interpreter from sh to bash.
Even after all that it still gives the same errors and I have zero idea why Icinga2 doesn’t like it. I’m pretty proficient with bash, I’ve been using Linux for over a decade, but this boggles the mind.