Can't get curl to post host info, can get curl to get info

Hi there everyone.

I have an issue that I need some help with. I’ve made some progress, but I’m getting stuck with the curl call to update the target host. First, some background. We have some Windows IOT appliances that are being deployed at many different sites. For one reason or another, it’s not possible for static IPs to always be assigned to these hosts. I have written some powershell that will grab the current IP address and spit it out to a text file when it’s run. If the txt file already exists, it will grab the current IP address, spit it out to a txt file, and compare the hashes of the two files. If they match, there’s nothing to do. If they don’t match, it should use the icinga API to update the address of the host with the current IP address.

For the life of me, I can’t get the curl command to update the host. This is the command I’m using:

curl.exe -k -s -u “u:p” -H ‘Accept: application/json’ -X POST ‘``https://masterURL:5665/v1/objects/hosts/hostname’`` -d ‘{ ““attrs””: { ““address””: ““10.120.1.110”” }, ““pretty””: true }’

This is the result:

{
“error”: 404,
“status”: “No objects found.”
}

Interestingly enough, I can get a curl command to grab info about the host.

curl.exe -H ‘Accept: application/json’ -k -s -u “u:p” GET ‘``https://masterURL.radnet.rdlx.pvt:5665/v1/objects/hosts?host=hostname’

This is the result:

{“results”:[{“attrs”:{“__name”:“hostname”,“acknowledgement”:0,“acknowledgement_expiry”:0,“acknowledgement_last_change”:0,“action_url”:“”,“active”:true,“address”:“10.120.1.112”,……….}

Maybe I’m going about this wrong, so please correct me if that’s the case. Maybe it would be better to try and use the IFW? Thank you for your time.

Thanks for posting. Even after taking a second look at your modifying curl command, it looks quite right - also compared to the example from the docs. Some ideas to check:

  1. In your second querying query, the Icinga 2 master URL differs. Is this just a copy/paste or redaction failure or do you might have two different Icinga 2 setups?
  2. What are the permissions of your ApiUser “u”? To modify host objects, objects/modify/Host is required.
  3. What is written to the icinga2.log when sending the modifying API request?

Hi Alvar,

number 1 was definitely a copy paste error.

I think you may have discovered the error. I use that api user to generate tickets when working with Linux hosts. I didn’t even think to look at the user’s permissions again to see if they were allowed to modify hosts. I did discover another small, related issue. I think I meant to use the director API rather than the normal icinga API, so now I’m running into similar issues again.

curl.exe -u “u:k” -H ‘Accept:application/json’ -X PUT ‘https://master/icingaweb2/director/host’ -d ‘{““object_type””: ““object””, ““object_name””: ““mapwdressv02.radnet.rdlx.pvt””, ““address””: ““127.0.0.1””}’ -v

Host maicingamaster1.radnet.rdlx.pvt:443 was resolved.
* IPv6: (none)
* IPv4: 10.120.1.111
* Trying 10.120.1.111:443…
* schannel: disabled automatic use of client certificate
* ALPN: curl offers http/1.1
* ALPN: server accepted http/1.1
* Connected to maicingamaster1.radnet.rdlx.pvt (10.120.1.111) port 443
* using HTTP/1.x
* Server auth using Basic with user ‘configurator’
> PUT /icingaweb2/director/host HTTP/1.1
> Host: maicingamaster1.radnet.rdlx.pvt
> Authorization: Basic Y29uZmlndXJhdG9yOno3czNncXoyNGtqNW8zZHg=
> User-Agent: curl/8.13.0
> Accept:application/json
> Content-Length: 120
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 120 bytes
< HTTP/1.1 404 Not Found
< Date: Mon, 01 Dec 2025 23:31:12 GMT
< Server: Apache/2.4.52 (Ubuntu)
< Content-Length: 46
< Content-Type: application/json
<
{“status”:“error”,“message”:“Page not found.”}* Connection #0 to host