Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Appmonitor CLI client
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IML Open Source
Appmonitor CLI client
Commits
526e4c8f
Commit
526e4c8f
authored
2 months ago
by
Axel Hahn
Browse files
Options
Downloads
Patches
Plain Diff
set argc and argv from $_SERVER; update help output
parent
5b2583b1
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/amcli.php
+43
-17
43 additions, 17 deletions
src/amcli.php
with
43 additions
and
17 deletions
src/amcli.php
+
43
−
17
View file @
526e4c8f
...
@@ -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 STD
OUT
."
);
_wd
(
"Verbose mode enabled. Showing debug infos on STD
ERR
."
);
}
}
_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
);
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment