Files
gravity/ระบบ SOAR integration ร่วมกับ Wazuh/scratch/wazuh_api_test.php
T
2026-09-16 23:20:08 +07:00

59 lines
1.9 KiB
PHP

<?php
// Let's create a quick test script to check what the Wazuh API returns for agents and syscollector
require_once __DIR__ . '/../vendor/autoload.php';
use Dotenv\Dotenv;
if (file_exists(__DIR__ . '/../.env')) {
$dotenv = Dotenv::createImmutable(__DIR__ . '/..');
$dotenv->load();
}
$apiUrl = $_ENV['WAZUH_API_URL'] ?? 'https://127.0.0.1:55000';
$apiUser = $_ENV['WAZUH_API_USER'] ?? 'wazuh-wui';
$apiPass = $_ENV['WAZUH_API_PASSWORD'] ?? 'wazuh-wui';
// 1. Get Token
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiUrl . '/security/user/authenticate');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, "$apiUser:$apiPass");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode !== 200) {
die("Auth failed: $response");
}
$token = json_decode($response, true)['data']['token'] ?? null;
if (!$token) die("No token");
echo "Token: OK\n";
// 2. Get Agents
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiUrl . '/agents?limit=2');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ["Authorization: Bearer $token"]);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$response = curl_exec($ch);
curl_close($ch);
echo "Agents:\n" . substr($response, 0, 500) . "...\n";
// 3. Get Hardware
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiUrl . '/syscollector/hardware'); // Does this work globally?
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ["Authorization: Bearer $token"]);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$response = curl_exec($ch);
curl_close($ch);
echo "Hardware:\n" . substr($response, 0, 500) . "...\n";