I need to get all of service status in Centreon using REST API. However, I can't retrieve the values at all. It only returns a 404 error.
How can I resolve a problem like this with Centreon?
Here, my code:
import requests
import json
def authentification():
# données authentification
payload = '{"security": {"credentials": {"login": "XXXXXXXXXX", "password": "XXXXXXXX"}}}'
headers = {'content-type': 'application/json'}
#requête authentification
r = requests.post('http://192.168.17.141/centreon/api/beta/login', data=payload, headers=headers)
#on récupère le token
json = r.json()
#initialisation du header pour le token
headers = dict()
headers['X-AUTH-TOKEN'] = json['security']['token']
print(headers)
return(headers)
def get_service_status(authToken):
#Requête
headers = {'centreon-auth-token': auth_token}
response = requests.get('http://192.168.17.141/centreon/api/monitoring/services&search={""}', headers=authToken)
if response.status_code == 200:
print("OK1")
services = response.json()
for service in services:
print(f"Service: {service['description']}, Status: {service['state']}")
else:
print(f"Erreur: {response.status_code}")
auth_token = authentification()
get_service_status(auth_token)