From d6c4336124b3adcaf39e8f2d1f8bc992a0f70d99 Mon Sep 17 00:00:00 2001 From: easylo Date: Mon, 5 Sep 2016 21:20:37 +0200 Subject: [PATCH] step 1 adding statuscake --- src/includes/functions.inc.php | 16 +++++++- src/lang/en_US.lang.php | 7 ++++ .../Config/Controller/ConfigController.php | 6 +++ .../Server/Controller/ServerController.php | 2 + .../Util/Server/Updater/StatusNotifier.php | 34 ++++++++++++++++- .../default/module/config/config.tpl.html | 37 ++++++++++++++++++- .../module/server/server/update.tpl.html | 17 +++++++++ 7 files changed, 115 insertions(+), 4 deletions(-) diff --git a/src/includes/functions.inc.php b/src/includes/functions.inc.php index ec725f67..1b120830 100755 --- a/src/includes/functions.inc.php +++ b/src/includes/functions.inc.php @@ -469,6 +469,18 @@ function psm_build_mail($from_name = null, $from_email = null) { return $phpmailer; } +/** + * Prepare a new StatusCake util. + * + * @return \Pushover + */ +function psm_build_statuscake() { + $statuscake = new \StatusCake(); + $statuscake->setAccountToken(psm_get_conf('statuscake_account_token')); + + return $statuscake; +} + /** * Prepare a new Pushover util. * @@ -697,7 +709,7 @@ function psm_password_decrypt($key, $encryptedString) if (empty($key)) throw new \InvalidArgumentException('invalid_encryption_key'); - + $data = base64_decode($encryptedString); $iv = substr($data, 0, mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC)); @@ -713,4 +725,4 @@ function psm_password_decrypt($key, $encryptedString) ); return $decrypted; -} \ No newline at end of file +} diff --git a/src/lang/en_US.lang.php b/src/lang/en_US.lang.php index 07c1d5d1..5e871a71 100755 --- a/src/lang/en_US.lang.php +++ b/src/lang/en_US.lang.php @@ -146,6 +146,8 @@ $sm_lang = array( 'sms' => 'SMS', 'send_sms' => 'Send SMS', 'pushover' => 'Pushover', + 'statuscake' => 'StatusCake', + 'statuscake_test_id' => 'StatusCake test id', 'users' => 'Users', 'delete_title' => 'Delete server', 'delete_message' => 'Are you sure you want to delete server \'%1\'?', @@ -220,8 +222,11 @@ $sm_lang = array( 'pushover_status' => 'Allow sending Pushover messages', 'pushover_description' => 'Pushover is a service that makes it easy to get real-time notifications. See their website for more info.', 'pushover_clone_app' => 'Click here to create your Pushover app', + 'statuscake_app' => 'Click here to create your StatusCake account', 'pushover_api_token' => 'Pushover App API Token', 'pushover_api_token_description' => 'Before you can use Pushover, you need to register an App at their website and enter the App API Token here.', + 'statuscake_account_token' => 'StatusCake Account Token', + 'statuscake_account_token_description' => 'For using push test you need to add your account key.', 'alert_type' => 'Select when you\'d like to be notified.', 'alert_type_description' => 'Status change: '. 'You will receive a notifcation when a server has a change in status. So from online -> offline or offline -> online.
'. @@ -243,9 +248,11 @@ $sm_lang = array( 'tab_email' => 'Email', 'tab_sms' => 'SMS', 'tab_pushover' => 'Pushover', + 'tab_statuscake' => 'StatusCake', 'settings_email' => 'Email settings', 'settings_sms' => 'Text message settings', 'settings_pushover' => 'Pushover settings', + 'settings_statuscake' => 'StatusCake settings', 'settings_notification' => 'Notification settings', 'settings_log' => 'Log settings', 'auto_refresh' => 'Auto-refresh', diff --git a/src/psm/Module/Config/Controller/ConfigController.php b/src/psm/Module/Config/Controller/ConfigController.php index d058de63..9dc3241a 100644 --- a/src/psm/Module/Config/Controller/ConfigController.php +++ b/src/psm/Module/Config/Controller/ConfigController.php @@ -288,9 +288,11 @@ class ConfigController extends AbstractController { 'label_tab_email' => psm_get_lang('config', 'tab_email'), 'label_tab_sms' => psm_get_lang('config', 'tab_sms'), 'label_tab_pushover' => psm_get_lang('config', 'tab_pushover'), + 'label_tab_statuscake' => psm_get_lang('config', 'tab_statuscake'), 'label_settings_email' => psm_get_lang('config', 'settings_email'), 'label_settings_sms' => psm_get_lang('config', 'settings_sms'), 'label_settings_pushover' => psm_get_lang('config', 'settings_pushover'), + 'label_settings_statuscake' => psm_get_lang('config', 'settings_statuscake'), 'label_settings_notification' => psm_get_lang('config', 'settings_notification'), 'label_settings_log' => psm_get_lang('config', 'settings_log'), 'label_general' => psm_get_lang('config', 'general'), @@ -331,11 +333,15 @@ class ConfigController extends AbstractController { 'label_pushover_status' => psm_get_lang('config', 'pushover_status'), 'label_pushover_clone_app' => psm_get_lang('config', 'pushover_clone_app'), 'pushover_clone_url' => PSM_PUSHOVER_CLONE_URL, + 'label_statuscake_app' => psm_get_lang('config', 'statuscake_app'), + 'statuscake_url' => 'https://www.statuscake.com/', 'label_pushover_api_token' => psm_get_lang('config', 'pushover_api_token'), 'label_pushover_api_token_description' => sprintf( psm_get_lang('config', 'pushover_api_token_description'), PSM_PUSHOVER_CLONE_URL ), + 'label_statuscake_account_token' => psm_get_lang('config', 'statuscake_account_token'), + 'label_statuscake_account_token_description' => psm_get_lang('config', 'statuscake_account_token_description'), 'label_alert_type' => psm_get_lang('config', 'alert_type'), 'label_alert_type_description' => psm_get_lang('config', 'alert_type_description'), 'label_alert_type_status' => psm_get_lang('config', 'alert_type_status'), diff --git a/src/psm/Module/Server/Controller/ServerController.php b/src/psm/Module/Server/Controller/ServerController.php index 0fd9a4d1..aa4f25ec 100644 --- a/src/psm/Module/Server/Controller/ServerController.php +++ b/src/psm/Module/Server/Controller/ServerController.php @@ -457,6 +457,8 @@ class ServerController extends AbstractServerController { 'label_sms' => psm_get_lang('servers', 'sms'), 'label_send_sms' => psm_get_lang('servers', 'send_sms'), 'label_pushover' => psm_get_lang('servers', 'pushover'), + 'label_statuscake' => psm_get_lang('servers', 'statuscake'), + 'label_statuscake_test_id' => psm_get_lang('servers', 'statuscake_test_id'), 'label_users' => psm_get_lang('servers', 'users'), 'label_warning_threshold' => psm_get_lang('servers', 'warning_threshold'), 'label_warning_threshold_description' => psm_get_lang('servers', 'warning_threshold_description'), diff --git a/src/psm/Util/Server/Updater/StatusNotifier.php b/src/psm/Util/Server/Updater/StatusNotifier.php index 0edfde98..962a54c8 100755 --- a/src/psm/Util/Server/Updater/StatusNotifier.php +++ b/src/psm/Util/Server/Updater/StatusNotifier.php @@ -60,6 +60,18 @@ class StatusNotifier { */ protected $send_pushover = false; + /** + * Account for sending StatusCake Notification + * @var string send_statuscake_account_id + */ + 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? * @var boolean $save_log @@ -96,6 +108,8 @@ class StatusNotifier { $this->send_emails = psm_get_conf('email_status'); $this->send_sms = psm_get_conf('sms_status'); $this->send_pushover = psm_get_conf('pushover_status'); + $this->send_statuscake_account_id = psm_get_conf('statuscake_account_id'); + $this->send_statuscake_test_id = psm_get_conf('statuscake_test_id'); $this->save_logs = psm_get_conf('log_status'); } @@ -188,6 +202,12 @@ class StatusNotifier { $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; } @@ -224,6 +244,18 @@ class StatusNotifier { } } + protected function notifyByStatusCake($users, $send_statuscake_test_id) { + + $statuscake = psm_build_statuscake(); + $statuscake->setTestId($send_statuscake_test_id) + + // Log + if(psm_get_conf('log_pushover')) { + $log_id = psm_add_log($this->server_id, 'statuscake', $message); + } + + } + /** * This functions performs the pushover notifications * @@ -330,4 +362,4 @@ class StatusNotifier { "); return $users; } -} \ No newline at end of file +} diff --git a/src/templates/default/module/config/config.tpl.html b/src/templates/default/module/config/config.tpl.html index 103c52a8..578789c9 100644 --- a/src/templates/default/module/config/config.tpl.html +++ b/src/templates/default/module/config/config.tpl.html @@ -5,6 +5,7 @@
  • {{ label_tab_email }}
  • {{ label_tab_sms }}
  • {{ label_tab_pushover }}
  • +
  • {{ label_tab_statuscake }}
  • @@ -238,6 +239,40 @@
    + +
    +
    + {{ label_settings_statuscake }} + +
    + +
    +

    + +

    {{ label_statuscake_account_token_description|raw }}

    +
    +
    +
    + +
    +
    +
    + + + + {{ macro.csrf_input() }} - \ No newline at end of file + diff --git a/src/templates/default/module/server/server/update.tpl.html b/src/templates/default/module/server/server/update.tpl.html index 2378d21e..17cf2b49 100644 --- a/src/templates/default/module/server/server/update.tpl.html +++ b/src/templates/default/module/server/server/update.tpl.html @@ -137,6 +137,23 @@ + +
    + + {% if warning_statuscake %}

    {% endif %} +
    + +
    +
    + +
    + +
    +
    +