Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • Legacy_Php7
  • master
2 results

Target

Select target project
  • iml-open-source/imldeployment
1 result
Select Git revision
  • Legacy_Php7
  • master
2 results
Show changes
Commits on Source (25)
Showing
with 771 additions and 265 deletions
# ======================================================================
#
# GENERATED BY docker/init.sh - template: ./templates/dot_env - e2cde05722688ff85d3a93e9cd55787e
# GENERATED BY init.sh - template: ./templates/dot_env - e2cde05722688ff85d3a93e9cd55787e
# values to be used in docker-composer.yml
#
# ======================================================================
......
#
# GENERATED BY docker/init.sh - template: ./templates/web-server-Dockerfile - 42dce773c83597a7d05af398bdd66d15
# GENERATED BY init.sh - template: ./templates/web-server-Dockerfile - 42dce773c83597a7d05af398bdd66d15
#
FROM php:8.1-apache
......
#
# GENERATED BY docker/init.sh - template: ./templates/vhost_app.conf - 9a9cf79de5a3584c0cef6cb79c339c25
# GENERATED BY init.sh - template: ./templates/vhost_app.conf - 9a9cf79de5a3584c0cef6cb79c339c25
#
......
;
; GENERATED BY docker/init.sh - template: ./templates/extra-php-config.ini - 80c23edaf568e2c36b9926fe2339e481
; GENERATED BY init.sh - template: ./templates/extra-php-config.ini - 80c23edaf568e2c36b9926fe2339e481
;
[PHP]
......
#
# GENERATED BY docker/init.sh - template: ./templates/docker-compose.yml - 97c88229bd2b5099544c013052b8d9c3
# GENERATED BY init.sh - template: ./templates/docker-compose.yml - 97c88229bd2b5099544c013052b8d9c3
#
# ======================================================================
#
......
......@@ -4,8 +4,12 @@
# DOCKER PHP DEV ENVIRONMENT :: INIT
#
# ----------------------------------------------------------------------
# 2021-11-nn <axel.hahn@iml.unibe.ch>
# 2022-07-19 <axel.hahn@iml.unibe.ch> support multiple dirs for setfacl
# 2021-11-nn v1.0 <axel.hahn@iml.unibe.ch>
# 2022-07-19 v1.1 <axel.hahn@iml.unibe.ch> support multiple dirs for setfacl
# 2022-11-16 v1.2 <www.axel-hahn.de> use docker-compose -p "$APP_NAME"
# 2022-12-18 v1.3 <www.axel-hahn.de> add -p "$APP_NAME" in other docker commands
# 2022-12-20 v1.4 <axel.hahn@unibe.ch> replace fgrep with grep -F
# 2023-03-06 v1.5 <www.axel-hahn.de> up with and without --build
# ======================================================================
cd $( dirname $0 )
......@@ -14,6 +18,8 @@ cd $( dirname $0 )
# git@git-repo.iml.unibe.ch:iml-open-source/docker-php-starterkit.git
selfgitrepo="docker-php-starterkit.git"
_version="1.5"
# ----------------------------------------------------------------------
# FUNCTIONS
# ----------------------------------------------------------------------
......@@ -86,7 +92,7 @@ function _removeGitdata(){
function _fix_no-db(){
local _file=$1
if [ $DB_ADD = false ]; then
typeset -i local iStart=$( cat ${_file} | fgrep -n "$CUTTER_NO_DATABASE" | cut -f 1 -d ':' )-1
typeset -i local iStart=$( cat ${_file} | grep -Fn "$CUTTER_NO_DATABASE" | cut -f 1 -d ':' )-1
if [ $iStart -gt 0 ]; then
sed -ni "1,${iStart}p" ${_file}
fi
......@@ -186,7 +192,7 @@ function _showContainers(){
local bLong=$1
h2 CONTAINERS
if [ -z "$bLong" ]; then
docker-compose ps
docker-compose -p "$APP_NAME" ps
else
docker ps | grep $APP_NAME
fi
......@@ -233,7 +239,7 @@ action=$1
while true; do
echo
echo -e "\e[32m===== INITIALIZER FOR APP [$APP_NAME] ===== \e[0m"
echo -e "\e[32m===== INITIALIZER FOR DOCKER APP [$APP_NAME] v$_version ===== \e[0m\n\r"
if [ -z "$action" ]; then
......@@ -246,7 +252,8 @@ while true; do
echo " t - generate files from templates"
echo " T - remove generated files"
echo
echo " u - startup containers docker-compose up -d"
echo " u - startup containers docker-compose ... up -d"
echo " U - startup containers docker-compose ... up -d --build"
echo " s - shutdown containers docker-compose stop"
echo " r - remove containers docker-compose rm -f"
echo
......@@ -281,24 +288,27 @@ while true; do
_showInfos
_wait
;;
u)
if docker-compose --verbose up -d --remove-orphans --build; then
# test ! -z "${APP_ONSTARTUP}" && sleep 2 && docker exec -it appmonitor-server /bin/bash -c "${APP_ONSTARTUP}"
u|U)
dockerUp="docker-compose -p "$APP_NAME" --verbose up -d --remove-orphans"
if [ "$action" = "U" ]; then
dockerUp+=" --build"
fi
if $dockerUp; then
echo "In a web browser:"
echo " $frontendurl"
else
echo "ERROR: docker-compose up failed :-/"
docker-compose logs | tail
docker-compose -p "$APP_NAME" logs | tail
fi
echo
_wait
;;
s)
docker-compose stop
docker-compose -p "$APP_NAME" stop
;;
r)
docker-compose rm -f
docker-compose -p "$APP_NAME" rm -f
;;
c)
docker ps
......
......@@ -14,7 +14,8 @@
"basepath": "https://git-repo.iml.unibe.ch/iml-open-source/imldeployment/tree/master/docs"
},
"links": {
"GitHub Repo": "https://git-repo.iml.unibe.ch/iml-open-source/imldeployment/"
"GitHub Repo": "https://git-repo.iml.unibe.ch/iml-open-source/imldeployment/",
"IML Opensource": "https://os-docs.iml.unibe.ch/"
},
"theme": "daux-blue",
"search": true
......
/*
patch css elements of daux.io blue theme
version 2022-05-13
override css elements of daux.io blue theme
version 2022-11-30
*/
/* ---------- vars ---------- */
:root {
/* background colors */
--bg:none;
--bg-body: #fff;
--bg-navlinkactive:#f4f4f4;
--bg-navlinkactive: linear-gradient(-90deg,rgba(0,0,0,0), rgba(40,60,80,0.05) 30%);
--bg-pre:#f8f8f8;
--bg-toc: #fff;
/* foreground colors */
--color: #234;
--navlinkactive:#f33;
--title: #aaa;
--link:#12a;
--toclink:rgba(40,60,80,0.8);
--h1: rgba(40,60,80,0.8);
--h1-bottom: 1px solid rgba(40,60,80,0.1);
--h2: #468;
--h3: #579;
/* Axels Overrides */
--color-text: #222;
--link-color: #822;
--brand-color: var(--color-secondary);
--brand-background: var(--body-background);
--hr-color: none;
--search-field-background: none;
--search-field-border-color: none;
--sidebar-background: var(--body-background);
--sidebar-border-color: none;
--sidebar-link-active-background: #e8f4f6;
--sidebar-link-active-background: #eee;
/* Axels custom values */
--axel_bg-toc: var(--body-background);
--axel_bg-toc-head: #f8f8f8;
--axel_brand-background: none;
--axel_brand-pre-background: rgb(255, 0, 51);
;
--axel_brand-pre-background-hover: rgb(255, 0, 51);
;
--axel_h1_header: none;
--axel_h1: #345;
--axel_h1-bg: none;
--axel_h1-bottom: 3px solid none;
--axel_h2: #156;
--axel_h2-bg: #f8fafb;
--axel_h2-bottom: 2px solid #467;
--axel_h2-hero-bottom: 2px solid #912;
--axel_h3: #278;
--axel_h3-bottom: 1px solid #ddd;
--axel_hero_bg: #f8f8f8;
--axel_nav-bg: #fcfcfc;
--axel_nav-buttomborder: #ddd;
--axel_pre-background: #f8f8f8;
--axel-th-background: #d0e0e8;
--axel-article-nav-border-top: 0px dotted #ddd;
}
/* ---------- tags ---------- */
.dark {
/* Axels Overrides */
--color-text: #c0c0c0;
--link-color: #b44;
--brand-color: var(--color-text);
--brand-background: var(--body-background);
--hr-color: none;
--code-tag-background-color_: #bcc;
--search-field-background: none;
--search-field-border-color: none;
--sidebar-background: var(--body-background);
--sidebar-border-color: none;
--sidebar-link-active-background: #333;
/* Axels custom values */
--axel_bg-toc: var(--body-background);
--axel_bg-toc-head: #333;
--axel_brand-background: none;
--axel_brand-pre-background: rgb(255, 0, 51);
;
--axel_brand-pre-background-hover: rgb(255, 0, 51);
;
--axel_h1_header: none;
--axel_h1: #777;
--axel_h1-bg: none;
--axel_h1-bottom: none;
--axel_h2: #467;
--axel_h2-bg: #202020;
--axel_h2-bottom: 2px solid #256;
--axel_h2-hero-bottom: 2px solid #712;
--axel_h3: #589;
--axel_h3-bottom: 1px solid #333;
--axel_hero_bg: #242424;
--axel_nav-bg: #242424;
--axel_nav-buttomborder: #555;
--axel_pre-background: #bcc;
--axel-th-background: #203038;
--axel-article-nav-border-top: 0px dotted #234;
}
/* ---------- left side ---------- */
a.Brand::before {
background: rgb(255,0,51);
background: var(--axel_brand-pre-background);
color: #fff;
font-family: arial;
font-weight: bold;
padding: 0.5em 0.3em;
content: 'IML';
margin-right: 0.4em;
float: left;
}
body, *{color: var(--color);}
body{background: var(--bg-body);}
a{color: var(--link);}
a:hover{opacity: 0.7;}
h1>a{ color:var(--title);}
_h1:nth-child(1){position: fixed; background: var(--bg); box-shadow: 0 0 1em #ccc; padding: 0 1em}
h1:nth-child(1)>a{ color:var(--navlinkactive); }
.s-content h1{color: var(--h1); font-size: 200%; font-weight:bold; margin-top: 2em; border-bottom: var(--h1-bottom);}
.s-content h2{color: var(--h2); font-size: 160%; }
.s-content h3{color: var(--h3); font-size: 140%; }
.s-content h4{margin: 0; font-size: 100%; text-align: center; background-color: rgba(0,0,0,0.05);padding: 0.3em;}
.s-content pre{
background: var(--bg-pre);
a.Brand:hover::before {
background: var(--axel_brand-pre-background-hover);
}
/* ---------- classes ---------- */
.required{color:#a42;}
.optional{color:#888;}
a.Brand {
background: var(--axel_brand-background);
font-size: 200%;
height: 4em;
}
/* ---------- page header: breadcrumb ---------- */
.Page__header {
border: none;
}
/* ----- top left */
.Brand,
.Columns__left {
background: var(--bg);
border-right: 0px solid #e7e7e9;
color: var(--color);
.Page__header a {
color: var(--axel_h1_header);
}
.Brand{font-size: 200%;
background_: linear-gradient(-10deg,#fff 50%, #ddd);
background: var(--bg);
.Page__header h1 {
font-size: 1.3em;
}
.Columns__right__content {
background: var(--bg);
/* ---------- page content ---------- */
.s-content {
padding-top: 1em;
}
/* ----- Navi left */
.s-content h1 {
background: var(--axel_h1-bg);
color: var(--axel_h1);
font-size: 200%;
font-weight: bold;
margin-bottom: 2em;
margin-top: 2em;
border-bottom: var(--axel_h1-bottom);
}
.Nav a:hover{
background: none;
color: var(--navlinkactive) !important;
.s-content h2 {
background: var(--axel_h2-bg);
color: var(--axel_h2);
font-size: 180%;
font-weight: bold;
margin-top: 4em;
border-bottom: var(--axel_h2-bottom);
}
.Nav__item--active {
border-right_: 0.3em solid var(--navlinkactive);
h1:first-of-type {
margin-top: 0em;
}
.Nav__item--active > a{
background: var(--bg-navlinkactive);
color: var(--navlinkactive);
h2:first-of-type {
margin-top: 0em;
}
.Nav .Nav .Nav__item--active a {
color: var(--navlinkactive);
.s-content h3 {
background: var(--axel_h3-bg);
color: var(--axel_h3);
font-size: 150%;
font-weight: bold;
margin-top: 3em;
border-bottom: var(--axel_h3-bottom);
}
.Nav .Nav .Nav__item a {
opacity: 1;
.s-content h4 {
margin: 0;
font-size: 100%;
text-align: center;
background-color: rgba(0, 0, 0, 0.05);
padding: 0.3em;
}
.Nav__item--open > a {
background-color: var(--bg);
.s-content pre {
background: var(--axel_pre-background);
}
.Nav a[href*="__Welcome"]{
background: url("/icons/house.png") no-repeat 10px 4px ;
padding-left: 40px;
/* FIX smaller fnt size in tables */
.s-content table {
font-size: 1em;
}
.Nav a[href*="__How_does_it_work"]{
background: url("/icons/light-bulb.png") no-repeat 10px 4px ;
padding-left: 40px;
.s-content table th {
background: var(--axel-th-background);
}
.s-content h3 code {
border: none;
background: none;
}
article nav {
border-top: var(--axel-article-nav-border-top);
margin: 8em 0 5em;
}
.Pager li>a {
padding: 1em 2em;
}
/* ---------- classes ---------- */
.required {
color: #a42;
}
/* FIX smaller fnt size in tables */
.s-content table {
font-size: 1em;
.optional {
color: #888;
}
div.hero {
background: var(--axel_hero_bg);
border-radius: 2em;
padding: 5em 2em;
text-align: center;
margin-bottom: 1.5em;
}
div.hero h2 {
color: var(--color-text);
background: none;
border-bottom: var(--axel_h2-hero-bottom);
font-size: 300%;
margin: 0 0 2em;
}
/* TOC */
/* ---------- TOC ---------- */
@media(min-width:1700px) {
.TableOfContentsContainer {
position: fixed;
......@@ -140,37 +226,42 @@ h1:nth-child(1)>a{ color:var(--navlinkactive); }
}
.TableOfContentsContainer {
background-color: var(--axel_bg-toc);
padding: 0.5em;
}
.s-content .TableOfContentsContainer h4 {
background-color: var(--axel_bg-toc-head);
border-top-left-radius: 1em;
background-color: var(--bg-toc);
border-left: 2px solid rgba(0,0,0,0.05);
padding: 0em;
font-size: 1.1em;
margin: 0;
padding: 0;
}
.TableOfContentsContainer__content {
border: none;
.TableOfContentsContainer__content {
border-width: 1px;
font-size: 0.5em;
}
ul.TableOfContents ul {
list-style-type: none;
padding-left: 1em;
}
.TableOfContentsContainer a{ color:var(--toclink);}
.TableOfContentsContainer__content > .TableOfContents > li + li {
border-top: none;
}
.TableOfContentsContainer__content > .TableOfContents > li {
border-bottom: 1px dashed #ddd;
/* ----- Icons on links --- */
.EditOn a::before{
content: '✏️ ';
}
/* pager - prev .. next */
.s-content{
margin-bottom: 6em;
.Links a[href^="https://github.com/"]::before {
content: '🌐 ';
}
.Pager{
border-top: 1px dashed #aaa; margin: 0; padding: 1em;
.Links a[href^="https://git-repo.iml.unibe.ch/"]::before {
content: '🌐 ';
}
.Pager a{
color:var(--navlinkactive);
.Links a[href^="https://os-docs.iml.unibe.ch"]::before {
content: '📗 ';
}
\ No newline at end of file
......@@ -98,7 +98,7 @@ return [
'presets'=>[<%= @replace["messenger-slack-presets"] %>],
],
'email'=>[
'from'=>[<%= @replace["messenger-email-from"] %>],
'from'=><%= @replace["messenger-email-from"] %>,
],
],
......
......@@ -112,7 +112,7 @@ foreach(array('server/config', 'server/tmp') as $sMyDir){
// ----------------------------------------------------------------------
require_once($sApproot.'/server/classes/appmonitor-server.class.php');
$oServer=new appmonitorserver();
$iCount=count($oServer->apiGetAppIds());
$iCount=count($oServer->getAppIds());
$oMonitor->addCheck(
array(
"name" => "appcounter",
......
<?php
/**
* ____________________________________________________________________________
*
* _____ _____ __ _____ _ _
* | | | | ___ ___ ___| |___ ___|_| |_ ___ ___
* |- -| | | | |__ | .'| . | . | | | | . | | | _| . | _|
* |_____|_|_|_|_____| |__,| _| _|_|_|_|___|_|_|_|_| |___|_|
* |_| |_|
* _ _ _
* ___| |_|___ ___| |_
* | _| | | -_| | _|
* |___|_|_|___|_|_|_|
*
* ____________________________________________________________________________
*
* CUSTOM CHECK BASED ON SHELL COMMANDS
*
* Execute a shell command.
* ____________________________________________________________________________
*
* 2022-09-19 <axel.hahn@iml.unibe.ch>
*
*/
class checkExec extends appmonitorcheck{
/**
* get default group of this check
* @param array $aParams - see run() method
* @return array
*/
public function getGroup($aParams){
return 'service';
}
/**
* check execution of a command
* @param array $aParams
* array(
* "command" {string} command to execute
* "output" {bool} flag: show output; default: true
*
* "exitOK" {array} array of integegers for ok exitcodes
* "exitWarn" {array} array of integegers for exitcodes with warning
* "exitCritical" {array} array of integegers for exitcodes that result in an error
*
* // TODO ... MAYBE
* "searchOK" {string} search string that must be found in output
* "searchWarn" {string} if search string is found check returns with warning
* "searchCritical" {string} if search string is found check returns with critical
* )
* @return boolean
*/
public function run($aParams) {
$this->_checkArrayKeys($aParams, "command");
$_sCmd=$aParams['command'];
$_bShowOutput=isset($aParams['output']) ? !!$aParams['output'] : true;
$_aRcOK=isset($aParams['exitOK']) ? $aParams['exitOK'] : [];
$_aRcWarning=isset($aParams['exitWarn']) ? $aParams['exitWarn'] : [];
$_aRcCritical=isset($aParams['exitCritical']) ? $aParams['exitCritical'] : [];
$_sMode='default';
if(count($_aRcOK) + count($_aRcWarning) + count($_aRcCritical)){
$_sMode='exitcode';
}
exec($_sCmd,$aOutput, $iRc);
$_sOut=$_bShowOutput ? '<br>'.implode("<br>", $aOutput) : '';
switch($_sMode){
// non-zero exitcode is an error
case "default":
if ($iRc) {
return [
RESULT_ERROR,
'command failed with exitcode '.$iRc.': [' . $_sCmd . ']'.$_sOut
];
} else {
return[
RESULT_OK,
'OK [' . $_sCmd . '] ' .$_sOut
];
};
break;;
// handle given custom exitcodes
case "exitcode":
if (in_array($iRc, $_aRcCritical)){
return [
RESULT_ERROR,
'Critical exitcode '.$iRc.' detected: [' . $_sCmd . ']'.$_sOut
];
}
if (in_array($iRc, $_aRcWarning)){
return [
RESULT_WARNING,
'Warning exitcode '.$iRc.' detected: [' . $_sCmd . ']'.$_sOut
];
}
if ($iRc == 0 || in_array($iRc, $_aRcOK)){
return [
RESULT_OK,
'OK exitcode '.$iRc.' detected: [' . $_sCmd . ']'.$_sOut
];
}
return [
RESULT_UNKNOWN,
'UNKNOWN - unhandled exitcode '.$iRc.' detected: [' . $_sCmd . ']'.$_sOut
];
case "search":
return[
RESULT_UNKNOWN,
'UNKNOWN method [' . $_sMode . '] - is not implemented yet.'
];
break;;
default:
return[
RESULT_UNKNOWN,
'UNKNOWN mode [' . htmlentities($_sMode) . '].'
];
} // switch($_sMode)
}
}
<?php
/**
* ____________________________________________________________________________
*
* _____ _____ __ _____ _ _
* | | | | ___ ___ ___| |___ ___|_| |_ ___ ___
* |- -| | | | |__ | .'| . | . | | | | . | | | _| . | _|
* |_____|_|_|_|_____| |__,| _| _|_|_|_|___|_|_|_|_| |___|_|
* |_| |_|
* _ _ _
* ___| |_|___ ___| |_
* | _| | | -_| | _|
* |___|_|_|___|_|_|_|
*
* ____________________________________________________________________________
*
* CHECK PING RESPONSE TIME VIA ICMP
* ____________________________________________________________________________
*
* 2022-07-05 <axel.hahn@iml.unibe.ch>
* 2022-09-16 <axel.hahn@iml.unibe.ch> read error before closing socket.
* 2022-11-22 <axel.hahn@iml.unibe.ch> Use exec with detecting MS Win for the ping parameter for count of pings
*/
class checkPing extends appmonitorcheck{
/**
* get default group of this check
* @param array $aParams
* @return array
*/
public function getGroup(){
return 'network';
}
/**
* check ping to a target
* @param array $aParams
* array(
* host string optional hostname to connect; default: 127.0.0.1
* timeout integer OBSOLET (because using exec): optional timeout in sec; default: 5
* )
* @return boolean
*/
public function run($aParams) {
$sHost = array_key_exists('host', $aParams) ? $aParams['host'] : '127.0.0.1';
$sParamCount=strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' ? "n" : "c";
$iRepeat=1;
$sCommand="ping -$sParamCount $iRepeat $sHost 2>&1";
exec($sCommand, $aOut, $iRc);
$sOut=implode("\n", $aOut);
if ($iRc>0){
return [RESULT_ERROR, "ERROR: ping to $sHost failed.\n".$sOut];
}
return [RESULT_OK, "OK: ping to $sHost\n".$sOut];
/*
Socket functions require root :-/
if (!function_exists('socket_create')){
return [RESULT_UNKNOWN, "UNKNOWN: Unable to perform ping test. The socket module is not enabled in the php installation."];
}
// ICMP ping packet with a pre-calculated checksum
$package = "\x08\x00\x7d\x4b\x00\x00\x00\x00PingHost";
$socket = socket_create(AF_INET, SOCK_RAW, getprotobyname('icmp'));
// TODO
if(!$socket){
die("ERROR: unable to create socket");
}
socket_set_option(
$socket,
SOL_SOCKET,
SO_RCVTIMEO,
array(
"sec"=>(isset($aParams["timeout"]) && (int)$aParams["timeout"]) ? (int)$aParams["timeout"] : $this->_iTimeoutTcp, // timeout in seconds
"usec"=>0
)
);
$start = microtime(true);
socket_connect($socket, $sHost, 0);
$connect = socket_send($socket, $package, strLen($package), 0);
if($connect){
if (socket_read($socket, 255)){
$result = microtime(true) - $start;
socket_close($socket);
return [RESULT_OK,
"OK: ping to $sHost",
array(
'type'=>'counter',
'count'=>$result,
'visual'=>'line',
)
];
} else {
$aResult=[RESULT_ERROR, "ERROR: ping to $sHost failed after connect." . socket_strerror(socket_last_error($socket))];
socket_close($socket);
return $aResult;
}
} else {
return [RESULT_ERROR, "ERROR: ping to $sHost failed. " . socket_strerror(socket_last_error($socket))];
}
*/
}
}
......@@ -14,10 +14,13 @@
*
* ____________________________________________________________________________
*
* CHECK SWLITE CONNECTION USING PDO
* CHECK TCP CONNECTION TO A GIVEN PORT
* ____________________________________________________________________________
*
* 2021-10-27 <axel.hahn@iml.unibe.ch>
* 2022-07-05 <axel.hahn@iml.unibe.ch> send unknown if socket module is not activated.
* 2022-09-16 <axel.hahn@iml.unibe.ch> read error before closing socket.
* 2022-12-05 <axel.hahn@unibe.ch> add @ sign at socket functions to prevent warning
*
*/
class checkPortTcp extends appmonitorcheck{
......@@ -46,9 +49,13 @@ class checkPortTcp extends appmonitorcheck{
$sHost = array_key_exists('host', $aParams) ? $aParams['host'] : '127.0.0.1';
$iPort = (int) $aParams['port'];
if (!function_exists('socket_create')){
return [RESULT_UNKNOWN, "UNKNOWN: Unable to perform tcp test. The socket module is not enabled in the php installation."];
}
// from http://php.net/manual/de/sockets.examples.php
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
$socket = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket === false) {
return [RESULT_UNKNOWN, "ERROR: $sHost:$iPort was not checked. socket_create() failed: " . socket_strerror(socket_last_error())];
}
......@@ -63,10 +70,11 @@ class checkPortTcp extends appmonitorcheck{
)
);
$result = socket_connect($socket, $sHost, $iPort);
$result = @socket_connect($socket, $sHost, $iPort);
if ($result === false) {
$aResult=[RESULT_ERROR, "ERROR: $sHost:$iPort failed. " . socket_strerror(socket_last_error($socket))];
socket_close($socket);
return [RESULT_ERROR, "ERROR: $sHost:$iPort failed. " . socket_strerror(socket_last_error($socket))];
return $aResult;
} else {
socket_close($socket);
return [RESULT_OK, "OK: $sHost:$iPort was connected."];
......
......@@ -12,6 +12,9 @@ class build_base implements iBuildplugin{
protected $_sBuildDir = false;
protected $_sOutfile = false;
protected $_sPluginId = false;
protected $_aPlugininfos = false;
protected $_sLang = "en-en";
protected $_aLang = [];
......
<?php
/**
* ----------------------------------------------------------------------
*
* Debug logging during a client request.
* So you can measure any action find bottlenecks in your code.
*
* Licence: GNU GPL 3.0
* Source: https://github.com/axelhahn/ahlogger
* Docs: https://www.axel-hahn.de/docs/ahlogger/
*
* USAGE:<br>
* (1) Trigger a message with add() to add a marker<br>
* (2) The render() method lists all items in a table with time since start
* and the delta to the last message. <br>
*
* @author www.axel-hahn.de
*
* @author hahn
* ----------------------------------------------------------------------
* 2016-02-26 init
* 2016-11-19 add memory usage
* (...)
* 2022-09-25 add memory tracking, add cli renderer
* 2022-09-27 css updates
* 2022-10-02 add emoji chars
* 2022-10-16 mark longest action with an icon
* 2022-12-15 make it compatible to PHP 8.2; add doc + comments
* ----------------------------------------------------------------------
*/
class logger {
protected $aMessages=array();
protected $bShowDebug=true;
/**
* @var {array} array of added messages
*/
protected $aMessages = [];
/**
* @var {bool} flag: show debug infos? default: false
*/
protected $bShowDebug = false;
/**
* @var {int} memory usage on start
*/
protected $_iMemStart = false;
/**
* @var {string} dynamic prefix for used css - it is set in the cronstructor
*/
protected $sCssPrefix = '';
// ----------------------------------------------------------------------
// CONSTRUCTOR
// ----------------------------------------------------------------------
/**
* constuctor
......@@ -18,33 +61,15 @@ class logger {
*/
public function __construct($sInitMessage = "Logger was initialized.") {
$this->_iMemStart=memory_get_usage();
$this->enableDebug(true);
$this->add($sInitMessage);
$this->sCssPrefix='debug-'.md5(microtime(true));
return true;
}
/**
* enable / disable debugging
* @param type $bEnable
* @return type
*/
public function enableDebug($bEnable=false){
return $this->bShowDebug=$bEnable;
}
/**
* enable client debugging by a given array of allowed ip addresses
* @param array $aIpArray
* @return boolean
*/
public function enableDebugByIp($aIpArray){
$this->enableDebug(false);
if (!$_SERVER || !is_array($_SERVER) || !array_key_exists("REMOTE_ADDR", $_SERVER)){
return false;
}
if (array_search($_SERVER['REMOTE_ADDR'], $aIpArray)!==false){
$this->enableDebug(true);
}
}
// ----------------------------------------------------------------------
// PUBLIC METHODS
// ----------------------------------------------------------------------
/**
* add a logging message
......@@ -56,94 +81,238 @@ class logger {
if (!$this->bShowDebug){
return false;
}
global $aCfg;
$this->aMessages[] = array(
'time' => microtime(true),
'message' => $sMessage,
'level'=>$sLevel
'level' => preg_replace('/[^a-z0-9\-\_]/', '', $sLevel),
'memory' => memory_get_usage()
);
if ($sLevel=="MAIL"){
mail($aCfg["emailDeveloper"], "studmed - booking tool - Logmessage", $sMessage);
}
return true;
}
/**
* render output of all logging messages
* enable / disable debugging
* @param type $bEnable
* @return type
*/
public function render(){
if (!$this->bShowDebug){
public function enableDebug($bEnable=true){
return $this->bShowDebug=!!$bEnable;
}
/**
* enable client debugging by a given array of allowed ip addresses
* @param array $aIpArray list of ip addresses in a flat array
* @return boolean
*/
public function enableDebugByIp($aIpArray){
$this->enableDebug(false);
if (!$_SERVER || !is_array($_SERVER) || !array_key_exists("REMOTE_ADDR", $_SERVER)){
return false;
}
$sOut='';
if (array_search($_SERVER['REMOTE_ADDR'], $aIpArray)!==false){
$this->enableDebug(true);
}
}
/**
* helper function: prepare array of added massages before output
* - detect warnings and errors
* - detect needed time for each action
* - detect longest action
* - detect maximum of memory usage
* - calculate total time
*
* @return array
*/
protected function _prepareRendering(){
$iMem=memory_get_usage();
$this->add('<hr>');
$this->add('Memory on start: ' . number_format($this->_iMemStart, 0, '.', ',') . " bytes");
$this->add('Memory on end: ' . number_format($iMem, 0, '.', ',') . " bytes");
$this->add('Memory peak: ' . number_format(memory_get_peak_usage(), 0, '.', ',') . " bytes");
$aReturn=[
'totaltime' => false,
'level' => false,
'warnings' => '',
'errors' => '',
'maxrowid' => false,
'maxtime' => false,
'result' => []
];
$sStarttime = $this->aMessages[0]["time"];
$iLasttime = $sStarttime;
$iCounter = 0;
$sMaxRowId = false;
$iMaxtime = -1;
$sWarnings=false;
$iLasttime=$sStarttime;
$iMaxmem = -1;
$bHasWarning = false;
$bHasError = false;
foreach ($this->aMessages as $aLogentry) {
$iCounter++;
$sTrId='debugTableRow'.$iCounter;
if($aLogentry["level"]=="warning"){
$bHasWarning=true;
}
if($aLogentry["level"]=="error"){
$bHasError=true;
}
$sTrId = $this->sCssPrefix.'debugTableRow' . $iCounter;
$iDelta = $aLogentry["time"] - $iLasttime;
if ($iDelta > $iMaxtime) {
$iMaxtime = $iDelta;
$sMaxRowId = $sTrId;
}
$iMaxmem=max($aLogentry["memory"], $iMaxmem);
$sStyle=($iDelta > 1)?'color: #f82;':'';
if (($iDelta > 1)){
$sWarnings.='<a href="#'.$sTrId.'" title="'.sprintf("%01.4f", $iDelta).' s">'.$iCounter.'</a>&nbsp;';
if (($iDelta > 1) || $aLogentry["level"] == "warning") {
$aReturn['warnings'].='<a href="#' . $sTrId . '" title="' . sprintf("%01.4f", $iDelta) . ' s">' . $iCounter . '</a>&nbsp;';
}
$sOut.='<tr class="'.$aLogentry["level"].'" id="'.$sTrId.'" style="'.$sStyle.'">'.
'<td>'.$iCounter.'</td>'.
'<td>'.sprintf("%01.3f", $aLogentry["time"]-$sStarttime).'</td>'.
'<td>'.sprintf("%01.3f", $iDelta).'</td>'.
'<td>'.$aLogentry["level"].'</td>'.
'<td>'.$aLogentry["message"].'</td>'.
'</tr>';
if ($aLogentry["level"] == "error") {
$aReturn['errors'].='<a href="#' . $sTrId . '" title="' . sprintf("%01.4f", $iDelta) . ' s">' . $iCounter . '</a>&nbsp;';
}
$aReturn['entries'][]=[
'time'=>$aLogentry["time"],
'level'=>$aLogentry["level"],
'message'=>$aLogentry["message"],
'memory'=>sprintf("%01.2f", $aLogentry["memory"]/1024/1024), // MB
'trid'=>$sTrId,
'trclass'=>$aLogentry["level"],
'counter'=>$iCounter,
'timer'=>sprintf("%01.3f", $aLogentry["time"] - $sStarttime),
'delta'=>sprintf("%01.0f", $iDelta*1000),
];
$iLasttime = $aLogentry["time"];
}
$aReturn['level']=($bHasWarning
? ($bHasError ? 'error' : 'warning')
: ''
);
$aReturn['maxrowid']=$sMaxRowId;
$aReturn['maxtime']=sprintf("%01.3f", $iMaxtime);
$aReturn['maxmem']=sprintf("%01.2f", $iMaxmem/1024/1024);
$aReturn['totaltime']=sprintf("%01.3f", $aLogentry['time']-$aReturn['entries'][0]['time']);
return $aReturn;
}
/**
* get html code for a progressbar with divs
* @param {int|float} $iVal value between 0..max value
* @param {int|float} $iMax max value
* @return {string}
*/
protected function _getBar($iVal, $iMax){
$iWidth=$iVal/$iMax*100;
return '<div class="bar"><div class="progress" style="width: '.$iWidth.'%;">&nbsp;</div></div>';
}
/**
* render output of all logging messages
*/
public function render() {
if (!$this->bShowDebug){
return false;
}
$iTotal=$iLasttime-$sStarttime;
if ($sWarnings){
$sWarnings='<br>warnings:&nbsp;'.$sWarnings;
$aData=$this->_prepareRendering();
/*
Array
(
[totaltime] => 0.006
[errors] =>
[warnings] => 3
[maxrowid] => debugTableRow3
[maxtime] => 0.005
[result] => Array
(
)
[entries] => Array
mit Elementen
Array
(
[time] => 1663959608.2566
[level] => info
[message] => Logger was initialized.
[memory] => 538056
[trid] => debugTableRow1
[trclass] => info
[trstyle] =>
[counter] => 1
[timer] => 0.000
[delta] => 0.000
)
*/
$sOut='';
// echo '<pre>'; print_r($aData); die();
foreach ($aData['entries'] as $aLogentry){
$sOut.='<tr class="'.$this->sCssPrefix.'-level-' . $aLogentry["level"] . ''.($aLogentry["trid"]==$aData["maxrowid"] ? ' '.$this->sCssPrefix.'-maxrow' : '').'" '
.'id="' . $aLogentry["trid"] . '">' .
'<td>' . $aLogentry["counter"] . '</td>' .
'<td>' . $aLogentry["level"] . '</td>' .
'<td>' . $aLogentry["timer"] . '</td>' .
'<td>' . $this->_getBar($aLogentry["delta"], $aData["maxtime"]*1000). $aLogentry["delta"] .' ms'.($aLogentry["delta"]==$aData['maxtime']*1000 ? ' ⏱️' : '').'</td>' .
'<td>' . $this->_getBar($aLogentry["memory"], $aData["maxmem"]) . $aLogentry["memory"] .' MB'. '</td>' .
'<td>' . $aLogentry["message"] . '</td>' .
'</tr>';
}
if ($sOut){
$sOut = '
<style>
.'.$this->sCssPrefix.'-info {position: fixed; top: 6em; right: 1em; background: rgba(200,228,255, 0.8); border: 1px solid; z-index: 99999;}
.'.$this->sCssPrefix.'-info .head {background: rgba(0,0,0,0.4); color: #fff;padding: 0em 0.5em 0.2em; }
.'.$this->sCssPrefix.'-info .content {padding: 0.5em; }
.'.$this->sCssPrefix.'-info .content .total {font-size: 160%; color: rgba(0,0,0,0.5); margin: 0.3em 0; display: inline-block;}
.'.$this->sCssPrefix.'-messages {margin: 5em 2em 2em;}
.'.$this->sCssPrefix.'-messages .bar {background: rgba(0,0,0,0.03); height: 1.4em; position: absolute; width: 6em; border-right: 1px solid rgba(0,0,0,0.2);}
.'.$this->sCssPrefix.'-messages .progress {background: rgba(100,140,180,0.2); height: 1.4em; padding: 0;}
.'.$this->sCssPrefix.'-messages table{background: #fff; color: #222;table-layout:fixed; }
.'.$this->sCssPrefix.'-messages table th{background: none;}
.'.$this->sCssPrefix.'-messages table th.barcol{min-width: 7em; position: relative;}
.'.$this->sCssPrefix.'-messages table td{padding: 3px; vertical-align: top;}
.'.$this->sCssPrefix.'-messages table th:hover{background:#aaa !important;}
if ($sOut) $sOut='
<div style="position: fixed; right: 1em; top: 6em; background: rgba(255,80,80, 0.1); padding: 0.5em;">
<span style="font-size: 130%;">total:&nbsp;'.sprintf("%01.3f", $iTotal).'&nbsp;s</span><br>
<span>longest&nbsp;action:&nbsp;<a href="#'.$sMaxRowId.'">'.sprintf("%01.3f", $iMaxtime).'&nbsp;s</a></span>
<span>'.$sWarnings.'</span>
.'.$this->sCssPrefix.'-level-info{background: #e0e8f8; color:#124}
.'.$this->sCssPrefix.'-level-warning{background: #fcf8e3; color: #980;}
.'.$this->sCssPrefix.'-level-error{background: #fce0e0; color: #944;}
.'.$this->sCssPrefix.'-maxrow{color:#f33; font-weight: bold;}
</style>
<div class="'.$this->sCssPrefix.' '.$this->sCssPrefix.'-info '.$this->sCssPrefix.'-level-'.$aData['level'].'">
<div class="head">ahLogger</div>
<div class="content">
<span class="total">⏱️ ' . $aData['totaltime'] . '&nbsp;s</span><br>
🪲 <a href="#'.$this->sCssPrefix.'-messages">Debug infos</a> | 🔺 <a href="#">top</a><br>
<span>longest&nbsp;action: ⏱️&nbsp;<a href="#' . $aData['maxrowid'] . '">' . ($aData['maxtime']*1000) . '&nbsp;ms</a></span>
' . ($aData['errors'] ? '<br><span>‼️ Errors: '.$aData['errors'] . '</span>' : '').'
' . ($aData['warnings'] ? '<br><span>⚠️ Warnings: '.$aData['warnings'] . '</span>' : '').'
</div>
<br>
<br>
<br>
<br>
<br>
<h3>DEBUG</h3><br>
<table class="datatable table table-striped debugtable">
</div>
<div id="'.$this->sCssPrefix.'-messages" class="'.$this->sCssPrefix.' '.$this->sCssPrefix.'-messages">
DEBUG :: LOG MESSAGES<br>'
. ($aData['errors'] ? '<span>Errors: '.$aData['errors'] . '</span><br>' : '')
. ($aData['warnings'] ? '<span>Warnings: '.$aData['warnings'] . '</span><br>' : '')
.'<br>
<table >
<thead>
<tr>
<th>#</th>
<th>delta to start time</th>
<th>delta to previuos</th>
<th>level</th>
<th>time [s]</th>
<th class="barcol">delta</th>
<th class="barcol">memory</th>
<th>message</th>
</tr></thead><tbody>
' . $sOut . '</tbody></table>'
. '<script>$(\'#'.$sMaxRowId.'\').css(\'color\', \'#f00\');</script>';
;
}
return $sOut;
}
/**
......@@ -154,32 +323,19 @@ class logger {
if (!$this->bShowDebug){
return false;
}
$sOut='';
$sStarttime=$this->aMessages[0]["time"];
$iCounter=0;
$sMaxRowId=false;
$iMaxtime=-1;
$sWarnings=false;
$iLasttime=$sStarttime;
$aData=$this->_prepareRendering();
foreach ($this->aMessages as $aLogentry){
$iCounter++;
$iDelta=$aLogentry["time"]-$iLasttime;
$sOut.=$aLogentry["level"].' '
. $iCounter.' '
.sprintf("%01.3f", $aLogentry["time"]-$sStarttime).' '
.sprintf("%01.3f", $iDelta).' '
.$aLogentry["level"].' '
$sOut='';
foreach ($aData['entries'] as $aLogentry){
$sOut.=$aLogentry["timer"].' | '
.$aLogentry["delta"].' ms | '
.$aLogentry["level"].' | '
.(sprintf("%01.3f", $aLogentry["memory"]/1024/1024)).' MB | '
.$aLogentry["message"].' '
. "\n"
;
$iLasttime=$aLogentry["time"];
}
// $iTotal=$iLasttime-$sStarttime;
$sOut.="\nTotal time: ".$aData['totaltime'] . "\n";
return $sOut;
}
}
......@@ -42,14 +42,16 @@ class messenger {
}
/**
* send an email if _aCfg['email'] exists
* send an email if _aCfg['email']['to'] exists
*/
private function _sendEmail(){
if (array_key_exists('email', $this->_aCfg) && array_key_exists('to', $this->_aCfg['email'])
) {
if (isset($this->_aCfg['email']['to']) && $this->_aCfg['email']['to']) {
preg_match('/^(.*)\n/', $this->_sMessage, $aTmp);
$sSubject = $aTmp[0];
return mail($this->_aCfg['email']['to'], $sSubject, $this->_sMessage, "From: " . $this->_aCfg['email']['from'] . "\r\n" .
return mail(
$this->_aCfg['email']['to'],
$sSubject, $this->_sMessage,
"From: " . $this->_aCfg['email']['from'] . "\r\n" .
"Reply-To: " . $this->_aCfg['email']['from'] . "\r\n"
);
}
......@@ -57,15 +59,15 @@ class messenger {
}
/**
* send a message to slack if _aCfg['slack'] exists
* send a message to slack if _aCfg['slack']['incomingurl'] exists
*/
private function _sendToSlack(){
if (array_key_exists('slack', $this->_aCfg)) {
if (isset($this->_aCfg['slack']['incomingurl']) && $this->_aCfg['slack']['incomingurl']) {
require_once(__DIR__ . '/../../vendor/shooker/shooker.php');
$shkr = new Shooker();
$shkr->setupIncoming($this->_aCfg['slack']['incomingurl']);
$sUser=(array_key_exists('user', $this->_aCfg['slack'])? $this->_aCfg['slack']['user']: false);
$sIcon=(array_key_exists('icon', $this->_aCfg['slack'])? $this->_aCfg['slack']['icon']: false);
$sUser=(isset($this->_aCfg['slack']['user'])? $this->_aCfg['slack']['user']: false);
$sIcon=(isset($this->_aCfg['slack']['icon'])? $this->_aCfg['slack']['icon']: false);
return $shkr->sendMessage($this->_sMessage, $sUser, $sIcon);
}
return false;
......
......@@ -647,7 +647,7 @@ class project extends base {
$this->getAllPhaseInfos();
foreach ($this->_aData["phases"] as $sPhase => $aData) {
foreach (array_keys($this->_aPlaces) as $sPlace) {
if (array_key_exists($sPlace, $aData) && array_key_exists("version", $aData[$sPlace])) {
if (isset($aData[$sPlace]["version"])) {
$this->_aVersions[$aData[$sPlace]["version"]][] = array('phase' => $sPhase, 'place' => $sPlace);
}
}
......
......@@ -176,7 +176,7 @@ class rollout_awx extends rollout_base {
// ----- Checks:
$sCmdChecks='';
if($aConfig['extravars']){
if(isset($aConfig['extravars']) && $aConfig['extravars']){
$aTmp=json_decode($aConfig['extravars'], 1);
if (!$aTmp || !is_array($aTmp) || !count($aTmp) ){
$sCmdChecks.='echo "ERROR: Value in extravars has wrong Syntax - this is no JSON: '.$aConfig['extravars'].'"; exit 1; ';
......@@ -184,14 +184,14 @@ class rollout_awx extends rollout_base {
$aConfig['extravars']=json_encode($aTmp);
}
if(!(int)$aConfig['inventory']){
if(!isset($aConfig['inventory']) || !(int)$aConfig['inventory']){
$sCmdChecks.='echo "ERROR: no inventory was given."; exit 1; ';
}
// ----- Send variables having values only
$aBodyvars=array();
foreach(['inventory'=>'inventory', 'limit'=>'limit', 'job_tags'=>'tags', 'extra_vars'=>'extravars'] as $sParam=>$sVarkey){
if ($aConfig[$sVarkey]) {
if (isset($aConfig[$sVarkey]) && $aConfig[$sVarkey]) {
$aBodyvars[$sParam]=$aConfig[$sVarkey];
}
}
......
......@@ -120,6 +120,7 @@ if(is_array($aData) && count($aData)){
// $sTable.='<tr>';
foreach ($aRow as $sKey=>$sValue){
// $sTable.='<td class="'.$sKey.'"><a href="'.$sUrl.'">'.$sValue.'</a></td>';
$sOnclick='';
$sLabel=strstr($sValue, '"')
? htmlentities($sValue)
: '<a href="#" onclick="$(\'#eFilter\').val(\''.$sValue.'\');filterTable();" title="click to filter by ['.$sValue.']">'.htmlentities($sValue).'</a>'
......
......@@ -143,7 +143,7 @@ switch ($sAction) {
// case 'other-varname':
case 'version':
if ($oVersion->updateVar($sVarname, $sValue)) {
echo "OK: $sVarname was updated.";
echo "OK: $sVarname was updated.".PHP_EOL."new value: $sValue".PHP_EOL;
} else {
echo "ERROR: update for $sVarname failed.";
}
......