[IMPROVED] Error Handling, logging
This commit is contained in:
parent
3ee2874110
commit
ab73e9ad0f
@ -9,6 +9,11 @@ class Monitoring extends Base {
|
|||||||
$this->table = 'monitoring';
|
$this->table = 'monitoring';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store Uptime Robot status information as JSON in settings table
|
||||||
|
* @param none
|
||||||
|
* @return bool true on success, false on error
|
||||||
|
**/
|
||||||
public function storeUptimeRobotStatus() {
|
public function storeUptimeRobotStatus() {
|
||||||
if ($api_keys = $this->setting->getValue('monitoring_uptimerobot_private_key')) {
|
if ($api_keys = $this->setting->getValue('monitoring_uptimerobot_private_key')) {
|
||||||
$aJSONData = array();
|
$aJSONData = array();
|
||||||
@ -28,11 +33,17 @@ class Monitoring extends Base {
|
|||||||
}
|
}
|
||||||
if (!$this->setting->setValue('monitoring_uptimerobot_status', json_encode($aAllMonitorsStatus)) || !$this->setting->setValue('monitoring_uptimerobot_lastcheck', time())) {
|
if (!$this->setting->setValue('monitoring_uptimerobot_status', json_encode($aAllMonitorsStatus)) || !$this->setting->setValue('monitoring_uptimerobot_lastcheck', time())) {
|
||||||
$this->setErrorMessage('Failed to store uptime status: ' . $setting->getError());
|
$this->setErrorMessage('Failed to store uptime status: ' . $setting->getError());
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch Uptime Robot Status from settings table
|
||||||
|
* @param none
|
||||||
|
* @return array Data on success, false on failure
|
||||||
|
**/
|
||||||
public function getUptimeRobotStatus() {
|
public function getUptimeRobotStatus() {
|
||||||
if ($json = $this->setting->getValue('monitoring_uptimerobot_status'))
|
if ($json = $this->setting->getValue('monitoring_uptimerobot_status'))
|
||||||
return json_decode($json, true);
|
return json_decode($json, true);
|
||||||
|
|||||||
@ -32,9 +32,15 @@ class Tools extends Base {
|
|||||||
|
|
||||||
// run the query
|
// run the query
|
||||||
$res = curl_exec($ch);
|
$res = curl_exec($ch);
|
||||||
if ($res === false) throw new Exception('Could not get reply: '.curl_error($ch));
|
if ($res === false) {
|
||||||
|
$this->setErrorMessage('Could not get reply: '.curl_error($ch));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
$dec = json_decode($res, true);
|
$dec = json_decode($res, true);
|
||||||
if (!$dec) throw new Exception('Invalid data received, please make sure connection is working and requested API exists');
|
if (!$dec) {
|
||||||
|
$this->setErrorMessage('Invalid data received, please make sure connection is working and requested API exists');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return $dec;
|
return $dec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user