Skip to content

Commit

Permalink
Merge pull request #117 from iml-it/visual-options
Browse files Browse the repository at this point in the history
Visual options
v0.145

* add config entry to show tags in app details
* add config entry to show/ hide validation warnings
* update format of notification email
* update docs
  • Loading branch information
axelhahn authored Dec 9, 2024
2 parents 29eb32c + 1438db9 commit c146bc3
Show file tree
Hide file tree
Showing 53 changed files with 209 additions and 62 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---
title: Server configuration
keywords: "files, settings, configuration"
---

## Configuration files

The config is in json syntax. The files are located in
Expand Down Expand Up @@ -64,6 +69,7 @@ appmonitor-server-config-defaults.json to appmonitor-server-config.json
"age": true,
"checks": true,
"times": true,
"tags": true,
"receiver": true,
"notification": true
}
Expand Down Expand Up @@ -239,3 +245,41 @@ Example:

The list of appmonitor client urls is in appmonitor-server-urls.json.
This file is not part of the repository. It will be created if you store the first url.

## View

The key "view" has 2 subnodes

* "overview" - tiles to show on application overview page
* "appdetails" - tiles to show on application detail page

key | description
--------------------|---------------------------
validationwarnings | Show validation warnings in app overview and app detail page

### view:overview

Set it true or false to set the visibility.

Key | Description
---------------|---------------------------
"webapps" | number of web applications
"hosts" | number of hosts
"checks" | number of checks total for all web apps
"notification" | show stats if notifications are currently enabled

### view:appdetails

Set it true or false to set the visibility.

Key | Description
---------------|---------------------------
"appstatus" | number of web applications
"httpcode" | http status code of last check
"age" | age of the currently visible information and TTL
"checks" | number of checks total for current web app
"times" | total time to perform all checks of the web app (if available)
"tags" | show count of tags and its names
"receiver" | show app specific notification recerivers
"notification" | show stats if notifications are currently enabled

Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---
title: Notifications
keywords: "email, slack, application specific receivers, global receivers"
---

## Introduction

Notifications will be triggered if ...
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
85 changes: 85 additions & 0 deletions public_html/pmu
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/bin/bash
# ======================================================================
#
# pmu - process memory usage
#
# ----------------------------------------------------------------------
# 2013-07-31 v1.0 Axel Hahn
# 2023-01-10 v1.1 Axel Hahn shell fixes; add total status
# 2023-12-22 v1.2 Axel Hahn speedup factor 5..10
# ======================================================================

typeset -i lines=0
_version=1.2

# ----------------------------------------------------------------------
# MAIN
# ----------------------------------------------------------------------

echo "_______________________________________________________________________________
>>>> Memory usage by each process in MB v$_version
"

# ----- show help
if [ "$1" = "-?" -o "$1" = "-h" -o "$1" = "--help" ]; then
self=$( basename $0 )
cat <<EOF
HELP
$self groups all processes and shows their memory usage in MB.
The output is ordered by largest consumers.
Coloumns:
process process name
total MB aggregated memory by all processes
count count of processes
average MB average memory usage (total divided by count)
You can limit the output by intger parameter for count of lines to show.
SYNTAX:
$self shows all processes
$self [integer] limit output to top n consumers
$self [-? -h --help] show this help
EXAMPLE:
$self 10 shows top 10 consumers
EOF
exit 0
fi


# ----- output of total status
top -n 1 -E M -b | head | grep -E "^(Tasks|MiB Mem|MiB Spch)"
echo "_______________________________________________________________________________
"

# ----- aggregate data

pslist=$( ps -yle )
pslist2=$(
for processname in $( echo "$pslist" | awk {'print $13'} | sort -u | grep -Fv "/")
do
grep " ${processname}$" <<< "$pslist"| awk '
{x += $8;y += 1; process=$13}
END {printf "%-15s %10.0f %5s %10.3f\n", process, x/1024, y, x/(y*1024)}' 2>/dev/null
done | sort -k 2 -n -r
)

# ----- output for processes
lines=$1
echo "process total MB count average MB"
echo "--------------- ---------- ----- ----------"

if [ $lines -gt 0 ]; then
echo "$pslist2" | head -$lines
else
echo "$pslist2"
fi
echo

exit

# ----------------------------------------------------------------------
59 changes: 36 additions & 23 deletions public_html/server/classes/appmonitor-server-gui.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* SERVICING, REPAIR OR CORRECTION.<br>
* <br>
* --------------------------------------------------------------------------------<br>
* @version 0.143
* @version 0.145
* @author Axel Hahn
* @link https://github.com/iml-it/appmonitor
* @license GPL
Expand All @@ -44,14 +44,15 @@
* 2024-11-26 0.142 [email protected] handle invalid response data
* 2024-11-29 0.143 [email protected] filter by multiple tags
* 2024-12-06 0.144 [email protected] prevent multiple values of same tag (see functions.js)
* 2024-12-09 0.145 [email protected] shwo tags in appdetails; config flag: show validation warnings
*/
class appmonitorserver_gui extends appmonitorserver
{
/**
* Version
* @var string
*/
protected string $_sVersion = "0.144";
protected string $_sVersion = "0.145";

/**
* Title/ project name
Expand Down Expand Up @@ -419,6 +420,7 @@ protected function _generateWebappTiles(string $sAppId): string
}

foreach ($this->_aCfg['view']['appdetails'] as $key => $bVisibility) {
if(!$bVisibility) continue;
switch ($key) {
case 'appstatus':
$aLast = $this->oNotification->getAppLastResult();
Expand All @@ -437,27 +439,23 @@ protected function _generateWebappTiles(string $sAppId): string
);
break;
case 'httpcode':
$sReturn .= $bVisibility
? $this->_getTile([
$sReturn .= $this->_getTile([
'result' => ((int) $aHostdata['httpstatus'] == 0 || $aHostdata['httpstatus'] >= 400)
? RESULT_ERROR
: false,
'label' => $this->_tr('Http-status'),
'count' => $aHostdata['httpstatus'] ? $aHostdata['httpstatus'] : '??',
])
: '';
]);
break;
case 'age':
$bOutdated = isset($aHostdata["outdated"]) && $aHostdata["outdated"];
$sReturn .= $bVisibility
? $this->_getTile([
$sReturn .= $this->_getTile([
'result' => $bOutdated ? RESULT_ERROR : RESULT_OK,
'icon' => $this->_aIco['age'],
'label' => $this->_tr('age-of-result'),
'count' => '<span class="timer-age-in-sec">' . (time() - $aHostdata['ts']) . '</span>s',
'more' => $this->_tr('TTL') . '=' . $aHostdata['ttl'] . 's',
])
: '';
]);
break;
case 'checks':
$sReturn .= $bVisibility && isset($aHostdata['summary']['total'])
Expand Down Expand Up @@ -488,26 +486,34 @@ protected function _generateWebappTiles(string $sAppId): string
// .'<pre>'.print_r($this->oNotification->getAppNotificationdata(), 1).'</pre>'
. (count($aSlackChannels) ? '<span title="' . implode("\n", array_keys($aSlackChannels)) . '">' . count($aSlackChannels) . ' x ' . $this->_aIco['notify-slack'] . '</span> ' : '');
$iNotifyTargets = count($aEmailNotifiers) + count($aSlackChannels);
$sReturn .= $bVisibility
? $this->_getTile([
$sReturn .= $this->_getTile([
'result' => $iNotifyTargets ? false : RESULT_WARNING,
'icon' => $this->_aIco['notifications'],
'label' => $this->_tr('Notify-address'),
'count' => $iNotifyTargets,
'more' => $sMoreNotify
])
: '';
]);
break;
case 'notification':
$sSleeping = $this->oNotification->isSleeptime();
$sReturn .= $bVisibility
? $this->_getTile([
$sReturn .= $this->_getTile([
'result' => ($sSleeping ? RESULT_WARNING : false),
'icon' => ($sSleeping ? $this->_aIco['sleepmode-on'] : $this->_aIco['sleepmode-off']),
'label' => ($sSleeping ? $this->_tr('Sleepmode-on') : $this->_tr('Sleepmode-off')),
'more' => $sSleeping,
])
: '';
]);
break;
case 'tags':
$aTags = $this->_data[$sAppId]['meta']['tags'] ?? [];

$sTaglist = implode(', ', $aTags);
$sReturn .= $this->_getTile([
'result' => $sTaglist ? RESULT_OK : RESULT_WARNING,
'icon' => $this->_aIco['tag'],
'count' => count($aTags),
'label' => $this->_tr('Tags'),
'more' => $sTaglist ?: $this->_tr('Tags-none'),
]);
break;

default:
Expand Down Expand Up @@ -666,7 +672,8 @@ protected function _checkClientResponse(string $sAppId): bool|array
$aErrors[] = $this->_tr('msgErr-missing-key-meta-' . $sMetakey);
}
}
foreach (['ttl', 'time', 'notifications'] as $sMetakey) {
unset($aData['meta']['tags']);
foreach (['ttl', 'time', 'notifications', 'tags'] as $sMetakey) {
if (!isset($aData['meta'][$sMetakey])) {
$aWarnings[] = $this->_tr('msgWarn-missing-key-meta-' . $sMetakey);
}
Expand Down Expand Up @@ -1375,7 +1382,7 @@ public function generateViewApp(string $sAppId): string
(isset($aEntries["result"]) && isset($aEntries["result"]["result"]) && isset($aEntries["result"]["website"]) && isset($aEntries["result"]["host"]))
) {

// ---
// --- top breadcrumb
$sTopHeadline = $oA->getSectionHead(
''
. '<a href="#divwebs"'
Expand Down Expand Up @@ -1404,9 +1411,12 @@ public function generateViewApp(string $sAppId): string
]);
}

if (!$sValidationContent && $aValidatorResult) {
$bShowWarnings=!!$this->_aCfg['view']['validationwarnings'] ?? true;
if (!$sValidationContent && $aValidatorResult ) {
foreach ($aValidatorResult as $sSection => $aMessageItems) {
if (count($aMessageItems)) {
if (count($aMessageItems)
&& ( $sSection == 'error' || $sSection == 'warning' && $bShowWarnings )
) {
$sDivContent = '';
foreach ($aMessageItems as $sSingleMessage) {
$sDivContent .= '- ' . $sSingleMessage . '<br>';
Expand Down Expand Up @@ -2018,11 +2028,14 @@ function _generateWeblist(bool $bSkipOk = false, array $aOptions = []): array
: $this->_getIconClass($this->_aIco['host']);
$sAppLabel = str_replace('.', '.&shy;', $this->_getAppLabel($sAppId));

$bShowWarnings=!!$this->_aCfg['view']['validationwarnings'] ?? true;
$aValidaion = $this->_checkClientResponse($sAppId);
$sValidatorinfo = '';
if ($aValidaion) {
foreach ($aValidaion as $sSection => $aMessages) {
if (count($aValidaion[$sSection])) {
if (count($aValidaion[$sSection])
&& ( $sSection == 'error' || ($sSection == 'warning' && $bShowWarnings) )
) {
$sValidatorinfo .= '<span class="ico' . $sSection . '" title="' . sprintf($this->_tr('Validator-' . $sSection . '-title'), count($aMessages)) . '">' . $this->_aIco[$sSection] . '</span> ' . count($aMessages);
}
}
Expand Down
11 changes: 7 additions & 4 deletions public_html/server/classes/notificationhandler.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ public function notify(): bool
return false;
}
$iChangetype = $this->_detectChangetype();
$iResult = $this->_aAppResult['result']['result'];
$iResult = $this->_aAppResult['result']['result'] ?? RESULT_ERROR;

// get the highest value for a delay
$iMaxDelay = max(array_values($this->_aDelayNotification));
Expand Down Expand Up @@ -735,18 +735,21 @@ protected function sendAllNotifications(): bool
'htmlmessage' => '
<style>
body{background: #f8f8f8; font-size: 1.1em; font-family: Arial, Helvetica, sans-serif; text-align: center;}
body>div{background: #fff; margin: 1em auto; border: #eee 2px solid; padding: 1em; max-width: 1000px; text-align: left;}
h1{background: #eee; border-bottom: 2px solid #800; color: #666; padding: 0.5em; margin: 0 0 1em 0;}
h2{color: #888; padding: 0.5em; margin: 0 0 1em 0;}
body>div{background: #fff; margin: 1em auto; border: #eee 2px solid; padding: 0; max-width: 1000px; text-align: left;}
body>div>div{padding: 1em; }
h1{background: #eee; border-bottom: 2px solid #800; color: #666; font-size: 130%; padding: 0.5em; margin: 0 0 1em 0;}
h2{color: #888; padding: 0em; margin: 0 0 1em 0;}
.footer{background: #f8f8f8; padding: 0.5em; margin-top: 3em; text-align: right;}
.result-0{color: green; background: #dfd; }
.result-1{color: purple; background: #fdf; }
.result-2{color: #a60; background: #fec; }
.result-3, .error{color: #c00; background: #fdd; }
</style>
<h1>IML Appmonitor</h1>
<div>
' . $sMessage
.'<br><br><div class="footer"><strong>IML Appmonitor</strong> | GNU GPL 3.0 | Source <a href="https://github.com/iml-it/appmonitor">Github</a></div>'
.'</div>'
,
];
// $sSendMethod="send_$sPlugin";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@
"age": true,
"checks": true,
"times": true,
"tags": true,
"receiver": true,
"notification": true
}
},
"validationwarnings": true
}
}
19 changes: 19 additions & 0 deletions public_html/server/email.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

$sTO="[email protected]";
$sSUBJECT="AppMonitor - ".date("Y-m-d H:i:s");
$sBody="
Hallihallo
Hier ist meine Test-Nachricht.
Viele Grusse
Axel
";

echo "$sTO - $sSUBJECT<br>";
echo "$sBody<br>";

$ret = mail($sTO, $sSUBJECT, $sBody);
var_dump($ret); // (bool)true

6 changes: 5 additions & 1 deletion public_html/server/lang/de-de.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@
"Sleepmode-on": "Zzz ... Meldungen sind AUS",
"Sleepmode-off": "Meldungen sind AN",

"Tags": "Tags",
"Tags-none": "Kein Tag gesetzt",

"Time": "Zeit",
"Time-for-all-checks": "Zeiten aller Checks",

Expand Down Expand Up @@ -196,7 +199,8 @@
"msgWarn-missing-key-meta-ttl":"Es wurde kein TTL gesetzt via meta > ttl. Es wird der Default verwendet.",
"msgWarn-missing-key-meta-notifications":"Es gibt keine Sektion meta > notifications. Im Fehlerfall gibt es keine Meldung an Entwickler / Product Owner dieser Applikation.",
"msgWarn-no-notifications":"In der Sektion meta > notification > [target] ist kein Empf&auml;nger. Im Fehlerfall gibt es keine Meldung an Entwickler / Product Owner dieser Applikation.",
"msgWarn-missing-key-meta-time":"Es gibt keine Messdaten - es wurde kein Wert gesetzt via meta > time.",
"msgWarn-missing-key-meta-time":"Es gibt keine Zeitmessung am Client - es wurde kein Wert gesetzt via meta > time.",
"msgWarn-missing-key-meta-tags":"Es wurden keine Tags definiert: meta > tags fehlt.",

"zzz_lastentry": "This is just a Dummy entry without comma at the end of line"
},
Expand Down
Loading

0 comments on commit c146bc3

Please sign in to comment.