Skip to main content
Solved

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

  • Jul 30, 2024 1:46 PM UTC
  • 6 replies
  • 335 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"}'
     
View original

6 replies

vcoum
Centreon Lord Commander
Forum|alt.badge.img+13
  • Centreon Lord Commander
  • Jul 30, 2024 2:42 PM UTC

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
  • Answer
  • Jul 30, 2024 2:42 PM UTC

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 **
  • Jul 31, 2024 10:05 AM UTC

I will test it.

Thanks again for this quick answer.

 


Forum|alt.badge.img+4
  • Author
  • Steward **
  • Jul 31, 2024 10:18 AM UTC

Test is OK.

Very good ! 😁


Forum|alt.badge.img+5
  • Steward ***
  • Feb 9, 2025 10:12 PM UTC

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 **
  • Feb 10, 2025 8:19 AM UTC
  • 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"}'