Skip to content
Snippets Groups Projects
Commit 526e4c8f authored by Axel Hahn's avatar Axel Hahn
Browse files

set argc and argv from $_SERVER; update help output

parent 5b2583b1
Branches
No related tags found
No related merge requests found
...@@ -9,22 +9,26 @@ ...@@ -9,22 +9,26 @@
* --------------------------------------------------------------------- * ---------------------------------------------------------------------
* 2025-03-04 v0.1 Initial version * 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-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; $FLAG_DEBUG = 0;
$VERSION = "0.1"; $VERSION = "0.3";
// ---MARK---INCLUDE-CHECKS---START--- // ---MARK---INCLUDE-CHECKS---START---
if (!file_exists(__DIR__ . "/include_checks.php")) { 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"; echo "Run the ../installer.php first!\n";
exit(1); exit(1);
} }
if (!include __DIR__ . "/include_checks.php") { 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"; echo "Check its generation by installer or run the installer again.\n";
exit(2); exit(2);
} }
...@@ -84,24 +88,45 @@ function _wd($s): void ...@@ -84,24 +88,45 @@ function _wd($s): void
function _showHelp(): void function _showHelp(): void
{ {
global $VERSION; global $VERSION;
$_self = basename(__FILE__); $_self = str_replace('.php', '', basename(__FILE__));
echo "IML Appmonitor as CLI client $VERSION echo "
IML Appmonitor as CLI client $VERSION
This client performs appmonitor checks and puts the results as JSON to stdout. This client performs appmonitor checks and puts the results as JSON to stdout.
You can use the compiled binary on non PHP systems. It contains all checks that are available in the PHP appmonitor client.
(c) 2025 Institute for Medical education * University of Bern 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 -h, --help Print this help and exit
-i, --ini Set an INI File to parse -i, --ini Set an INI File to parse
-l, --list list available checks and exit -l, --list list available checks and exit
-m, --modules list available Php modules in this binary 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 -V, --version Show version and exit
EXAMPLES:
👉 EXAMPLES:
$_self -i=my.ini $_self -i=my.ini
$_self --ini=my.ini $_self --ini=my.ini
...@@ -128,7 +153,7 @@ if ($argc > 1) { ...@@ -128,7 +153,7 @@ if ($argc > 1) {
if (isset($ARGS['-v']) || isset($ARGS['--verbose'])) { if (isset($ARGS['-v']) || isset($ARGS['--verbose'])) {
$FLAG_DEBUG = 1; $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)); _wd("CLI ARGS: " . print_r($ARGS ?? [], 1));
...@@ -171,25 +196,25 @@ if (isset($ARGS['-m']) || isset($ARGS['--modules'])) { ...@@ -171,25 +196,25 @@ if (isset($ARGS['-m']) || isset($ARGS['--modules'])) {
$inifile = $ARGS["--ini"] ?? ($ARGS["-i"] ?? ""); $inifile = $ARGS["--ini"] ?? ($ARGS["-i"] ?? "");
if (!$inifile) { 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); exit(3);
} }
_wd("Using ini file '$inifile'."); _wd("Using ini file '$inifile'.");
if (!file_exists($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); exit(4);
} }
try{ try{
$aIni = parse_ini_file($inifile, true); $aIni = parse_ini_file($inifile, true);
} catch (Exception $e) { } 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); exit(5);
} }
if (!is_array($aIni)) { 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); exit(5);
} }
...@@ -223,8 +248,9 @@ foreach ($aChecks as $sKey => $aCheck) { ...@@ -223,8 +248,9 @@ foreach ($aChecks as $sKey => $aCheck) {
if(!is_array($aCheck['params'])){ if(!is_array($aCheck['params'])){
$aArray = json_decode($aCheck['params'], 1); $aArray = json_decode($aCheck['params'], 1);
if (!is_array($aArray)) { 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 "Value in $inifile: $aCheck[params]\n";
echo "OR: Try to use multiple lines 'params[<KEY>]=<VALUE>' instead.\n";
exit(6); exit(6);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment