diff --git a/docs/30_Usage.md b/docs/30_Usage.md index c16e5c0ffe7273233d336bd865f490af2b866806..fc6ae8da08ecd552a2a1dbe08dcfd87972855412 100644 --- a/docs/30_Usage.md +++ b/docs/30_Usage.md @@ -85,6 +85,7 @@ The binary could stop and exit with non zero exitcode. | 4 | Given Ini file does not exist | 5 | Given Ini file cannot be parsed | 6 | Ini value `params=` is no JSON +| 7 | The key 'function' is not set in the given check. It defines the check function to call. ### appmonitor-client class diff --git a/src/amcli.php b/src/amcli.php index 73f3e354ff4684f9c2b78decf9006ee243a6e278..f796f6d9ac8bd782c7d00455f4f84174d3cc933e 100755 --- a/src/amcli.php +++ b/src/amcli.php @@ -18,6 +18,8 @@ * 2025-03-09 v0.4 more colors in output of debug and help * 2025-03-14 v0.5 add build infos * 2025-03-14 v0.6 add meta tags, check count+visual; add _json2array() + * 2025-03-17 v0.7 update help + * 2025-03-17 v0.8 check missing 'function' in check. get php client version * ====================================================================== */ @@ -26,7 +28,8 @@ $argc = $_SERVER['argc']; $argv = $_SERVER['argv']; $FLAG_DEBUG = 0; -$VERSION = "0.7"; +$VERSION = "0.8"; +$PHPCLIENTVERSION = "not-detected"; $AMCLI_BUILD_DATE = "never"; @@ -100,18 +103,18 @@ function _wd($s): void */ function _showHelp(): void { - global $VERSION; + global $VERSION, $PHPCLIENTVERSION; $_self = str_replace('.php', '', basename(__FILE__)); echo " _____ _____ __ _____ _ _ | | | | ___ ___ ___| |___ ___|_| |_ ___ ___ |- -| | | | |__ | .'| . | . | | | | . | | | _| . | _| |_____|_|_|_|_____| |__,| _| _|_|_|_|___|_|_|_|_| |___|_| - |_| |_| - \e[1mCLI client v$VERSION\e[0m + |_| |_| \e[1mCLI client v$VERSION\e[0m + This client performs appmonitor checks and puts the results as JSON to stdout. -It contains all checks that are available in the PHP appmonitor client. +It contains all checks that are available in the PHP appmonitor client v$PHPCLIENTVERSION. You can use the compiled binary to monitor any non PHP webapp without implementing the checks for your programming language. @@ -201,6 +204,7 @@ _wd("CLI ARGS: " . print_r($ARGS ?? [], 1)); _wd("Initializing appmonitor class"); $oMonitor = new appmonitor(); +$PHPCLIENTVERSION = $oMonitor->getVersion(); $sPreSpace = " - "; // show version @@ -219,7 +223,7 @@ if (isset($ARGS['-b']) || isset($ARGS['--buildinfos'])) { echo "amcli v$VERSION (".PHP_OS.")\n\n"; echo "Build date: $AMCLI_BUILD_DATE\n"; echo "\n"; - echo "Compiled with PHP ".PHP_VERSION."\n"; + echo "Compiled PHP client v$PHPCLIENTVERSION with PHP ".PHP_VERSION."\n"; echo "Including these modules:\n"; $sModules=" "; $i=0; @@ -298,6 +302,7 @@ $aIni['notifications']['slack']=_json2array($aIni['notifications']['slack'] ?? n _set("setHost", $aIni['meta']['host'] ?? null); _set("setWebsite", $aIni['meta']['website'] ?? null); _set("setTtl", $aIni['meta']['ttl'] ?? null); +_set("setVersion", "amcli-$VERSION-using"); foreach ($aIni['meta']['tags'] ?? [] as $sValue) { _set("addTag", $sValue); @@ -322,16 +327,20 @@ foreach ($aChecks as $sKey => $aCheck) { $aParams = _json2array($aCheck['params'] ?? []); if (!is_array($aParams)) { echo "⌠ERROR: key 'params' for check [$sKey] must be \n- a hash or\n- valid JSON\n- not set\n"; - echo "Value in $inifile: $aCheck[params]\n"; + echo "Value in $inifile: $aCheck[params]??[]\n"; echo "Try to use multiple lines 'params[<KEY>]=<VALUE>'.\n"; exit(6); } + if(!isset($aCheck['function'])){ + echo "⌠ERROR: Missing key 'function' in check [$sKey].\n"; + exit(7); + } $aAddCheck = [ "name" => $aCheck['name'] ?? $sKey, "description" => $aCheck['description'] ?? "", "check" => [ - "function" => $aCheck['function'], + "function" => $aCheck['function'] ?? "not set", "params" => $aParams, ], ];