Notify-by-email.pl not working

Hi all

Had a lot of errors getting the script to run and managed to correct most of the errors by adding the following to the start of the script:

BEGIN {
    $ENV{OMD_ROOT} = '/omd/sites/poc';
    $ENV{OMD_SITE} = 'poc';
}

However I am still getting the following error:

Use of uninitialized value in concatenation (.) or string at /omd/sites/poc/lib/nagios/plugins/notify-by-email.pl line 98.
sh: 1: Syntax error: end of file unexpected

The code looks like this:

sub send_mail {
        $mail .= ' ' . join ' ',map { "-S".$_ } @vars;
        open (MAIL,"|$mail $macro{'CONTACTEMAIL'}") || die("Couldn't open $mail: $!");  //THIS IS LINE 98
        print MAIL $output;
        close MAIL;
}

I’d output the values of the variables used in line 98, something like

print "$mail\n";
print "$maco{'CONTACTEMAIL'}\n";
open (MAIL,"|$mail $macro{'CONTACTEMAIL'}") || die("Couldn't open $mail: $!");
1 Like

Missing environment variables are a sure sign that you run things with the wrong user. Don’t run those scripts as root user. Always change into the site user first.

Testing notifications is easier with the “send custom notification” external command in the Thruk interface.

Hi All

Issue was resolved by using the old notification commands instead of the new ones (https://labs.consol.de/omd/howtos/html_notifications/index.html). I also added the “f” switch to the command and sorted my problem.

Thanks for the help!

Regards,
Yoface