Page 1 of 1

Importing Config Files

Posted: Fri Dec 11, 2020 12:10 pm
by rexmundo
Hi

We have written a powershell script to take a CSV file and generate host and service config objects that we want to import into Nagios XI.

As a test we generate a file called:

<hostname>.cfg

The contents are:

define host {
host_name <hostname>
use <template name>
address <FQDN>
parents <host1>,<host2>
}

I put it in the /usr/local/nagios/etc/import folder. Then run the xiprepimport check against it. There is no output or change or new files created. I then import through the UI.

It errors with "Table for import definition '" is not available!".

There are now 2 <hostname>.cfg files. One in the import folder and another in the /etc parent folder. The one in the /etc folder contains the same information as the one in import folder.

"Apply Configuration" now is failing with an error "Could not register service (config file '/usr/local/nagions/etc/services/<hostname>.cfg',starting on line 30".
This is bizzare as there are no services assigned to that configuration, its just a host.
The file '/usr/local/nagions/etc/services/<hostname>.cfg' does not exist, and there is no such configuration in the dropdown for the services, so there is no way I can fix it from the UI.

The only option is to reverse to snapshot, so I am bit confused and unsure how to progress.

rgds
G

Re: Importing Config Files

Posted: Mon Dec 14, 2020 12:40 pm
by benjaminsmith
Hi rexmundo,

If the configuration fails it will revert back to the last known good configuration. You can do this manually by going to Configure > CCM > Quick Tools > Configuration Snapshots. However, as long as you have files in the import directory, it will attempt to import those when you Apply Configuration.

Run the following tail command during the apply configuration to capture more details on the error and post them to the thread.

Code: Select all

tail -f /usr/local/nagiosxi/var/cmdsubsys.log
Then zip up the configuration files, and send them in PM message. Thanks, Benjamin

Code: Select all

zip -r /tmp/nagiossupport.zip /usr/local/nagios/etc

Re: Importing Config Files

Posted: Tue Dec 15, 2020 11:43 am
by rexmundo
Hi

thanks for the response.
Removing the file from the import folder indeed causes the commit to succeed.

Tailing the log file however produced no output at all.. just dots..

I started comparing the files with other hosts from the hosts folder. I knew my config is ok because I could create that host using that data using the API.
In the end it was the file encoding. Mine was UTF8 and Nagios didnt like it. I had to convert it to ASCII by opening it in VI and writing it using ++enc=ascii

Is there a way for Nagios to read UTF8 files?

Re: Importing Config Files

Posted: Wed Dec 16, 2020 11:56 am
by benjaminsmith
HI,
Is there a way for Nagios to read UTF8 files?
I believe there might be another issue here (possibly with the file itself), my default system is using ASCII, but if I change language (to Japanese) the configuration files will be written in UTF-8 character set and it is able to apply configuration and import config files in UTF-8 character set.

--Benjamin