Deleting variables by using the API

A Host has the following custom parameters:

“vars”: {
“http_address”: “$host.address$”,
“http_expect”: “”,
“http_sni”: true,
“http_ssl”: true,
“http_vhost”: “fsc-web.kpmgedge.com”,
“port”: 443.0
},

However the command looks like this:

“command”: [
“/usr/lib64/nagios/plugins/check_http”,
“–no-body”,
“–sni”,
“-H”,
fsc-web.kpmgedge.com”,
“-I”,
kasplatfkast.outsystemsenterprise.com”,
“-S”,
“-e”,
"401",
“-f”,
“ok”,
“-t”,
“25”,
"-u",
"/"
],

The templates do not contain default value for the -u (http_uri) as such it should be blank.
However as you can see the command for some reason has the “/” in it.
Also I have tried to remove the vars.http_expect so it would take the default from the template by running the following command:

curl -v -k -s -u root:c9056922911a5cfc -H 'Accept: application/json' -X POST 'https://localhost:5665/v1/objects/hosts/syd.KPMG.prod-fsc-web.fsc-web.kpmgedge.com.http' \
-d '{ "templates": [ "base.tmpl" ], "attrs": { "address": "kasplatfkast.outsystemsenterprise.com", "vars.http_address": "$host.address$", "vars.http_vhost": "fsc-web.kpmgedge.com", "vars.port": 443, "vars.http_ssl": true, "vars.http_sni" : true } }'  | python -m json.tool

But it seems to have no effect although I got the 200 ok:

{
“results”: [
{
“code”: 200.0,
“name”: “syd.KPMG.prod-fsc-web.fsc-web.kpmgedge.com.http”,
“status”: “Attributes updated.”,
“type”: “Host”
}
]
}

The vars still remain within the blank value set previously.
Is there a way to ensure that a variable is wiped from a host and check via the API ?

Hi,

the http CheckCommand from the ITL sets http_uri to default /. If you really don’t want to use it, I’d suggest to use a different CheckCommand then, e.g. something like this:

object CheckCommand "http-no-uri" {
  import "http"

  arguments.remove("-u")
}

References

Dictionary#remove: https://icinga.com/docs/icinga2/latest/doc/18-library-reference/#dictionaryremove
Templates: https://icinga.com/docs/icinga2/latest/doc/03-monitoring-basics/#templates (“You can also import existing non-template objects.”).

Cheers,
Michael

The issue is that in other hosts I do need that variable and I am assigning it a value, but in the ones where I do not, and am using the same template, the values are populated although the host has the empty values ( as you can see in the example above).

I want to use the same CheckCommand definitions for all these hosts, if possible, as it makes the provisioning much simpler.

The host doesn’t specify http_uri and as such, the default value of the CheckCommand gets used. That’s what is going on in your described scenario.

The culprit here is that you cannot easily remove that default value, other than my described solution.

Cheers,
Michael

Hi Michael

I might have not explained myself properly, the idea is to update a variable on the Host so the check will take a new value.
If i want to have the URI for a period of time ( as the web server added a new page that needs testing) and then remove it, I need the host to stay the same and the check to stay the same, but want just to update / revoke a value for the variables defined in the host.

Mhhhh wouldn’t this create a heavily volatile service check then with different parameters being set, and no-one may really follow its history over time? To me, modifying the URL is actually really changing the unique key for this check, and it certainly would be better to just delete service A and add service B with the updated URL then.

Cheers,
Michael

1 Like

The issue in this case that the host is using an http based check as the “alive” check, not ping, so sometimes there is a need to update the variables within the host to match the changes of the web server answering.

We do not want to remove the host and recreate it, but to update the variables it has to match the new status of the web server.

Ok, then coming back to Deleting variables by using the API - this is the only solution I can provide. Maybe others have done it differently.

Cheers,
Michael