Configure SMTP w/o using XI GUI

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
toodaly
Posts: 63
Joined: Wed Jun 19, 2013 3:39 pm

Configure SMTP w/o using XI GUI

Post by toodaly »

I have been able to set up SMTP through the Nagios XI GUI (Admin->Manage Email Settings). I'd like to be able to script the Nagios SMTP configuration. What file (e.g. .cfg) is this information located in?

Thanks
User avatar
eloyd
Cool Title Here
Posts: 2190
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

Re: Configure SMTP w/o using XI GUI

Post by eloyd »

Nagios XI stores this information in a database. It's not recommended to alter the database information directly.
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoyd
I'm a Nagios Fanatic! • Join our public Nagios Discord Server!
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: Configure SMTP w/o using XI GUI

Post by ssax »

eloyd is correct, we generally recommend users do not directly interact with the database.

That being said, if you wanted to do it for science..

* Make sure you have a good DB backup / VM snapshot

Those values are stored in the xi_options postgresql DB.

Here is an example of what the data can be:

mail_method = "smtp" OR "sendmail"
mail_from_address = "Nagios XI <[email protected]>"
smtp_host = "smtp.domain.net"
smtp_port = "587"
smtp_username = "[email protected]"
smtp_password = "yourpassword"
smtp_security = "none" OR "tls" OR "ssl"
mail_settings_configured = "1"

Since the version of psql does not have UPSERT functionality or IF EXISTS you should delete them first:

Code: Select all

echo "DELETE FROM xi_options WHERE name IN ('mail_method', 'mail_from_address', 'smtp_host', 'smtp_port', 'smtp_username', 'smtp_password', 'smtp_security', 'mail_settings_configured');" | psql nagiosxi nagiosxi
Then add them (MAKE SURE TO CHANGE THE VALUES):

Code: Select all

echo "INSERT INTO xi_options (name, value) VALUES ('mail_method', 'smtp'), ('mail_from_address', 'Nagios XI <[email protected]>'), ('smtp_host', 'smtp.domain.net'), ('smtp_port', '587'), ('smtp_username', '[email protected]'), ('smtp_password', 'yourpassword'), ('smtp_security', 'none'), ('mail_settings_configured', '1');" | psql nagiosxi nagiosxi
User avatar
eloyd
Cool Title Here
Posts: 2190
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

Re: Configure SMTP w/o using XI GUI

Post by eloyd »

For science! :geek:
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoyd
I'm a Nagios Fanatic! • Join our public Nagios Discord Server!
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Configure SMTP w/o using XI GUI

Post by abrist »

:P
Did that help OP?
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
toodaly
Posts: 63
Joined: Wed Jun 19, 2013 3:39 pm

Re: Configure SMTP w/o using XI GUI

Post by toodaly »

I have zero experience with postgres, but I'm willing to try it in a test environment. The farthest I got was:
psql -V, returned 8.4.13
which psql, returned /usr/bin/psql
I assume Nagios XI installs this as I can't see psql or postgres in the base Linux VM that I use.

Do I perform the actions mentioned by ssax in psql or postgres? Is there a way to execute this from the command line? Will I be able to see a before and after in the Nagios XI Admin -> Manage Email Settings page?

Thanks.
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: Configure SMTP w/o using XI GUI

Post by ssax »

Yes, postgresql (psql) are installed by the Nagios XI installer and and XI should be installed before you run the commands.

Those commands that I posted are meant to be run from the command line (or in a script). Just make sure you have good backups/vm snapshots before doing any changes.
User avatar
eloyd
Cool Title Here
Posts: 2190
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

Re: Configure SMTP w/o using XI GUI

Post by eloyd »

psql is the postgres command line utility. Postgres is the name of the database management program. @ssax gave you what you need to know:
echo "DELETE FROM xi_options WHERE name IN ('mail_method', 'mail_from_address', 'smtp_host', 'smtp_port', 'smtp_username', 'smtp_password', 'smtp_security', 'mail_settings_configured');" | psql nagiosxi nagiosxi

echo "INSERT INTO xi_options (name, value) VALUES ('mail_method', 'smtp'), ('mail_from_address', 'Nagios XI <[email protected]>'), ('smtp_host', 'smtp.domain.net'), ('smtp_port', '587'), ('smtp_username', '[email protected]'), ('smtp_password', 'yourpassword'), ('smtp_security', 'none'), ('mail_settings_configured', '1');" | psql nagiosxi nagiosxi
Replace "[email protected]" and "yourpassword" and "smtp.domain.net" and "587" with appropriate values for your SMTP system.
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoyd
I'm a Nagios Fanatic! • Join our public Nagios Discord Server!
toodaly
Posts: 63
Joined: Wed Jun 19, 2013 3:39 pm

Re: Configure SMTP w/o using XI GUI

Post by toodaly »

I should have read the command closer in that the echo was piping the string to the psql command.

However, we have achieved success. The commands worked. I observed the before (default settings) in XI, ran the commands, clicked refresh, and observed the after in XI.

Score one for science!!!

Thanks your help.
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Configure SMTP w/o using XI GUI

Post by tmcdonald »

Great!

I'll be closing this thread now, but feel free to open another if you need anything in the future!
Former Nagios employee
Locked