Skip to main content

Bonjour ,

j’ai fait un script en php pour afficher l’état d’un service host avec le token,

la partie token fonctionne très bien, en revanche j’ai une erreur sur l’affichage de l’état de service cpu pour mon host

voir l’erreur

 

voici mon script 

<?php

 

// 1er appel API CENTREON pour obtenir le token de connexion.

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "http://monserveur:port/centreon/api/index.php?action=authenticate");

curl_setopt($ch, CURLOPT_POST, true);

curl_setopt($ch, CURLOPT_POSTFIELDS, "username=clapi-mon-poller&password=mdp");

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response  = curl_exec($ch);

//echo $response;

curl_close($ch);

 

// Formatage du retour du cURL.

$response = substr("$response", 14);

//echo "<br> $response";

 

$token = substr("$response", 0, -2);

echo "<br> $token";

 

// 2eme appel API CENTREON pour obtenir le status d'un service particulier en utilisant le token obtenu.

 

$headers = array(

"Content-Type" => "application/json",

"centreon-auth-token" => "$token"

);

 

 

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "http://monserveur:port/centreon/api/index.php?object=centreon_realtime_services&action=list&limit=1&fields=state&search=CPU&searchHost=serveur1");

curl_setopt($ch, CURLOPT_POST, true);

curl_setopt($ch, CURLOPT_HEADER, true);

curl_setopt($ch, CURLOPT_VERBOSE, true);

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$status = curl_exec($ch);

echo "<br> $status";

curl_close($ch);

 

 

une idée sur l’erreur ou si quelqu’un a une meilleur proposition ?

Hi @idi, Please ask your problem in English. This will help all other non-french speaking users who have the same issue to benefit from the solutions that will be proposed. Thank you for your understanding


Hello ,

I made a script in php to display the status of a host service with the token,

the token part works very well, however I have an error on the display of the cpu service status for my host

see error

here is my script

==============

<?php

 

// 1er appel API CENTREON pour obtenir le token de connexion.

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "http://monserveur:port/centreon/api/index.php?action=authenticate");

curl_setopt($ch, CURLOPT_POST, true);

curl_setopt($ch, CURLOPT_POSTFIELDS, "username=clapi-poller&password=mdp");

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response  = curl_exec($ch);

//echo $response;

curl_close($ch);

 

// Formatage du retour du cURL.

$response = substr("$response", 14);

//echo "<br> $response";

 

$token = substr("$response", 0, -2);

echo "<br> $token";

 

// 2eme appel API CENTREON pour obtenir le status d'un service particulier en utilisant le token obtenu.

 

$headers = array(

"Content-Type" => "application/json",

"centreon-auth-token" => "$token"

);

 

 

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "http://monserveur:port/centreon/api/index.php?object=centreon_realtime_services&action=list&limit=1&fields=state&search=CPU&searchHost=serveur1");

curl_setopt($ch, CURLOPT_POST, true);

curl_setopt($ch, CURLOPT_HEADER, true);

curl_setopt($ch, CURLOPT_VERBOSE, true);

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$status = curl_exec($ch);

echo "<br> $status";

curl_close($ch);

========================


Any idea what's wrong or if anyone has a better suggestion?


Hello,

my need is to display the status of a service in real

CURL -s "http://$IP_CENTREON/centreon/api/index.php?object=centreon_realtime_services&action=list&limit=1&fields=state&search=CPU&searchHost=nomserveur" -H 'Content-Type: application/json' -H 'centreon-auth-token: '$TOKEN'' | $JQ 'length'`

 

 

 

my result is not correct

Hello @idi 

You can use this command to get all the real time information about your service.

curl --location --request GET 'https://IP_ADDRESS:443/centreon/api/latest/monitoring/hosts/YOUR_HOST_ID/services/YOUR_SERVICE_ID' \

--header 'X-AUTH-TOKEN: YOUR_TOKEN'

But first you will need to get the host and service IDs.


Hello @sduret 

 
here is the error

curl --location --request GET 'http://myserveur:443/centreon/api/latest/monitoring/hosts/1589/services/8381' -H 'Content-Type: application/json' -H 'centreon-auth-token: 'zVLeK3XyUV9iWELUxnA59zFBtaPBO30jbcijN31Jv3o=''

 


Hello

Your server uses HTTP or HTTPS?
if it’s HTTP, you can remove “:443”

What is your current Centreon release?

rpm -qa centreon-web


Can you send us the result of this command?

grep -A2 -Ri '<LocationMatch' /opt/rh/httpd24/root/etc/httpd/conf.d/10-centreon.conf

 


Reply