From 813a9594fb947ec0079390ae536cf94ddca5c967 Mon Sep 17 00:00:00 2001 From: Yasen Pramatarov Date: Sun, 1 Sep 2024 16:40:47 +0300 Subject: [PATCH] Fixes status checks --- functions.php | 27 +++++++++++++++------------ index.php | 21 +++++++++++++++++++-- 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/functions.php b/functions.php index 1d12a48..b26bdff 100644 --- a/functions.php +++ b/functions.php @@ -10,22 +10,25 @@ function getNginxConnections() { return intval(trim($connections)); } + +// get prosody data +function getProsodyStatus() { + $status = trim(shell_exec('systemctl is-active prosody')); + return ($status === 'active') ? 'running' : 'not running'; +} + + +// get jicofo data +function getJicofoStatus() { + $status = trim(shell_exec('systemctl is-active jicofo')); + return ($status === 'active') ? 'running' : 'not running'; +} + + // get JVB data function getJVBStatus() { $status = trim(shell_exec('systemctl is-active jitsi-videobridge')); return ($status === 'active') ? 'running' : 'not running'; } - - - -function getProsodyStatus() { - $status = trim(shell_exec('systemctl is-active prosody')); - return ($status === 'active') ? 'running' : 'not running'; -} -function getJicofoStatus() { - $status = trim(shell_exec('systemctl is-active jicofo')); - return ($status === 'active') ? 'running' : 'not running'; -} - ?> diff --git a/index.php b/index.php index f10e6c9..b7ec3d8 100644 --- a/index.php +++ b/index.php @@ -2,19 +2,36 @@ include 'functions.php'; +$scriptname = basename($_SERVER['SCRIPT_NAME']); +$request = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); + // the response is in JSON header('Content-Type: application/json'); // nginx status -if ($_SERVER['REQUEST_URI'] === '/nginx') { +if ($request === '/nginx' || $request === "/$scriptname/nginx") { $data = [ 'nginx_status' => getNginxStatus(), 'nginx_connections' => getNginxConnections(), ]; echo json_encode($data, JSON_PRETTY_PRINT) . "\n"; +// prosody status +} elseif ($request === '/prosody' || $request === "/$scriptname/prosody") { + $data = [ + 'prosody_status' => getProsodyStatus(), + ]; + echo json_encode($data, JSON_PRETTY_PRINT) . "\n"; + +// jicofo status +} elseif ($request === '/jicofo' || $request === "/$scriptname/jicofo") { + $data = [ + 'jicofo_status' => getJicofoStatus(), + ]; + echo json_encode($data, JSON_PRETTY_PRINT) . "\n"; + // jvb status -} elseif ($_SERVER['REQUEST_URI'] === '/jvb') { +} elseif ($request === '/jvb' || $request === "/$scriptname/jvb") { $data = [ 'jvb_status' => getJVBStatus(), ];