health->v1->healthService->check(new CheckRequest()); echo ' Status: ' . ServingStatus::name($health->getStatus()) . "\n\n"; if (!getenv('OPENSTATUS_API_KEY')) { echo "2. Skipping monitor operations (OPENSTATUS_API_KEY not set)\n"; echo " Set OPENSTATUS_API_KEY to test monitor operations.\n"; exit(0); } echo "2. Listing monitors...\n"; $listResponse = $client->monitor->v1->monitorService->listMonitors(new ListMonitorsRequest()); $httpMonitors = iterator_to_array($listResponse->getHttpMonitors()); $tcpMonitors = iterator_to_array($listResponse->getTcpMonitors()); $dnsMonitors = iterator_to_array($listResponse->getDnsMonitors()); printf(" Found %d monitors:\n", $listResponse->getTotalSize()); printf(" - HTTP: %d\n", count($httpMonitors)); printf(" - TCP: %d\n", count($tcpMonitors)); printf(" - DNS: %d\n", count($dnsMonitors)); if (count($httpMonitors) > 0) { echo "\n3. HTTP Monitors:\n"; foreach ($httpMonitors as $monitor) { printf( " - %s: %s (%s)\n", $monitor->getName(), $monitor->getUrl(), $monitor->getActive() ? 'active' : 'paused', ); } $firstHttp = $httpMonitors[0]; $monitorId = $firstHttp->getId(); echo "\n4. Listing HTTP response logs for monitor {$monitorId}...\n"; $logsResponse = $client->monitor->v1->monitorService->listMonitorHTTPResponseLogs( new ListMonitorHTTPResponseLogsRequest(['id' => $monitorId, 'limit' => 10]), ); $logs = iterator_to_array($logsResponse->getLogs()); $pagination = $logsResponse->getPagination(); printf(" Found %d logs (hasMore=%s)\n", count($logs), $pagination?->getHasMore() ? 'true' : 'false'); foreach ($logs as $log) { $ts = gmdate('c', (int) ((int) $log->getTimestamp() / 1000)); $status = $log->hasStatusCode() ? (string) $log->getStatusCode() : '—'; printf( " %s %s %dms %s id=%s\n", $ts, $status, $log->getLatency(), Region::name($log->getRegion()), $log->hasId() ? $log->getId() : '—', ); } if (count($logs) > 0) { $firstLog = $logs[0]; if ($firstLog->hasId()) { $logId = $firstLog->getId(); echo "\n5. Getting log detail for {$logId}...\n"; $detailResponse = $client->monitor->v1->monitorService->getMonitorHTTPResponseLog( new GetMonitorHTTPResponseLogRequest(['id' => $monitorId, 'log_id' => $logId]), ); $detail = $detailResponse->getLog(); if ($detail !== null) { printf(" URL: %s\n", $detail->getUrl()); printf(" Errored: %s\n", $detail->getError() ? 'true' : 'false'); printf(" Message: %s\n", $detail->hasMessage() ? $detail->getMessage() : '—'); $inner = $detail->getLog(); printf( " Status: %s\n", $inner !== null && $inner->hasStatusCode() ? (string) $inner->getStatusCode() : '—', ); printf(" Assertions: %s\n", $detail->hasAssertions() ? $detail->getAssertions() : '—'); } } } }