function email_plugin_notify($check,$check_result,$subscription,$alt_email=false) {
  global $status_array;
  $user = new User($subscription->getUserId());
  $email = new fEmail();
  // This sets up fSMTP to connect to the gmail SMTP server
  // with a 5 second timeout. Gmail requires a secure connection.
  $smtp = new fSMTP(sys_var('smtp_server'), sys_var('smtp_port'), TRUE, 5);
  $smtp->authenticate(sys_var('smtp_user'), sys_var('smtp_pass'));
  if ($alt_email) {
    $email_address = usr_var('alt_email',$user->getUserId());
  } else {
    $email_address = $user->getEmail(); 
  }
  $email->addRecipient($email_address, $user->getUsername());
  // Set who the email is from
  $email->setFromEmail(sys_var('email_from'), sys_var('email_from_display'));
  // Set the subject include UTF-8 curly quotes
  $email->setSubject(str_replace('{check_name}', $check->prepareName(), sys_var('email_subject')));
  // Set the body to include a string containing UTF-8
  $state = $status_array[$check_result->getStatus()];
  $email->setHTMLBody("<p>$state Alert for {$check->prepareName()} </p><p>The check returned {$check_result->prepareValue()}</p><p>Warning Threshold is : ". $check->getWarn() . "</p><p>Error Threshold is : ". $check->getError() . '</p><p>View Alert Details : <a href="' . fURL::getDomain() . '/' . CheckResult::makeURL('list',$check_result) . '">'.$check->prepareName()."</a></p>");
  $email->setBody("
  $state Alert for {$check->prepareName()}
The check returned {$check_result->prepareValue()}
Warning Threshold is : ". $check->getWarn() . "
Error Threshold is : ". $check->getError() . "
           ");
  try {  
    $message_id = $email->send($smtp);
  } catch ( fConnectivityException $e) { 
    fCore::debug("email send failed",FALSE);
  }
}
Beispiel #2
0
function irccat_notify($check, $check_result, $subscription)
{
    global $status_array;
    $state = $status_array[$check_result->getStatus()];
    if ($state == 'OK') {
        $event_type = 'resolve';
    } else {
        $event_type = 'trigger';
    }
    $user = new User($subscription->getUserId());
    $irccat_channel = usr_var('irccat_channel', $user->getUserId());
    $irccat_ircnick = usr_var('irccat_ircnick', $user->getUserId());
    if (!empty($irccat_channel)) {
        $irc_target = $irccat_channel;
    } elseif (!empty($irccat_ircnick)) {
        $irc_target = '@' . $irccat_ircnick;
    } else {
        echo "No IRC Channel or Nickname selected for this users check " . $user->getUserId() . "\n";
        return false;
    }
    $message = $irc_target . " " . str_replace(array('{check_name}', '{check_state}'), array($check->prepareName(), $state), sys_var('irccat_subject')) . " Current : " . $check_result->prepareValue() . ", Error : " . $check->getError() . ", Warning : " . $check->getWarn();
    $fp = fsockopen(sys_var('irccat_hostname'), sys_var('irccat_port'), $errno, $errstr, 30);
    if (!$fp) {
        echo "{$errstr} ({$errno})<br />\n";
    } else {
        stream_set_timeout($fp, 4);
        fwrite($fp, $message);
        fclose($fp);
    }
}
Beispiel #3
0
function email_plugin_notify_master($check, $check_result, $subscription, $alt_email = false)
{
    global $status_array;
    $user = new User($subscription->getUserId());
    $email = new fEmail();
    // This sets up fSMTP to connect to the gmail SMTP server
    // with a 5 second timeout. Gmail requires a secure connection.
    $smtp = new fSMTP(sys_var('smtp_server'), sys_var('smtp_port'), sys_var('require_ssl') === 'true' ? TRUE : FALSE, 5);
    if (sys_var('require_auth') === 'true') {
        $smtp->authenticate(sys_var('smtp_user'), sys_var('smtp_pass'));
    }
    if ($alt_email) {
        $email_address = usr_var('alt_email', $user->getUserId());
    } else {
        $email_address = $user->getEmail();
    }
    $email->addRecipient($email_address, $user->getUsername());
    // Set who the email is from
    $email->setFromEmail(sys_var('email_from'), sys_var('email_from_display'));
    $state = $status_array[$check_result->getStatus()];
    // Set the subject include UTF-8 curly quotes
    if ($state == 'OK') {
        $email->setSubject(str_replace('{check_name}', $check->prepareName(), sys_var('email_end_alert_subject')));
    } else {
        $email->setSubject(str_replace('{check_name}', $check->prepareName(), sys_var('email_subject')));
    }
    // Set the body to include a string containing UTF-8
    $check_type = '';
    if ($check->getType() == 'threshold') {
        $check_type = ' Threshold';
    } elseif ($check->getType() == 'predictive') {
        $check_type = ' Standard Deviation';
    }
    $state_email_injection = $state . " Alert ";
    if ($state == 'OK') {
        $state_email_injection = "Everything's back to normal ";
    }
    // Remind : ('0' => 'OK', '1'   => 'Error', '2' => 'Warning');
    $state_int = $check_result->getStatus();
    if ($state_int == 0) {
        $color = "green";
    } else {
        if ($state_int == 2) {
            $color = "orange";
        } else {
            $color = "red";
        }
    }
    $html_body = "<p style='color:" . $color . ";'>" . $state_email_injection . "for {$check->prepareName()} </p>" . "<p>The check returned {$check_result->getValue()}</p>" . "<p>Warning" . $check_type . " is : " . $check->getWarn() . "</p>" . "<p>Error" . $check_type . " is : " . $check->getError() . "</p>" . "<p>View Alert Details : <a href='" . $GLOBALS['TATTLE_DOMAIN'] . '/' . CheckResult::makeURL('list', $check_result) . "'>" . $check->prepareName() . "</a></p>";
    $email->setHTMLBody($html_body);
    $email->setBody("\n  {$state} Alert for {$check->prepareName()}\nThe check returned {$check_result->getValue()}\nWarning" . $check_type . " is : " . $check->getWarn() . "\nError" . $check_type . " is : " . $check->getError() . "\n           ");
    try {
        $message_id = $email->send($smtp);
    } catch (fConnectivityException $e) {
        fCore::debug($e, FALSE);
        fCore::debug("email send failed", FALSE);
        $e->printMessage();
        $e->printTrace();
    }
}
Beispiel #4
0
function pushover_plugin_notify($check, $check_result, $subscription)
{
    $user = new User($subscription->getUserId());
    global $status_array;
    $check_status = $status_array[$check_result->getStatus()];
    $check_name = $check->prepareName();
    $check_value = $check_result->prepareValue();
    $check_warning_level = $check->getWarn();
    $check_error_level = $check->getError();
    $check_type = $check->getType();
    $title = "{$check_status} for {$check_name}";
    $message = "Check returned: {$check_value}\n" . "Warning {$check_type} is: {$check_warning_level}\n" . "Error {$check_type} is: {$check_error_level}";
    $data = array('token' => sys_var('pushover_plugin_application_token'), 'user' => usr_var('pushover_plugin_user_key', $user->getUserId()), 'message' => $message, 'title' => $title, 'url' => $GLOBALS['TATTLE_DOMAIN'] . '/' . CheckResult::makeURL('list', $check_result));
    $options = array('http' => array('header' => "Content-type: application/x-www-form-urlencoded\r\n", 'method' => 'POST', 'content' => http_build_query($data)));
    $result = file_get_contents("https://api.pushover.net/1/messages.json", false, stream_context_create($options));
}
Beispiel #5
0
function hipchat_master_notify($check, $check_result, $subscription, $toUser = true)
{
    global $status_array;
    global $debug;
    if (!is_callable('curl_init')) {
        fCore::debug("!!! WARNING !!! function curl_init() not found, probably php-curl is not installed");
    }
    $state = $status_array[$check_result->getStatus()];
    if (strtolower($state) == 'ok') {
        $color = sys_var('hipchat_ok_color');
    } elseif (strtolower($state) == 'warning') {
        $color = sys_var('hipchat_warning_color');
    } elseif (strtolower($state) == 'error') {
        $color = sys_var('hipchat_error_color');
    }
    $url = $GLOBALS['TATTLE_DOMAIN'] . '/' . CheckResult::makeURL('list', $check_result);
    $data = array('color' => $color, 'notify' => sys_var('hipchat_notify') == 'true' ? true : false, 'message_format' => 'html', 'message' => "<b>" . $check->prepareName() . "</b><br />The check returned: {$check_result->getValue()}<br />View Alert Details : <a href=\"" . $url . "\">" . $url . "</a>");
    if ($debug && $toUser == false) {
        $url = 'https://api.hipchat.com/v2/room?auth_token=' . sys_var('hipchat_apikey');
        $c = curl_init();
        curl_setopt($c, CURLOPT_URL, $url);
        curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
        fCore::debug("Rooms: " . curl_exec($c) . "\n", FALSE);
        fCore::debug("URL: " . 'https://api.hipchat.com/v2/room/' . strtolower(sys_var('hipchat_room')) . '/notification?auth_token=' . sys_var('hipchat_apikey') . "\n", FALSE);
        fCore::debug("Data: " . print_r($data, true) . "\n", FALSE);
    }
    if ($toUser == false) {
        $url = 'https://api.hipchat.com/v2/room/' . strtolower(sys_var('hipchat_room')) . '/notification?auth_token=' . sys_var('hipchat_apikey');
    } else {
        $url = 'https://api.hipchat.com/v2/user/' . usr_var('hipchat_user', $subscription->getUserId()) . '/message?auth_token=' . sys_var('hipchat_apikey');
    }
    fCore::debug("HipChat Calling: {$url}", FALSE);
    $c = curl_init();
    curl_setopt($c, CURLOPT_URL, $url);
    curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($c, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen(json_encode($data))));
    curl_setopt($c, CURLOPT_POSTFIELDS, json_encode($data));
    $response = curl_exec($c);
    if ($response === false) {
        fCore::debug("Curl error: " . curl_error($c) . "\n", FALSE);
    }
    echo "\n\nResponse: " . curl_getinfo($c, CURLINFO_HTTP_CODE) . ' - ' . $response . "\n\n";
}
Beispiel #6
0
 $subject_mail = fRequest::get('subject_mail');
 $content_mail = fRequest::get('content_mail');
 if (fRequest::isPost()) {
     if (empty($subject_mail) || empty($content_mail)) {
         fMessaging::create('error', fURL::get(), "You have to fill the subject and the content to send this mail");
     } else {
         fRequest::validateCSRFToken(fRequest::get('token'));
         $recipients = array();
         $id_user_session = fSession::get('user_id');
         $user_session = new User($id_user_session);
         $recipients[] = array("mail" => $user_session->getEmail(), "name" => $user_session->getUsername());
         $alt_ids = array();
         $subscription_alt = Subscription::findAll($check_id, NULL, NULL, NULL, TRUE);
         foreach ($subscription_alt as $alt) {
             $user = new User($alt->getUserId());
             $recipients[] = array("mail" => usr_var('alt_email', $user->getUserId()), "name" => $user->getUsername());
             $alt_ids[] = $alt->getUserId();
         }
         $subscriptions = $db->query("SELECT DISTINCT user_id,check_id FROM subscriptions WHERE check_id=" . $check_id . ";");
         foreach ($subscriptions as $sub) {
             $user_id = $sub['user_id'];
             if (!in_array($user_id, $alt_ids) && $user_id != $id_user_session) {
                 $user = new User($sub['user_id']);
                 $recipients[] = array("mail" => $user->getEmail(), "name" => $user->getUsername());
             }
         }
         if (!empty($recipients)) {
             // Send the mail to everybody
             notify_multiple_users($user_session, $recipients, $subject_mail, $content_mail);
             fMessaging::create('success', fURL::get(), 'The mail "' . $subject_mail . '" was successfully sent to all the users who subscribe to "' . $check->getName() . '"');
         } else {