Skip to main content
Solved

REST API : "HOST panel : create services linked to the template too" switch y/n


Forum|alt.badge.img+4

Bonjour,

 

In the host panel, there is a radio switch “ Create Service linked to the template too”.

Is it possible to activate it with the rest API?

 

With the REST API, i am creating new hosts from template.

But the new hosts don t have services linked to the template.

Is it possible to add these services linked to the template with the rest API?

 

Thanks for the future answer,

Mathias

 

Best answer by vcoum

Hello,

Yes you can do it

  • Via CLAPI
    centreon -u admin -p 'password' -o HOST -a applytpl -v "HOSTNAME"
  • Via APIv1 using cURL
    #First get auth token
    curl -X POST "http://localhost/centreon/api/index.php?action=authenticate" -F 'username=admin' -F 'password=Centreon!123'
    #Output
    {"authToken":"API_TOKEN"}
    
    #Then send the request using your token
    curl "http://localhost/centreon/api/index.php?action=action&object=centreon_clapi" -H "centreon-auth-token: API_TOKEN" -d '{"action": "applytpl", "object": "HOST", "values": "HOSTNAME"}'
     
View original

vcoum
Centreon Lord Commander
Forum|alt.badge.img+13
  • Centreon Lord Commander
  • July 30, 2024

Hello,

Yes you can do it

  • Via CLAPI
    centreon -u admin -p 'password' -o HOST -a applytpl -v "HOSTNAME"
  • Via APIv1 using cURL
    #First get auth token
    curl -X POST "http://localhost/centreon/api/index.php?action=authenticate" -F 'username=admin' -F 'password=Centreon!123'
    #Output
    {"authToken":"API_TOKEN"}
    
    #Then send the request using your token
    curl "http://localhost/centreon/api/index.php?action=action&object=centreon_clapi" -H "centreon-auth-token: API_TOKEN" -d '{"action": "applytpl", "object": "HOST", "values": "HOSTNAME"}'

vcoum
Centreon Lord Commander
Forum|alt.badge.img+13
  • Centreon Lord Commander
  • July 30, 2024

Hello,

Yes you can do it

  • Via CLAPI
    centreon -u admin -p 'password' -o HOST -a applytpl -v "HOSTNAME"
  • Via APIv1 using cURL
    #First get auth token
    curl -X POST "http://localhost/centreon/api/index.php?action=authenticate" -F 'username=admin' -F 'password=Centreon!123'
    #Output
    {"authToken":"API_TOKEN"}
    
    #Then send the request using your token
    curl "http://localhost/centreon/api/index.php?action=action&object=centreon_clapi" -H "centreon-auth-token: API_TOKEN" -d '{"action": "applytpl", "object": "HOST", "values": "HOSTNAME"}'
     

Forum|alt.badge.img+4
  • Steward **
  • July 31, 2024

I will test it.

Thanks again for this quick answer.

 


Forum|alt.badge.img+4
  • Steward **
  • July 31, 2024

Test is OK.

Very good ! 😁


Forum|alt.badge.img+5
  • Steward ***
  • February 9, 2025

Hello @vocum , @mathias :) 
I was searching for this exact same thing, but it doesnt work for me with API. 

[root@ip-10-0-12-126 ~]# centreon -u dummy -p 'vuYAQ#9gr!5u5xx' -o HOST -a applytpl -v "REVERSE-PROXY-2"
Return code end :

But if I click the “ Create Service linked to the template too” on the GUI , its works. I didnt had any issues with any other clapi command, seems strange this one fails. 

Centreon v.24.10.3


Forum|alt.badge.img+4
  • Steward **
  • February 10, 2025
  • Via CLAPI
    centreon -u admin -p 'password' -o HOST -a applytpl -v "HOSTNAME"
  • Via APIv1 using cURL
    #First get auth token
    curl -X POST "http://localhost/centreon/api/index.php?action=authenticate" -F 'username=admin' -F 'password=Centreon!123'
    #Output
    {"authToken":"API_TOKEN"}
    
    #Then send the request using your token
    curl "http://localhost/centreon/api/index.php?action=action&object=centreon_clapi" -H "centreon-auth-token: API_TOKEN" -d '{"action": "applytpl", "object": "HOST", "values": "HOSTNAME"}'
     

 

 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings