Skip to main content
Solved

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

  • July 30, 2024
  • 6 replies
  • 236 views

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"}'
     

6 replies

vcoum
Centreon Lord Commander
Forum|alt.badge.img+13
  • Centreon Lord Commander
  • 137 replies
  • 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
  • 137 replies
  • Answer
  • 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
  • Author
  • Steward **
  • 17 replies
  • July 31, 2024

I will test it.

Thanks again for this quick answer.

 


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

Test is OK.

Very good ! 😁


Forum|alt.badge.img+5
  • Steward ***
  • 14 replies
  • 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
  • Author
  • Steward **
  • 17 replies
  • 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"}'