Ejemplo n.º 1
0
            fCore::debug("next check is lt then now\n", FALSE);
        } else {
            fCore::debug("not less then now\n", FALSE);
        }
        // If It's been more then the Repeat Delay or the Status has changed
        if ($next_check->lt($end) || $check->getLastCheckStatus() != $result) {
            fCore::debug("Send Notification \n", FALSE);
            fCore::debug("State :" . $result . ":\n", FALSE);
            $check_result = new CheckResult();
            $check_result->setCheckId($check->getCheckId());
            $check_result->setStatus($result);
            $check_result->setValue($check_value);
            $check_result->setState(0);
            $check->setLastCheckStatus($result);
            $check->setLastCheckValue($check_value);
            $check->setLastCheckTime($end);
            $check_result->store();
            $check->store();
            $subscriptions = Subscription::findAll($check->getCheckId());
            foreach ($subscriptions as $subscription) {
                $notify_function = $subscription->getMethod() . '_notify';
                if (function_exists($notify_function)) {
                    $notify_result = $notify_function($check, $check_result, $subscription);
                }
            }
        } else {
            fCore::debug("Skip Notification \n", FALSE);
        }
    }
    fCore::debug("check done moving to next \n\n", FALSE);
}
Ejemplo n.º 2
0
        fMessaging::create('error', $manage_url, 'The subscription requested ' . fHTML::encode($check_id) . ' could not be found');
        fURL::redirect($manage_url);
    } catch (fExpectedException $e) {
        fMessaging::create('error', fURL::get(), $e->getMessage());
    }
    include VIEW_PATH . '/add_edit_subscription.php';
    // --------------------------------- //
} elseif ('add' == $action) {
    $subscription = new Subscription();
    //Load details of the check we are going to subscribe to
    $check = new Check($check_id);
    if (fRequest::isPost()) {
        try {
            $subscription->populate();
            fRequest::validateCSRFToken(fRequest::get('token'));
            $subscription->store();
            fMessaging::create('affected', $manage_url, $check->getName());
            fMessaging::create('success', $manage_url, 'The subscription to ' . $check->getName() . ' was successfully created');
            fURL::redirect($manage_url);
        } catch (fExpectedException $e) {
            fMessaging::create('error', fURL::get(), $e->getMessage());
        }
    }
    include VIEW_PATH . '/add_edit_subscription.php';
} else {
    $user = new User(fSession::get('user_id'));
    $page_num = fRequest::get('page', 'int', 1);
    $subscriptions = Subscription::findAll(NULL, fSession::get('user_id'), $GLOBALS['PAGE_SIZE'], $page_num);
    //  $subscriptions = $user->buildSubscriptions();
    include VIEW_PATH . '/list_subscriptions.php';
}
Ejemplo n.º 3
0
 if ($action == 'notifyAll') {
     try {
         $check = new Check($check_id);
         $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
Ejemplo n.º 4
0
$breadcrumbs[] = array('name' => 'Checks', 'url' => Check::makeUrl('list'), 'active' => false);
$action = fRequest::getValid('action', array('list', 'add', 'edit', 'delete'));
$sort = fCRUD::getSortColumn(array('name', 'target', 'warn', 'error', 'status', 'timestamp', 'count'));
$sort_dir = fCRUD::getSortDirection('asc');
$check_id = fRequest::get('check_id', 'integer');
$check_list_url = Check::makeURL('list');
// --------------------------------- //
if ('delete' == $action) {
    try {
        $obj = new Check($check_id);
        $delete_text = 'Are you sure you want to delete the check : <strong>' . $obj->getName() . '</strong>?';
        if (fRequest::isPost()) {
            fRequest::validateCSRFToken(fRequest::get('token'));
            $obj->delete();
            // Do our own Subscription and CheckResult cleanup instead of using ORM
            $subscriptions = Subscription::findAll($check_id);
            foreach ($subscriptions as $subscription) {
                $subscription->delete();
            }
            $check_results = CheckResult::findAll($check_id);
            foreach ($check_results as $check_result) {
                $check_result->delete();
            }
            fMessaging::create('success', fURL::get(), 'The check ' . $obj->getName() . ' was successfully deleted');
            fURL::redirect($check_list_url);
        }
    } catch (fNotFoundException $e) {
        fMessaging::create('error', fURL::get(), 'The check requested, ' . fHTML::encode($date) . ', could not be found');
        fURL::redirect($check_list_url);
    } catch (fExpectedException $e) {
        fMessaging::create('error', fURL::get(), $e->getMessage());