PHP code example of mtxserv / wazuh-api

1. Go to this page and download the library: Download mtxserv/wazuh-api library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mtxserv / wazuh-api example snippets




use Wazuh\WazuhClient;
use GuzzleHttp\Exception\GuzzleException;
use JsonException;

=> 'https://wazuh.my.instance:55000',
    'wazuh_user' => 'my_user',
    'wazuh_password' => 'my_password',
    'verify' => true, // SSL Certificate verification
]);

try {
    // Retrieve list of agents
    $response = $client->get('/agents');

    // Decode JSON response and handle JSON exceptions
    try {
        $json = json_decode($response->getBody()->getContents(), true, 512, JSON_THROW_ON_ERROR);
    } catch (JsonException $jsonException) {
        echo 'JSON decoding error: ', $jsonException->getMessage(), "\n";
        return;
    }

    var_dump($json);
} catch (GuzzleException $e) {
    echo 'HTTP request error: ', $e->getMessage(), "\n";
}