Email trough exchange if ping fail and when is restored

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
Hoygen83
Posts: 16
Joined: Mon Oct 28, 2019 10:30 am

Email trough exchange if ping fail and when is restored

Post by Hoygen83 »

Hello,
I just installed nagios core 4.4.5 on a ubuntu machine 19.10 lts.
The thing I am trying to achieve should be easy but I'm having an hard time finding out how to do it in nagios.
I have a printer connected via wifi and I want to receive an email when the printer can not be pinged from nagios.
If the printer can be pinged again I want to receive another email telling me that the issue is no longer present.
The email should be sent through an exchange server.
I think that such a task should be explained somewhere in the documentation.

The example file /usr/local/nagios/etc/objects/commands.cfg is not helping

Code: Select all

define command {

    command_name    notify-host-by-email
    command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDAT$
}



define command {

    command_name    notify-service-by-email
    command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time$
}
I can see the printer and the service but how do I make nagios send an email if service is down or if it gets up again?
how do I make nagios send email through exchange?
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Email trough exchange if ping fail and when is restored

Post by scottwilkerson »

Not sure where you got those default commands but the real defaults look something like this and send mail piping through the mail program on the server

Code: Select all

define command {

    command_name    notify-host-by-email
    command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
}

define command {

    command_name    notify-service-by-email
    command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
}
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
Locked