RestAPI way to Automatically add bulk of server in Icinga


We had been successfully using director to add the servers manually in iCinga. We have a method to add servers using Director Automation as well which will sync data from a file / DB and keep the list upto date. But we are seeing some downside to the method. For example if a hostname has to delete it has to be deleted from the DB / Sheet. Because the sync will bring it back if you just delete from icinga director
We do not want to maintain a CMDB in icinga itself.

So to simplify the onboarding we want to onboard using simple restAPI way.

Step 1: The agent is installed using SALT
Step 2: We see the new hostname in icinga ca list (yes we do not create ticket and sign it. We use another script locally running on icinga master)
Step 3: We lookup the host-details (Operating System and IP address) by looking at the fqdn in icinga ca list
Step 4: We now want to add the host object using simple restAPI

The following information need to be added

  1. Cluster Zone
  2. Host Template (based on Step 3 OS Lookup Windows / Linux)
  3. Display Name : Same as FQDN
  4. IP Address we have from Step 3 Above
  5. Inherited Group (May not be required as Host-template already has host-group defined)
  6. Environment : A custom field created for mentioning Test / Dev / Prod (We have the value in Lookup from Step3 Above)

Can you please share the restAPI query which I can use to create a host object with the above information


just one tipp. Dont ask others to do the work you should do. At least you could try to read the docs and write it by yourself. If you run in problems then, you usualy get help here to get it running. But no one here willl do the work for you.


Sorry Carsten. Usually I try exploring myself. But you know playing in production environment sometimes is tricky - specially if you are not very very familiar with tool. “Learning phase you know”. :slight_smile:

I may have missed but I couldn’t see an example of a curl -k -v command to add a host - if you can even point me to the right place rest I will do it. I have even been able to do it with downtimes looking at the document. But couldn’t find an example to add host (I admit may be I have missed)

Look at here:

Also a note from my site:
With regard to your answer it looks like you don’t have a test environment. Because of testing updates, quality assurance’s still recommended. We develop and test all our scripts on our test systems and if it works we deploy it with salt on our productions system.
And pls keep in mind that the installations of the IT infrastructure from us in the community are different. As @anon66228339 mentioned we can only give you tips if you show us what you have and which may not work.

An also an example from our environment:
I wrote many scripts to get data from our internal CMDB. This data will joined with some addional data from other DBs (e.g. SCOM, web applications). It the beginning it was one script with a hudge SQL. It was an recursive SQL. But at the end our DB admin was not really happy with this solution. So I split this in many smaller SQLs. The data processing is done in seperate scripts. With them we created many CSV-file for the module “fileshipper”. This method works fine the last years. And it was also ok, if a colleague wanted other checks or we have to import more data from other systems, APIs etc.
Now we have to change this. Because we saw the border of many CSV files and the fileshipper module.
The last weeks I rewrite my diffrent scripts and adapt it to a new situation and new systems. The new script write one JSON file for our import.
Another idea was to get the data directly from our diffrent databases. This is possible with the director, but we had to fetch data from our DB2 databases, which doesn’t work. I never found a solution for this.

Damn it - i was searching all along in the icinga API document and not in director. Thank You very much.

I have last question - more on tips and best practice direction

What is the recommended way to add remove a node

  1. Use RestAPI to directly create a Host Object using script
  2. Use DB to store the data first and then sync with Director Automation (it is reducing the usability of director - as if I delete something from director it gets recreated due to sync. We have to delete from DB manually)

Best practice? It’s difficult to say. It’s depending how your infrastructure work. But in our experience withe the import from the director it is better not to mix two methods.
If you have the data in a database take it from there. If you collect the data with your salt-minion, you could create the host in icinga using the director api.
In short: it’s depending from were your data come from.

Thanks Stevie

We do not have the data in database.
We install the agent using salt. Then a local script periodically looks into

icinga ca list

if it sees a new agent picks the FQDN - gather other information. Enters in the DB a table in icinga DB itself. Then using director automation sync to create the host object.
The good side is we have a DB to restore in case something gets screwed up. Well may be it is good may be it is useless as all CA etc will have to be renewed in a actual screw up scenario. Only time will tell
The downside is - we are actually reducing the functionality of Director. If we have to remove a server we can easily delete from director - but that doesn’t remove from the custom table and in the next sync it will recreate the object.

Also we need to think of deleting a server. Is there a restAPI to remove as well? I will explore that though.

So considering above (restAPI way or Director sync way) which one is suggested by icinga community

If you have no own CMDB for documentiation, maybe it’s the best way for you to use the director API with the information what the salt-minion knows/collect.
I don’t know if there would be a function like this or this Ansible modules for Icinga Director for salt.
But it should be possible with the command salt-call grains.items and little scripting to create a host object for the director api.