From db2ed26e65db6e2b644635fd1a094fad4ba240e5 Mon Sep 17 00:00:00 2001 From: Jonathan Miller Date: Sat, 6 Jun 2026 11:01:33 -0500 Subject: [PATCH] feat: heartbeat sends full health payload and client info Monitor plugin now includes live health data (16 checks) and client info (company name, email from Joomla config) in the heartbeat payload. Health data is fetched via local HTTP call to /?mokowaas=health to reuse existing auth and check logic without internal coupling. MokoWaaSBase can use client_info for auto-contact creation and the health payload for dashboard visualization without separate polling. Authored-by: Moko Consulting Co-Authored-By: Claude Opus 4.6 (1M context) --- .../src/Extension/Monitor.php | 62 +++++++++++++++++-- 1 file changed, 56 insertions(+), 6 deletions(-) diff --git a/source/packages/plg_system_mokowaas_monitor/src/Extension/Monitor.php b/source/packages/plg_system_mokowaas_monitor/src/Extension/Monitor.php index 750da3a7..addcb36a 100644 --- a/source/packages/plg_system_mokowaas_monitor/src/Extension/Monitor.php +++ b/source/packages/plg_system_mokowaas_monitor/src/Extension/Monitor.php @@ -109,16 +109,30 @@ class Monitor extends CMSPlugin implements SubscriberInterface $app = $this->getApplication(); + $config = Factory::getConfig(); + $payload = [ - 'token' => $healthToken, - 'domain' => $domain, - 'site_name' => Factory::getConfig()->get('sitename', 'Joomla'), - 'site_url' => $siteUrl, - 'joomla_version' => (new Version())->getShortVersion(), - 'php_version' => PHP_VERSION, + 'token' => $healthToken, + 'domain' => $domain, + 'site_name' => $config->get('sitename', 'Joomla'), + 'site_url' => $siteUrl, + 'joomla_version' => (new Version())->getShortVersion(), + 'php_version' => PHP_VERSION, 'mokowaas_version' => $this->getMokoWaaSVersion(), + 'client_info' => [ + 'company' => $config->get('sitename', ''), + 'email' => $config->get('mailfrom', ''), + ], ]; + // Include live health data by calling the local health endpoint + $healthData = $this->fetchLocalHealth($siteUrl, $healthToken); + + if ($healthData !== null) + { + $payload['health'] = $healthData; + } + $endpoint = $baseUrl . '/api/index.php/v1/mokowaasbase/heartbeat'; $json = json_encode($payload, JSON_UNESCAPED_SLASHES); @@ -165,6 +179,42 @@ class Monitor extends CMSPlugin implements SubscriberInterface } } + /** + * Fetch health data from the local site's health endpoint. + * + * @param string $siteUrl Local site URL. + * @param string $healthToken Health API token. + * + * @return array|null Parsed health data or null on failure. + */ + private function fetchLocalHealth(string $siteUrl, string $healthToken): ?array + { + $url = $siteUrl . '/?mokowaas=health'; + + $ch = curl_init($url); + curl_setopt_array($ch, [ + CURLOPT_RETURNTRANSFER => true, + CURLOPT_TIMEOUT => 10, + CURLOPT_FOLLOWLOCATION => true, + CURLOPT_SSL_VERIFYPEER => false, + CURLOPT_HTTPHEADER => [ + 'Authorization: Bearer ' . $healthToken, + 'Accept: application/json', + ], + ]); + + $response = curl_exec($ch); + $code = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE); + curl_close($ch); + + if ($code !== 200 || empty($response)) + { + return null; + } + + return json_decode($response, true) ?: null; + } + /** * Get the installed MokoWaaS package version. */