set up email alerts using mailx

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.
nib01
Posts: 31
Joined: Tue Oct 09, 2018 9:31 am

Re: set up email alerts using mailx

Post by nib01 »

Do you mean copy the Contact information from contact.cfg file to linuxhosts.cfg file where rancid host is?
User avatar
tgriep
Madmin
Posts: 9177
Joined: Thu Oct 30, 2014 9:02 am

Re: set up email alerts using mailx

Post by tgriep »

No, edit the Contact Group called admin, add the contact to it in the member list.
Save and restart Nagios to apply the change.
That is much easier to do as you only have to add the contact to one place, the Contact Group.

Take a look at this link for descriptions of the Objects and how they are formatted.
https://assets.nagios.com/downloads/nag ... tions.html
Be sure to check out our Knowledgebase for helpful articles and solutions!
mayuril
Posts: 1
Joined: Wed Jan 16, 2019 5:28 am
Contact:

Re: set up email alerts using mailx

Post by mayuril »

This is an all-in-one command that sends email to $TO_EMAIL_ADDRESS . You need to also replace these $FROM_EMAIL_ADDRESS and $FRIENDLY_NAME variables with your email and name.

$ mailx -v -s "$EMAIL_SUBJECT" \
-S smtp=smtp://smtp.ust.hk \
-S from="$FROM_EMAIL_ADDRESS($FRIENDLY_NAME)" \
$TO_EMAIL_ADDRESS
mailx will read the email content from STDIN. Type in the email main content and input “Ctrl+d” to tell mailx you have finished the content. The mail will be sent out. You can also use pipes like:
User avatar
tgriep
Madmin
Posts: 9177
Joined: Thu Oct 30, 2014 9:02 am

Re: set up email alerts using mailx

Post by tgriep »

Thanks @mayuril for the help.
Be sure to check out our Knowledgebase for helpful articles and solutions!
nib01
Posts: 31
Joined: Tue Oct 09, 2018 9:31 am

Re: set up email alerts using mailx

Post by nib01 »

mayuril wrote:This is an all-in-one command that sends email to $TO_EMAIL_ADDRESS . You need to also replace these $FROM_EMAIL_ADDRESS and $FRIENDLY_NAME variables with your email and name.

$ mailx -v -s "$EMAIL_SUBJECT" \
-S smtp=smtp://smtp.ust.hk \
-S from="$FROM_EMAIL_ADDRESS($FRIENDLY_NAME)" \
$TO_EMAIL_ADDRESS
mailx will read the email content from STDIN. Type in the email main content and input “Ctrl+d” to tell mailx you have finished the content. The mail will be sent out. You can also use pipes like:
Ive tried above command to send email, see screenshot photo, and it works fine without any error.

The problem that Im facing right now is the client within linuxhosts.cfg file, I did some testing by shutting down one of the host (rancid) I expect to send an email notification to the email Ive setup within commands.cfg, but it didnt work.
Attachments
nagios_send_email_all_in_one_command.PNG
User avatar
tgriep
Madmin
Posts: 9177
Joined: Thu Oct 30, 2014 9:02 am

Re: set up email alerts using mailx

Post by tgriep »

Can you post all of the Nagios config files so we can view the settings to verify that the settings for the contact, host, services, groups are setup correctly?
Be sure to check out our Knowledgebase for helpful articles and solutions!
nib01
Posts: 31
Joined: Tue Oct 09, 2018 9:31 am

Re: set up email alerts using mailx

Post by nib01 »

Please see attached nagios config files. For the Services and Groups config file, these two config files are combined with the hosts to be monitored. Please let me know if you need additional information.
Attachments
linuxhosts.cfg
(10.36 KiB) Downloaded 284 times
contacts.cfg
(3.22 KiB) Downloaded 280 times
commands.cfg
(7.42 KiB) Downloaded 272 times
User avatar
tgriep
Madmin
Posts: 9177
Joined: Thu Oct 30, 2014 9:02 am

Re: set up email alerts using mailx

Post by tgriep »

Can you post the config file that contains the generic-contact template and the linux-server template?
Typically, the templates have the Host and Service Notifications enabled and also the contact template but I would have to see them for sure to verify that they are set.

Another thing, can you go to the Notification Report and see if you can find the host there and is so, post the entry?
Be sure to check out our Knowledgebase for helpful articles and solutions!
nib01
Posts: 31
Joined: Tue Oct 09, 2018 9:31 am

Re: set up email alerts using mailx

Post by nib01 »

See attached generic-contact template and lnux-server template config. As far as I can see Host and Service Notifications are both enabled.

Also, Id like to verify if this free version of Nagios able to support VM instances because all of the servers that we have to monitor are mostly VMs (ProxMox VMs and VMware ESXi VMs) beside Network switch, router and firewall.
Attachments
templates.cfg
(12.49 KiB) Downloaded 300 times
User avatar
tgriep
Madmin
Posts: 9177
Joined: Thu Oct 30, 2014 9:02 am

Re: set up email alerts using mailx

Post by tgriep »

Check the nagios.cfg file and make sure notifications are enabled. Check this setting.

Code: Select all

enable_notifications=1
Then restart the nagios service and test to see if the Notifications are working.

Can you go to the Notification Report and see if you can find the host there and post what it look like?orking.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked