Nagios XI 5 - REST API - Hostgroups

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
User avatar
WillemDH
Posts: 2320
Joined: Wed Mar 20, 2013 5:49 am
Location: Ghent
Contact:

Nagios XI 5 - REST API - Hostgroups

Post by WillemDH »

Hello,

Just noticed that when I GET a HOST object, the hostgroups are not listed:

Code: Select all

curl -XGET "http://nagios/nagiosxi/api/v1/objects/host?apikey=4n9mb3g98lezfezfegzeggze9pkurft4s9jpihmbsk8t&pretty=1&host_name=srv2012test.domain"
{
    "hostlist": {
        "recordcount": "1",
        "host": {
            "@attributes": {
                "id": "13923"
            },
            "instance_id": "1",
            "host_name": "srv2012test.domain",
            "is_active": "1",
            "config_type": "1",
            "alias": "srv2012test.domain",
            "display_name": "srv2012test.domain",
            "address": "10.54.26.13",
            "check_interval": "5",
            "retry_interval": "1",
            "max_check_attempts": "3",
            "first_notification_delay": "0",
            "notification_interval": "1440",
            "passive_checks_enabled": "1",
            "active_checks_enabled": "1",
            "notifications_enabled": "1",
            "notes": "",
            "notes_url": "",
            "action_url": "",
            "icon_image": "win_server.png",
            "icon_image_alt": "",
            "statusmap_image": "win_server.png"
        }
    }
}
As I was trying to convert my http://outsideit.net/naf-reconfigure-na ... ostgroups/ script to make use of the new REST API. is it possible there is no way to add hostgroups or remove hostgroups yet with the new REST API? Or is it me?
Nagios XI 5.8.1
https://outsideit.net
jdalrymple
Skynet Drone
Posts: 2620
Joined: Wed Feb 11, 2015 1:56 pm

Re: Nagios XI 5 - REST API - Hostgroups

Post by jdalrymple »

While it doesn't answer the question you have, I would first like to know how the host is added to the hostgroup.

Did you create a hostgroup, then in the hostgroup definition add hosts to it?

Or did you create hostgroup, then in the host definition add hostgroups?

I think one way might provide you what you expect to see, and the other maybe not? I truly wish that you couldn't add hosts in the hostgroup definition - it's just confusing.

Update: Devs confirmed, it's something they will need to add.
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Nagios XI 5 - REST API - Hostgroups

Post by tmcdonald »

You can get hostgroup status like so: curl -XGET "http://192.168.1.100/nagiosxi/api/v1/ob ... y&pretty=1"

You can create a hostgroup like so: curl -XPOST "http://192.168.1.100/nagiosxi/api/v1/co ... y&pretty=1" -d "hostgroup_name=testapihostgroup&alias=127.0.0.1&applyconfig=1"

But it does not appear at the moment that hostgroup information is included. This is likely due to the structure of the backend database tables. There is one table for hosts, one table for hostgroups, and an intermediary table joining them. Likely the API is just pulling the information from the host table and not referencing the joining table. I will see if I can get a dev to confirm.

And to address JR's post, it does not seem to matter where you make the association.
Former Nagios employee
User avatar
WillemDH
Posts: 2320
Joined: Wed Mar 20, 2013 5:49 am
Location: Ghent
Contact:

Re: Nagios XI 5 - REST API - Hostgroups

Post by WillemDH »

I know how to get hostgroup status and create hostgroups. I just expected the hostgroups added in the host definition to show up when doing

Code: Select all

curl -XGET "http://nagios/nagiosxi/api/v1/objects/host?apikey=4n9mb3g98lezfezfegzeggze9pkurft4s9jpihmbsk8t&pretty=1&host_name=srv2012test.domain"
Update: Devs confirmed, it's something they will need to add.
Ok, thanks for confirming. I pushed an update of my script on the Exchange as it had a bug, I'll continue using that for now. Please close
Nagios XI 5.8.1
https://outsideit.net
Locked