Page 1 of 1
Configure SMTP w/o using XI GUI
Posted: Mon Jun 22, 2015 6:30 pm
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
Re: Configure SMTP w/o using XI GUI
Posted: Mon Jun 22, 2015 7:08 pm
by eloyd
Nagios XI stores this information in a database. It's not recommended to alter the database information directly.
Re: Configure SMTP w/o using XI GUI
Posted: Tue Jun 23, 2015 12:13 pm
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
Re: Configure SMTP w/o using XI GUI
Posted: Tue Jun 23, 2015 12:50 pm
by eloyd
For science!

Re: Configure SMTP w/o using XI GUI
Posted: Tue Jun 23, 2015 4:09 pm
by abrist

Did that help OP?
Re: Configure SMTP w/o using XI GUI
Posted: Wed Jun 24, 2015 10:04 am
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.
Re: Configure SMTP w/o using XI GUI
Posted: Wed Jun 24, 2015 10:09 am
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.
Re: Configure SMTP w/o using XI GUI
Posted: Wed Jun 24, 2015 10:09 am
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.
Re: Configure SMTP w/o using XI GUI
Posted: Wed Jun 24, 2015 12:00 pm
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.
Re: Configure SMTP w/o using XI GUI
Posted: Wed Jun 24, 2015 12:06 pm
by tmcdonald
Great!
I'll be closing this thread now, but feel free to open another if you need anything in the future!