96 lines
2.6 KiB
PHP
96 lines
2.6 KiB
PHP
<?php
|
|
// Test script to debug create_ticket_api.php
|
|
echo "=== Testing create_ticket_api.php ===\n\n";
|
|
|
|
// Load the API key from hwmonDaemon .env
|
|
$hwmonEnv = '/etc/hwmonDaemon/.env';
|
|
$apiKey = null;
|
|
|
|
if (file_exists($hwmonEnv)) {
|
|
$lines = file($hwmonEnv, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
|
foreach ($lines as $line) {
|
|
if (strpos($line, 'TICKET_API_KEY=') === 0) {
|
|
$apiKey = trim(substr($line, 15));
|
|
// Remove quotes if present
|
|
if ((substr($apiKey, 0, 1) === '"' && substr($apiKey, -1) === '"') ||
|
|
(substr($apiKey, 0, 1) === "'" && substr($apiKey, -1) === "'")) {
|
|
$apiKey = substr($apiKey, 1, -1);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!$apiKey) {
|
|
echo "ERROR: Could not load API key from $hwmonEnv\n";
|
|
exit(1);
|
|
}
|
|
|
|
echo "API Key loaded: " . substr($apiKey, 0, 10) . "...\n\n";
|
|
|
|
// Test data
|
|
$testTicket = [
|
|
'title' => 'Test Ticket from PHP Script',
|
|
'description' => 'This is a test ticket to debug the API',
|
|
'priority' => '3',
|
|
'category' => 'Test',
|
|
'type' => 'Issue',
|
|
'status' => 'Open'
|
|
];
|
|
|
|
echo "Sending test ticket...\n";
|
|
echo "URL: http://10.10.10.45/create_ticket_api.php\n\n";
|
|
|
|
// Make the API call
|
|
$ch = curl_init('http://10.10.10.45/create_ticket_api.php');
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
|
'Content-Type: application/json',
|
|
'Authorization: Bearer ' . $apiKey
|
|
]);
|
|
curl_setopt($ch, CURLOPT_POST, 1);
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($testTicket));
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
curl_setopt($ch, CURLOPT_VERBOSE, true);
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
|
|
|
|
// Capture verbose output
|
|
$verbose = fopen('php://temp', 'w+');
|
|
curl_setopt($ch, CURLOPT_STDERR, $verbose);
|
|
|
|
$response = curl_exec($ch);
|
|
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
$curlError = curl_error($ch);
|
|
|
|
// Get verbose output
|
|
rewind($verbose);
|
|
$verboseLog = stream_get_contents($verbose);
|
|
fclose($verbose);
|
|
|
|
curl_close($ch);
|
|
|
|
echo "HTTP Code: $httpCode\n";
|
|
echo "cURL Error: " . ($curlError ?: 'None') . "\n\n";
|
|
|
|
echo "=== Raw Response ===\n";
|
|
echo "Length: " . strlen($response) . " bytes\n";
|
|
echo "Content:\n";
|
|
var_dump($response);
|
|
echo "\n";
|
|
|
|
if ($response) {
|
|
echo "=== Decoded JSON ===\n";
|
|
$decoded = json_decode($response, true);
|
|
if ($decoded === null) {
|
|
echo "ERROR: Failed to decode JSON\n";
|
|
echo "JSON Error: " . json_last_error_msg() . "\n";
|
|
} else {
|
|
print_r($decoded);
|
|
}
|
|
} else {
|
|
echo "ERROR: Empty response received\n";
|
|
}
|
|
|
|
echo "\n=== cURL Verbose Log ===\n";
|
|
echo $verboseLog;
|
|
echo "\n";
|