Update host labels using RestAPI

Is there a better way?

Using the webapi previously it was quite “easy” to update host labels, we already knew the existing labels so we could add/remove/modify that list and just push that to the webapi.

With the RestAPI we need to retrieve the “e-tag” and such making on extra API call per host. We have thousands of hosts so when we need to update the host labels on every host it now takes hours.

Not sure why the e-tag should be needed here just to update labels.
Any other way this can be done?

1 Like

The E-Tag-way is the better way: It prevents accidental overwrites.
Consider this example:

  • You pull the host configuration through the API.
  • For some reason it takes minutes until you actually send back an update.
  • In the meantime another person or automation changed the host.

What should be the outcome? Would you want to overwrite the data? Would you want to inspect it again and potentially change your own update to it? With the old Web API it would just be overwritten with all possible ramifications.

Now the E-Tag ensures, that you become aware, if someone or something changed the host while you were editing it. This enables you to re-iterate and make sure your update to the data does not break anything.

There is a silver bullet though: Werk #15886: etag: allow star tag on endpoints that enforce etag policy
Be advised: Ignoring the E-Tag will render all the aforementioned safety mechanisms void. It forces your change to be submitted, even it might break something.

3 Likes

Yes it has its purpose and specially if you manage things on folders or other aspects of the system where there are. multiple interactions.

However, as mentioned no one can modify labels on our environment, there is one script to rule them all and its reading from our CMDB/IPAM to get right labels. So I’m 101% sure no one else is changing labels, and even if they where I would overwrite them anyhow the next sync…

I was not aware of this WERK thanks a lot. It will help us in this specific cornercase. We use e-tag in all our other endpoints when it makes sense to have consistency.

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed. Contact an admin if you think this should be re-opened.