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
59664048
Commit
59664048
authored
3 months ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
1st version of amcli with all checks included
parent
a3ad8cbb
No related branches found
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
+48
-40
48 additions, 40 deletions
src/amcli.php
with
48 additions
and
40 deletions
src/amcli.php
+
48
−
40
View file @
59664048
#!/usr/bin/env php
<?php
/**
* ======================================================================
*
* IML APPMONITOR CLIENT
* AS CLI APP
*
* ---------------------------------------------------------------------
* 2025-03-04 v0.1 Initial version
* ======================================================================
*/
# chdir(__DIR__);
$FLAG_DEBUG
=
0
;
$VERSION
=
"0.
0.
1"
;
$VERSION
=
"0.1"
;
// ---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
"Run the ../installer.php first!
\n
"
;
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
"Check its generation by installer or run the installer again.
\n
"
;
exit
(
2
);
...
...
@@ -62,7 +72,6 @@ function _wd($s): void
{
global
$FLAG_DEBUG
;
if
(
$FLAG_DEBUG
)
{
// echo "DEBUG: $s\n";
fwrite
(
STDERR
,
"DEBUG:
$s
\n
"
);
}
}
...
...
@@ -81,19 +90,25 @@ 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
!!! This tool is in alpha stadium !!!
SYNTAX:
$_self
[OPTIONS] -i <INIFILE>
SYNTAX:
$_self
[OPTIONS] --ini=<INI-FILE>
OPTIONS:
-h, --help Print this help and exit
-i, --ini Set an INI File to parse
-l, --list list available checks and exit
; --ini will be ignored
-m, --modules list available Php modules in this binary
-v, --verbose
V
erbose output
-l, --list list available checks and exit
-m, --modules list available Php modules in this binary
and exit
-v, --verbose
Enable v
erbose output
-V, --version Show version and exit
EXAMPLES:
$_self
-i=my.ini
$_self
--ini=my.ini
Execute checks from INI file 'my.ini'.
$_self
--list
List available checks.
"
;
}
...
...
@@ -112,6 +127,7 @@ if ($argc > 1) {
if
(
isset
(
$ARGS
[
'-v'
])
||
isset
(
$ARGS
[
'--verbose'
]))
{
$FLAG_DEBUG
=
1
;
_wd
(
"Verbose mode enabled. Showing debug infos on STDOUT."
);
}
_wd
(
"CLI ARGS: "
.
print_r
(
$ARGS
??
[],
1
));
...
...
@@ -134,45 +150,45 @@ if (isset($ARGS['-h']) || isset($ARGS['--help'])) {
_wd
(
"Initializing appmonitor class"
);
$oMonitor
=
new
appmonitor
();
$sPreSpace
=
" - "
;
// show builtin checks
if
(
isset
(
$ARGS
[
'-l'
])
||
isset
(
$ARGS
[
'--list'
]))
{
_wd
(
"Showing checks"
);
echo
implode
(
"
\n
"
,
$oMonitor
->
listChecks
());
echo
$sPreSpace
.
implode
(
"
\n
$sPreSpace
"
,
$oMonitor
->
listChecks
());
exit
(
0
);
}
// show builtin modules
if
(
isset
(
$ARGS
[
'-m'
])
||
isset
(
$ARGS
[
'--modules'
]))
{
_wd
(
"Showing php modules"
);
$aMods
=
get_loaded_extensions
();
$aMods
=
get_loaded_extensions
();
sort
(
$aMods
);
echo
implode
(
"
\n
"
,
$aMods
);
echo
$sPreSpace
.
implode
(
"
\n
$sPreSpace
"
,
$aMods
);
exit
(
0
);
}
$inifile
=
$ARGS
[
"--ini"
]
??
(
$ARGS
[
"-i"
]
??
""
);
if
(
!
$inifile
)
{
echo
"ERROR: Set an INI File using -i=<FILE> (or --ini=<FILE>).
\n
"
;
exit
(
1
);
exit
(
3
);
}
_wd
(
"Using ini file '
$inifile
'."
);
if
(
!
file_exists
(
$inifile
))
{
echo
"ERROR: INI File '
$inifile
' does not exist.
\n
"
;
exit
(
1
);
exit
(
4
);
}
$aIni
=
parse_ini_file
(
$inifile
,
true
);
if
(
!
is_array
(
$aIni
))
{
echo
"ERROR: INI File '
$inifile
' could not be parsed.
\n
"
;
exit
(
1
);
exit
(
5
);
}
_wd
(
"Parsed INI data: "
.
print_r
(
$aIni
,
1
));
// ----------------------------------------------------------------------
// set metadata
...
...
@@ -192,12 +208,14 @@ foreach ($aIni['notifications']['slack'] ?? [] as $sValue) {
_set
(
"addSlackWebhook"
,
$sChannel
,
$sWebhook
);
}
// ----------------------------------------------------------------------
// loop over checks
$aChecks
=
$aIni
;
unset
(
$aChecks
[
"meta"
]);
unset
(
$aChecks
[
"notifications"
]);
$aArray
=
[];
$aArray
=
[];
foreach
(
$aChecks
as
$sKey
=>
$aCheck
)
{
$aChecks
[
$sKey
][
'name'
]
=
$aCheck
[
'name'
]
??
$sKey
;
if
(
$aCheck
[
'params'
])
{
...
...
@@ -205,42 +223,26 @@ foreach ($aChecks as $sKey => $aCheck) {
if
(
!
is_array
(
$aArray
))
{
echo
"ERROR: key 'params' for check [
$sKey
] must be JSON.
\n
"
;
echo
"Value in
$inifile
:
$aCheck[params]
\n
"
;
exit
(
1
);
exit
(
6
);
}
}
$aAddCheck
=
[
$aAddCheck
=
[
"name"
=>
$aCheck
[
'name'
]
??
$sKey
,
"description"
=>
$aCheck
[
'description'
],
"description"
=>
$aCheck
[
'description'
]
??
""
,
"check"
=>
[
"function"
=>
$aCheck
[
'function'
],
"params"
=>
$aArray
??
[],
],
];
foreach
([
"group"
,
"parent"
,
"worstresult"
]
as
$sCustomKey
)
{
foreach
([
"group"
,
"parent"
,
"worstresult"
]
as
$sCustomKey
)
{
if
(
isset
(
$aCheck
[
$sCustomKey
]))
{
$aAddCheck
[
$sCustomKey
]
=
$aCheck
[
$sCustomKey
];
}
}
_wd
(
"Execute Check '
$sKey
': "
.
print_r
(
$aAddCheck
,
1
));
$oMonitor
->
addCheck
(
$aAddCheck
);
/*
$oMonitor->addCheck(
[
"name" => "hello plugin",
"description" => "Test a plugin ... plugins/checks/hello.php",
"check" => [
"function" => "Hello",
"params" => [
"message" => "Here I am",
],
],
]
);
*/
}
...
...
@@ -252,3 +254,9 @@ $oMonitor->setResult();
_wd
(
"Send response"
);
$oMonitor
->
render
();
$sOut
=
ob_get_contents
();
ob_end_clean
();
echo
$sOut
;
// ----------------------------------------------------------------------
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