Page 1 of 1

Setting the REST API Key

Posted: Tue Feb 14, 2017 1:29 pm
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

Re: Setting the REST API Key

Posted: Tue Feb 14, 2017 1:34 pm
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": ""
        }
    }
}

Re: Setting the REST API Key

Posted: Tue Feb 14, 2017 5:31 pm
by grenley
That worked great!
Thanks very much!
Rick

Re: Setting the REST API Key

Posted: Tue Feb 14, 2017 5:34 pm
by rkennedy
Awesome! Would you mind if we marked this thread resolved?

Re: Setting the REST API Key

Posted: Wed Mar 01, 2017 2:00 pm
by tmcdonald
Closing.