Exemple #1
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();
    }
}
function email_notify($check,$check_result,$subscription) {
 global $status_array;
 $user = new User($subscription->getUserId());
 echo 'email plugin!';
 $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('smtp.gmail.com', 465, TRUE, 5);
 $smtp->authenticate('*****@*****.**', 'example');
 $email->addRecipient($user->getEmail(), $user->getUsername());
 // Set who the email is from
 $email->setFromEmail('*****@*****.**','Tattle');
 // Set the subject include UTF-8 curly quotes
 $email->setSubject('Tattle : Alert for ' . $check->prepareName());
 // 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);
 }


}
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);
  }
}
Exemple #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));
}
Exemple #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";
}
Exemple #6
0
        echo $status_array[$row['status']];
        ?>
</td>
        <td><?php 
        echo $row['timestamp'];
        ?>
</td>
        <td><?php 
        echo $row['count'];
        ?>
</td>
        <td><a href="<?php 
        echo CheckResult::makeURL('list', $check);
        ?>
">View</a> | <a href="<?php 
        echo CheckResult::makeURL('ackAll', $check);
        ?>
">Clear</a>
        </td>
        </tr>
    <?php 
    }
    //if paging is needed
    if ($total_pages > 1) {
        ?>
    </tbody></table>
    <div class="pagination">
      <ul class="pager">
        <li class="<?php 
        echo $prev_class;
        ?>
Exemple #7
0
        ?>
    	<tr>
        <td><?php 
        echo $row['name'];
        ?>
</td>
        <td><?php 
        echo $status_array[$row['status']];
        ?>
</td>
        <td><?php 
        echo $row['count'];
        ?>
</td>
        <td><a href="<?php 
        echo CheckResult::makeURL('list', $check);
        ?>
">View</a>
        </td>
        </tr>
    <?php 
    }
    ?>
    </tbody></table></span>
    <?php 
} catch (fNoRowsException $e) {
    ?>
	<p class="info">There are currently no Alerts based on your subscriptions. Smile, looks like everything is happy!</p>
	<?php 
}
?>
Exemple #8
0
                    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 {
                        fMessaging::create('error', fURL::get(), "Nobody subscribe to this check");
                    }
                }
            }
        } catch (fNotFoundException $e) {
            fMessaging::create('error', $manage_url, 'The check requested, ' . fHTML::encode($check_id) . ', could not be found');
            fURL::redirect($manage_url);
        } catch (fExpectedException $e) {
            fMessaging::create('error', fURL::get(), $e->getMessage());
        }
        $page_num = fRequest::get('page', 'int', 1);
        $url_redirect = CheckResult::makeURL('list', $check) . "&page=" . $page_num;
        fURL::redirect($url_redirect);
    } else {
        $page_num = fRequest::get('page', 'int', 1);
        $check_results = CheckResult::findAll($check_id, false, $GLOBALS['PAGE_SIZE'], $page_num);
        include VIEW_PATH . '/list_check_results.php';
    }
}
             </div>
           </div>
           </fieldset>
           <fieldset>
             <div class="form-group actions">
             <div class="controls">
             <input class="btn btn-primary" type="submit" value="Save" />
             <?php 
if ($action == 'edit') {
    ?>
             	<a href="<?php 
    echo Check::makeURL('delete', $check_type, $check);
    ?>
" class="btn btn-default" >Delete</a>
             	<a href="<?php 
    echo CheckResult::makeURL("list", $check);
    ?>
" class="btn btn-default">View</a>
             	<a href="<?php 
    echo Subscription::makeURL('add', $check);
    ?>
" class="btn btn-default">Subscribe</a>
             <?php 
}
?>
             <div class="required"><em>*</em> Required field</div>
             <input type="hidden" name="token" value="<?php 
echo fRequest::generateCSRFToken();
?>
" />
<?php 
Exemple #10
0
    <th>Latest Status</th>
    <th>Last Alert</th>
    <th>Alert Count</th>
    <th>Action</th>
       </tr></thead><tbody>    
	<?php
	$first = TRUE;
	foreach ($results as $row) {
          $check = new Check($row['check_id']);
		?>
    	<tr>
        <td><?=$row['name']; ?></td>
        <td><?=($row['status'] == 2 ? 'Warning' : 'Error'); ?></td>
        <td><?=$row['timestamp']; ?></td>
	<td><?=$row['count']; ?></td>
        <td><a href="<?=CheckResult::makeURL('list', $check); ?>">View</a> | <a href="<?=CheckResult::makeURL('ackAll', $check); ?>">Clear</a>
        </td>
        </tr>
    <?php }
    //check to see if paging is needed
    $total_pages = ceil($alert_count / $GLOBALS['PAGE_SIZE']);
    if ($total_pages > 1) {
      $prev_class = 'previous'; 
      $prev_link = fURL::get() . '?page=' . ($page_num - 1);
      $next_class = 'next';
      $next_link = fURL::get() . '?page=' . ($page_num + 1);
      if ($page_num == 1) {
        $prev_class .= ' disabled';
        $prev_link = '#';
      } elseif ($page_num == $total_pages) {
        $next_class .= ' disabled';
                         <span id="warn_threshold"><?php echo $check->prepareWarn();?></span>
                         <span id="check_id"><?php echo $check->prepareCheckId();?></span> 
                      </div>

            </div>

        </div>
<!--<span><?php echo Check::showGraph($check); ?></span>
          <span><?php echo Check::showGraph($check,true,'-24Hours',320,true); ?></span> -->
    </fieldset>
<?php
  try {
    $check_results->tossIfEmpty();
    $affectd = fMessaging::retrieve('affected',fURL::get());
   ?>
        <a class="btn small primary" href="<?php echo CheckResult::makeURL('ackAll', $check = new Check($check_id)) ?>">Clear All</a>
	<table class="zebra-striped">
    <tr>
    <th>Status</th>
    <th>Value</th>
    <th>Error</th>
    <th>Warn</th>
    <th>State</th>
    <th>Time</th>
       </tr>    
	<?php
	$first = TRUE;
	foreach ($check_results as $check_result) {
        $check = new Check($check_result->getCheck_Id());
		?>
    	<tr>
Exemple #12
0
</div>
<a class="btn btn-default" href="<?php 
echo Check::makeURL('edit', $check->getType(), $check);
?>
">Edit check</a>
<a href="<?php 
echo Subscription::makeURL('add', $check);
?>
" class="btn btn-default">Subscribe</a>
<?php 
try {
    $check_results->tossIfEmpty();
    $affectd = fMessaging::retrieve('affected', fURL::get());
    ?>
        <a class="btn small btn-primary" href="<?php 
    echo CheckResult::makeURL('ackAll', $check = new Check($check_id));
    ?>
">Clear All</a>
        <table class="table table-bordered table-striped">
    <tr>
    <th>Status</th>
    <th>Value</th>
    <th>Error</th>
    <th>Warn</th>
    <th>State</th>
    <th>Time</th>
       </tr>
<?php 
    $first = TRUE;
    foreach ($check_results as $check_result) {
        $check = new Check($check_result->getCheck_Id());
          <thead>
    <tr>    
    <th>Check</th>
    <th>Latest Status</th>
    <th>Alert Count</th>
    <th>Action</th>
       </tr></thead><tbody>    
	<?php
	$first = TRUE;
	foreach ($results as $row) {
          $check = new Check($row['check_id']);
		?>
    	<tr>
        <td><?php echo $row['name'] ?></td>
        <td><?php echo ($row['status'] == 2 ? 'Warning' : 'Error'); ?></td>
        <td><?php echo $row['count'] ?></td>
        <td><a href="<?php echo CheckResult::makeURL('list', $check) ?>">View</a>
        </td>
        </tr>
    <?php } ?>
    </tbody></table></span>
    <?
} catch (fNoRowsException $e) {
	?>
	<p class="info">There are currently no Alerts based on your subscriptions. Smile, looks like everything is happy!</p>
	<?php
}
?>
</div>
<?php $tmpl->place('footer') ?>