Skip to content
Snippets Groups Projects
Commit ca923db0 authored by hahn's avatar hahn
Browse files

update appmonitor client scripts

parent 9fb0c666
No related branches found
No related tags found
1 merge request!17update appmonitor client scripts
...@@ -119,6 +119,7 @@ class appmonitorcheck { ...@@ -119,6 +119,7 @@ class appmonitorcheck {
"name" => $this->_aConfig["name"], "name" => $this->_aConfig["name"],
"description" => $this->_aConfig["description"], "description" => $this->_aConfig["description"],
"group" => isset($this->_aConfig["group"]) ? $this->_aConfig["group"] : false, "group" => isset($this->_aConfig["group"]) ? $this->_aConfig["group"] : false,
"parent" => isset($this->_aConfig["parent"]) ? $this->_aConfig["parent"] : false,
"result" => RESULT_UNKNOWN, "result" => RESULT_UNKNOWN,
"value" => false, "value" => false,
"type" => false, "type" => false,
......
...@@ -54,7 +54,7 @@ class appmonitor { ...@@ -54,7 +54,7 @@ class appmonitor {
* value is in seconds * value is in seconds
* @var int * @var int
*/ */
protected $_sVersion = 'php-client-v0.99'; protected $_sVersion = 'php-client-v0.109';
/** /**
* config: default ttl for server before requesting the client check again * config: default ttl for server before requesting the client check again
......
{
"meta": {
"host": "my-computer",
"website": "localhost",
"ttl": 300,
"result": 1
},
"checks": [
{
"name": "simple ok",
"description": "Very simple test",
"result": 0,
"value": "The appmonitor client is reachable."
},
{
"name": "simple unknown",
"description": "a dummy test with unknown status",
"result": 1,
"value": "any message"
},
{
"name": "simple warning",
"description": "a dummy warning",
"result": 2,
"value": "warning message"
},
{
"name": "dummy error",
"description": "a dummy error test",
"result": 3,
"value": "ERROR: the error message was not found"
}
]
}
\ No newline at end of file
<?php
/* ______________________________________________________________________
*
* A P P M O N I T O R :: CLIENT - CHECK :: GENERAL INCLUDE
* ______________________________________________________________________
*
* The idea behind is to a file with the same actions on all your
* installations and hosts that can be deployed by a software delivery service
* (Puppet, Ansible, ...)
*
* Instruction:
* (1) copy sample file to general_include.php and enable wished features below
* (2) in your checks enable it by
* @include 'general_include.php';
* see index.sample.php too
*
* @author: Axel Hahn
* ----------------------------------------------------------------------
* 2018-06-30 v0.1
*/
// ----------------------------------------------------------------------
// SECURITY STUFF ... protect access to monitoring data
// ----------------------------------------------------------------------
// --- check an IP range of allowed clients
/*
$oMonitor->checkIp(array(
'127.0.0.1',
'::1',
'192.168.',
));
*/
// --- check a token
// an incoming request must have the param ?token=123
// $oMonitor->checkToken('token', '123');
// ----------------------------------------------------------------------
// NOTIFICATION
// ----------------------------------------------------------------------
// $oMonitor->addEmail('sysadmin@example.com');
// $oMonitor->addSlackWebhook(array("mywebhook"=> "https://hooks.slack.com/services/(...)"));
...@@ -27,7 +27,7 @@ $sCfgfile='../../config/inc_projects_config.php'; ...@@ -27,7 +27,7 @@ $sCfgfile='../../config/inc_projects_config.php';
$oMonitor->addCheck( $oMonitor->addCheck(
array( array(
"name" => "read Cfg file", "name" => "read config file",
"description" => "Check if config file is readable", "description" => "Check if config file is readable",
"check" => array( "check" => array(
"function" => "File", "function" => "File",
...@@ -66,6 +66,7 @@ foreach (array( ...@@ -66,6 +66,7 @@ foreach (array(
array( array(
"name" => "dir $sKey", "name" => "dir $sKey",
"description" => $aItem['descr'], "description" => $aItem['descr'],
"parent" => "read config file",
"check" => array( "check" => array(
"function" => "File", "function" => "File",
"params" => array( "params" => array(
...@@ -83,6 +84,7 @@ $oMonitor->addCheck( ...@@ -83,6 +84,7 @@ $oMonitor->addCheck(
"description" => "The file storage must have some space left", "description" => "The file storage must have some space left",
"check" => array( "check" => array(
"function" => "Diskfree", "function" => "Diskfree",
"parent" => "read config file",
"params" => array( "params" => array(
"directory" => $aConfig['archiveDir'], "directory" => $aConfig['archiveDir'],
"warning" => "2GB", "warning" => "2GB",
...@@ -115,6 +117,7 @@ $oMonitor->addCheck( ...@@ -115,6 +117,7 @@ $oMonitor->addCheck(
"name" => "ci projects", "name" => "ci projects",
"description" => "Count of Projects in CI Webgui", "description" => "Count of Projects in CI Webgui",
"group" => "monitor", "group" => "monitor",
"parent" => "read config file",
"check" => array( "check" => array(
"function" => "Simple", "function" => "Simple",
"params" => array( "params" => array(
...@@ -131,6 +134,7 @@ $oMonitor->addCheck( ...@@ -131,6 +134,7 @@ $oMonitor->addCheck(
"name" => "ci inProgress", "name" => "ci inProgress",
"description" => "Projects in progress", "description" => "Projects in progress",
"group" => "monitor", "group" => "monitor",
"parent" => "read config file",
"check" => array( "check" => array(
"function" => "Simple", "function" => "Simple",
"params" => array( "params" => array(
...@@ -147,6 +151,7 @@ $oMonitor->addCheck( ...@@ -147,6 +151,7 @@ $oMonitor->addCheck(
"name" => "ci hasqueue", "name" => "ci hasqueue",
"description" => "Waiting for install", "description" => "Waiting for install",
"group" => "monitor", "group" => "monitor",
"parent" => "read config file",
"check" => array( "check" => array(
"function" => "Simple", "function" => "Simple",
"params" => array( "params" => array(
...@@ -159,17 +164,7 @@ $oMonitor->addCheck( ...@@ -159,17 +164,7 @@ $oMonitor->addCheck(
) )
); );
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']){ include 'plugins/apps/shared_check_ssl.php';
$oMonitor->addCheck(
array(
"name" => "Certificate check",
"description" => "Check if SSL cert is valid and does not expire soon",
"check" => array(
"function" => "Cert",
),
)
);
}
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
...@@ -196,6 +191,7 @@ if(isset($aConfig['foreman']['api'])){ ...@@ -196,6 +191,7 @@ if(isset($aConfig['foreman']['api'])){
"name" => "Foreman $sForemanKey", "name" => "Foreman $sForemanKey",
"description" => "Count of Foreman $sForemanKey", "description" => "Count of Foreman $sForemanKey",
"group" => "monitor", "group" => "monitor",
"parent" => "read config file",
"check" => array( "check" => array(
"function" => "Simple", "function" => "Simple",
"params" => array( "params" => array(
...@@ -233,6 +229,7 @@ if(count($aConfig['mirrorPackages'])){ ...@@ -233,6 +229,7 @@ if(count($aConfig['mirrorPackages'])){
"name" => "mirror target $sHostKey", "name" => "mirror target $sHostKey",
"description" => "Sync target of generated packages", "description" => "Sync target of generated packages",
"group" => "network", "group" => "network",
"parent" => "read config file",
"check" => array( "check" => array(
"function" => "Simple", "function" => "Simple",
"params" => array( "params" => array(
...@@ -269,6 +266,7 @@ foreach(array( ...@@ -269,6 +266,7 @@ foreach(array(
"name" => 'port check '.$aDescr['host'].':'.$aDescr['port'], "name" => 'port check '.$aDescr['host'].':'.$aDescr['port'],
"description" => $aDescr['descr'], "description" => $aDescr['descr'],
"group" => "cloud", "group" => "cloud",
"parent" => "read config file",
"check" => array( "check" => array(
"function" => "PortTcp", "function" => "PortTcp",
"params" => array( "params" => array(
...@@ -290,6 +288,7 @@ $oMonitor->addCheck( ...@@ -290,6 +288,7 @@ $oMonitor->addCheck(
array( array(
"name" => "Sqlite DB for action logs", "name" => "Sqlite DB for action logs",
"description" => "Connect sqlite db ". basename($sSqlitefile), "description" => "Connect sqlite db ". basename($sSqlitefile),
"parent" => "read config file",
"check" => array( "check" => array(
"function" => "SqliteConnect", "function" => "SqliteConnect",
"params" => array( "params" => array(
...@@ -306,6 +305,7 @@ $oMonitor->addCheck( ...@@ -306,6 +305,7 @@ $oMonitor->addCheck(
array( array(
"name" => "plugin Load", "name" => "plugin Load",
"description" => "current load", "description" => "current load",
"parent" => false,
"check" => array( "check" => array(
"function" => "Loadmeter", "function" => "Loadmeter",
"params" => array( "params" => array(
...@@ -320,6 +320,7 @@ $oMonitor->addCheck( ...@@ -320,6 +320,7 @@ $oMonitor->addCheck(
array( array(
"name" => "plugin ApacheProcesses", "name" => "plugin ApacheProcesses",
"description" => "Apache processes", "description" => "Apache processes",
"parent" => false,
"check" => array( "check" => array(
"function" => "ApacheProcesses", "function" => "ApacheProcesses",
"params" => array( "params" => array(
......
<?php
/* ______________________________________________________________________
*
* A P P M O N I T O R :: CLIENT - CHECK :: SAMPLE
* ______________________________________________________________________
*
* this is a sample file for the appmonitor client
* copy the sample file to index.php and modify it as needed (see ../readme.md).
*
*/
require_once('classes/appmonitor-client.class.php');
$oMonitor = new appmonitor();
// set a name with application name and environment or hostname
$oMonitor->setWebsite('[My CMS on host XY]');
// how often the server should ask for updates
$oMonitor->setTTL(300);
// a general include ... the idea is to a file with the same actions on all
// installations and hosts that can be deployed by a software delivery service
// (Puppet, Ansible, ...)
@include 'general_include.php';
// add any tag to add it in the filter list in the server web gui
// $oMonitor->addTag('cms');
// $oMonitor->addTag('production');
// ----------------------------------------------------------------------
// include default checks for an application
// @require 'plugins/apps/[name-of-app].php';
// add a few custom checks
// $oMonitor->addCheck(...)
$oMonitor->addCheck(
array(
"name" => "hello plugin",
"description" => "Test a plugin ... plugins/checks/hello.php",
"check" => array(
"function" => "Hello",
"params" => array(
"message" => "Here I am",
),
),
)
);
// ----------------------------------------------------------------------
$oMonitor->setResult();
$oMonitor->render();
// ----------------------------------------------------------------------
<?php
/* ______________________________________________________________________
*
* A P P M O N I T O R :: CLIENT - CHECKS for server instance
* ______________________________________________________________________
*
* requires variable $sApproot
*
* @author: Axel Hahn
* ----------------------------------------------------------------------
* 2019-04-29 aded check for ssl cert; removed a check
* 2019-05-17 aded check http to config- and tmp dir
* 2021-11-nn removed all checks ... created as single files
* 2022-03-28 move checks into plugins/apps/
*/
// ----------------------------------------------------------------------
// files and dirs
// ----------------------------------------------------------------------
$oMonitor->addCheck(
array(
"name" => "write to ./tmp/",
"description" => "Check cache storage",
// "group" => "folder",
"check" => array(
"function" => "File",
"params" => array(
"filename" => $sApproot . "/server/tmp",
"dir" => true,
"writable" => true,
),
),
)
);
$oMonitor->addCheck(
array(
"name" => "write to ./config/",
"description" => "Check config target directory",
// "group" => "folder",
"check" => array(
"function" => "File",
"params" => array(
"filename" => $sApproot . "/server/config",
"dir" => true,
"writable" => true,
),
),
)
);
$oMonitor->addCheck(
array(
"name" => "check config file",
"description" => "The config file must be writable",
"parent" => "write to ./config/",
// "group" => "file",
"check" => array(
"function" => "File",
"params" => array(
"filename" => $sApproot . "/server/config/appmonitor-server-config.json",
"file" => true,
"writable" => true,
),
),
)
);
// ----------------------------------------------------------------------
// protect dirs against web access
// specialty: if the test results in an error, the total result switches
// to WARNING -> see worstresult value
// ----------------------------------------------------------------------
$sBaseUrl = 'http'.(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] ? 's' : '')
.'://'.$_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT']
.dirname(dirname($_SERVER['REQUEST_URI']));
foreach(array('server/config', 'server/tmp') as $sMyDir){
$oMonitor->addCheck(
array(
"name" => "http to $sMyDir",
"description" => "Check if the $sMyDir directory is not accessible (counts as warning on fail)",
"group" => "deny",
"check" => array(
"function" => "HttpContent",
"params" => array(
"url" => $sBaseUrl . "/$sMyDir/readme.md",
"status" => 403,
),
),
"worstresult" => RESULT_WARNING
)
);
}
// ----------------------------------------------------------------------
// count of current projects
// ----------------------------------------------------------------------
require_once($sApproot.'/server/classes/appmonitor-server.class.php');
$oServer=new appmonitorserver();
$iCount=count($oServer->apiGetAppIds());
$oMonitor->addCheck(
array(
"name" => "appcounter",
"description" => "Monitored apps",
"group" => "monitor",
"parent" => "check config file",
"check" => array(
"function" => "Simple",
"params" => array(
"result" => RESULT_OK,
"value" => "Found monitored web apps: $iCount",
"count" => $iCount,
"visual" => "simple",
),
),
)
);
// ----------------------------------------------------------------------
// check running service
// ----------------------------------------------------------------------
require_once($sApproot.'/server/classes/tinyservice.class.php');
ob_start();
$oService = new tinyservice($sApproot.'/server/service.php', 15, $sApproot.'/server/tmp');
$sIsStopped=$oService->canStart();
$out=ob_get_contents();
ob_clean();
$oMonitor->addCheck(
array(
"name" => "running service",
"description" => "Check if the service is running",
"group" => "service",
"check" => array(
"function" => "Simple",
"params" => array(
"result" => ($sIsStopped ? RESULT_WARNING : RESULT_OK),
"value" => ($sIsStopped
? "Info: Service is NOT running. Apps are checked interactively only (if the appmonitor web ui is running). | Output: $out"
: "OK, service is running. | Output: $out"
),
),
),
"worstresult" => RESULT_OK
)
);
// ----------------------------------------------------------------------
// check certificate if https is used
// ----------------------------------------------------------------------
include 'shared_check_ssl.php';
// ----------------------------------------------------------------------
// plugin test
// ----------------------------------------------------------------------
/*
*
* AS A DEMO: using a custom plugin:
*
$oMonitor->addCheck(
array(
"name" => "plugin test",
"description" => "minimal test of the plugin plugins/checkHello.php",
"check" => array(
"function" => "Hello",
"params" => array(
"message" => "Here I am",
),
),
)
);
$oMonitor->addCheck(
array(
"name" => "plugin Load",
"description" => "check current load",
"check" => array(
"function" => "Loadmeter",
"params" => array(
"warning" => 1.0,
"error" => 3,
),
),
"worstresult" => RESULT_OK
)
);
$oMonitor->addCheck(
array(
"name" => "plugin ApacheProcesses",
"description" => "check count running Apache processes",
"check" => array(
"function" => "ApacheProcesses",
"params" => array(
),
),
"worstresult" => RESULT_OK
)
);
*/
// ----------------------------------------------------------------------
<?php
/* ______________________________________________________________________
*
* A P P M O N I T O R :: GENERIC CHECK SSL CERT
*
* If https is enabled on standard port 443 the validity of the
* certificate.
* If the current appplication uses http only this check does nothing.
*
* ______________________________________________________________________
*
* @author: Axel Hahn
* ----------------------------------------------------------------------
* 2022-03-28 created
*/
// ----------------------------------------------------------------------
// check certificate - only if https is used
// ----------------------------------------------------------------------
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']){
$oMonitor->addCheck(
array(
"name" => "Certificate check",
"description" => "Check if SSL cert is valid and does not expire soon",
"check" => array(
"function" => "Cert",
),
)
);
}
// ----------------------------------------------------------------------
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment