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 pagerduty_notify($check, $check_result)
{
    global $status_array;
    $state = $status_array[$check_result->getStatus()];
    if ($state == 'OK') {
        $event_type = 'resolve';
    } else {
        $event_type = 'trigger';
    }
    $data = array('service_key' => sys_var('pagerduty_servicekey'), 'incident_key' => 'tattle_' . $check->getCheckId(), 'event_type' => $event_type, 'description' => str_replace(array('{check_name}', '{check_state}'), array($check->prepareName(), $state), sys_var('pagerduty_subject')), 'details' => array('state' => $state, 'current_value' => $check_result->prepareValue(), 'error_level' => $check->getError(), 'warning_level' => $check->getWarn()));
    $ctx = stream_context_create(array('http' => array('method' => 'POST', 'header' => 'Content-Type:application/x-www-form-urlencodedi\\r\\n', 'content' => json_encode($data))));
    file_get_contents('https://events.pagerduty.com/generic/2010-04-15/create_event.json', null, $ctx);
}
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
function notify_multiple_users($user_from, $recipients, $subject, $body)
{
    $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'));
    }
    // Add the recipients
    foreach ($recipients as $rec) {
        $email->addRecipient($rec['mail'], $rec['name']);
    }
    // Set who the email is from
    $email->setFromEmail($user_from->getEmail(), $user_from->getUsername());
    // Set the subject
    $email->setSubject($subject);
    // Set the body
    $email->setHTMLBody($body);
    $email->setBody($body);
    try {
        $message_id = $email->send($smtp);
    } catch (fConnectivityException $e) {
        fCore::debug($e, FALSE);
        fCore::debug("email send failed", FALSE);
        $e->printMessage();
        $e->printTrace();
    }
}