enable statuscake
parent
d6c4336124
commit
62b081db57
|
@ -18,7 +18,8 @@
|
||||||
"php-pushover/php-pushover": "dev-master",
|
"php-pushover/php-pushover": "dev-master",
|
||||||
"twig/twig": "1.*",
|
"twig/twig": "1.*",
|
||||||
"paragonie/random_compat" : "1.1.6",
|
"paragonie/random_compat" : "1.1.6",
|
||||||
"indigophp/hash-compat" : "1.1.0"
|
"indigophp/hash-compat" : "1.1.0",
|
||||||
|
"php-statuscake/php-statuscake": "0.2"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"files": [
|
"files": [
|
||||||
|
|
|
@ -4,8 +4,8 @@
|
||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"hash": "8f27400edd82e99aa35998a3e01fc23e",
|
"hash": "ee6fcd5efd7619a347226c9ea90caf32",
|
||||||
"content-hash": "3d1c36ee7e11634bc149bfc9a250e4ae",
|
"content-hash": "96a691d2bd6f2b93d99df6599cd6c24e",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "indigophp/hash-compat",
|
"name": "indigophp/hash-compat",
|
||||||
|
@ -174,6 +174,36 @@
|
||||||
},
|
},
|
||||||
"time": "2014-07-30 13:55:53"
|
"time": "2014-07-30 13:55:53"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "php-statuscake/php-statuscake",
|
||||||
|
"version": "0.2",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/easylo/php-statuscake.git",
|
||||||
|
"reference": "567e734404b77178527c510623431df7753bdb5e"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/easylo/php-statuscake/zipball/567e734404b77178527c510623431df7753bdb5e",
|
||||||
|
"reference": "567e734404b77178527c510623431df7753bdb5e",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"files": [
|
||||||
|
"Statuscake.php"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Laurent RICHARD",
|
||||||
|
"email": "easylo@gmail.com"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "PHP class for the statuscake.com project",
|
||||||
|
"time": "2016-09-06 22:55:34"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "phpmailer/phpmailer",
|
"name": "phpmailer/phpmailer",
|
||||||
"version": "v5.2.6",
|
"version": "v5.2.6",
|
||||||
|
|
|
@ -472,7 +472,7 @@ function psm_build_mail($from_name = null, $from_email = null) {
|
||||||
/**
|
/**
|
||||||
* Prepare a new StatusCake util.
|
* Prepare a new StatusCake util.
|
||||||
*
|
*
|
||||||
* @return \Pushover
|
* @return \Statuscake
|
||||||
*/
|
*/
|
||||||
function psm_build_statuscake() {
|
function psm_build_statuscake() {
|
||||||
$statuscake = new \StatusCake();
|
$statuscake = new \StatusCake();
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
/**
|
/**
|
||||||
* Current PSM version
|
* Current PSM version
|
||||||
*/
|
*/
|
||||||
define('PSM_VERSION', '3.2.0');
|
define('PSM_VERSION', '3.2.1');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* URL to check for updates. Will not be checked if turned off on config page.
|
* URL to check for updates. Will not be checked if turned off on config page.
|
||||||
|
|
|
@ -62,6 +62,7 @@ class ConfigController extends AbstractController {
|
||||||
'sms_gateway_password',
|
'sms_gateway_password',
|
||||||
'sms_from',
|
'sms_from',
|
||||||
'pushover_api_token',
|
'pushover_api_token',
|
||||||
|
'statuscake_account_token',
|
||||||
);
|
);
|
||||||
|
|
||||||
private $default_tab = 'general';
|
private $default_tab = 'general';
|
||||||
|
|
|
@ -73,6 +73,8 @@ abstract class AbstractServerController extends AbstractController {
|
||||||
`s`.`email`,
|
`s`.`email`,
|
||||||
`s`.`sms`,
|
`s`.`sms`,
|
||||||
`s`.`pushover`,
|
`s`.`pushover`,
|
||||||
|
`s`.`statuscake`,
|
||||||
|
`s`.`statuscake_test_id`,
|
||||||
`s`.`warning_threshold`,
|
`s`.`warning_threshold`,
|
||||||
`s`.`warning_threshold_counter`,
|
`s`.`warning_threshold_counter`,
|
||||||
`s`.`timeout`,
|
`s`.`timeout`,
|
||||||
|
|
|
@ -206,10 +206,12 @@ class ServerController extends AbstractServerController {
|
||||||
'edit_email_selected_' . $edit_server['email'] => 'selected="selected"',
|
'edit_email_selected_' . $edit_server['email'] => 'selected="selected"',
|
||||||
'edit_sms_selected_' . $edit_server['sms'] => 'selected="selected"',
|
'edit_sms_selected_' . $edit_server['sms'] => 'selected="selected"',
|
||||||
'edit_pushover_selected_' . $edit_server['pushover'] => 'selected="selected"',
|
'edit_pushover_selected_' . $edit_server['pushover'] => 'selected="selected"',
|
||||||
|
'edit_statuscake_selected_' . $edit_server['statuscake'] => 'selected="selected"',
|
||||||
|
'edit_value_statuscake_test_id' => $edit_server['statuscake_test_id'],
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
$notifications = array('email', 'sms', 'pushover');
|
$notifications = array('email', 'sms', 'pushover','statuscake');
|
||||||
foreach($notifications as $notification) {
|
foreach($notifications as $notification) {
|
||||||
if(psm_get_conf($notification . '_status') == 0) {
|
if(psm_get_conf($notification . '_status') == 0) {
|
||||||
$tpl_data['warning_' . $notification] = true;
|
$tpl_data['warning_' . $notification] = true;
|
||||||
|
@ -268,6 +270,8 @@ class ServerController extends AbstractServerController {
|
||||||
'email' => in_array($_POST['email'], array('yes', 'no')) ? $_POST['email'] : 'no',
|
'email' => in_array($_POST['email'], array('yes', 'no')) ? $_POST['email'] : 'no',
|
||||||
'sms' => in_array($_POST['sms'], array('yes', 'no')) ? $_POST['sms'] : 'no',
|
'sms' => in_array($_POST['sms'], array('yes', 'no')) ? $_POST['sms'] : 'no',
|
||||||
'pushover' => in_array($_POST['pushover'], array('yes', 'no')) ? $_POST['pushover'] : 'no',
|
'pushover' => in_array($_POST['pushover'], array('yes', 'no')) ? $_POST['pushover'] : 'no',
|
||||||
|
'statuscake' => in_array($_POST['statuscake'], array('yes', 'no')) ? $_POST['statuscake'] : 'no',
|
||||||
|
'statuscake_test_id' => trim(strip_tags(psm_POST('statuscake_test_id', ''))),
|
||||||
);
|
);
|
||||||
// make sure websites start with http://
|
// make sure websites start with http://
|
||||||
if($clean['type'] == 'website' && substr($clean['ip'], 0, 4) != 'http') {
|
if($clean['type'] == 'website' && substr($clean['ip'], 0, 4) != 'http') {
|
||||||
|
|
|
@ -146,6 +146,7 @@ class Installer {
|
||||||
('sms_from', '1234567890'),
|
('sms_from', '1234567890'),
|
||||||
('pushover_status', '0'),
|
('pushover_status', '0'),
|
||||||
('pushover_api_token', ''),
|
('pushover_api_token', ''),
|
||||||
|
('statuscake_account_token', ''),
|
||||||
('password_encrypt_key', '" . sha1(microtime()) . "'),
|
('password_encrypt_key', '" . sha1(microtime()) . "'),
|
||||||
('alert_type', 'status'),
|
('alert_type', 'status'),
|
||||||
('log_status', '1'),
|
('log_status', '1'),
|
||||||
|
@ -229,6 +230,8 @@ class Installer {
|
||||||
`email` enum('yes','no') NOT NULL default 'yes',
|
`email` enum('yes','no') NOT NULL default 'yes',
|
||||||
`sms` enum('yes','no') NOT NULL default 'no',
|
`sms` enum('yes','no') NOT NULL default 'no',
|
||||||
`pushover` enum('yes','no') NOT NULL default 'yes',
|
`pushover` enum('yes','no') NOT NULL default 'yes',
|
||||||
|
`statuscake` enum('yes','no') NOT NULL default 'yes',
|
||||||
|
`statuscake_test_id` varchar(50) NULL,
|
||||||
`warning_threshold` mediumint(1) unsigned NOT NULL DEFAULT '1',
|
`warning_threshold` mediumint(1) unsigned NOT NULL DEFAULT '1',
|
||||||
`warning_threshold_counter` mediumint(1) unsigned NOT NULL DEFAULT '0',
|
`warning_threshold_counter` mediumint(1) unsigned NOT NULL DEFAULT '0',
|
||||||
`timeout` smallint(1) unsigned NULL DEFAULT NULL,
|
`timeout` smallint(1) unsigned NULL DEFAULT NULL,
|
||||||
|
@ -290,6 +293,9 @@ class Installer {
|
||||||
if(version_compare($version_from, '3.2.0', '<')) {
|
if(version_compare($version_from, '3.2.0', '<')) {
|
||||||
$this->upgrade320();
|
$this->upgrade320();
|
||||||
}
|
}
|
||||||
|
if(version_compare($version_from, '3.2.1', '<')) {
|
||||||
|
$this->upgrade321();
|
||||||
|
}
|
||||||
psm_update_conf('version', $version_to);
|
psm_update_conf('version', $version_to);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -469,4 +475,17 @@ class Installer {
|
||||||
// Drop old user_id('s) column
|
// Drop old user_id('s) column
|
||||||
$this->execSQL("ALTER TABLE `" . PSM_DB_PREFIX . "log` DROP COLUMN `user_id`;");
|
$this->execSQL("ALTER TABLE `" . PSM_DB_PREFIX . "log` DROP COLUMN `user_id`;");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Upgrade for v3.2.1 release
|
||||||
|
*/
|
||||||
|
protected function upgrade321() {
|
||||||
|
$queries = array();
|
||||||
|
|
||||||
|
psm_update_conf('statuscake_account_token', '');
|
||||||
|
$queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "servers` ADD `statuscake` enum('yes','no') NOT NULL default 'yes', ADD `statuscake_test_id` varchar(50) NULL AFTER `pushover`;";
|
||||||
|
|
||||||
|
$this->execSQL($queries);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,12 +66,6 @@ class StatusNotifier {
|
||||||
*/
|
*/
|
||||||
protected $send_statuscake_account_id = null;
|
protected $send_statuscake_account_id = null;
|
||||||
|
|
||||||
/**
|
|
||||||
* Test for sending StatusCake Notification
|
|
||||||
* @var string send_statuscake_test_id
|
|
||||||
*/
|
|
||||||
protected $send_statuscake_test_id = null;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save log records?
|
* Save log records?
|
||||||
* @var boolean $save_log
|
* @var boolean $save_log
|
||||||
|
@ -108,8 +102,7 @@ class StatusNotifier {
|
||||||
$this->send_emails = psm_get_conf('email_status');
|
$this->send_emails = psm_get_conf('email_status');
|
||||||
$this->send_sms = psm_get_conf('sms_status');
|
$this->send_sms = psm_get_conf('sms_status');
|
||||||
$this->send_pushover = psm_get_conf('pushover_status');
|
$this->send_pushover = psm_get_conf('pushover_status');
|
||||||
$this->send_statuscake_account_id = psm_get_conf('statuscake_account_id');
|
$this->send_statuscake_account_token = psm_get_conf('statuscake_account_token');
|
||||||
$this->send_statuscake_test_id = psm_get_conf('statuscake_test_id');
|
|
||||||
$this->save_logs = psm_get_conf('log_status');
|
$this->save_logs = psm_get_conf('log_status');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,6 +115,7 @@ class StatusNotifier {
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function notify($server_id, $status_old, $status_new) {
|
public function notify($server_id, $status_old, $status_new) {
|
||||||
|
|
||||||
if(!$this->send_emails && !$this->send_sms && !$this->save_logs) {
|
if(!$this->send_emails && !$this->send_sms && !$this->save_logs) {
|
||||||
// seems like we have nothing to do. skip the rest
|
// seems like we have nothing to do. skip the rest
|
||||||
return false;
|
return false;
|
||||||
|
@ -135,7 +129,7 @@ class StatusNotifier {
|
||||||
$this->server = $this->db->selectRow(PSM_DB_PREFIX . 'servers', array(
|
$this->server = $this->db->selectRow(PSM_DB_PREFIX . 'servers', array(
|
||||||
'server_id' => $server_id,
|
'server_id' => $server_id,
|
||||||
), array(
|
), array(
|
||||||
'server_id', 'ip', 'port', 'label', 'type', 'pattern', 'status', 'error', 'active', 'email', 'sms', 'pushover',
|
'server_id', 'ip', 'port', 'label', 'type', 'pattern', 'status', 'error', 'active', 'email', 'sms', 'pushover', 'statuscake','statuscake_test_id',
|
||||||
));
|
));
|
||||||
if(empty($this->server)) {
|
if(empty($this->server)) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -165,6 +159,15 @@ class StatusNotifier {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check if statuscake is enabled for this server
|
||||||
|
if( !is_null($this->send_statuscake_account_token) && !empty($this->send_statuscake_account_token)
|
||||||
|
&& $this->server['statuscake'] == 'yes'
|
||||||
|
&& !is_null($this->server['statuscake_test_id']) && !empty($this->server['statuscake_test_id'])
|
||||||
|
) {
|
||||||
|
// yay lets wake those nerds up!
|
||||||
|
$this->notifyByStatusCake($users, $this->server['statuscake_test_id']);
|
||||||
|
}
|
||||||
|
|
||||||
if(!$notify) {
|
if(!$notify) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -202,12 +205,6 @@ class StatusNotifier {
|
||||||
$this->notifyByPushover($users);
|
$this->notifyByPushover($users);
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if statuscake is enabled for this server
|
|
||||||
if( !is_null($this->send_statuscake_account_id) && !is_null($this->send_statuscake_test_id) && $this->server['send_statuscake'] == 'yes') {
|
|
||||||
// yay lets wake those nerds up!
|
|
||||||
$this->notifyByStatusCake($users, $this->send_statuscake_test_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $notify;
|
return $notify;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -244,16 +241,19 @@ class StatusNotifier {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function notifyByStatusCake($users, $send_statuscake_test_id) {
|
protected function notifyByStatusCake($users, $statuscake_test_id) {
|
||||||
|
|
||||||
$statuscake = psm_build_statuscake();
|
$statuscake = psm_build_statuscake();
|
||||||
$statuscake->setTestId($send_statuscake_test_id)
|
$statuscake->setTestId($statuscake_test_id);
|
||||||
|
$statuscake->setTime(11);
|
||||||
|
$statuscake->setStatusCode(200);
|
||||||
|
|
||||||
// Log
|
// Log
|
||||||
if(psm_get_conf('log_pushover')) {
|
//if(psm_get_conf('log_statuscake')) {
|
||||||
$log_id = psm_add_log($this->server_id, 'statuscake', $message);
|
// $log_id = psm_add_log($this->server_id, 'statuscake', $message);
|
||||||
}
|
//}
|
||||||
|
|
||||||
|
$statuscake->send();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue