Page 1 of 2
Force overwrite on import of configurations
Posted: Tue Jan 24, 2017 10:57 am
by WillemDH
Hello,
So I have a script which is able to update NSClient++ to a specific version, generate a nsclient.ini configuration file and generate the host and service config in Nagios. That way I can switch easily between the legacy nsclient and the modern nsclient (>0.4.1.105). Each type (legacy - modern) has a different set of services each using their own template, meaning I can also switch between NRPE versions.. I'm using the import folder on the Nagios XI server to import the update configuration.
Is it possible to force a full overwrite when importing nagios configuration files? At this time when I put Nagios cfg files (in the correct format) in the /usr/local/nagios/etc/import/ folder the new services are added to the old services. This while I expected the new configs to overwrite the existing host and it's services.
If there is no way to force an overwrite with the import folder, is the only other way to clean this up to first delete teh host and it's services with:
Run each of the following scripts from: /usr/local/nagiosxi/scripts
cd /usr/local/nagiosxi/scripts/
./nagiosql_delete_service.php –-config=LOC_MASShost_1
After the services have successfully been deleted, the host can be removed as well:
./nagiosql_delete_host.php –-host=LOC_MASShost_1
Once the host is removed, the new configuration can be applied and verified by running the reconfigure_nagios.sh
./reconfigure_nagios.sh
This implies I would need two 'apply configurations' for each host I would update to a modern NSCLient version? Knowing that my applies are already a long and painful operation I would really love some way to force overwrite an existing host.
(see screenshot for the result of the two configs added to each other instead of being overwrited)
Grtz
Willem
Re: Force overwrite on import of configurations
Posted: Tue Jan 24, 2017 5:29 pm
by mcapra
If you use the "Import Config Files" tool under the CCM in the GUI, there's an option to overwrite existing configurations and favor the files:
2017_01_24_16_21_46_CCM_Nagios_XI.png
The helper script leveraged by
reconfigure_nagios.sh (which is
nagiosql_importall.php) also uses this in the wget request it makes when importing (notice
chbOverwrite passed via GET):
Code: Select all
$cmdline="/usr/bin/wget --load-cookies=".$cookiefile." ".$url." --no-check-certificate --post-data 'backend=1&cmd=admin&type=import&importsubmitted=true&chbOverwrite=1&subForm=Import&selImportFile[]=".$f."' -O nagiosql.import.monitoring";
It's interesting to me that this script's conventions in particular aren't correctly overwriting existing configurations. If you do the same process via the GUI, does this achieve the desired effect? We may need to modify the CCM in some small way to correct this, but I want to be sure the GUI is first doing what you'd like.
Re: Force overwrite on import of configurations
Posted: Wed Jan 25, 2017 4:18 am
by WillemDH
Just tested the 'overwrite' function in the 'import config files' page and although I was hopeful, it seems this does not overwrite the existing host and it's services with the imported host and it's services.. All additional services in the imported config file are just added to the older services that already existed resulting in a combination of services trying to use the legacy commands and the modern NSClient commands.
Can you please try reproduce this? This seem like a bug no?
Re: Force overwrite on import of configurations
Posted: Wed Jan 25, 2017 7:16 am
by BanditBBS
Not a bug, you are asking for a new feature. I use as is now when wanting to add new services to hosts or when wanting to make mass changes. I never havewanted it to delete stuff not in the import files. I can see the desire though, but would need to be a new option.
You could also try and use the API instead of imports and it should work nicely.
Re: Force overwrite on import of configurations
Posted: Wed Jan 25, 2017 7:36 am
by WillemDH
A new feature is ok for me. Although I do wonder what the function of the checkbox "overwrite database" is in that case...
Re: Force overwrite on import of configurations
Posted: Wed Jan 25, 2017 7:40 am
by BanditBBS
That check box is in case a service in the import file already exists in the CCM. If it is checked then the import file wins, if not checked then the already existing service in CCM isn't touched.
Re: Force overwrite on import of configurations
Posted: Wed Jan 25, 2017 7:50 am
by WillemDH
Hmm ok. Not a logical name imho. Well what about a second checkbox which is called delete/write config"..?
I tried the new api, but it has too many shortcomings imho. Maybe you know an answer?
1) No way to delete a host and all it's services in one webrequest?
When trying to delete a host, I get:
Code: Select all
{
"error": "Host cannot be deleted using this method. Must be deleted through the CCM."
}
2) No way to use host and service templates? I have tried some combinations, but it seems templates were forgotten in the new api? Please correct me if i'm wrong. Also some variables are required?? This while we historically set these in the templates.. For example max_check_attempts and check_period.
Code: Select all
{
"error": "Missing required variables",
"missing": [
"max_check_attempts",
"check_period"
]
}
Also using the api means we have to be careful with the api tokens. Once you have such an api token, it's very easy to create an admin and do whatever you want? SSH based automation is much more secure imho.
So unless I'm wrong, some thing are not documented or I'm missing the ball, the api is just not usable at this time. using the import folder is much easier when using an ssh based automation soluttion such as Rundeck. I guess I'll have to delete the host and services for now with nagiosql_delete_service.php and nagiosql_delete_host.php. This sucks as it requires a lot of extra applying.
But please correct me if i'm wrong.

Re: Force overwrite on import of configurations
Posted: Wed Jan 25, 2017 8:01 am
by BanditBBS
Yeah, agree, it could be renamed or explained better and a second checkbox added.
In regard to the API, yes, everything you want to do is technically able to be done, sort of.
1.) You need to delete the services and then the host.
2.) Easy, i do it all the time and it works great, example:
Code: Select all
curl -k -XPOST "https://xxx.xxx.xxxx.com/nagiosxi/api/v1/config/service?apikey=MYAPI&pretty=1" -d "host_name=xxxx-xxx-dap33&service_description=DEVASCP%20-%20Apps%20-%20Weblogic%20Managed%20Server&check_command=check_by_nrpe_procs%211:%211:%21-a -Dweblogic.Name=WLS_DISCO -C java%20-u%20appldas1&use=extn_generic-service-5&servicegroups=extn_devascp&force=1"
You can use templates like in my example and then add the force=1 to ignore required variables. You also don't have to have the appli config on them like I don't. You can issue all the commands you want and then use the API call to apply and only apply once. I have a spreadsheet I can send you that can give you some ideas, I'll email you when I get to work.
Re: Force overwrite on import of configurations
Posted: Wed Jan 25, 2017 8:06 am
by WillemDH
I'll email you when I get to work.
Thanks, looking forward to that.
About your 1, is it possible to delete 'all services for a host?
Re: Force overwrite on import of configurations
Posted: Wed Jan 25, 2017 8:53 am
by BanditBBS
WillemDH wrote:About your 1, is it possible to delete 'all services for a host?
With a very quick script, yeah, it could be done. I do not believe there is a single command though. You can have issues, just like you would with import deleting stuff(when/if feature added) if it has dependent relationships. I'm at work now, so look for an email soon-ish.