brennerm / check-mk-web-api

Python library to talk to the Check_Mk Web API
https://brennerm.github.io/check-mk-web-api/
MIT License
53 stars 26 forks source link

editing hosts #7

Closed FlorianHeigl closed 5 years ago

FlorianHeigl commented 5 years ago

Hi ;-)

So, one thing I had postponed a month back and just returned to:

Check_MK Fehler: Unbekanntes Attribut: tags

(same with folder)

I can imagine API-side issues updating folders (would love none though) but since I can't do even tags, it feels strange.

I've tried for a bit, sending back the same structure as one receives on get_host using update_host seems to not be possible. Do you have any advice about modifying what's in the attributes dictionary of the API query?

My use case is manyfold, first I store a hash of the system's host tags and other stuff in the alias field, then I compare that value to see if any system has been updated in CMDB etc. If yes, I want to apply the updates to the existing host.

For now I think I can work around by deleting the node, but if you got an example updating more than the ip I would be very curious.

brennerm commented 5 years ago

Hey @FlorianHeigl, following the Check_MK Web API command reference it seems like the proper way would be use the same attribute name that you receive from the get_host endpoint.

As you already tried this I cannot think of another way to achieve the desired outcome.

Maybe you can contact the Check_MK support and ask if this is possible using the Web API.

Yogibaer75 commented 5 years ago

Hi Max and Florian,

for the problem with the host update i found the following solution. First create a dictionary with the desired tags inside - example attributes = {'tag_nw_hersteller':'nw_cisco','tag_criticality': 'offline'} And then make the following request api.make_request('edit_host', data={'hostname': updatedhost, 'attributes': attributes}) This is working nicely in one of my bigger setups with automatic update the hosts from a CMDB.

FlorianHeigl commented 5 years ago

@Yogibaer75 Hi Andreas ;-) Have you per chance also found a way to do bulk updates? I didn't care try yet, meaning I do a few thousand API calls ;-)

brennerm commented 5 years ago

Never heard of bulk operations using the API. Just loop through your hosts and update them using this library. That's what it's for. ;)

Yogibaer75 commented 5 years ago

I have done these updates with over 1000 switches and had no problems with performance. It takes some time yes but it was working stable. The only "bulk" operations are all the get_all things.

brennerm commented 5 years ago

@FlorianHeigl Have a look at this. These endpoints are not supported by the library yet but I'm currently working on implementing these. If this solves your problem please close this issue.

FlorianHeigl commented 5 years ago

closing already since the solution was direct passing of the dict. i didn't yet get around to write our stuff, but am sure it'll work. will also ask for a 1.5 upgrade but since we moved into a different department's cmk, I suppose that will take a while :-)