Setting the REST API Key

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
grenley
Posts: 96
Joined: Tue May 13, 2014 6:06 pm

Setting the REST API Key

Post by grenley »

Hi.
I want to use the REST api to get and delete objects.
It works great in my testing.
At buildout, we will have hundreds of XI servers so keeping track of the individual api keys is prohibitive.
Is there a way to set the key on each XI?
Thanks,
Rick
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

Re: Setting the REST API Key

Post by mcapra »

Not via the GUI directly, though you can do it in the database directly on a per-user basis:

Code: Select all

echo "UPDATE nagiosxi.xi_users SET api_key='mycoolkey' WHERE  username='nagiosadmin';" | mysql -uroot -pnagiosxi
In action:

Code: Select all

[root@xi-stable ~]# curl -XGET "http://192.168.67.1/nagiosxi/api/v1/objects/host?apikey=mycoolkey&pretty=1&host_name=localhost"
{
    "hostlist": {
        "recordcount": "1",
        "host": {
            "@attributes": {
                "id": "143"
            },
            "instance_id": "1",
            "host_name": "localhost",
            "is_active": "1",
            "config_type": "1",
            "alias": "localhost",
            "display_name": "localhost",
            "address": "127.0.0.1",
            "check_interval": "5",
            "retry_interval": "1",
            "max_check_attempts": "10",
            "first_notification_delay": "0",
            "notification_interval": "120",
            "passive_checks_enabled": "1",
            "active_checks_enabled": "1",
            "notifications_enabled": "1",
            "notes": "",
            "notes_url": "",
            "action_url": "",
            "icon_image": "",
            "icon_image_alt": "",
            "statusmap_image": ""
        }
    }
}
Former Nagios employee
https://www.mcapra.com/
grenley
Posts: 96
Joined: Tue May 13, 2014 6:06 pm

Re: Setting the REST API Key

Post by grenley »

That worked great!
Thanks very much!
Rick
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Setting the REST API Key

Post by rkennedy »

Awesome! Would you mind if we marked this thread resolved?
Former Nagios Employee
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Setting the REST API Key

Post by tmcdonald »

Closing.
Former Nagios employee
Locked