Submit service update trhough Nagios API

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
morabanc
Posts: 199
Joined: Tue Jul 10, 2012 8:14 am

Submit service update trhough Nagios API

Post by morabanc »

Hi team,

I don't know if its posible (give me an alternative) but we would like to do it.

For example, for a remote server, execute an api "https://ip/nagiosxi/api" specifying the host name, service name, status (critical, arning,..) and description.

If it's not posible can you give me an alternative ?

Thanks a lot
kyang

Re: Submit service update trhough Nagios API

Post by kyang »

Are you trying to get a single service update?

Going into the XI Home Page --> Help --> Under Rest API Docs you will see --> Object reference. (Look at the parameters and examples for help.)

Something like this will get 1 record of the service status for Ping which is under the host_name localhost/

Code: Select all

curl -XGET "http://192.168.4.125/nagiosxi/api/v1/objects/servicestatus?apikey=t0bMmNo0qFu70qFZO93e8sSIqREI82WV2nHna5oTZc0gWFgK4ier47qOe4smlohm&pretty=1&host_name=localhost&service_description=Ping&records=1"

Code: Select all

            "instance_id": "1",
            "service_id": "148",
            "host_id": "143",
            "host_name": "localhost",
            "host_alias": "localhost",
            "name": "PING",
            "host_display_name": "",
            "host_address": "127.0.0.1",
            "display_name": "PING",
            "status_update_time": "2018-02-06 16:04:45",
            "status_text": "PING OK - Packet loss = 0%, RTA = 0.04 ms",
            "status_text_long": "",
            "current_state": "0",
            "performance_data": "rta=0.039000ms;100.000000;500.000000;0.000000 pl=0%;20;60;0",
            "should_be_scheduled": "1",
            "check_type": "0",
            "last_state_change": "2017-12-01 20:07:04",
            "last_hard_state_change": "2017-05-13 23:17:34",
            "last_hard_state": "0",
            "last_time_ok": "2018-02-06 16:04:41",
            "last_time_warning": "1969-12-31 18:00:00",
            "last_time_critical": "2017-12-01 14:46:57",
            "last_time_unknown": "1969-12-31 18:00:00",
            "last_notification": "1969-12-31 18:00:00",
            "next_notification": "1969-12-31 18:00:00",
            "no_more_notifications": "0",
            "acknowledgement_type": "0",
            "current_notification_number": "0",
            "process_performance_data": "1",
            "obsess_over_service": "1",
            "event_handler_enabled": "1",
            "modified_service_attributes": "0",
            "event_handler": "",
            "check_command": "check_ping!100.0,20%!500.0,60%!!!!!!",
            "normal_check_interval": "5",
            "retry_check_interval": "1",
            "check_timeperiod_id": "125",
            "icon_image": "",
            "icon_image_alt": "",
            "has_been_checked": "1",
            "current_check_attempt": "1",
            "max_check_attempts": "4",
            "last_check": "2018-02-06 16:04:41",
            "next_check": "2018-02-06 16:09:41",
            "state_type": "1",
            "notifications_enabled": "1",
            "problem_acknowledged": "0",
            "flap_detection_enabled": "1",
            "is_flapping": "0",
            "percent_state_change": "0",
            "latency": "0",
            "execution_time": "4.003",
            "scheduled_downtime_depth": "0",
            "passive_checks_enabled": "1",
            "active_checks_enabled": "1"
        }
    }
}
Is this what you were looking for?
morabanc
Posts: 199
Joined: Tue Jul 10, 2012 8:14 am

Re: Submit service update trhough Nagios API

Post by morabanc »

Hi kyang,

It seems to be what I search.

Only one question, how we can get the API key ?


Thanks,
Eric
kyang

Re: Submit service update trhough Nagios API

Post by kyang »

Sounds good.

The API key is generated for you and stays the same.

You will see it in the help (Rest API docs) on the example cURL request commands.
morabanc
Posts: 199
Joined: Tue Jul 10, 2012 8:14 am

Re: Submit service update trhough Nagios API

Post by morabanc »

Hi kyang,

Thanks for your time.

I'm sorry but i can't see what you say, below i attach you our "Help" menu in nagiosXI.


Thanks,
Eric
You do not have the required permissions to view the files attached to this post.
kyang

Re: Submit service update trhough Nagios API

Post by kyang »

Sorry, I should have gotten the version of your XI.

You are using a very old XI version. Which uses the backend API --> The backend API is now deprecated.

The API key for the backend API is located here
Go to: Admin->Manage Components->Backend API URL->select your user from the "User" drop-down menu->Apply Settings.

Example:
&username=test&ticket=0b6o4ukv0serk6jeq6ko9isn7sbl2qnv6tn9pb8q5jjnp65hbn9k939fuj4teoth
I would suggest installing the new XI version 5.4.12 to get access to the new REST API which will have these documentations in the help section.
morabanc
Posts: 199
Joined: Tue Jul 10, 2012 8:14 am

Re: Submit service update trhough Nagios API

Post by morabanc »

Thank you very much kyang :)

We'll have a look on the upgrade.

By the way, when I launch the curl from another server i get this error. Maybe because i have an old version, the curl api path are different:

<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /nagiosxi/api/v1/objects/servicestatus was not found on this server.</p>
<hr>
</body></html>


The url of curl is: curl -XGET "http://server-ip/nagiosxi/api/v1/object ... &records=1"

By the way, I check installed components and i see the "backend api" ( i attach you a pic) but i can't choose a user in scroll.

Thanks for your help once again :)
You do not have the required permissions to view the files attached to this post.
morabanc
Posts: 199
Joined: Tue Jul 10, 2012 8:14 am

Re: Submit service update trhough Nagios API

Post by morabanc »

I attach you the screen that I have to choose a user
You do not have the required permissions to view the files attached to this post.
kyang

Re: Submit service update trhough Nagios API

Post by kyang »

I'm not entirely sure why that is happening.

It's probably best to take a look at upgrading or installing a clean system with the new XI version if you don't have much hosts or services.
By the way, when I launch the curl from another server i get this error. Maybe because i have an old version, the curl api path are different:
Yes, because the older version is using the backend API. Whereas, the new version is using the Rest API and provides great documentation on using it.
morabanc
Posts: 199
Joined: Tue Jul 10, 2012 8:14 am

Re: Submit service update trhough Nagios API

Post by morabanc »

Thanks kyang,

We will take a look on upgrade.


Regards :)
Locked