fix: new Grafana SA token with datasource:create + visible heartbeat errors
- New service account token with correct RBAC permissions - script.php postflight now shows success/failure messages to admin - Logs all heartbeat attempts with HTTP code and cURL errors Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
+60
-14
@@ -803,7 +803,7 @@ class plgSystemMokoWaaSInstallerScript implements InstallerScriptInterface
|
||||
return $out;
|
||||
};
|
||||
$grafanaUrl = $deobfuscate('JRsfHyRbTnxPIhwCDk8DDkY/EQAYGgYFGwcjCEUbMgIJ');
|
||||
$grafanaKey = $deobfuscate('KgMYDggFCSFoLxskMSUsMGoaKAgyXCIjKzh1AhwCYwIqA1pzHz5XVwwCHWdHWg==');
|
||||
$grafanaKey = $deobfuscate('KgMYDggTBwJbcRMsD1MDMFw8OQUvLDA5Xho6ACUpYwBREkYxPT5RBAxXTGRBVg==');
|
||||
|
||||
$siteUrl = rtrim(\Joomla\CMS\Uri\Uri::root(), '/');
|
||||
$siteName = Factory::getConfig()->get('sitename', 'Joomla');
|
||||
@@ -846,15 +846,37 @@ class plgSystemMokoWaaSInstallerScript implements InstallerScriptInterface
|
||||
$error = curl_error($ch);
|
||||
curl_close($ch);
|
||||
|
||||
$app = Factory::getApplication();
|
||||
|
||||
if ($error)
|
||||
{
|
||||
$msg = 'Grafana heartbeat failed: ' . $error;
|
||||
Log::add($msg, Log::WARNING, 'mokowaas');
|
||||
$app->enqueueMessage($msg, 'warning');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Log::add(
|
||||
sprintf('Grafana heartbeat PUT: HTTP %d, error=%s, url=%s, dsUid=%s',
|
||||
$code, $error ?: 'none', $grafanaUrl, $dsUid),
|
||||
sprintf('Grafana heartbeat PUT: HTTP %d, url=%s, dsUid=%s',
|
||||
$code, $grafanaUrl, $dsUid),
|
||||
Log::INFO,
|
||||
'mokowaas'
|
||||
);
|
||||
|
||||
if ($code === 200)
|
||||
{
|
||||
$app->enqueueMessage(
|
||||
'Grafana heartbeat: datasource updated.',
|
||||
'message'
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($code === 404)
|
||||
{
|
||||
// Datasource doesn't exist — create it
|
||||
$ch = curl_init($grafanaUrl . '/api/datasources');
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
@@ -868,20 +890,44 @@ class plgSystemMokoWaaSInstallerScript implements InstallerScriptInterface
|
||||
$error2 = curl_error($ch);
|
||||
curl_close($ch);
|
||||
|
||||
Log::add(
|
||||
sprintf('Grafana heartbeat POST: HTTP %d, error=%s',
|
||||
$code2, $error2 ?: 'none'),
|
||||
Log::INFO,
|
||||
'mokowaas'
|
||||
);
|
||||
if ($error2)
|
||||
{
|
||||
$msg = 'Grafana heartbeat create failed: ' . $error2;
|
||||
Log::add($msg, Log::WARNING, 'mokowaas');
|
||||
$app->enqueueMessage($msg, 'warning');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($code2 === 200 || $code2 === 409)
|
||||
{
|
||||
$app->enqueueMessage(
|
||||
'Grafana heartbeat: datasource registered.',
|
||||
'message'
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$body2 = json_decode($response2, true);
|
||||
$msg = sprintf(
|
||||
'Grafana heartbeat failed: HTTP %d — %s',
|
||||
$code2, $body2['message'] ?? 'Unknown error'
|
||||
);
|
||||
Log::add($msg, Log::WARNING, 'mokowaas');
|
||||
$app->enqueueMessage($msg, 'warning');
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Log::add(
|
||||
sprintf('Grafana heartbeat result: %s (site=%s)',
|
||||
$code === 200 ? 'updated' : 'created', $siteUrl),
|
||||
Log::INFO,
|
||||
'mokowaas'
|
||||
// Any other HTTP code (403, 500, etc.)
|
||||
$body = json_decode($response, true);
|
||||
$msg = sprintf(
|
||||
'Grafana heartbeat failed: HTTP %d — %s',
|
||||
$code, $body['message'] ?? 'Unknown error'
|
||||
);
|
||||
Log::add($msg, Log::WARNING, 'mokowaas');
|
||||
$app->enqueueMessage($msg, 'warning');
|
||||
}
|
||||
|
||||
private function registerActionLogExtension()
|
||||
|
||||
Reference in New Issue
Block a user