Answers: <p>You should add the correct zone attribute for the host and the service, so they will propagate to the client node.</p>
  
  <p>Add <code>"zone": "client.com"</code> to the api requests.</p>
  
Answers: CC BY-SA 3.0
Answers: 2018-02-14T12:40:24.147Z
Answers: 2018-02-14T12:40:24.147Z
Answers: Max Vlaschuk-Gorelik
Body: <p>I am trying to do add service of client using icinga2 api. I have followed <a href="https://github.com/saurabh-hirani/icinga2-api-examples" rel="nofollow noreferrer">https://github.com/saurabh-hirani/icinga2-api-examples</a>. Here is what I have done so far.</p>
  
  <p>First I created zone and endpoint in master as follows:</p>
  
  <p><strong>Endpoint</strong></p>
  
  <pre><code>Object Endpoint "client.com" {
  }
  </code></pre>
  
  <p><strong>Zone</strong></p>
  
  <pre><code>Object Zone "client.com" {
      endpoints = [ "client.com" ]
      parent = "master.com"
  }
  </code></pre>
  
  <p>Restarted icinga2</p>
  
  <p>Then in client server</p>
  
  <pre><code>#!/bin/bash -e
  
  . icinga2_vars
  
  
  echo "CREATING HOSTGROUP"
  
  
  curl -s -u $ICINGA2_API_USER:$ICINGA2_API_PASSWORD \
      -H 'Accept: application/json' -X PUT \
      -k "https://$ICINGA2_HOST:$ICINGA2_API_PORT/v1/objects/hostgroups/client_hostgroup" \
      -d '{ "attrs": {
              "display_name": "client host group"
  } }' | python -m json.tool
  
  
  echo "CREATING HOST"
  
  
  curl -s -u $ICINGA2_API_USER:$ICINGA2_API_PASSWORD  \
      -H 'Accept: application/json' -X PUT \
      -k "https://$ICINGA2_HOST:$ICINGA2_API_PORT/v1/objects/hosts/client.com" \
      -d '{ "templates": [ "generic-host" ],
          "attrs": {
          "address": "127.0.0.1",
          "check_command": "hostalive",
          "groups": ["client_hostgroup"],
          "vars.notification['mail']": {
              "groups": ["client_hostgroup_users"]
              }
  } }' | python -m json.tool
  
  echo "CREATING SERVICE"
  
  
  curl -s -u $ICINGA2_API_USER:$ICINGA2_API_PASSWORD  \
      -H 'Accept: application/json' -X PUT \
      -k "https://$ICINGA2_HOST:$ICINGA2_API_PORT/v1/objects/services/client.com!load" \
      -d '{
          "templates": [ "generic-service" ],
          "attrs": {
              "display_name": "check load",
              "check_command" : "load",
              "command_endpoint": "client.com",
              "host_name": "client.com"
          }
  }' | python -m json.tool
  </code></pre>
  
  <p>It is working but checking service of master itself. It should check service of client server.</p>
  
Comments: CC BY-SA 3.0
Comments: 2017-08-04T16:53:04.920Z
Comments: Let me know if anyone have better approach with nrpe so that we do not have to touch master server. all commands will be send to client server from master.
Comments: Prakash
Tags: <monitoring>
Title: Service check with api in Icinga2
UserDisplayName: Prakash
ThreadText: # Service check with api in Icinga2
  
  (Asked by: username_0 on 2017-08-04)
  
  I am trying to do add service of client using icinga2 api. I have followed <https://github.com/saurabh-hirani/icinga2-api-examples>. Here is what I have done so far.
  
  First I created zone and endpoint in master as follows:
  
  **Endpoint**
  
  ```
  Object Endpoint "client.com" {
  }
  
  ```
  
  **Zone**
  
  ```
  Object Zone "client.com" {
      endpoints = [ "client.com" ]
      parent = "master.com"
  }
  
  ```
  
  Restarted icinga2
  
  Then in client server
  
  ```
  #!/bin/bash -e
  
  . icinga2_vars
  
  echo "CREATING HOSTGROUP"
  
  curl -s -u $ICINGA2_API_USER:$ICINGA2_API_PASSWORD \
      -H 'Accept: application/json' -X PUT \
      -k "https://$ICINGA2_HOST:$ICINGA2_API_PORT/v1/objects/hostgroups/client_hostgroup" \
      -d '{ "attrs": {
              "display_name": "client host group"
  } }' | python -m json.tool
  
  echo "CREATING HOST"
  
  curl -s -u $ICINGA2_API_USER:$ICINGA2_API_PASSWORD  \
      -H 'Accept: application/json' -X PUT \
      -k "https://$ICINGA2_HOST:$ICINGA2_API_PORT/v1/objects/hosts/client.com" \
      -d '{ "templates": [ "generic-host" ],
          "attrs": {
          "address": "127.0.0.1",
          "check_command": "hostalive",
          "groups": ["client_hostgroup"],
          "vars.notification['mail']": {
              "groups": ["client_hostgroup_users"]
              }
  } }' | python -m json.tool
  
  echo "CREATING SERVICE"
  
  curl -s -u $ICINGA2_API_USER:$ICINGA2_API_PASSWORD  \
      -H 'Accept: application/json' -X PUT \
      -k "https://$ICINGA2_HOST:$ICINGA2_API_PORT/v1/objects/services/client.com!load" \
      -d '{
          "templates": [ "generic-service" ],
          "attrs": {
              "display_name": "check load",
              "check_command" : "load",
              "command_endpoint": "client.com",
              "host_name": "client.com"
          }
  }' | python -m json.tool
  
  ```
  
  It is working but checking service of master itself. It should check service of client server.
  
  **Tags:** monitoring
  
  > **Comments:**
  > **username_0**: Let me know if anyone have better approach with nrpe so that we do not have to touch master server. all commands will be send to client server from master.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-02-14. Score: 1
  
  You should add the correct zone attribute for the host and the service, so they will propagate to the client node.
  
  Add `"zone": "client.com"` to the api requests.
  
  
  ---
  
  