Clear-Host $username = "logincentreon" $password = "thepassword" #Récupération d'un token depuis un login/mdp $MonBody = @{ "username"=$username "password"=$password } $Result = Invoke-RestMethod "https://urldevotrecentreon.com/centreon/api/index.php?action=authenticate" -Method Post -Body $MonBody $MonToken = $Result.authToken write-host $MonToken #Interrogation de l'api qui donne la liste des hôtes, cf https://docs.centreon.com/fr/docs/api/rest-api-v1/#host $MonBody = @{ "action"="show" "object"="host" } $MonBodyenjson = $MonBody | ConvertTo-Json $MonHeader = @{ "centreon-auth-token"=$MonToken } $MonHeaderenJson = $MonHeader | ConvertTo-Json $Result = Invoke-RestMethod "https://urldevotrecentreon.com/centreon/api/index.php?action=action&object=centreon_clapi" -Method Post -Headers $MonHeader -Body $MonBodyenjson -ContentType 'application/json' foreach ($UnHost in $Result.result){ Write-Host "$($UnHost.name) $($UnHost.address) $($UnHost.id)" } write-host "Recherche des services en état critique" #Interrogation de l'api qui donne l'état des services #https://docs.centreon.com/fr/docs/api/rest-api-v1/#service-status $MonBodyenjson = $MonBody | ConvertTo-Json $Result = Invoke-RestMethod "https://urldevotrecentreon.com/centreon/api/index.php?object=centreon_realtime_services&action=list&status=Critical&limit=1000000" -Method Get -Headers $MonHeader -ContentType 'application/json' foreach ($UnService in $Result | Where-Object {$_.acknowledged -eq 0 -and $_.state -eq 2}){ Write-Host "$($UnService.name) $($UnService.state) $($UnService.output)" }