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
Configure SMTP w/o using XI GUI
Re: Configure SMTP w/o using XI GUI
Nagios XI stores this information in a database. It's not recommended to alter the database information directly.
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoyd
I'm a Nagios Fanatic! • Join our public Nagios Discord Server!
Re: Configure SMTP w/o using XI GUI
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:
Then add them (MAKE SURE TO CHANGE THE VALUES):
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
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 nagiosxiRe: Configure SMTP w/o using XI GUI
For science! 
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoyd
I'm a Nagios Fanatic! • Join our public Nagios Discord Server!
Re: Configure SMTP w/o using XI GUI
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.
"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.
Re: Configure SMTP w/o using XI GUI
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.
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
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.
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
psql is the postgres command line utility. Postgres is the name of the database management program. @ssax gave you what you need to know:
Replace "[email protected]" and "yourpassword" and "smtp.domain.net" and "587" with appropriate values for your SMTP system.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
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoyd
I'm a Nagios Fanatic! • Join our public Nagios Discord Server!
Re: Configure SMTP w/o using XI GUI
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.
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
Great!
I'll be closing this thread now, but feel free to open another if you need anything in the future!
I'll be closing this thread now, but feel free to open another if you need anything in the future!
Former Nagios employee