ApplyConfig feedback from API

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
IPOInS
Posts: 25
Joined: Tue Jan 14, 2020 6:08 am

ApplyConfig feedback from API

Post by IPOInS »

When submitting either the parameter applyconfig to any existing API function or the specific applyconfig command itself all you ever get back as a response is that the command has been successfully submitted.
However, it doesn't tell you if the apply was actually successful and that no errors were found. To do this you have to check the status via the browser.

I've been looking at possible work arounds such as creating a custom API endpoint to retrieve the 'configuration snapshot' list (using the same call your PHP script uses via CCM "get_nagioscore_config_snapshots()"). This works fine, and allows me to see if the latest snapshot is an error.
This can also be useful prior to 'applyconfig' to make sure it's in a fit state before committing any changes.

Is there some other API call I can make to query the result of the applyconfig or could this be another feature request?
Being able to query the configuration snapshots as a standard API call would also be nice :)

Thanks.
User avatar
cdienger
Support Tech
Posts: 5045
Joined: Tue Feb 07, 2017 11:26 am

Re: ApplyConfig feedback from API

Post by cdienger »

What version of XI are you using? I tested on a 5.8.1 machine, and the apply configuration command will return command_id as well which you can then use to check its status. It does look like command_id is missing when applyconfig is used as a parameter so there may be room for improvement here.

With applyconfig command for example:

Code: Select all

curl -XPOST "https://xi_ip/nagiosxi/api/v1/system/applyconfig?apikey=<apikey>" -k 
I get:

Code: Select all

{"success":"Apply config command has been sent to the backend.","command_id":26}
and can look up command_id 26 with:

Code: Select all

curl -XGET "https://xi_ip/nagiosxi/api/v1/system/command/26?apikey=<apikey>&pretty=1" -k
To return:

Code: Select all

        "command_id": "26",
        "submitter_id": "1",
        "command": "17",
        "submission_time": "2021-01-19 16:20:49",
        "event_time": "2021-01-19 16:20:49",
        "processing_time": "2021-01-19 16:20:50",
        "status_code": "2",
        "result_code": "0",
        "result": "--------------------------------------"
status_code 2 mean it is completed and result_code 0 means it completed successfully.

The custom endpoint to check the snapshots sounds useful. If you can attach it to this thread I can submit it along with a feature request to our dev team.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
IPOInS
Posts: 25
Joined: Tue Jan 14, 2020 6:08 am

Re: ApplyConfig feedback from API

Post by IPOInS »

D'oh! Good point. I've checked this and found that powershell was hiding the output of command_Id because of how it displays object output when two or more outputs have different column names (submit the change then apply in this case), I was only seeing the Success output.
I can see the command_Id output being returned and I'll certainly use that now for validating updates. Thanks.


Regarding the snapshot custom API, here's the content of the nagiosxicustomendpoints.inc.php file:

Code: Select all

<?php

// include the xi component helper
require_once(dirname(__FILE__) . '/../componenthelper.inc.php');

// define/call our component initialize function
nagiosxicustomendpoints_component_init();
function nagiosxicustomendpoints_component_init()
{
	// information to pass to xi about our component
	$args = array(
		COMPONENT_NAME =>           "nagiosxi_custom_endpoints",
		COMPONENT_VERSION =>        "1.0.0",
		COMPONENT_AUTHOR =>         "IPOInS",
		COMPONENT_DESCRIPTION =>    "Nagios XI Custom API Endpoints",
		COMPONENT_TITLE =>          "Nagios XI Custom API Endpoints"
	);

	// register with xi
	register_component("nagiosxi_custom_endpoints", $args);

	// register our custom api handler
	register_custom_api_callback('custom', 'configsnapshot', 'nagiosxicustomendpoints_custom_nagioscoresnapshot');
}

// the function to be called when we reach our custom endpoint via api
function nagiosxicustomendpoints_custom_nagioscoresnapshot() {
	$snapshots = get_nagioscore_config_snapshots();
	return json_encode($snapshots);
}
?>
The get_nagioscore_config_snapshots() function is what's used via the CCM link Configuration Snapshots:
https://<NAGIOSSERVER>/nagiosxi/admin/coreconfigsnapshots.php
User avatar
cdienger
Support Tech
Posts: 5045
Joined: Tue Feb 07, 2017 11:26 am

Re: ApplyConfig feedback from API

Post by cdienger »

Thanks! I've submitted a feature request for an official snapshot endpoint for the API.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
IPOInS
Posts: 25
Joined: Tue Jan 14, 2020 6:08 am

Re: ApplyConfig feedback from API

Post by IPOInS »

one thing though. The output from the command doesn't indicate if there are any warnings reported in the config.

Correct me if I'm wrong, but these can only be found when viewing the output from the snapshot. It would be nice to get this in result_code or a new column name.
User avatar
cdienger
Support Tech
Posts: 5045
Joined: Tue Feb 07, 2017 11:26 am

Re: ApplyConfig feedback from API

Post by cdienger »

I will add that to the feature request. Thanks for the input!
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Locked