1

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.

  • 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. – Err0rr Aug 4 '17 at 16:53
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.