add time for statuscake
parent
807f07eb46
commit
4c07c7e59d
|
@ -131,6 +131,7 @@ class StatusNotifier {
|
|||
), array(
|
||||
'server_id', 'ip', 'port', 'label', 'type', 'pattern', 'status', 'rtime', 'header_name', 'header_value', 'error', 'active', 'email', 'sms', 'pushover', 'statuscake','statuscake_test_id',
|
||||
));
|
||||
|
||||
if(empty($this->server)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -160,61 +161,70 @@ class StatusNotifier {
|
|||
}
|
||||
|
||||
// check if statuscake is enabled for this server
|
||||
if( !is_null($this->send_statuscake_account_token) && !empty($this->send_statuscake_account_token)
|
||||
if( $this->server['status'] == 'on' && !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!
|
||||
<<<<<<< HEAD
|
||||
$this->notifyByStatusCake($users, $this->server['statuscake_test_id']);
|
||||
}
|
||||
|
||||
if(!$notify) {
|
||||
return false;
|
||||
}
|
||||
=======
|
||||
$this->notifyByStatusCake($users, $this->server['statuscake_test_id'], $this->server['rtime']);
|
||||
}
|
||||
|
||||
if(!$notify) {
|
||||
return false;
|
||||
}
|
||||
>>>>>>> add time for statuscake
|
||||
|
||||
// first add to log (we use the same text as the SMS message because its short..)
|
||||
if($this->save_logs) {
|
||||
if($this->save_logs) {
|
||||
psm_add_log(
|
||||
$this->server_id,
|
||||
'status',
|
||||
psm_parse_msg($status_new, 'sms', $this->server)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$users = $this->getUsers($this->server_id);
|
||||
|
||||
if(empty($users)) {
|
||||
return $notify;
|
||||
}
|
||||
|
||||
// check if email is enabled for this server
|
||||
if($this->send_emails && $this->server['email'] == 'yes') {
|
||||
// send email
|
||||
$this->notifyByEmail($users);
|
||||
}
|
||||
|
||||
// check if sms is enabled for this server
|
||||
if($this->send_sms && $this->server['sms'] == 'yes') {
|
||||
// yay lets wake those nerds up!
|
||||
$this->notifyByTxtMsg($users);
|
||||
}
|
||||
|
||||
// check if pushover is enabled for this server
|
||||
if($this->send_pushover && $this->server['pushover'] == 'yes') {
|
||||
// yay lets wake those nerds up!
|
||||
$this->notifyByPushover($users);
|
||||
}
|
||||
$users = $this->getUsers($this->server_id);
|
||||
|
||||
if(empty($users)) {
|
||||
return $notify;
|
||||
}
|
||||
|
||||
/**
|
||||
// check if email is enabled for this server
|
||||
if($this->send_emails && $this->server['email'] == 'yes') {
|
||||
// send email
|
||||
$this->notifyByEmail($users);
|
||||
}
|
||||
|
||||
// check if sms is enabled for this server
|
||||
if($this->send_sms && $this->server['sms'] == 'yes') {
|
||||
// yay lets wake those nerds up!
|
||||
$this->notifyByTxtMsg($users);
|
||||
}
|
||||
|
||||
// check if pushover is enabled for this server
|
||||
if($this->send_pushover && $this->server['pushover'] == 'yes') {
|
||||
// yay lets wake those nerds up!
|
||||
$this->notifyByPushover($users);
|
||||
}
|
||||
|
||||
return $notify;
|
||||
}
|
||||
|
||||
/**
|
||||
* This functions performs the email notifications
|
||||
*
|
||||
* @param array $users
|
||||
* @return boolean
|
||||
*/
|
||||
protected function notifyByEmail($users) {
|
||||
protected function notifyByEmail($users) {
|
||||
// build mail object with some default values
|
||||
$mail = psm_build_mail();
|
||||
$mail->Subject = utf8_decode(psm_parse_msg($this->status_new, 'email_subject', $this->server));
|
||||
|
@ -239,13 +249,13 @@ class StatusNotifier {
|
|||
$mail->Send();
|
||||
$mail->ClearAddresses();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function notifyByStatusCake($users, $statuscake_test_id) {
|
||||
protected function notifyByStatusCake($users, $statuscake_test_id, $rtime) {
|
||||
|
||||
$statuscake = psm_build_statuscake();
|
||||
$statuscake->setTestId($statuscake_test_id);
|
||||
$statuscake->setTime(11);
|
||||
$statuscake->setTime(($rtime*1000));
|
||||
$statuscake->setStatusCode(200);
|
||||
|
||||
// Log
|
||||
|
@ -254,15 +264,15 @@ class StatusNotifier {
|
|||
//}
|
||||
|
||||
$statuscake->send();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* This functions performs the pushover notifications
|
||||
*
|
||||
* @param array $users
|
||||
* @return boolean
|
||||
*/
|
||||
protected function notifyByPushover($users) {
|
||||
protected function notifyByPushover($users) {
|
||||
// Remove users that have no pushover_key
|
||||
foreach($users as $k => $user) {
|
||||
if (trim($user['pushover_key']) == '') {
|
||||
|
@ -308,15 +318,15 @@ class StatusNotifier {
|
|||
}
|
||||
$pushover->send();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* This functions performs the text message notifications
|
||||
*
|
||||
* @param array $users
|
||||
* @return boolean
|
||||
*/
|
||||
protected function notifyByTxtMsg($users) {
|
||||
protected function notifyByTxtMsg($users) {
|
||||
$sms = psm_build_sms();
|
||||
if(!$sms) {
|
||||
return false;
|
||||
|
@ -343,14 +353,14 @@ class StatusNotifier {
|
|||
$result = $sms->sendSMS($message);
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Get all users for the provided server id
|
||||
* @param int $server_id
|
||||
* @return array
|
||||
*/
|
||||
public function getUsers($server_id) {
|
||||
public function getUsers($server_id) {
|
||||
// find all the users with this server listed
|
||||
$users = $this->db->query("
|
||||
SELECT `u`.`user_id`, `u`.`name`,`u`.`email`, `u`.`mobile`, `u`.`pushover_key`, `u`.`pushover_device`
|
||||
|
@ -361,5 +371,5 @@ class StatusNotifier {
|
|||
)
|
||||
");
|
||||
return $users;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue