Skip to content
Snippets Groups Projects
Commit d82d6c89 authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

update first simple example

parent 60ab4324
No related branches found
No related tags found
No related merge requests found
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
<?php <?php
chdir(__DIR__); chdir(__DIR__);
$FLAG_DEBUG=0;
$VERSION="0.0.1";
// ---MARK---INCLUDE-CHECKS---START--- // ---MARK---INCLUDE-CHECKS---START---
if(! file_exists("include_checks.php")){ if(! file_exists("include_checks.php")){
...@@ -19,11 +20,112 @@ if(!include "include_checks.php"){ ...@@ -19,11 +20,112 @@ if(!include "include_checks.php"){
// ---MARK---INCLUDE-CHECKS---END // ---MARK---INCLUDE-CHECKS---END
if($argc>1) // --------------------------------------------------------------------
parse_str(implode('&',array_slice($argv, 1)), $_GET); //
// FUNCTIONS
//
// --------------------------------------------------------------------
function _wd($s):void
{
global $FLAG_DEBUG;
if($FLAG_DEBUG){
// echo "DEBUG: $s\n";
fwrite(STDERR, "DEBUG: $s\n");
}
}
function _showHelp(): void
{
global $VERSION;
$_self=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
!!! This tool is in alpha stadium !!!
SYNTAX: $_self [OPTIONS]
OPTIONS:
-v, --verbose Verbose output
-h, --help Print this help
-i, --ini INI File
";
}
// --------------------------------------------------------------------
//
// MAIN
//
// --------------------------------------------------------------------
// put params to $ARGS
if($argc>1){
parse_str(implode('&',array_slice($argv, 1)), $ARGS);
}
// check params
if (isset($ARGS['-v']) || isset($ARGS['--verbose'])) {
$FLAG_DEBUG=1;
}
_wd("CLI ARGS: ".print_r($ARGS, 1));
if (isset($ARGS['-h']) || isset($ARGS['--help'])) {
_wd("Showing help");
_showHelp();
exit(0);
}
$inifile=$ARGS["--ini"]??($ARGS["-i"]??"simple.ini");
_wd("Using ini file '$inifile'.");
if(!file_exists($inifile)){
echo "ERROR: INI File '$inifile' does not exist.\n";
exit(1);
}
$aIni=parse_ini_file($inifile);
if(!is_array($aIni)){
echo "ERROR: INI File '$inifile' could not be parsed.\n";
exit(1);
}
_wd("Parsed INI data: ".print_r($aIni, 1));
// ----------------------------------------------------------------------
_wd("Initializing appmonitor class");
$oMonitor = new appmonitor();
$oMonitor->addEmail('sysadmin@example.com');
$oMonitor->addSlackWebhook("mywebhook", "https://hooks.slack.com/services/(...)");
$oMonitor->addCheck(
[
"name" => "hello plugin",
"description" => "Test a plugin ... plugins/checks/hello.php",
"check" => [
"function" => "Hello",
"params" => [
"message" => "Here I am",
],
],
]
);
// ----------------------------------------------------------------------
// send the response
echo "PARAMS: "; _wd("Setting result");
print_r($_GET); $oMonitor->setResult();
_wd("Send response");
$oMonitor->render();
[meta]
host = "www.example.com"
website = "Company website"
ttl = 300
tags[]="monitoring"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment