NagiosXI API v2 | Host Status 1 vs. Many query results

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Post Reply
snapier3
Posts: 144
Joined: Tue Apr 23, 2019 7:12 pm

NagiosXI API v2 | Host Status 1 vs. Many query results

Post by snapier3 »

I don't know if this is the place but, here it goes.

While familiarizing myself with v2 of the API I noticed that there is an issue when a single item is returned for the host & service class of the status endpoint.

Here's an example python using a limited query to isolate localhost and return only one result.

Code: Select all


#VARS FOR API
myxi = "192.168.1.1"
myep = "status"
mycls = "host"
qry = "&name=localhost"
mytkn = "auth_token" #provided by nagiosxi api

#NAGIOSXI API V2 
def api2(myxi,myep,mycls,qry,mytkn):

    try:
        myurl = "https://{}/nagiosxi/api/v2/{}/{}?{}&token={}".format(myxi,myep,mycls,qry,mytkn)
        
        #GET RESULTS
        response = requests.get(myurl, verify=False)
        r = response.json()
    
    except Exception as e:
        r = e
        
    finally:    
        return r

Results are returned but... not exactly what I expected. I got strings?!

Code: Select all

HOSTCOUNT=1
<class 'str'>
@attributes2
<class 'str'>
instance_id
<class 'str'>
host_id
<class 'str'>
name
<class 'str'>
display_name
<class 'str'>
address
<class 'str'>
alias
<class 'str'>
status_update_time
<class 'str'>
status_text
<class 'str'>
status_text_long
<class 'str'>
current_state
<class 'str'>
icon_image
<class 'str'>
icon_image_alt
<class 'str'>
performance_data
<class 'str'>
should_be_scheduled
<class 'str'>
check_type
<class 'str'>
last_state_change
<class 'str'>
last_hard_state_change
<class 'str'>
last_hard_state
<class 'str'>
last_time_up
<class 'str'>
last_time_down
<class 'str'>
last_time_unreachable
<class 'str'>
last_notification
<class 'str'>
next_notification
<class 'str'>
no_more_notifications
<class 'str'>
acknowledgement_type
<class 'str'>
current_notification_number
<class 'str'>
event_handler_enabled
<class 'str'>
process_performance_data
<class 'str'>
obsess_over_host
<class 'str'>
modified_host_attributes
<class 'str'>
event_handler
<class 'str'>
check_command
<class 'str'>
normal_check_interval
<class 'str'>
retry_check_interval
<class 'str'>
check_timeperiod_id
<class 'str'>
has_been_checked
<class 'str'>
current_check_attempt
<class 'str'>
max_check_attempts
<class 'str'>
last_check
<class 'str'>
next_check
<class 'str'>
state_type
<class 'str'>
notifications_enabled
<class 'str'>
problem_acknowledged
<class 'str'>
passive_checks_enabled
<class 'str'>
active_checks_enabled
<class 'str'>
flap_detection_enabled
<class 'str'>
is_flapping
<class 'str'>
percent_state_change
<class 'str'>
latency
<class 'str'>
execution_time
<class 'str'>
scheduled_downtime_depth
<class 'str'>
notes
<class 'str'>
notes_url
<class 'str'>
action_url
.

Now if the query is formatted to return 2 or more hosts/services, we get something that looks more usable.

Using the same example from above but, passing in a query to isolate two hosts.

Code: Select all

qry = "&name=in:localhost,u2204ncpa"

Code: Select all

HOSTCOUNT=2
<class 'dict'>
{'@attributes': {'id': '3'}, 'instance_id': '1', 'host_id': '205', 'name': 'u2204ncpa', 'display_name': 'u2204ncpa', 'address': '192.168.1.136', 'alias': 'linux-columbia-mo', 'status_update_time': '2024-09-26 16:30:36', 'status_text': 'Server is Up', 'status_text_long': {}, 'current_state': '0', 'icon_image': 'ubuntu.png', 'icon_image_alt': {}, 'performance_data': {}, 'should_be_scheduled': '1', 'check_type': '1', 'last_state_change': '2024-09-25 18:56:48', 'last_hard_state_change': '2024-09-25 18:56:48', 'last_hard_state': '0', 'last_time_up': '2024-09-23 19:03:50', 'last_time_down': '2024-09-25 18:56:48', 'last_time_unreachable': '1970-01-01 00:00:00', 'last_notification': '2024-09-25 18:56:48', 'next_notification': '1970-01-01 00:00:00', 'no_more_notifications': '0', 'acknowledgement_type': '0', 'current_notification_number': '0', 'event_handler_enabled': '1', 'process_performance_data': '1', 'obsess_over_host': '1', 'modified_host_attributes': '1', 'event_handler': {}, 'check_command': {}, 'normal_check_interval': '5', 'retry_check_interval': '3', 'check_timeperiod_id': '173', 'has_been_checked': '1', 'current_check_attempt': '1', 'max_check_attempts': '2', 'last_check': '2024-09-25 18:56:48', 'next_check': '2024-09-26 16:35:36', 'state_type': '1', 'notifications_enabled': '1', 'problem_acknowledged': '0', 'passive_checks_enabled': '1', 'active_checks_enabled': '1', 'flap_detection_enabled': '1', 'is_flapping': '0', 'percent_state_change': '0', 'latency': '0.0031169999856501818', 'execution_time': '0', 'scheduled_downtime_depth': '0', 'notes': 'ht-linux-columbia-mo (38.95171,-92.33407)', 'notes_url': {}, 'action_url': {}}

<class 'dict'>
{'@attributes': {'id': '1'}, 'instance_id': '1', 'host_id': '178', 'name': 'localhost', 'display_name': 'localhost', 'address': '127.0.0.1', 'alias': 'localhost', 'status_update_time': '2024-09-26 16:30:51', 'status_text': 'OK - 127.0.0.1: rta 0.018ms lost 0%', 'status_text_long': {}, 'current_state': '0', 'icon_image': {}, 'icon_image_alt': {}, 'performance_data': 'rta=0.018ms;3000.000;5000.000;0; pl=0%;80;100;0;100 rtmax=0.036ms;;;; rtmin=0.013ms;;;;', 'should_be_scheduled': '1', 'check_type': '0', 'last_state_change': '2024-08-14 05:07:28', 'last_hard_state_change': '2024-08-14 05:07:28', 'last_hard_state': '0', 'last_time_up': '2024-09-26 16:30:51', 'last_time_down': '1970-01-01 00:00:00', 'last_time_unreachable': '1970-01-01 00:00:00', 'last_notification': '1970-01-01 00:00:00', 'next_notification': '1970-01-01 00:00:00', 'no_more_notifications': '0', 'acknowledgement_type': '0', 'current_notification_number': '0', 'event_handler_enabled': '1', 'process_performance_data': '1', 'obsess_over_host': '1', 'modified_host_attributes': '0', 'event_handler': {}, 'check_command': 'check-host-alive', 'normal_check_interval': '5', 'retry_check_interval': '1', 'check_timeperiod_id': '167', 'has_been_checked': '1', 'current_check_attempt': '1', 'max_check_attempts': '10', 'last_check': '2024-09-26 16:30:51', 'next_check': '2024-09-26 16:35:51', 'state_type': '1', 'notifications_enabled': '1', 'problem_acknowledged': '0', 'passive_checks_enabled': '1', 'active_checks_enabled': '1', 'flap_detection_enabled': '1', 'is_flapping': '0', 'percent_state_change': '0', 'latency': '0.00368200009688735', 'execution_time': '0.009706', 'scheduled_downtime_depth': '0', 'notes': {}, 'notes_url': {}, 'action_url': {}} 
There is bupkis on v2 of the API so I'm definitely finding my own way.
--SN
User avatar
jmichaelson
Posts: 383
Joined: Wed Aug 23, 2023 1:02 pm

Re: NagiosXI API v2 | Host Status 1 vs. Many query results

Post by jmichaelson »

You're getting deep into the guts of XI here. As such it would be helpful to know which version of XI, NDO, Core, etc. you're using
Please let us know if you have any other questions or concerns.

-Jason
snapier3
Posts: 144
Joined: Tue Apr 23, 2019 7:12 pm

Re: NagiosXI API v2 | Host Status 1 vs. Many query results

Post by snapier3 »

jmichaelson wrote: Thu Sep 26, 2024 2:14 pm You're getting deep into the guts of XI here. As such it would be helpful to know which version of XI, NDO, Core, etc. you're using
Instance in question is nothing special just a stock install.
Ubuntu 24.04
NagiosXI 1.2.2

In the progress of writing a component for use with Neptune and the singular result issue is havoc with development.

V1 of the API is quite well documented as V2 progresses it would be great if we could get some of the same, a roadmap even...

--SN
snapier3
Posts: 144
Joined: Tue Apr 23, 2019 7:12 pm

Re: NagiosXI API v2 | Host Status 1 vs. Many query results

Post by snapier3 »

I figured it out, we are now back to contacts and permissions...
:shock:
Man I seriously hope that the authentication on v2 gets better.
:?
SMH
User avatar
jmichaelson
Posts: 383
Joined: Wed Aug 23, 2023 1:02 pm

Re: NagiosXI API v2 | Host Status 1 vs. Many query results

Post by jmichaelson »

If you have suggestions, I'd be happy to open a feature request with them for you! Of course we can't commit to anything here, but I can make the request.
Please let us know if you have any other questions or concerns.

-Jason
snapier3
Posts: 144
Joined: Tue Apr 23, 2019 7:12 pm

Re: NagiosXI API v2 | Host Status 1 vs. Many query results

Post by snapier3 »

If basic auth is going to be the method going forward which means it will remain unencrypted, can it handle Base64 Clear Text?
I mean it's still text but, I don't ever have to store or transmit usernames and passwords in plain text

I do hope that a basic authentication strategy is avoided for accessing the API.
This method will increase the toil associated in administering XI by adding the need to manage object contact association and current user permission configurations.

--
While the POST/PUT/DELETE for objects (that does not use raw import) get worked out the status classes can be extended for hostgroups,servicegroups,contacts, and commands in the same method as used with host and service classes.

Relying on the common.php isn't the most attractive for status calls but it does seem to work and still works with the limited query options that are currently available for these two.
  • status/host
    status/service
--
account/session returns a list, everything else returns a type of dict.

--
Documentation

--
Feature visibility in the NagiosXI Change Logs
bbahn
Posts: 385
Joined: Thu Jan 12, 2023 5:42 pm

Re: NagiosXI API v2 | Host Status 1 vs. Many query results

Post by bbahn »

Thanks for taking note of this. I have filed an issue for improving this.
Actively advancing awesome answers with ardent alliteration, aptly addressing all ambiguities. Amplify your acumen and avail our amicable assistance. Eagerly awaiting your astute assessments of our advice.
Post Reply