81 lines
3.5 KiB
PHP
81 lines
3.5 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Services\CortexXdrService;
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\Config;
|
|
|
|
class TestCortexConnection extends Command
|
|
{
|
|
protected $signature = 'cortex:test';
|
|
protected $description = 'Test connectivity to Cortex XDR API and display results.';
|
|
|
|
public function handle(CortexXdrService $cortexService)
|
|
{
|
|
$this->info("--- Cortex XDR Connectivity Test ---");
|
|
|
|
// 1. Config Check
|
|
$key = Config::get('services.cortex.key');
|
|
$id = Config::get('services.cortex.id');
|
|
$url = Config::get('services.cortex.url');
|
|
|
|
$this->line("\n1. Checking Environment Variables:");
|
|
$this->line(" - API Key: " . ($key ? 'OK (' . substr($key, 0, 5) . '...)' : 'MISSING'));
|
|
$this->line(" - API Key ID: " . ($id ? 'OK (' . $id . ')' : 'MISSING'));
|
|
$this->line(" - Base URL: " . ($url ? 'OK (' . $url . ')' : 'MISSING'));
|
|
|
|
if (!$key || !$id || !$url) {
|
|
$this->error("\n[ERROR] Configuration is incomplete.");
|
|
$this->line("You need to add the following variables to your .env file:");
|
|
if (!$key) $this->line(" - CORTEX_XDR_API_KEY=your_api_key");
|
|
if (!$id) $this->line(" - CORTEX_XDR_API_KEY_ID=your_key_id (Integer ID)");
|
|
if (!$url) $this->line(" - CORTEX_XDR_BASE_URL=https://api-fqdn.xdr.cortex.paloaltonetworks.com");
|
|
|
|
$this->warn("\nIMPORTANT: After editing .env, you may need to restart 'php artisan serve' for the web app to see changes.");
|
|
return 1;
|
|
}
|
|
|
|
// 2. Test Incidents
|
|
$this->info("\n2. Testing API Connection (Incidents)...");
|
|
try {
|
|
$incidents = $cortexService->getIncidents();
|
|
if (empty($incidents)) {
|
|
$this->warn("No incidents returned. (This might be normal if no incidents exist, or check API permissions).");
|
|
} else {
|
|
$this->info("SUCCESS: Fetched " . count($incidents) . " incidents.");
|
|
if (count($incidents) > 0) {
|
|
$this->line("DEBUG: First Incident ID: " . ($incidents[0]['incident_id'] ?? 'N/A'));
|
|
$this->line("DEBUG: Incident keys: " . print_r(array_keys($incidents[0]), true));
|
|
$this->line("DEBUG: Incident values: " . print_r(array_values($incidents[0]), true));
|
|
}
|
|
$this->line("Latest Incident ID: " . ($incidents[0]['incident_id'] ?? 'N/A'));
|
|
|
|
}
|
|
} catch (\Exception $e) {
|
|
$this->error("EXCEPTION: " . $e->getMessage());
|
|
}
|
|
|
|
// 3. Test Endpoints
|
|
$this->info("\n3. Testing API Connection (Endpoints)...");
|
|
try {
|
|
$endpoints = $cortexService->getEndpoints();
|
|
if (empty($endpoints)) {
|
|
$this->warn("No endpoints returned.");
|
|
} else {
|
|
$this->info("SUCCESS: Fetched " . count($endpoints) . " endpoints.");
|
|
if (count($endpoints) > 0) {
|
|
$ep = $endpoints[0];
|
|
$this->line("DEBUG: First Endpoint Status key: 'endpoint_status' => " . ($ep['endpoint_status'] ?? 'N/A'));
|
|
$this->line("DEBUG: Keys available: " . print_r(array_keys($ep), true));
|
|
$this->line("DEBUG: First Endpoint Status key: 'endpoint_status' => " . ($ep['endpoint_status'] ?? 'N/A'));
|
|
}
|
|
}
|
|
} catch (\Exception $e) {
|
|
$this->error("EXCEPTION: " . $e->getMessage());
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
}
|