From f99d4869145326edf781a24caa2164073b480020 Mon Sep 17 00:00:00 2001 From: "Hahn Axel (hahn)" <axel.hahn@unibe.ch> Date: Wed, 5 Mar 2025 16:35:01 +0100 Subject: [PATCH] check dynamic values from env --- tests/00_start.php | 2 +- tests/100_set_metadata.php | 8 ++------ tests/300_dynamic_value.php | 31 +++++++++++++++++++++++++++++++ tests/configs/dynamic_values.ini | 24 ++++++++++++++++++++++++ tests/configs/metadata.ini | 2 +- 5 files changed, 59 insertions(+), 8 deletions(-) create mode 100644 tests/300_dynamic_value.php create mode 100644 tests/configs/dynamic_values.ini diff --git a/tests/00_start.php b/tests/00_start.php index 416a2bd..e36f200 100755 --- a/tests/00_start.php +++ b/tests/00_start.php @@ -5,7 +5,7 @@ require_once __DIR__.'/../inc_functions.php'; require_once __DIR__.'/../inc_vars.php'; $AMCLI??=__DIR__.'/../src/amcli.php'; -$AMCLI=__DIR__.'/../built_packages/amcli'; +// $AMCLI=__DIR__.'/../built_packages/amcli'; _chdir(__DIR__); diff --git a/tests/100_set_metadata.php b/tests/100_set_metadata.php index faad586..edbdd63 100644 --- a/tests/100_set_metadata.php +++ b/tests/100_set_metadata.php @@ -5,7 +5,7 @@ echo " WHAT: Set application metadata "; -$sInifile=__DIR__."/configs/metadata.ini"; +$sInifile="configs/metadata.ini"; // -------------------------------------------------------------------- // FUNCTION @@ -52,11 +52,7 @@ foreach($aIni["notifications"]["email"]??[] as $sEmail){ _ok(); echo "\n"; } -foreach($aIni["notifications"]["slack"]??[] as $sValue){ - $aArray = json_decode($sValue, 1); - $sChannel = array_keys($aArray)[0]; - $sWebhook = array_values($aArray)[0]; - +foreach($aIni["notifications"]["slack"]??[] as $sChannel => $sWebhook){ echo "Check Slack '$sChannel'\n"; compare_strings("Check Slack '$sChannel'", $sWebhook, $aResponse["meta"]["notifications"]['slack'][$sChannel]??''); } diff --git a/tests/300_dynamic_value.php b/tests/300_dynamic_value.php new file mode 100644 index 0000000..8e2936f --- /dev/null +++ b/tests/300_dynamic_value.php @@ -0,0 +1,31 @@ +#!/usr/bin/env php +<?php + +echo " +WHAT: Test dynamic ini value +"; + +$sInifile="configs/dynamic_values.ini"; + +echo "--- Content of ini file:\n" + .preg_replace( + "/.*(params.*\n)\n.*/s", + "$1", + file_get_contents($sInifile) + )."\n" + ; +$aIni=parse_ini_file($sInifile, 1); + +echo "--- parsed ini value for the check:\n"; +print_r($aIni["hello plugin"]['params']); +$sMessage=$aIni["hello plugin"]['params']['message']??false; +if($sMessage) +{ + if(strstr($sMessage, "\$\{")){ + _abort('in params -> message the variable $\{USER\} was not replaced'); + } else { + _ok('in params -> message the variable $\{USER\} was replaced'); + } +} else { + _abort("Message param was not found."); +} diff --git a/tests/configs/dynamic_values.ini b/tests/configs/dynamic_values.ini new file mode 100644 index 0000000..dab4cb4 --- /dev/null +++ b/tests/configs/dynamic_values.ini @@ -0,0 +1,24 @@ +; ======================================================================= +; +; 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> +; +; ======================================================================= + +; ----------------------------------------------------------------------- +; CHECKS +; ----------------------------------------------------------------------- + +["hello plugin"] +description='I test a dynamic value USER = ${USER}' +function="hello" + +; to have dynamic values in params do not use JSON but array syntax +params[message]="Here is ${USER}" + +; ----------------------------------------------------------------------- diff --git a/tests/configs/metadata.ini b/tests/configs/metadata.ini index 0909722..d81e6f8 100644 --- a/tests/configs/metadata.ini +++ b/tests/configs/metadata.ini @@ -28,7 +28,7 @@ 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" }' +slack["#support-channel2"]="https://hooks.slack.com/services/XXXXXX/YYYYYY/ZZZZZ" ; ----------------------------------------------------------------------- -- GitLab