set / retrieve parents, templates via api call

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
lukesullivan
Posts: 34
Joined: Tue Jan 24, 2017 11:12 am

set / retrieve parents, templates via api call

Post by lukesullivan »

It looks like the api docs are not exhaustive for fields that can be set on a host. I have two hosts, laka.noc and lono.noc. I would like lono to be a parent of laka. Laka otherwise has all it's parameters configured correctly, so I force post it with just the parents parameter (which appears to be undocumented):

[lukas@nagiosxi-dev ~]$ curl -k -XPOST "https://nagiosxi-dev.noc.harvard.edu/na ... h&pretty=1" -d "host_name=laka.noc.harvard.edu&parents=lono.noc.harvard.edu&force=1&applyconfig=1"
{
"success": "Successfully added laka.noc.harvard.edu to the system. Config applied, Nagios Core was restarted."
}

When I look at laka in the ccm, I can see it has a parent of lono, but if I http/get the host, I do not see parentage.

[lukas@nagiosxi-dev ~]$ curl -k -XGET "https://nagiosxi-dev.noc.harvard.edu/na ... arvard.edu"
{
"hostlist": {
"recordcount": "1",
"host": {
"@attributes": {
"id": "509"
},
"instance_id": "1",
"host_name": "laka.noc.harvard.edu",
"is_active": "1",
"config_type": "1",
"alias": "laka.noc.harvard.edu",
"display_name": "laka.noc.harvard.edu",
"address": "laka.noc.harvard.edu",
"check_interval": "5",
"retry_interval": "1",
"max_check_attempts": "2",
"first_notification_delay": "0",
"notification_interval": "5",
"passive_checks_enabled": "1",
"active_checks_enabled": "1",
"notifications_enabled": "1",
"notes": "this is a test from Luke and Mike",
"notes_url": "",
"action_url": "",
"icon_image": "",
"icon_image_alt": "",
"statusmap_image": ""
}
}
}

Is there a way to programmatically retrieve the list of parents of a host?

Similarly, is it possible to get a list of templates that are applied (via the use= parameter when posting a host/service)?

thanks,

-Luke
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

Re: set / retrieve parents, templates via api call

Post by mcapra »

The end goal of the API will to be to have the API handle "all of the things". It's not there yet, but that is the end goal.

You are correct that a GET against objects/host does not return the parents for a given host. Inheritance is a complex issue within Nagios Core that's not yet fully solved for the API.

Although, outside of the REST API, you should be able to get that via a call to the JSON CGIs found here:

Code: Select all

http://<nagios_xi_host>/nagios/cgi-bin/objectjson.cgi
An example to get the parents of host 192.168.67.99:

Code: Select all

[root@xi-stable ~]# curl -XGET 'http://nagiosadmin:[email protected]/nagios/cgi-bin/objectjson.cgi?query=host&hostname=192.168.67.99'
{
  "format_version": 0,
  "result": {
    "query_time": 1493067000000,
    "cgi": "objectjson.cgi",
    "user": "nagiosadmin",
    "query": "host",
    "query_status": "released",
    "program_start": 1493066997000,
    "last_data_update": 1493066997000,
    "type_code": 0,
    "type_text": "Success",
    "message": ""
  },
  "data": {
    "host": {
      "name": "192.168.67.99",
      "name": "192.168.67.99",
      "display_name": "192.168.67.99",
      "alias": "192.168.67.99",
      "address": "192.168.67.99",
      "parent_hosts": [
        "192.168.67.106",
        "192.168.67.107",
        "192.168.67.97"
      ],
      "child_hosts": [
      ],
      "services": [
        "test dollar",
        "System Log Critical Errors",
        "Swap Usage",
        "Ping",
        "Page File Usage",
        "Memory Usage",
        "Ethernet0 Bandwidth - Outbound",
        "Ethernet0 Bandwidth - Inbound",
        "Drive E: Disk Usage",
        "Drive C: Disk Usage",
        "Disk Usage on E:/",
        "Disk Usage on C:/",
        "CPU Usage"
      ],
      "check_command": "check_ping!1000.0,50%!2000.0,80%!!!!!!",
      "initial_state": 0,
      "check_interval": 5.00,
      "retry_interval": 1.00,
      "max_attempts": 5,
      "event_handler": "",
      "contact_groups": [
      ],
      "contacts": [
        "nagiosadmin"
      ],
      "notification_interval": 60.00,
      "first_notification_delay": 0.00,
      "notifications_options": -1,
      "notification_period": "xi_timeperiod_24x7",
      "check_period": "xi_timeperiod_24x7",
      "flap_detection_enabled": true,
      "low_flap_threshold": 0.00,
      "high_flap_threshold": 0.00,
      "flap_detection_options": -1,
      "stalking_options": 0,
      "check_freshness": false,
      "freshness_threshold": 0,
      "process_performance_data": true,
      "checks_enabled": true,
      "accept_passive_checks": true,
      "event_handler_enabled": true,
      "retain_status_information": true,
      "retain_nonstatus_information": true,
      "obsess": true,
      "hourly_value": false,
      "notes": "",
      "notes_url": "",
      "action_url": "",
      "icon_image": "ncpa.png",
      "icon_image_alt": "",
      "vrml_image": "",
      "statusmap_image": "ncpa.png",
      "have_2d_coords": false,
      "x_2d": -1,
      "y_2d": -1,
      "have_3d_coords": false,
      "x_3d": 0.00,
      "y_3d": 0.00,
      "z_3d": 0.00,
      "should_be_drawn": true,
      "custom_variables": {
        "XIWIZARD": "ncpa"
      }
    }
  }
}
In which case, the parents are held in the parent_hosts array.
Former Nagios employee
https://www.mcapra.com/
dwhitfield
Former Nagios Staff
Posts: 4583
Joined: Wed Sep 21, 2016 10:29 am
Location: NoLo, Minneapolis, MN
Contact:

Re: set / retrieve parents, templates via api call

Post by dwhitfield »

Did @mcapra's post help you? Please let us know if you have any additional questions.
Locked