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

add first tests

parent e9890596
No related branches found
No related tags found
No related merge requests found
#!/bin/env php
<?php
require_once __DIR__.'/../inc_functions.php';
require_once __DIR__.'/../inc_vars.php';
$AMCLI??=__DIR__.'/../src/amcli.php';
echo "\n\nSTART TESTS\n\n";
foreach(glob("*.php") as $sFile){
if($sFile==basename(__FILE__)){
// SKIP
} else {
_h1("$sFile");
include $sFile;
}
}
_h1("DONE");
#!/usr/bin/env php
<?php
echo "
WHAT: Check if $AMCLI is executable
";
_exec("$AMCLI -V");
#!/usr/bin/env php
<?php
echo "
WHAT: Check if $AMCLI is executable in another place, eg.tmp
";
if(strstr($AMCLI, ".php")){
echo "SKIP: not for php script - it is for the binary only.\n";
return true;
}
$tmpfile="/tmp/".basename($AMCLI);
file_put_contents($tmpfile, file_get_contents($AMCLI));
chmod($tmpfile, 0700);
_exec("$tmpfile -V");
unlink($tmpfile);
#!/usr/bin/env php
<?php
echo "
WHAT: Check if $AMCLI shows a help page
";
_exec("$AMCLI -h");
#!/usr/bin/env php
<?php
echo "
WHAT: Set application metadata
";
$sInifile=__DIR__."/configs/metadata.ini";
// --------------------------------------------------------------------
// FUNCTION
// --------------------------------------------------------------------
function compare_strings($sKey, $sIniValue, $aResponseValue=null){
echo "Values for '$sKey':\n INI : $sIniValue\n Response: $aResponseValue\n ";
if ($sIniValue!=$aResponseValue){
_abort("Values differ");
}
_ok(); echo "\n";
}
// --------------------------------------------------------------------
// MAIN
// --------------------------------------------------------------------
// basic check ... the ini file is processed?
_exec("$AMCLI --ini='$sInifile'");
// --------------------------------------------------------------------
// yes. Now let's compare ini values and the response
exec("$AMCLI --ini='$sInifile'", $aOut, $rc);
$aIni=parse_ini_file($sInifile, 1);
$aResponse=json_decode($aOut[0], 1);
// print_r($aIni);
// print_r($aResponse);
// --------------------------------------------------------------------
echo "\n";
compare_strings("host", $aIni["meta"]["host"], $aResponse["meta"]["host"]);
compare_strings("website", $aIni["meta"]["website"], $aResponse["meta"]["website"]);
compare_strings("ttl", $aIni["meta"]["ttl"], $aResponse["meta"]["ttl"]);
foreach($aIni["notifications"]["email"]??[] as $sEmail){
echo "Check Email '$sEmail'\n";
if(array_search($sEmail, $aResponse["meta"]["notifications"]["email"])===false){
_abort("Email not found in response");
}
_ok(); echo "\n";
}
foreach($aIni["notifications"]["slack"]??[] as $sValue){
$aArray = json_decode($sValue, 1);
$sChannel = array_keys($aArray)[0];
$sWebhook = array_values($aArray)[0];
echo "Check Slack '$sChannel'\n";
compare_strings("Check Slack '$sChannel'", $sWebhook, $aResponse["meta"]["notifications"]['slack'][$sChannel]??'');
}
// --------------------------------------------------------------------
#!/usr/bin/env php
<?php
echo "
WHAT: Run check cert
";
_exec("$AMCLI --ini='".__DIR__."/configs/cert.ini'");
#!/usr/bin/env php
<?php
echo "
WHAT: Run check cert
";
_exec("$AMCLI --ini='".__DIR__."/configs/cert.ini'");
#!/usr/bin/env php
<?php
echo "
WHAT: Run check Exec
";
_exec("$AMCLI --ini='".__DIR__."/configs/exec.ini'");
#!/usr/bin/env php
<?php
echo "
WHAT: Run check File
";
_exec("$AMCLI --ini='".__DIR__."/configs/file.ini'");
#!/usr/bin/env php
<?php
echo "
WHAT: Run check Simple
";
_exec("$AMCLI --ini='".__DIR__."/configs/simple.ini'");
; =======================================================================
;
; APPMONITOR CLI CLIENT
;
; for the checks see its parameters
; <https://os-docs.iml.unibe.ch/appmonitor/PHP_client/Plugins/Checks/index.html>
;
; =======================================================================
; -----------------------------------------------------------------------
; CHECKS
; -----------------------------------------------------------------------
["Cert plugin"]
description="SSL certificate of www.example.com"
function="Cert"
params='{
"url": "https://www.example.com"
}'
; -----------------------------------------------------------------------
; =======================================================================
;
; APPMONITOR CLI CLIENT
;
; for the checks see its parameters
; <https://os-docs.iml.unibe.ch/appmonitor/PHP_client/Plugins/Checks/index.html>
;
; =======================================================================
; -----------------------------------------------------------------------
; CHECKS
; -----------------------------------------------------------------------
["Free disk space /tmp"]
description="Check free diskspace in /tmp"
function="Diskfree"
params='{
"directory": "/tmp",
"warning": "1GB",
"critical": "500MB"
}'
; -----------------------------------------------------------------------
; =======================================================================
;
; APPMONITOR CLI CLIENT
;
; for the checks see its parameters
; <https://os-docs.iml.unibe.ch/appmonitor/PHP_client/Plugins/Checks/index.html>
;
; =======================================================================
; -----------------------------------------------------------------------
; CHECKS
; -----------------------------------------------------------------------
["Exec uptime"]
description="Start uptime command"
function="Exec"
params='{
"command": "uptime"
}'
; -----------------------------------------------------------------------
; =======================================================================
;
; APPMONITOR CLI CLIENT
;
; for the checks see its parameters
; <https://os-docs.iml.unibe.ch/appmonitor/PHP_client/Plugins/Checks/index.html>
;
; =======================================================================
; -----------------------------------------------------------------------
; CHECKS
; -----------------------------------------------------------------------
["Check dir /tmp"]
description="Check existing dir"
function="File"
params='{
"filename": "/tmp",
"exists": true,
"flag": "dir",
"readable": true,
"writable": true
}'
["No maintenance"]
description="Check non existing maintenance flag file"
function="File"
params='{
"filename": "/some/where/maintenance.txt",
"exists": false,
"flag": "file"
}'
; -----------------------------------------------------------------------
; =======================================================================
;
; APPMONITOR CLI CLIENT
;
; for the checks see its parameters
; <https://os-docs.iml.unibe.ch/appmonitor/PHP_client/Plugins/Checks/index.html>
;
; =======================================================================
; -----------------------------------------------------------------------
; CHECKS
; -----------------------------------------------------------------------
["hello plugin"]
description="I sust wann say hello"
function="hello"
params='{
"message": "Here I am"
}'
; -----------------------------------------------------------------------
; =======================================================================
;
; APPMONITOR CLI CLIENT
;
; to understand the entries of metadata see JSON in
; <https://os-docs.iml.unibe.ch/appmonitor/Client/Description_of_response.html>
;
; for the checks see its parameters
; <https://os-docs.iml.unibe.ch/appmonitor/PHP_client/Plugins/Checks/index.html>
;
; =======================================================================
; -----------------------------------------------------------------------
; METADATA
; -----------------------------------------------------------------------
[meta]
host = "www.example.com"
website = "Company website"
ttl = 300
tags[]="monitoring"
[notifications]
email[]="support@example.com"
email[]="webmaster@example.com"
; for slack use the following format
; <channelname> + comma + <webhook url>
slack[]='{ "#support-channel": "https://hooks.slack.com/services/XXXXXX/YYYYYY/ZZZZZ" }'
; -----------------------------------------------------------------------
; CHECKS
; -----------------------------------------------------------------------
["hello plugin"]
description="I sust wann say hello"
function="hello"
params='{
"message": "Here I am"
}'
; -----------------------------------------------------------------------
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment