Nagios HTML Email Notifications Code
Brought to you by:
piegope
File | Date | Author | Commit |
---|---|---|---|
image-examples | 2017-08-17 | Heini Holm Andersen | [3226e4] Updated with example images folder |
php-html-email | 2017-09-25 | Heini Holm Andersen | [f7f9a3] Updated the fonts include url |
.DS_Store | 2017-09-25 | Heini Holm Andersen | [f7f9a3] Updated the fonts include url |
.gitattributes | 2017-08-17 | Heini Holm Andersen | [ae6646] Initial commit |
README.md | 2017-08-31 | Heini Holm Andersen | [9c2b48] Updated scripts and readme file |
Here are two php built scripts, one for sending Host Notifications and one for sending Service Notifications, as Responsive HTML email messages from your Nagios server.
Copyrights
Copyright (©) 2017 Heini Holm Andersen hhan@mail.fo
Copy the php-html-email folder to the Nagios plugins directory (usually named 'libexec') and make sure all files are owned by the user nagios uses and also that all files are made executable by the nagios user!
Then configure Nagios.
# 'notify-host-by-email-html' command definition
define command {
command_name notify-host-by-email-html
command_line $USER1$/php-html-email/nagios_host_mail "$NOTIFICATIONTYPE$" "$HOSTNAME$" "$HOSTALIAS$" "$HOSTSTATE$" "$HOSTADDRESS$" "$HOSTOUTPUT$" "$SHORTDATETIME$" "$CONTACTEMAIL$" "$TOTALHOSTSUP$" "$TOTALHOSTSDOWN$" "$NOTIFICATIONAUTHOR$" "$NOTIFICATIONCOMMENT$" "$LONGDATETIME$" "$HOSTDURATION$" "$HOSTDURATIONSEC$" "$LASTHOSTCHECK$" "$LASTHOSTSTATECHANGE$" "$NOTIFICATIONISESCALATED$" "$HOSTATTEMPT$" "$MAXHOSTATTEMPTS$" "$NOTIFICATIONRECIPIENTS$"
}
# 'notify-service-by-email-html' command definition
define command {
command_name notify-service-by-email-html
command_line $USER1$/php-html-email/nagios_service_mail "$NOTIFICATIONTYPE$" "$HOSTNAME$" "$HOSTALIAS$" "$HOSTSTATE$" "$HOSTADDRESS$" "$SERVICEOUTPUT$" "$SHORTDATETIME$" "$SERVICEDESC$" "$SERVICESTATE$" "$CONTACTEMAIL$" "$SERVICEDURATIONSEC$" "$SERVICEEXECUTIONTIME$" "$TOTALSERVICESWARNING$" "$TOTALSERVICESCRITICAL$" "$TOTALSERVICESUNKNOWN$" "$LASTSERVICEOK$" "$LASTSERVICEWARNING$" "$SERVICENOTIFICATIONNUMBER$" "$LONGSERVICEOUTPUT$" "$NOTIFICATIONAUTHOR$" "$NOTIFICATIONCOMMENT$" "$SERVICEDURATION$" "$NOTIFICATIONISESCALATED$" "$SERVICEATTEMPT$" "$MAXSERVICEATTEMPTS$" "$NOTIFICATIONRECIPIENTS$"
}
define contact{
name generic-contact
register 0
service_notification_commands notify-service-by-email-html
host_notification_commands notify-host-by-email-html
Open up these files and and scroll to the bottom to find the default configuration using PHPMailer. Say, to make it send email to your Gmail via Google SMTP server, just follow the configuration as stated.
<repo>/php-html-email/nagios_host_mail
<repo>/php-html-email/nagios_service_mail
$mail = new PHPMailer;
#$mail->SMTPDebug = 3;
$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->Username = 'someone@example.com';
$mail->Password = 'somepassword';