Page 1 of 1

Statehistory command via api

Posted: Thu Oct 10, 2019 11:24 am
by nms
Hi,

I am trying to build up some statistics for alarms via API.
What I am trying to achieve is this:

1. Number of HARD alarms PER host group (i.e irrespective of severity, unknown+critical_warning) but separate per host group
EX: Hostgrp1 - X alarms
Hostgrp2 - X alarms

2. The number of HARD alarms with NO host group (again irrespective of severity).

I know that you can call via api with:

Code: Select all

curl -XGET "http://<ipaddress>/nagiosxi/api/v1/objects/statehistory?apikey=<apikey>&last_hard_state=1"
but I can't understand how I can set the parameters for limiting to a host group and limit to state. I guess if you don't input a timeframe it defaults to 24hrs which is good for me.

Basically I am looking after the below parameters in the api:
2019-10-10_1810.png
Can you kindly help?

Rgds

Re: Statehistory command via api

Posted: Thu Oct 10, 2019 12:30 pm
by benjaminsmith
Hello @nms,

That endpoint does not contain a hostgroup field to lmit on. You can however do this by the host or object ID.

Code: Select all

    "stateentry": [
        {
            "instance_id": "1",
            "state_time": "2015-09-24 03:39:52",
            "object_id": "175",
            "objecttype_id": "2",
            "host_name": "127.0.0.1",
            "service_description": "Load",
            "state_change": "1",
            "state": "2",
            "state_type": "0",
            "current_check_attempt": "1",
            "max_check_attempts": "5",
            "last_state": "0",
            "last_hard_state": "0",
            "output": "awfawfawf"
        },
One thing to note, is that you can download the State History report in CSV format for running analyzing the data.
state-history.png