Can't add hosts via API, but adding them in web UI works

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Post Reply
cbeattie-unitrends
Posts: 84
Joined: Mon Oct 10, 2016 2:51 pm

Can't add hosts via API, but adding them in web UI works

Post by cbeattie-unitrends »

Hello,
I have one Nagios XI instance which has stopped adding new hosts via the API. However, adding them manually in the web UI works fine, and after manually adding them the API works just fine to remove them.

The API results show success, whether it's a new target or trying to add a target which already exists:

Code: Select all

success
-------
Added <new host name> to the system. Config imported but not yet applied.
Apply config command has been sent to the backend.
I found another topic describing a similar problem, which led me to finding out that STRICT_TRANS_TABLES were enabled. I disabled them by following this KB article, but that didn't seem to help.

This is on CentOS Stream 9 (x64), Nagios XI 2024R1.1.2. I am also having trouble trying to upgrade this system, which I'll open another topic for.
sgardil
Posts: 349
Joined: Wed Aug 09, 2023 9:58 am

Re: Can't add hosts via API, but adding them in web UI works

Post by sgardil »

cbeattie-unitrends wrote: Tue Aug 27, 2024 11:50 am Hello,
I have one Nagios XI instance which has stopped adding new hosts via the API. However, adding them manually in the web UI works fine, and after manually adding them the API works just fine to remove them.

The API results show success, whether it's a new target or trying to add a target which already exists:

Code: Select all

success
-------
Added <new host name> to the system. Config imported but not yet applied.
Apply config command has been sent to the backend.
I found another topic describing a similar problem, which led me to finding out that STRICT_TRANS_TABLES were enabled. I disabled them by following this KB article, but that didn't seem to help.

This is on CentOS Stream 9 (x64), Nagios XI 2024R1.1.2. I am also having trouble trying to upgrade this system, which I'll open another topic for.
Hey @cbeattie-unitrends

Sorry you are having this issue. Could you post what CLI command you are running to hit the api to try to add a new host? First line of thought is to check all the flags to make sure everything is correct. The response makes me think that the flag to apply the config isnt being sent. That being said if its not, does it still not show up if you apply config in the web gui?
cbeattie-unitrends
Posts: 84
Joined: Mon Oct 10, 2016 2:51 pm

Re: Can't add hosts via API, but adding them in web UI works

Post by cbeattie-unitrends »

Here's the code:

Code: Select all

$irm = @{
	Method      = "Post"
	Uri         = "$($nagios.url)config/host?apikey=$($nagios.password)"
	Body        = "host_name=$target&address=$($dns.Name)&use=generic-host&hostgroups=replication-targets&force=1"
	ErrorAction = 'Stop'
}
try {
	Invoke-RestMethod @irm
}
That particular bit doesn't use the &applyconfig=1 because the script it is part of calls the applyconfig URL ("$($nagios.url)system/applyconfig?apikey=$($nagios.password)") later in case there are multiple hosts being added to Nagios (which is where "Apply config command has been sent to the backend." is coming from. However, if I update the first URL to include &applyconfig=1, the output is:

Code: Select all

success
-------
Added <new host name> to the system. Config applied, Nagios Core was restarted.
But the added host still does not show up.

If I do not apply configs via either URL, there is no notification in the web UI that there is a configuration change awaiting application.

This script works just fine adding hosts to other Nagios instances and has successfully added hosts to this instance in the past, so I'm fairly certain the problem exists only in this one Nagios XI instance.
cbeattie-unitrends
Posts: 84
Joined: Mon Oct 10, 2016 2:51 pm

Re: Can't add hosts via API, but adding them in web UI works

Post by cbeattie-unitrends »

To add some more to it, as far as I can tell, the database tables are in good shape:

Code: Select all

[root@nagios ~]# db_user='root'; db_host='localhost'; db_pass=$(/usr/local/nagiosxi/scripts/get_mysql_passwords.sh | awk 'NR==1 {print $4}')
[root@nagios ~]# mysqlcheck --force --check --host=${db_host} --user=${db_user} --password=${db_pass} --all-databases
mysqlcheck: [Warning] Using a password on the command line interface can be insecure.
mysql.columns_priv                                 OK
mysql.component                                    OK
mysql.db                                           OK
mysql.default_roles                                OK
mysql.engine_cost                                  OK
mysql.func                                         OK
mysql.general_log                                  OK
mysql.global_grants                                OK
mysql.gtid_executed                                OK
mysql.help_category                                OK
mysql.help_keyword                                 OK
mysql.help_relation                                OK
mysql.help_topic                                   OK
mysql.innodb_index_stats                           OK
mysql.innodb_table_stats                           OK
mysql.password_history                             OK
mysql.plugin                                       OK
mysql.procs_priv                                   OK
mysql.proxies_priv                                 OK
mysql.replication_asynchronous_connection_failover OK
mysql.replication_asynchronous_connection_failover_managed OK
mysql.replication_group_configuration_version      OK
mysql.replication_group_member_actions             OK
mysql.role_edges                                   OK
mysql.server_cost                                  OK
mysql.servers                                      OK
mysql.slave_master_info                            OK
mysql.slave_relay_log_info                         OK
mysql.slave_worker_info                            OK
mysql.slow_log                                     OK
mysql.tables_priv                                  OK
mysql.time_zone                                    OK
mysql.time_zone_leap_second                        OK
mysql.time_zone_name                               OK
mysql.time_zone_transition                         OK
mysql.time_zone_transition_type                    OK
mysql.user                                         OK
nagios.nagios_acknowledgements                     OK
nagios.nagios_commands                             OK
nagios.nagios_commenthistory                       OK
nagios.nagios_comments                             OK
nagios.nagios_configfiles                          OK
nagios.nagios_configfilevariables                  OK
nagios.nagios_conninfo                             OK
nagios.nagios_contact_addresses                    OK
nagios.nagios_contact_notificationcommands         OK
nagios.nagios_contactgroup_members                 OK
nagios.nagios_contactgroups                        OK
nagios.nagios_contactnotificationmethods           OK
nagios.nagios_contactnotifications                 OK
nagios.nagios_contacts                             OK
nagios.nagios_contactstatus                        OK
nagios.nagios_customvariables                      OK
nagios.nagios_customvariablestatus                 OK
nagios.nagios_dbversion                            OK
nagios.nagios_downtimehistory                      OK
nagios.nagios_eventhandlers                        OK
nagios.nagios_externalcommands                     OK
nagios.nagios_flappinghistory                      OK
nagios.nagios_host_contactgroups                   OK
nagios.nagios_host_contacts                        OK
nagios.nagios_host_parenthosts                     OK
nagios.nagios_hostchecks                           OK
nagios.nagios_hostdependencies                     OK
nagios.nagios_hostescalation_contactgroups         OK
nagios.nagios_hostescalation_contacts              OK
nagios.nagios_hostescalations                      OK
nagios.nagios_hostgroup_members                    OK
nagios.nagios_hostgroups                           OK
nagios.nagios_hosts                                OK
nagios.nagios_hoststatus                           OK
nagios.nagios_instances                            OK
nagios.nagios_logentries                           OK
nagios.nagios_notifications                        OK
nagios.nagios_objects                              OK
nagios.nagios_processevents                        OK
nagios.nagios_programstatus                        OK
nagios.nagios_rebalance_affected_instances         OK
nagios.nagios_regions                              OK
nagios.nagios_runtimevariables                     OK
nagios.nagios_scheduleddowntime                    OK
nagios.nagios_service_contactgroups                OK
nagios.nagios_service_contacts                     OK
nagios.nagios_service_parentservices               OK
nagios.nagios_servicechecks                        OK
nagios.nagios_servicedependencies                  OK
nagios.nagios_serviceescalation_contactgroups      OK
nagios.nagios_serviceescalation_contacts           OK
nagios.nagios_serviceescalations                   OK
nagios.nagios_servicegroup_members                 OK
nagios.nagios_servicegroups                        OK
nagios.nagios_services                             OK
nagios.nagios_servicestatus                        OK
nagios.nagios_statehistory                         OK
nagios.nagios_systemcommands                       OK
nagios.nagios_timedeventqueue                      OK
nagios.nagios_timedevents                          OK
nagios.nagios_timeperiod_exception_timeranges      OK
nagios.nagios_timeperiod_exceptions                OK
nagios.nagios_timeperiod_exclusions                OK
nagios.nagios_timeperiod_timeranges                OK
nagios.nagios_timeperiods                          OK
nagiosql.tbl_command                               OK
nagiosql.tbl_contact                               OK
nagiosql.tbl_contactgroup                          OK
nagiosql.tbl_contacttemplate                       OK
nagiosql.tbl_domain                                OK
nagiosql.tbl_host                                  OK
nagiosql.tbl_hostdependency                        OK
nagiosql.tbl_hostescalation                        OK
nagiosql.tbl_hostextinfo                           OK
nagiosql.tbl_hostgroup                             OK
nagiosql.tbl_hosttemplate                          OK
nagiosql.tbl_info                                  OK
nagiosql.tbl_lnkContactToCommandHost               OK
nagiosql.tbl_lnkContactToCommandService            OK
nagiosql.tbl_lnkContactToContactgroup              OK
nagiosql.tbl_lnkContactToContacttemplate           OK
nagiosql.tbl_lnkContactToVariabledefinition        OK
nagiosql.tbl_lnkContactgroupToContact              OK
nagiosql.tbl_lnkContactgroupToContactgroup         OK
nagiosql.tbl_lnkContacttemplateToCommandHost       OK
nagiosql.tbl_lnkContacttemplateToCommandService    OK
nagiosql.tbl_lnkContacttemplateToContactgroup      OK
nagiosql.tbl_lnkContacttemplateToContacttemplate   OK
nagiosql.tbl_lnkContacttemplateToVariabledefinition OK
nagiosql.tbl_lnkHostToContact                      OK
nagiosql.tbl_lnkHostToContactgroup                 OK
nagiosql.tbl_lnkHostToHost                         OK
nagiosql.tbl_lnkHostToHostgroup                    OK
nagiosql.tbl_lnkHostToHosttemplate                 OK
nagiosql.tbl_lnkHostToVariabledefinition           OK
nagiosql.tbl_lnkHostdependencyToHost_DH            OK
nagiosql.tbl_lnkHostdependencyToHost_H             OK
nagiosql.tbl_lnkHostdependencyToHostgroup_DH       OK
nagiosql.tbl_lnkHostdependencyToHostgroup_H        OK
nagiosql.tbl_lnkHostescalationToContact            OK
nagiosql.tbl_lnkHostescalationToContactgroup       OK
nagiosql.tbl_lnkHostescalationToHost               OK
nagiosql.tbl_lnkHostescalationToHostgroup          OK
nagiosql.tbl_lnkHostgroupToHost                    OK
nagiosql.tbl_lnkHostgroupToHostgroup               OK
nagiosql.tbl_lnkHosttemplateToContact              OK
nagiosql.tbl_lnkHosttemplateToContactgroup         OK
nagiosql.tbl_lnkHosttemplateToHost                 OK
nagiosql.tbl_lnkHosttemplateToHostgroup            OK
nagiosql.tbl_lnkHosttemplateToHosttemplate         OK
nagiosql.tbl_lnkHosttemplateToVariabledefinition   OK
nagiosql.tbl_lnkServiceToContact                   OK
nagiosql.tbl_lnkServiceToContactgroup              OK
nagiosql.tbl_lnkServiceToHost                      OK
nagiosql.tbl_lnkServiceToHostgroup                 OK
nagiosql.tbl_lnkServiceToServicegroup              OK
nagiosql.tbl_lnkServiceToServicetemplate           OK
nagiosql.tbl_lnkServiceToVariabledefinition        OK
nagiosql.tbl_lnkServicedependencyToHost_DH         OK
nagiosql.tbl_lnkServicedependencyToHost_H          OK
nagiosql.tbl_lnkServicedependencyToHostgroup_DH    OK
nagiosql.tbl_lnkServicedependencyToHostgroup_H     OK
nagiosql.tbl_lnkServicedependencyToService_DS      OK
nagiosql.tbl_lnkServicedependencyToService_S       OK
nagiosql.tbl_lnkServicedependencyToServicegroup_DS OK
nagiosql.tbl_lnkServicedependencyToServicegroup_S  OK
nagiosql.tbl_lnkServiceescalationToContact         OK
nagiosql.tbl_lnkServiceescalationToContactgroup    OK
nagiosql.tbl_lnkServiceescalationToHost            OK
nagiosql.tbl_lnkServiceescalationToHostgroup       OK
nagiosql.tbl_lnkServiceescalationToService         OK
nagiosql.tbl_lnkServiceescalationToServicegroup    OK
nagiosql.tbl_lnkServicegroupToService              OK
nagiosql.tbl_lnkServicegroupToServicegroup         OK
nagiosql.tbl_lnkServicetemplateToContact           OK
nagiosql.tbl_lnkServicetemplateToContactgroup      OK
nagiosql.tbl_lnkServicetemplateToHost              OK
nagiosql.tbl_lnkServicetemplateToHostgroup         OK
nagiosql.tbl_lnkServicetemplateToServicegroup      OK
nagiosql.tbl_lnkServicetemplateToServicetemplate   OK
nagiosql.tbl_lnkServicetemplateToVariabledefinition OK
nagiosql.tbl_lnkTimeperiodToTimeperiod             OK
nagiosql.tbl_logbook                               OK
nagiosql.tbl_mainmenu                              OK
nagiosql.tbl_permission                            OK
nagiosql.tbl_permission_inactive                   OK
nagiosql.tbl_service                               OK
nagiosql.tbl_servicedependency                     OK
nagiosql.tbl_serviceescalation                     OK
nagiosql.tbl_serviceextinfo                        OK
nagiosql.tbl_servicegroup                          OK
nagiosql.tbl_servicetemplate                       OK
nagiosql.tbl_session                               OK
nagiosql.tbl_session_locks                         OK
nagiosql.tbl_settings                              OK
nagiosql.tbl_submenu                               OK
nagiosql.tbl_timedefinition                        OK
nagiosql.tbl_timeperiod                            OK
nagiosql.tbl_user                                  OK
nagiosql.tbl_variabledefinition                    OK
nagiosxi.xi_auditlog                               OK
nagiosxi.xi_auth_tokens                            OK
nagiosxi.xi_banner_messages                        OK
nagiosxi.xi_cmp_ccm_backups                        OK
nagiosxi.xi_cmp_favorites                          OK
nagiosxi.xi_cmp_nagiosbpi_backups                  OK
nagiosxi.xi_cmp_scheduledreports_log               OK
nagiosxi.xi_cmp_trapdata                           OK
nagiosxi.xi_cmp_trapdata_log                       OK
nagiosxi.xi_commands                               OK
nagiosxi.xi_deploy_agents                          OK
nagiosxi.xi_deploy_jobs                            OK
nagiosxi.xi_eventqueue                             OK
nagiosxi.xi_events                                 OK
nagiosxi.xi_link_users_messages                    OK
nagiosxi.xi_meta                                   OK
nagiosxi.xi_mibs                                   OK
nagiosxi.xi_options                                OK
nagiosxi.xi_sessions                               OK
nagiosxi.xi_sysstat                                OK
nagiosxi.xi_usermeta                               OK
nagiosxi.xi_users                                  OK
nagiosxi.xi_wizard_history                         OK
sys.sys_config                                     OK
nicklesta
Posts: 6
Joined: Wed Jul 12, 2023 8:10 pm

Re: Can't add hosts via API, but adding them in web UI works

Post by nicklesta »

1. Check Nagios XI Configuration
Ensure that Nagios XI's configuration files are correctly set up and that there are no issues with how configurations are applied. Sometimes, issues can arise if the configuration files are not being updated or if there are syntax errors.

Review Nagios XI Logs: Check the logs for any errors or warnings related to configuration changes.

Log file locations:
Nagios XI Logs: /usr/local/nagiosxi/var/ (look for audit.log or other relevant logs)
Nagios Core Logs: /usr/local/nagios/var/ (e.g., nagios.log, debug.log)
Configuration Files: Ensure that the configuration files in /usr/local/nagios/etc/objects/ (or other directories where your objects are stored) are being updated as expected.

2. Verify API and Configuration Import
When you add a hostslope via the API, it should trigger a configuration import, and then a configuration apply.

Manual Apply Config: Try manually applying the configuration from the Nagios XI web UI after adding a host via the API to see if it then appears correctly.

API Success Message: The success message you receive from the API indicates that the configuration import process was triggered. However, confirm that this process is completing successfully. Check the nagiosxi log for any import-related errors.
Post Reply