diff --git a/public_html/appmonitor/classes/appmonitor-checks.class.php b/public_html/appmonitor/classes/appmonitor-checks.class.php old mode 100644 new mode 100755 index 525aed631b57ab5c127226b72e45dda8e9dde1a7..dfff0ea6cb859808aacf89ff647b5122ee2886c6 --- a/public_html/appmonitor/classes/appmonitor-checks.class.php +++ b/public_html/appmonitor/classes/appmonitor-checks.class.php @@ -50,8 +50,9 @@ if(!defined('RESULT_OK')){ * 2019-06-05 0.88 axel.hahn@iml.unibe.ch add plugins<br> * 2021-10-28 0.93 axel.hahn@iml.unibe.ch add plugins<br> * 2021-12-14 0.93 axel.hahn@iml.unibe.ch split plugins into single files; added key group in a check<br> + * 2023-06-02 0.125 axel.hahn@unibe.ch replace array_key_exists for better readability * --------------------------------------------------------------------------------<br> - * @version 0.99 + * @version 0.125 * @author Axel Hahn * @link TODO * @license GPL @@ -63,24 +64,30 @@ class appmonitorcheck { // CONFIG // ---------------------------------------------------------------------- + /** + * starting time using microtime + * @var float|string + */ + protected $_iStart=0; + /** * config container * @var array */ - protected $_aConfig = array(); + protected $_aConfig = []; /** * data of all checks * @var array */ - protected $_aData = array(); + protected $_aData = []; /** * flat array with units for sizes * @var array */ - protected $_units = array( 'B', 'KB', 'MB', 'GB', 'TB'); + protected $_units = [ 'B', 'KB', 'MB', 'GB', 'TB' ]; /** * timeout in sec for tcp socket connections @@ -115,7 +122,7 @@ class appmonitorcheck { */ protected function _createDefaultMetadata() { - $this->_aData = array( + $this->_aData = [ "name" => $this->_aConfig["name"], "description" => $this->_aConfig["description"], "group" => isset($this->_aConfig["group"]) ? $this->_aConfig["group"] : false, @@ -124,7 +131,7 @@ class appmonitorcheck { "value" => false, "type" => false, "time" => false, - ); + ]; return true; } @@ -153,7 +160,7 @@ class appmonitorcheck { */ protected function _setCounter($aParams){ if(is_array($aParams) && count($aParams)){ - foreach(array('type', 'count', 'visual') as $sMyKey){ + foreach([ 'type', 'count', 'visual' ] as $sMyKey){ if(isset($aParams[$sMyKey])){ $this->_aData[$sMyKey]=$aParams[$sMyKey]; } @@ -169,7 +176,7 @@ class appmonitorcheck { * @param array $aCounter optional: counter with array keys type, count, visual * @return boolean */ - protected function _setReturn($iResult, $s, $aCounter=array()) { + protected function _setReturn($iResult, $s, $aCounter=[]) { $this->_setResult($iResult); $this->_setOutput($s); $this->_setCounter($aCounter); @@ -184,7 +191,7 @@ class appmonitorcheck { */ protected function _checkArrayKeys($aConfig, $sKeyList) { foreach (explode(",", $sKeyList) as $sKey) { - if (!array_key_exists($sKey, $aConfig)) { + if (!isset($aConfig[$sKey])) { header('HTTP/1.0 503 Service Unavailable'); die('<h1>503 Service Unavailable</h1>' . '<h2>Details</h2>' @@ -212,15 +219,15 @@ class appmonitorcheck { * perform a check * @param type $aConfig * Array - * ( + * [ * [name] => Dummy * [description] => Dummy Test - * [check] => array( + * [check] => [ * [function] => [check function] // i.e. Simple * [params] => [array] // optional; arguments for Check function * // its keys depend on the function - * ) - * ) + * ] + * ] * * @return array */ @@ -233,7 +240,7 @@ class appmonitorcheck { $this->_createDefaultMetadata(); $sCheck = preg_replace('/[^a-zA-Z0-9]/', '', $this->_aConfig["check"]["function"]); - $aParams = array_key_exists("params", $this->_aConfig["check"]) ? $this->_aConfig["check"]["params"] : array(); + $aParams = $this->_aConfig["check"]["params"] ?? []; // try to load as plugin from a plugin file $sPluginFile= strtolower($this->_sPluginDir.'/checks/'.$sCheck.'.php'); @@ -276,7 +283,7 @@ class appmonitorcheck { ); } if(!isset($aResponse[2])){ - $aResponse[2]=array(); + $aResponse[2]=[]; } $this->_setReturn($aResponse[0], $aResponse[1], $aResponse[2]); if (!$this->_aData['group'] && method_exists($oPlugin, "getGroup")){ @@ -295,7 +302,7 @@ class appmonitorcheck { * @return array */ public function listChecks() { - $aReturn = array(); + $aReturn = []; // return internal protected fuctions named "check[whatever]" $class = new ReflectionClass($this); foreach ($class->getMethods(ReflectionMethod::IS_PROTECTED) as $oReflectionMethod) { @@ -336,24 +343,24 @@ class appmonitorcheck { $sHost = isset($aUrldata['host']) ? $aUrldata['host'] : false; $iPort = isset($aUrldata['port']) ? $aUrldata['port'] : ((isset($aUrldata['scheme']) && $aUrldata['scheme'] === 'https') ? 443 : false); - $aSsl=array('capture_peer_cert' => true); + $aSsl=['capture_peer_cert' => true ]; if($bVerifyCert){ $aSsl['verify_peer']=false; $aSsl['verify_peer_name']=false; }; - $get = stream_context_create(array('ssl' => $aSsl)); + $get = stream_context_create([ 'ssl' => $aSsl ]); if(!$get){ - return array('_error' => 'Error: Cannot create stream_context'); + return [ '_error' => 'Error: Cannot create stream_context' ]; } $errno=-1; $errstr="stream_socket_client failed."; $read = stream_socket_client("ssl://$sHost:$iPort", $errno, $errstr, $iTimeout, STREAM_CLIENT_CONNECT, $get); if(!$read){ - return array('_error' => "Error $errno: $errstr; cannot create stream_socket_client with given stream_context to ssl://$sHost:$iPort; you can try to set the flag [verify] to false to check expiration date only."); + return [ '_error' => "Error $errno: $errstr; cannot create stream_socket_client with given stream_context to ssl://$sHost:$iPort; you can try to set the flag [verify] to false to check expiration date only." ]; } $cert = stream_context_get_params($read); if(!$cert){ - return array('_error' => "Error: socket was connected to ssl://$sHost:$iPort - but I cannot read certificate infos with stream_context_get_params "); + return [ '_error' => "Error: socket was connected to ssl://$sHost:$iPort - but I cannot read certificate infos with stream_context_get_params " ]; } $certinfo = openssl_x509_parse($cert['options']['ssl']['peer_certificate']); return $certinfo; @@ -362,7 +369,7 @@ class appmonitorcheck { /** * get human readable space value - * @param type $size + * @param integer $size * @return string */ protected function _getHrSize($size){ @@ -371,7 +378,7 @@ class appmonitorcheck { } /** * get a space in a real value if an integer has added MB|GB|... - * @param type $sValue + * @param string $sValue * @return integer */ protected function _getSize($sValue){ @@ -399,12 +406,12 @@ class appmonitorcheck { /** * compare function for 2 values - * @param any $verifyValue search value + * @param string $verifyValue search value * @param string $sCompare compare function; it is one of * IS - * GE - greater or equal * GT - greater - * @param any $value existing value + * @param string $value existing value * @return boolean */ protected function _compare($value, $sCompare, $verifyValue){ diff --git a/public_html/appmonitor/classes/appmonitor-client.class.php b/public_html/appmonitor/classes/appmonitor-client.class.php old mode 100644 new mode 100755 index 711c8e457f2bdd56708d42c8d2a611d6d8a1cf4f..7b026cf6f9f2d18f504148e6983d5844944450ee --- a/public_html/appmonitor/classes/appmonitor-client.class.php +++ b/public_html/appmonitor/classes/appmonitor-client.class.php @@ -75,14 +75,14 @@ class appmonitor { * @see _createDefaultMetadata() * @var array */ - protected $_aMeta = array(); + protected $_aMeta = []; /** * repended array of all checks * @see addCheck() * @var array */ - protected $_aChecks = array(); + protected $_aChecks = []; /** * for time measurements: start time @@ -107,14 +107,14 @@ class appmonitor { */ protected function _createDefaultMetadata() { $this->_iStart = microtime(true); - $this->_aMeta = array( + $this->_aMeta = [ "host" => false, "website" => false, "ttl" => false, "result" => false, "time" => false, "version" => $this->_sVersion, - ); + ]; // fill with default values $this->setHost(); @@ -192,7 +192,7 @@ class appmonitor { * @param type $aJob * @return type */ - public function addCheck($aJob = array()) { + public function addCheck($aJob = []) { require_once 'appmonitor-checks.class.php'; $oCheck = new appmonitorcheck(); @@ -221,10 +221,10 @@ class appmonitor { protected function _addNotification($sType, $sValue, $sKey = false) { $sTypeCleaned = preg_replace('/[^a-z]/', '', strtolower($sType)); if (!isset($this->_aMeta['notifications'])) { - $this->_aMeta['notifications'] = array(); + $this->_aMeta['notifications'] = []; } if (!isset($this->_aMeta['notifications'][$sTypeCleaned])) { - $this->_aMeta['notifications'][$sTypeCleaned] = array(); + $this->_aMeta['notifications'][$sTypeCleaned] = []; } if ($sKey) { $this->_aMeta['notifications'][$sTypeCleaned][$sKey] = $sValue; @@ -262,7 +262,7 @@ class appmonitor { */ public function addTag($sTag) { if(!isset($this->_aMeta['tags'])){ - $this->_aMeta['tags']=array(); + $this->_aMeta['tags']=[]; } $this->_aMeta['tags'][]=$sTag; return true; @@ -277,7 +277,7 @@ class appmonitor { * the ip must match from the beginning, i.e. * "127.0." will allow requests from 127.0.X.Y */ - public function checkIp($aAllowedIps = array()) { + public function checkIp($aAllowedIps = []) { if (!isset($_SERVER['REMOTE_ADDR']) || !count($aAllowedIps)) { return true; } @@ -335,7 +335,7 @@ class appmonitor { * verify array values and in case of an error abort and show all found errors */ protected function _checkData() { - $aErrors = array(); + $aErrors = []; if (!count($this->_aChecks)) { $aErrors[] = "No checks have been defined."; @@ -372,10 +372,10 @@ class appmonitor { * @return type */ public function getResults() { - return array( + return [ "meta" => $this->_aMeta, "checks" => $this->_aChecks, - ); + ]; } /** @@ -397,12 +397,12 @@ class appmonitor { } else { $sOut = json_encode($this->getResults(), JSON_PRETTY_PRINT); if ($bHighlight) { - $aMsg = array( + $aMsg = [ 0 => "OK", 1 => "UNKNOWN", 2 => "WARNING", 3 => "ERROR" - ); + ]; foreach (array_keys($aMsg) as $iCode) { $sOut = preg_replace('/(\"result\":\ ' . $iCode . ')/', '$1 <span class="result' . $iCode . '"> <--- ' . $aMsg[$iCode] . ' </span>', $sOut); } @@ -464,12 +464,12 @@ class appmonitor { header('Content-type: text/html'); header('Cache-Control: cache'); header('max-age: ' . $this->_aMeta["ttl"]); - $aMsg = array( + $aMsg = [ 0 => "OK", 1 => "UNKNOWN", 2 => "WARNING", 3 => "ERROR" - ); + ]; // $sOut = print_r($sJson, 1); $aData= json_decode($sJson, 1); diff --git a/public_html/appmonitor/git_update_appmonitor.sh b/public_html/appmonitor/git_update_appmonitor.sh old mode 100644 new mode 100755 diff --git a/public_html/appmonitor/plugins/apps/iml-appmonitor-server.php b/public_html/appmonitor/plugins/apps/iml-appmonitor-server.php old mode 100644 new mode 100755 diff --git a/public_html/appmonitor/plugins/apps/shared_check_ssl.php b/public_html/appmonitor/plugins/apps/shared_check_ssl.php index bdf8e68db39a774d3b64c9f2af386cf636600ece..c2f45b778e14194367197b336351205646034ce9 100644 --- a/public_html/appmonitor/plugins/apps/shared_check_ssl.php +++ b/public_html/appmonitor/plugins/apps/shared_check_ssl.php @@ -20,13 +20,13 @@ // ---------------------------------------------------------------------- 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( + "check" => [ "function" => "Cert", - ), - ) + ], + ] ); } diff --git a/public_html/appmonitor/plugins/checks/apacheprocesses.php b/public_html/appmonitor/plugins/checks/apacheprocesses.php old mode 100644 new mode 100755 index f2175375e7f1a580ceb4e50e284b107c894b79ef..aba2f3e657d1355080872511cd9bf9112f6cae07 --- a/public_html/appmonitor/plugins/checks/apacheprocesses.php +++ b/public_html/appmonitor/plugins/checks/apacheprocesses.php @@ -26,19 +26,19 @@ * Example with overriding all existing params * * $oMonitor->addCheck( - * array( + * [ * "name" => "plugin ApacheProcesses", * "description" => "check count running Apache processes", - * "check" => array( + * "check" => [ * "function" => "ApacheProcesses", - * "params" => array( + * "params" => [ * "url" => "https://localhost/status", * "warning" => 75, * "error" => 90, - * ), - * ), + * ], + * ], * "worstresult" => RESULT_OK - * ) + * ] * ); * ____________________________________________________________________________ * @@ -63,7 +63,7 @@ class checkApacheProcesses extends appmonitorcheck{ return false; } $sRegexScoreboard = '/<pre>(.*)\<\/pre\>/U'; - $aScore=array(); + $aScore=[]; $sStatusNobr = str_replace("\n", "", $sBody); if (preg_match_all($sRegexScoreboard, $sStatusNobr, $aTmpTable)) { @@ -142,17 +142,17 @@ class checkApacheProcesses extends appmonitorcheck{ // count => {float} value // visual => {string} one of bar|line|simple (+params) // - return array( + return [ $iResult, ($iActive===false ? 'Apache httpd server status is not available' : 'apache processes: '.print_r($aProcesses, 1)).' '.$sComment, ($iActive===false - ? array() - : array( + ? [] + : [ 'type'=>'counter', 'count'=>$iActive, 'visual'=>'line', - ) + ] ) - ); + ]; } } diff --git a/public_html/appmonitor/plugins/checks/cert.php b/public_html/appmonitor/plugins/checks/cert.php old mode 100644 new mode 100755 index ec5cca3331719fcdc170ad2bc92ba4a514702f30..e83fa9e30b85d8bc348fe1d0d794cf2a24ce0fb2 --- a/public_html/appmonitor/plugins/checks/cert.php +++ b/public_html/appmonitor/plugins/checks/cert.php @@ -22,17 +22,17 @@ * USAGE: * * $oMonitor->addCheck( - * array( + * [ * "name" => "SSL cert", * "description" => "Check SSL certificate of my domain", - * "check" => array( + * "check" => [ * "function" => "Cert", - * "params" => array( + * "params" => [ * "url" => "https://www.example.com", * "warning" => "30", - * ), - * ), - * ) + * ], + * ], + * ] * ); * ____________________________________________________________________________ * @@ -54,12 +54,12 @@ class checkCert extends appmonitorcheck{ /** * check SSL certificate * @param array $aParams - * array( + * [ * "url" optional: url to connect check; default: own protocol + server * "verify" optional: flag for verification of certificate or check for expiration only; default=true (=verification is on) * "warning" optional: count of days to warn; default=21 (=3 weeks) * "critical" optional: count of days to raise critical; default=5 - * ) + * ] * @return boolean */ public function run($aParams) { diff --git a/public_html/appmonitor/plugins/checks/diskfree.php b/public_html/appmonitor/plugins/checks/diskfree.php old mode 100644 new mode 100755 index 667dfeb00b9445b6d57aecca7b208198cd3f4056..403c94e50e6bce1b3bd550cd5b4f16691450f78f --- a/public_html/appmonitor/plugins/checks/diskfree.php +++ b/public_html/appmonitor/plugins/checks/diskfree.php @@ -33,11 +33,11 @@ class checkDiskfree extends appmonitorcheck{ /** * check free disk space on a given directory * @param array $aParams - * array( + * [ * "directory" directory that must exist * "warning" space for warning (optional) * "critical" minimal space - * ) + * ] * @return boolean */ public function run($aParams) { diff --git a/public_html/appmonitor/plugins/checks/exec.php b/public_html/appmonitor/plugins/checks/exec.php index a343cd9fcaa323174a1156b6fefcf03838c48df2..05ff55da9f7d658d1925772d12e6ec3c8a5a6720 100644 --- a/public_html/appmonitor/plugins/checks/exec.php +++ b/public_html/appmonitor/plugins/checks/exec.php @@ -35,7 +35,7 @@ class checkExec extends appmonitorcheck{ /** * check execution of a command * @param array $aParams - * array( + * [ * "command" {string} command to execute * "output" {bool} flag: show output; default: true * @@ -47,7 +47,7 @@ class checkExec extends appmonitorcheck{ * "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) { diff --git a/public_html/appmonitor/plugins/checks/file.php b/public_html/appmonitor/plugins/checks/file.php old mode 100644 new mode 100755 index c19b85dd2f7cc388a8c64a803d5c58fa9232a04c..590ac778c1c43c17c380c5c05892808ddc724be4 --- a/public_html/appmonitor/plugins/checks/file.php +++ b/public_html/appmonitor/plugins/checks/file.php @@ -45,7 +45,7 @@ class checkFile extends appmonitorcheck{ /** * check a file * @param array $aParams - * array( + * [ * "filename" directory that must exist * "exists" "filename" must exist/ must be absent * "dir" filetype directory @@ -54,12 +54,12 @@ class checkFile extends appmonitorcheck{ * "executable" flag executable * "readable" flag is readable * "writable" flag is writable - * ) + * ] * @return boolean */ public function run($aParams) { - $aOK = array(); - $aErrors = array(); + $aOK = []; + $aErrors = []; $this->_checkArrayKeys($aParams, "filename"); $sFile = $aParams["filename"]; @@ -71,7 +71,7 @@ class checkFile extends appmonitorcheck{ $aErrors[] = $sMyflag; } } - foreach (array('dir', 'executable', 'file', 'link', 'readable', 'writable') as $sFiletest) { + foreach ([ 'dir', 'executable', 'file', 'link', 'readable', 'writable' ] as $sFiletest) { if (isset($aParams[$sFiletest])) { $sTestCmd = 'return is_' . $sFiletest . '("' . $sFile . '");'; if (eval($sTestCmd) && $aParams[$sFiletest]) { diff --git a/public_html/appmonitor/plugins/checks/hello.php b/public_html/appmonitor/plugins/checks/hello.php old mode 100644 new mode 100755 index 8e1d9349375d591560796d8d560c040389286220..ebeb98184e1921e8de1df64505511c567808077e --- a/public_html/appmonitor/plugins/checks/hello.php +++ b/public_html/appmonitor/plugins/checks/hello.php @@ -26,16 +26,16 @@ * USAGE: * * $oMonitor->addCheck( - * array( + * [ * "name" => "hello plugin", * "description" => "test a plugin ... plugins/checkHello.php", - * "check" => array( + * "check" => [ * "function" => "Hello", - * "params" => array( + * "params" => [ * "message" => "Here I am", - * ), - * ), - * ) + * ], + * ], + * ] * ); * ____________________________________________________________________________ * @@ -69,9 +69,9 @@ class checkHello extends appmonitorcheck{ // count => {float} value // visual => {string} one of bar|line|simple (+params) // - return array( + return [ RESULT_OK, 'Hello world! My message is: ' .$aParams['message'] - ); + ]; } } diff --git a/public_html/appmonitor/plugins/checks/httpcontent.php b/public_html/appmonitor/plugins/checks/httpcontent.php old mode 100644 new mode 100755 index d924c59a2b4c5f08b74d286022a962866fb4a123..abbf1d779067801d619aedb62780321ed2c24397 --- a/public_html/appmonitor/plugins/checks/httpcontent.php +++ b/public_html/appmonitor/plugins/checks/httpcontent.php @@ -18,6 +18,7 @@ * ____________________________________________________________________________ * * 2021-10-26 <axel.hahn@iml.unibe.ch> + * 2022-12-21 <axel.hahn@unibe.ch> add flag sslverify * */ class checkHttpContent extends appmonitorcheck{ @@ -37,11 +38,12 @@ class checkHttpContent extends appmonitorcheck{ /** * make http request and test response body * @param array $aParams - * array( + * [ * url string url to fetch * timeout integer optional timeout in sec; default: 5 * headeronly boolean optional flag to fetch http response herader only; default: false = returns header and body * follow boolean optional flag to follow a location; default: false = do not follow + * sslverify boolean flag: enable/ disable verification of ssl certificate; default: true (verification is on) * status integer test for an expected http status code; if none is given then test fails on status 400 and greater * headercontains string test for a string in the http response header; it returns OK if the text was found * headernotcontains string test for a string in the http response header; it returns OK if the text was not found @@ -49,7 +51,7 @@ class checkHttpContent extends appmonitorcheck{ * bodycontains string test for a string in the http response body; it returns OK if the text was found * bodynotcontains string test for a string in the http response body; it returns OK if the text was not found * bodyregex string test for a regex in the http response body; it returns OK if the regex matches; example: "headerregex"=>"/lowercasematch/i" - * ) + * ] */ public function run($aParams) { $this->_checkArrayKeys($aParams, "url"); @@ -64,7 +66,7 @@ class checkHttpContent extends appmonitorcheck{ curl_setopt($ch, CURLOPT_NOBODY, isset($aParams["headeronly"]) && $aParams["headeronly"]); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, isset($aParams["follow"]) && $aParams["follow"]); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, isset($aParams["sslverify"]) ? !!$aParams["sslverify"] : 1); curl_setopt($ch, CURLOPT_TIMEOUT, (isset($aParams["timeout"]) && (int)$aParams["timeout"]) ? (int)$aParams["timeout"] : $this->_iTimeoutTcp); $res = curl_exec($ch); diff --git a/public_html/appmonitor/plugins/checks/loadmeter.php b/public_html/appmonitor/plugins/checks/loadmeter.php old mode 100644 new mode 100755 index d1a8c16c4f68a07a4ba78636da355e085127fcdb..8bc5daf1b50d94c5ebd320270541b085a937c4d7 --- a/public_html/appmonitor/plugins/checks/loadmeter.php +++ b/public_html/appmonitor/plugins/checks/loadmeter.php @@ -27,18 +27,18 @@ * USAGE: * * $oMonitor->addCheck( - * array( + * [ * "name" => "plugin Load", * "description" => "check current load", - * "check" => array( + * "check" => [ * "function" => "Loadmeter", - * "params" => array( + * "params" => [ * "warning" => 1.0, * "error" => 3, - * ), - * ), + * ], + * ], * "worstresult" => RESULT_OK - * ) + * ] * ); * ____________________________________________________________________________ * @@ -127,17 +127,18 @@ class checkLoadmeter extends appmonitorcheck{ // count => {float} value // visual => {string} one of bar|line|simple (+params) // - return array( + return [ $iResult, ($fLoad===false ? 'load value is not available' : 'current load is: '.$fLoad), ($fLoad===false - ? array() - : array( + ? [] + : [ 'type'=>'counter', 'count'=>$fLoad, 'visual'=>'line', - ) + ] ) - ); + ] + ; } } diff --git a/public_html/appmonitor/plugins/checks/mysqlconnect.php b/public_html/appmonitor/plugins/checks/mysqlconnect.php old mode 100644 new mode 100755 index d386146eba33710b540ce9127a6ce77320ee2a51..713424564a58cf26b850bde803725b2a43a85a8e --- a/public_html/appmonitor/plugins/checks/mysqlconnect.php +++ b/public_html/appmonitor/plugins/checks/mysqlconnect.php @@ -32,14 +32,14 @@ class checkMysqlConnect extends appmonitorcheck{ /** * check mysql connection to a database using mysqli realconnect * @param array $aParams - * array( + * [ * server string database hostname / ip address * user string db user * password string password for db user * db string schema / database name * port integer optional: port * timeout integer optional timeout in sec; default: 5 - * ) + * ] */ public function run($aParams) { $this->_checkArrayKeys($aParams, "server,user,password,db"); diff --git a/public_html/appmonitor/plugins/checks/pdoconnect.php b/public_html/appmonitor/plugins/checks/pdoconnect.php old mode 100644 new mode 100755 index 03f1d221716f61fa17b0f37c24255cce1bb60b47..7f8016b876f376f096360f059f642cf19211c405 --- a/public_html/appmonitor/plugins/checks/pdoconnect.php +++ b/public_html/appmonitor/plugins/checks/pdoconnect.php @@ -34,12 +34,12 @@ class checkPdoConnect extends appmonitorcheck{ * see http://php.net/manual/en/pdo.drivers.php * * @param array $aParams - * array( + * [ * connect string connect string * user string db user * password string password for db user * timeout integer optional timeout in sec; default: 5 - * ) + * ] */ public function run($aParams) { $this->_checkArrayKeys($aParams, "connect,user,password"); @@ -49,7 +49,7 @@ class checkPdoConnect extends appmonitorcheck{ $aParams['connect'], $aParams['user'], $aParams['password'], - array( + [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, // timeout @@ -57,7 +57,7 @@ class checkPdoConnect extends appmonitorcheck{ PDO::ATTR_TIMEOUT => (isset($aParams["timeout"]) && (int)$aParams["timeout"]) ? (int)$aParams["timeout"] : $this->_iTimeoutTcp, // mssql // PDO::SQLSRV_ATTR_QUERY_TIMEOUT => $this->_iTimeoutTcp, - ) + ] ); $db=null; return [RESULT_OK, "OK: Database was connected with PDO " . $aParams['connect']]; diff --git a/public_html/appmonitor/plugins/checks/phpmodules.php b/public_html/appmonitor/plugins/checks/phpmodules.php index 6f40ba054819294542910d2826f25db6a384b42a..29e2874bf2d995a268b3068a1297f40d1ccf41e9 100644 --- a/public_html/appmonitor/plugins/checks/phpmodules.php +++ b/public_html/appmonitor/plugins/checks/phpmodules.php @@ -33,10 +33,10 @@ class checkPhpmodules extends appmonitorcheck{ /** * check if system is listening to a given port * @param array $aParams - * array( + * [ * required array list of required php modules * optional array optional: list of optional php modules - * ) + * ] * @return boolean */ public function run($aParams) { diff --git a/public_html/appmonitor/plugins/checks/ping.php b/public_html/appmonitor/plugins/checks/ping.php index b10397d6a03351c8c3253bcf2ddf3ca298991189..fdb5910f3e31ab73c01fedb9c577016cd4e647b7 100644 --- a/public_html/appmonitor/plugins/checks/ping.php +++ b/public_html/appmonitor/plugins/checks/ping.php @@ -34,14 +34,14 @@ class checkPing extends appmonitorcheck{ /** * 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'; + $sHost = $aParams['host'] ?? '127.0.0.1'; $sParamCount=strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' ? "n" : "c"; $iRepeat=1; @@ -73,10 +73,10 @@ class checkPing extends appmonitorcheck{ $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); @@ -88,11 +88,11 @@ class checkPing extends appmonitorcheck{ socket_close($socket); return [RESULT_OK, "OK: ping to $sHost", - array( + [ 'type'=>'counter', 'count'=>$result, 'visual'=>'line', - ) + ] ]; } else { diff --git a/public_html/appmonitor/plugins/checks/porttcp.php b/public_html/appmonitor/plugins/checks/porttcp.php old mode 100644 new mode 100755 index 3161163e1e640a5ed78797bac3bbd15abee6eeb2..b9cee46833f34670043ecc59a86b7cc254636b31 --- a/public_html/appmonitor/plugins/checks/porttcp.php +++ b/public_html/appmonitor/plugins/checks/porttcp.php @@ -36,17 +36,17 @@ class checkPortTcp extends appmonitorcheck{ /** * check if system is listening to a given port * @param array $aParams - * array( + * [ * port integer port * host string optional hostname to connect; default: 127.0.0.1 * timeout integer optional timeout in sec; default: 5 - * ) + * ] * @return boolean */ public function run($aParams) { $this->_checkArrayKeys($aParams, "port"); - $sHost = array_key_exists('host', $aParams) ? $aParams['host'] : '127.0.0.1'; + $sHost = $aParams['host'] ?? '127.0.0.1'; $iPort = (int) $aParams['port']; if (!function_exists('socket_create')){ @@ -64,11 +64,11 @@ class checkPortTcp extends appmonitorcheck{ $socket, SOL_SOCKET, // socket level SO_SNDTIMEO, // timeout option - array( + [ "sec"=>(isset($aParams["timeout"]) && (int)$aParams["timeout"]) ? (int)$aParams["timeout"] : $this->_iTimeoutTcp, // timeout in seconds "usec"=>0 - ) - ); + ] + ); $result = @socket_connect($socket, $sHost, $iPort); if ($result === false) { diff --git a/public_html/appmonitor/plugins/checks/simple.php b/public_html/appmonitor/plugins/checks/simple.php old mode 100644 new mode 100755 index 15e6139a3681bd050009b1fbdfffb6f47ae34bc6..daacf0a363fbf1eb1bdd6b56129e6446c2009a51 --- a/public_html/appmonitor/plugins/checks/simple.php +++ b/public_html/appmonitor/plugins/checks/simple.php @@ -43,7 +43,7 @@ class checkSimple extends appmonitorcheck{ $this->_checkArrayKeys($aParams, "result,value"); // $this->_setReturn((int) $aParams["result"], $aParams["value"]); $aData=[]; - foreach(array('type', 'count', 'visual') as $sMyKey){ + foreach([ 'type', 'count', 'visual' ] as $sMyKey){ if(isset($aParams[$sMyKey])){ $aData[$sMyKey]=$aParams[$sMyKey]; } diff --git a/public_html/appmonitor/plugins/checks/sqliteconnect.php b/public_html/appmonitor/plugins/checks/sqliteconnect.php old mode 100644 new mode 100755 index 65b965cc372880103e7d9447828550b4ab67c2f3..1fc264c527c19de20de3a7a8776e8f4c8ef5e6f3 --- a/public_html/appmonitor/plugins/checks/sqliteconnect.php +++ b/public_html/appmonitor/plugins/checks/sqliteconnect.php @@ -33,10 +33,10 @@ class checkSqliteConnect extends appmonitorcheck{ /** * check sqlite connection * @param array $aParams - * array( + * [ * db string full path of sqlite file * timeout integer optional timeout in sec; default: 5 - * ) + * ] * @return boolean */ public function run($aParams) { @@ -56,9 +56,9 @@ class checkSqliteConnect extends appmonitorcheck{ $o = new PDO("sqlite:" . $aParams["db"], $aParams['user'], $aParams['password'], - array( + [ PDO::ATTR_TIMEOUT => (isset($aParams["timeout"]) && (int)$aParams["timeout"]) ? (int)$aParams["timeout"] : $this->_iTimeoutTcp, - ) + ] ); return [RESULT_OK, "OK: Sqlite database " . $aParams["db"] . " was connected"]; } catch (Exception $e) {