diff --git a/src/amcli.php b/src/amcli.php index db4bba27305f8b7054e98890861e76d964382a2d..769a9037a6363bf56f99dba4a9987f120887c0c2 100755 --- a/src/amcli.php +++ b/src/amcli.php @@ -9,22 +9,26 @@ * --------------------------------------------------------------------- * 2025-03-04 v0.1 Initial version * 2025-03-05 v0.2 slack notification as hash from ini; check params can be an hash value or JSON + * 2025-03-07 v0.3 set argc and argv from $_SERVER; update help output * ====================================================================== */ +// needed when starting compiled binary built from a PHAR file +$argc = $_SERVER['argc']; +$argv = $_SERVER['argv']; $FLAG_DEBUG = 0; -$VERSION = "0.1"; +$VERSION = "0.3"; // ---MARK---INCLUDE-CHECKS---START--- if (!file_exists(__DIR__ . "/include_checks.php")) { - echo "ERROR: File 'include_checks.php' does not exist yet..\n"; + echo "❌ ERROR: File 'include_checks.php' does not exist yet..\n"; echo "Run the ../installer.php first!\n"; exit(1); } if (!include __DIR__ . "/include_checks.php") { - echo "ERROR: Include of generated 'include_checks.php' failed.\n"; + echo "❌ ERROR: Include of generated 'include_checks.php' failed.\n"; echo "Check its generation by installer or run the installer again.\n"; exit(2); } @@ -84,24 +88,45 @@ function _wd($s): void function _showHelp(): void { global $VERSION; - $_self = basename(__FILE__); - echo "IML Appmonitor as CLI client $VERSION + $_self = str_replace('.php', '', basename(__FILE__)); + echo " +IML Appmonitor as CLI client $VERSION This client performs appmonitor checks and puts the results as JSON to stdout. -You can use the compiled binary on non PHP systems. -(c) 2025 Institute for Medical education * University of Bern +It contains all checks that are available in the PHP appmonitor client. +You can use the compiled binary to monitor any non PHP webapp without +implementing the checks for your programming language. -SYNTAX: $_self [OPTIONS] --ini=<INI-FILE> +You need to reference an INI file that contains the metadata and all checks. +Have a look to the online documentation for details. +You find example snippets in the source code of this project in tests/config/. + + 👤 Author: Axel Hahn + 📄 Source: https://git-repo.iml.unibe.ch/iml-open-source/appmonitor-cli-client + 📜 License: GNU GPL 3.0 + 📗 Docs: https://os-docs.iml.unibe.ch/appmonitor-cli-client/ + + (c) 2025 Institute for Medical Education * University of Bern + +............................................................................... + + +✨ SYNTAX: + + $_self [OPTIONS] --ini=<INI-FILE> + + +🔷 OPTIONS: -OPTIONS: -h, --help Print this help and exit -i, --ini Set an INI File to parse -l, --list list available checks and exit -m, --modules list available Php modules in this binary and exit - -v, --verbose Enable verbose output + -v, --verbose Enable verbose output (written to STDERR) -V, --version Show version and exit -EXAMPLES: + +👉 EXAMPLES: $_self -i=my.ini $_self --ini=my.ini @@ -128,7 +153,7 @@ if ($argc > 1) { if (isset($ARGS['-v']) || isset($ARGS['--verbose'])) { $FLAG_DEBUG = 1; - _wd("Verbose mode enabled. Showing debug infos on STDOUT."); + _wd("Verbose mode enabled. Showing debug infos on STDERR."); } _wd("CLI ARGS: " . print_r($ARGS ?? [], 1)); @@ -171,25 +196,25 @@ if (isset($ARGS['-m']) || isset($ARGS['--modules'])) { $inifile = $ARGS["--ini"] ?? ($ARGS["-i"] ?? ""); if (!$inifile) { - echo "ERROR: Set an INI File using -i=<FILE> (or --ini=<FILE>).\n"; + echo "❌ ERROR: Missing INI File. Use -h (or --help) for more infos.\n"; exit(3); } _wd("Using ini file '$inifile'."); if (!file_exists($inifile)) { - echo "ERROR: INI File '$inifile' does not exist.\n"; + echo "❌ ERROR: INI File '$inifile' does not exist.\n"; exit(4); } try{ $aIni = parse_ini_file($inifile, true); } catch (Exception $e) { - echo "ERROR: INI File '$inifile' could not be parsed.\n"; + echo "❌ ERROR: INI File '$inifile' could not be parsed.\n"; exit(5); } if (!is_array($aIni)) { - echo "ERROR: INI File '$inifile' could not be parsed as array.\n"; + echo "❌ ERROR: INI File '$inifile' could not be parsed as array.\n"; exit(5); } @@ -223,8 +248,9 @@ foreach ($aChecks as $sKey => $aCheck) { if(!is_array($aCheck['params'])){ $aArray = json_decode($aCheck['params'], 1); if (!is_array($aArray)) { - echo "ERROR: key 'params' for check [$sKey] must be JSON.\n"; + echo "❌ ERROR: key 'params' for check [$sKey] must be valid JSON.\n"; echo "Value in $inifile: $aCheck[params]\n"; + echo "OR: Try to use multiple lines 'params[<KEY>]=<VALUE>' instead.\n"; exit(6); } }