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

update appmonitor client

parent 74ea8386
No related branches found
No related tags found
1 merge request!66php8 only; added variable types; short array syntax; remove glyphicons
#!/bin/bash
# ======================================================================
#
# A P P M O N I T O R :: CLIENT - UPDATE
#
# _____ _____ __ _____ _ _
# | | | | ___ ___ ___| |___ ___|_| |_ ___ ___
# |- -| | | | |__ | .'| . | . | | | | . | | | _| . | _|
# |_____|_|_|_|_____| |__,| _| _|_|_|_|___|_|_|_|_| |___|_|
# |_| |_|
# _ _ _
# ___| |_|___ ___| |_
# | _| | | -_| | _|
# |___|_|_|___|_|_|_|
#
#
# INSTALLER + UPDATER
#
# This script will install or update the appmonitor client only.
#
......@@ -16,6 +28,7 @@
# 2022-04-12 0.2 <axel.hahn@iml.unibe.ch> add help; exclude unneeded files
# 2022-05-03 0.3 <axel.hahn@iml.unibe.ch> create general_include.php
# 2024-07-25 0.4 <axel.hahn@iml.unibe.ch> update quoting and comments
# 2024-07-31 0.5 <axel.hahn@iml.unibe.ch> Show more helpful information; wait on 1st install; added param -n
# ======================================================================
# ----------------------------------------------------------------------
......@@ -23,12 +36,16 @@
# ----------------------------------------------------------------------
readonly git_repo_url="https://github.com/iml-it/appmonitor.git"
readonly docs_url="https://os-docs.iml.unibe.ch/appmonitor/PHP_client/index.html"
readonly line="______________________________________________________________________________"
readonly version="0.4"
readonly version="0.5"
git_target=/tmp/git_data__appmonitor
client_from="${git_target}/public_html/client"
client_to="."
isUpdate=0
wait=1
cd "$( dirname "$0" )" || exit 1
......@@ -88,20 +105,22 @@ function _gitUpdate(){
# ----------------------------------------------------------------------
cat <<ENDOFHEADER
$line
IML Appmonitor client :: installer + updater v$version
$line
+-----------------------------------+
| |
| INSTALLER | |
| + | Appmonitor client |
| UPDATER | |
| |
+--------------------------- v$version --+
ENDOFHEADER
case "$1" in
-h|--help)
cat <<ENDOFHELP
The IML Appmonitor is free software.
Source: https://github.com/iml-it/appmonitor
Docs: https://os-docs.iml.unibe.ch/appmonitor
License: GNU GPL 3.0
This is a helper script to get the files of the IML Appmonitor
client part only.
......@@ -116,18 +135,26 @@ case "$1" in
On additional runs it updates the files.
USAGE:
$0 [OPTIONS] [TARGET]
$0 [target path]
OPTIONS:
-h|--help
Show this help and exit
-n|--nowait
Do not wait for RETURN on 1st installation.
Use it for an unattended installation.
default target is [.] (current directory)
$0 -h|--help
Show this help.
PARAMETERS:
TARGET
optional target path for the client files
default target is "." (current directory)
ENDOFHELP
exit 0
;;
-n|--nowait)
wait=0
;;
*)
if test -n "$1"
then
......@@ -144,6 +171,32 @@ esac
which rsync >/dev/null || exit 1
which git >/dev/null || exit 1
test -f general_include.php && isUpdate=1
if [ $isUpdate -eq 0 ]; then
cat <<WELCOME
Welcome to the Appmonitor client installation!
This is a helper script to get the client files of the IML Appmonitor.
They will be installed into the directory "$client_to" $( test "$client_to" = "." && (echo; echo -n " "; pwd) )
If this is not correct, press Ctrl + C to abort and use a
parameter to set another target directory.
"$( basename "$0" ) -h" shows a help and more options.
WELCOME
if [ $wait -eq 1 ]; then
echo -n " RETURN to continue ... "
read -r
fi
else
echo "Updating local files ..."
fi
echo
echo $line
echo ">>> #1 of 3 >>> update local git data"
echo
......@@ -179,7 +232,32 @@ echo
diff --color -r "$client_from" "$client_to"
echo
if [ $isUpdate -eq 0 ]; then
_fileupdate index.sample.php
cat <<INTRODUCTION
$line
DONE!
The Appmonitor client was installed.
- Please edit index.php and general_include.php.
- If you have multiple applications below webroot then you can
rename the file index.php to check-[appname].php eg.
check-cms.php, check-blog.php, ...
- Start "$( basename "$0" )" again to perform an update.
Maybe you want to create a cronjob for this.
INTRODUCTION
else
echo "Appmonitor client was updated."
fi
echo
echo "Documentation: $docs_url"
echo
echo $line
echo done.
......
......@@ -163,6 +163,24 @@ $oMonitor->addCheck(
// ----------------------------------------------------------------------
include 'shared_check_ssl.php';
$oMonitor->addCheck(
[
"name" => "plugin Load",
"description" => "current load",
"group" => 'monitor',
"parent" => false,
"check" => [
"function" => "Loadmeter",
"params" => [
"warning" => 1.0,
"error" => 3,
],
],
"worstresult" => RESULT_OK
]
);
// ----------------------------------------------------------------------
// plugin test
// ----------------------------------------------------------------------
......
<?php
/* ______________________________________________________________________
*
* A P P M O N I T O R :: CLIENT - INCLUDE FOR APP CHECKS :: ON END
* ______________________________________________________________________
*/
// $bStandalone was set in inc_appcheck_start.php
// send response if client was not initialized there
if($bStandalone){
$oMonitor->setResult();
$oMonitor->render();
}
// ----------------------------------------------------------------------
<?php
/* ______________________________________________________________________
*
* A P P M O N I T O R :: CLIENT - INCLUDE FOR APP CHECKS :: ON START
* ______________________________________________________________________
*/
// ----------------------------------------------------------------------
// CHECK IF THE APPROOT IS SET
// ----------------------------------------------------------------------
if (!$sApproot) {
header('HTTP/1.0 503 Service Unavailable');
echo "<h1>503 Service Unavailable</h1>";
echo 'ERROR:'.PHP_EOL;
echo '$sApproot was not set. Define it before including the application check.'.PHP_EOL;
echo 'Set the base folder of your application installation.'.PHP_EOL;
echo PHP_EOL;
echo 'Example:'.PHP_EOL;
echo '$sApproot = $_SERVER[\'DOCUMENT_ROOT\'];'.PHP_EOL;
echo '$sApproot = $_SERVER[\'DOCUMENT_ROOT\'].\'/myapp\';'.PHP_EOL;
die();
}
// initialize client and set very basic metadata ... if needed
$bStandalone=!(class_exists('appmonitor') && isset($oMonitor));
if($bStandalone){
require_once(__DIR__.'/../../classes/appmonitor-client.class.php');
$oMonitor = new appmonitor();
$oMonitor->setWebsite('Wordpress Instance');
@include __DIR__.'/../../general_include.php';
}
// ----------------------------------------------------------------------
// FUNCTIONS
// ----------------------------------------------------------------------
// ----------------------------------------------------------------------
<?php
/* ______________________________________________________________________
*
* WORK IN PROGRESS
*
* A P P M O N I T O R :: CLIENT - CHECK
* ______________________________________________________________________
*
* Check for a Wordpress instance.
* Blogsoftware https://wordpress.org/
*
* It checks
* - the write access to the config file
* - connect to mysql database (which is read from config)
* - ssl certificate (on https request only)
*
* @author: <axel.hahn@unibe.ch>
* ----------------------------------------------------------------------
* 2018-11-07 v0.01
* 2019-05-24 v0.02 detect include or standalone mode
* 2019-05-24 v0.03 detect include or standalone mode
* 2024-07-31 v0.04 first version for wordpress check in plugins/apps/
*/
require 'inc_appcheck_start.php';
// ----------------------------------------------------------------------
// Read config items
// ----------------------------------------------------------------------
$sConfigfile = $sApproot . '/wp-config.php';
if (!file_exists($sConfigfile)) {
header('HTTP/1.0 503 Service Unavailable');
die('ERROR: Config file [wp-config.php] was not found. Set a correct $sApproot pointing to wordpress install dir.');
}
require($sConfigfile);
$aDb=[
'server' => DB_HOST,
'username' => DB_USER,
'password' => DB_PASSWORD,
'database' => DB_NAME,
// 'port' => ??,
];
// ----------------------------------------------------------------------
// checks
// ----------------------------------------------------------------------
$oMonitor->addCheck(
[
"name" => "config file",
"description" => "The config file must be writable",
"check" => [
"function" => "File",
"params" => [
"filename" => $sConfigfile,
"file" => true,
"readable" => true,
"writable" => true,
],
],
]
);
$oMonitor->addCheck(
[
"name" => "Mysql Connect",
"description" => "Connect mysql server " . $aDb['server'] . " as user " . $aDb['username'] . " to scheme " . $aDb['database'],
"parent" => "config file",
"check" => [
"function" => "MysqlConnect",
"params" => [
"server" => $aDb['server'],
"user" => $aDb['username'],
"password" => $aDb['password'],
"db" => $aDb['database'],
// "port" => $aDb['port'],
],
],
]
);
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']){
$oMonitor->addCheck(
[
"name" => "Certificate check",
"description" => "Check if SSL cert is valid and does not expire soon",
"check" => [
"function" => "Cert",
],
]
);
}
// ----------------------------------------------------------------------
require 'inc_appcheck_end.php';
// ----------------------------------------------------------------------
<?php
/*
TEST CLIENT CHECKS
*/
// ----------------------------------------------------------------------
// INIT
$sApproot = str_replace('\\', '/', dirname(__DIR__));
// require_once(__DIR__.'/../classes/client_all_in_one.php');
// echo "OK: file client_all_in_one.php was loaded\n";
require_once(__DIR__.'/../classes/appmonitor-client.class.php');
$oMonitor = new appmonitor();
$oMonitor->listChecks();
echo "OK: class appmonitor was initialized\n";
// ----------------------------------------------------------------------
$oMonitor->addTag('monitoring');
// ----------------------------------------------------------------------
$oMonitor->addCheck(
[
"name" => "check config subdir",
"description" => "Check config target directory",
"check" => [
"function" => "File",
"params" => [
"filename" => $sApproot . "/server/config",
"dir" => true,
"writable" => true,
],
],
]
);
echo "OK: the plugin File check was added.\n";
// ----------------------------------------------------------------------
$oMonitor->setResult();
echo "OK: setResult() was executed.\n";
// ----------------------------------------------------------------------
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment