コード例 #1
0
ファイル: items.inc.php プロジェクト: SandipSingh14/Zabbix_
/**
 * Calculate nextcheck timestamp for an item
 *
 * the parameter $flexIntervals accepts data in a format:
 *
 *           +------------[;]<----------+
 *           |                          |
 *         ->+-[d/wd[-wd2],hh:mm-hh:mm]-+
 *
 *         d       - delay (0-n)
 *         wd, wd2 - day of week (1-7)
 *         hh      - hours (0-24)
 *         mm      - minutes (0-59)
 *
 * @param string $interfaceid
 * @param string $itemid
 * @param int $itemType
 * @param int $delay                 default delay
 * @param string $flexIntervals      flexible intervals
 * @param int $now                   current timestamp
 *
 * @return array
 */
function calculateItemNextcheck($interfaceid, $itemid, $itemType, $delay, $flexIntervals, $now)
{
    if ($delay == 0) {
        $delay = SEC_PER_YEAR;
    }
    // special processing of active items to see better view in queue
    if ($itemType == ITEM_TYPE_ZABBIX_ACTIVE) {
        $nextcheck = $now + $delay;
    } else {
        // try to find the nearest 'nextcheck' value with condition 'now' < 'nextcheck' < 'now' + SEC_PER_YEAR
        $arrOfFlexIntervals = explode(';', $flexIntervals);
        $t = $now;
        $tmax = $now + SEC_PER_YEAR;
        $try = 0;
        $shift = $itemType == ITEM_TYPE_JMX ? $interfaceid : $itemid;
        while ($t < $tmax) {
            // calculate 'nextcheck' value for the current interval
            $currentDelay = getCurrentDelay($delay, $arrOfFlexIntervals, $t);
            $nextcheck = $currentDelay * floor($t / $currentDelay) + $shift % $currentDelay;
            if ($try == 0) {
                while ($nextcheck <= $t) {
                    $nextcheck += $currentDelay;
                }
            } else {
                while ($nextcheck < $t) {
                    $nextcheck += $currentDelay;
                }
            }
            // 'nextcheck' < end of the current interval ?
            // the end of the current interval is the beginning of the next interval - 1
            if (getNextDelayInterval($arrOfFlexIntervals, $t, $nextInterval) && $nextcheck >= $nextInterval) {
                // 'nextcheck' is beyond the current interval
                $t = $nextInterval;
                $try++;
            } else {
                break;
            }
        }
        $delay = $currentDelay;
    }
    return array('nextcheck' => $nextcheck, 'delay' => $delay);
}
コード例 #2
0
ファイル: items.inc.php プロジェクト: hujingguang/work
/**
 * Calculate nextcheck timestamp for an item
 *
 * the parameter $flexIntervals accepts data in a format:
 *
 *           +------------[;]<----------+
 *           |                          |
 *         ->+-[d/wd[-wd2],hh:mm-hh:mm]-+
 *
 *         d       - delay (0-n)
 *         wd, wd2 - day of week (1-7)
 *         hh      - hours (0-24)
 *         mm      - minutes (0-59)
 *
 * @param string $seed               seed value applied to delay to spread item checks over the delay period
 * @param int $itemType
 * @param int $delay                 default delay, can be overridden
 * @param string $flexIntervals      flexible intervals
 * @param int $now                   current timestamp
 *
 * @return array
 */
function calculateItemNextcheck($seed, $itemType, $delay, $flexIntervals, $now)
{
    // special processing of active items to see better view in queue
    if ($itemType == ITEM_TYPE_ZABBIX_ACTIVE) {
        if ($delay != 0) {
            $nextcheck = $now + $delay;
        } else {
            $nextcheck = ZBX_JAN_2038;
        }
    } else {
        // try to find the nearest 'nextcheck' value with condition 'now' < 'nextcheck' < 'now' + SEC_PER_YEAR
        // if it is not possible to check the item within a year, fail
        $arrOfFlexIntervals = explode(';', $flexIntervals);
        $t = $now;
        $tmax = $now + SEC_PER_YEAR;
        $try = 0;
        while ($t < $tmax) {
            // calculate 'nextcheck' value for the current interval
            $currentDelay = getCurrentDelay($delay, $arrOfFlexIntervals, $t);
            if ($currentDelay != 0) {
                $nextcheck = $currentDelay * floor($t / $currentDelay) + $seed % $currentDelay;
                if ($try == 0) {
                    while ($nextcheck <= $t) {
                        $nextcheck += $currentDelay;
                    }
                } else {
                    while ($nextcheck < $t) {
                        $nextcheck += $currentDelay;
                    }
                }
            } else {
                $nextcheck = ZBX_JAN_2038;
            }
            // 'nextcheck' < end of the current interval ?
            // the end of the current interval is the beginning of the next interval - 1
            if (getNextDelayInterval($arrOfFlexIntervals, $t, $nextInterval) && $nextcheck >= $nextInterval) {
                // 'nextcheck' is beyond the current interval
                $t = $nextInterval;
                $try++;
            } else {
                break;
            }
        }
    }
    return $nextcheck;
}
コード例 #3
0
ファイル: items.inc.php プロジェクト: jbfavre/debian-zabbix
/**
 * Calculate nextcheck timestamp for an item using flexible intervals.
 *
 * the parameter $flexible_intervals is an array if strings that are in the following format:
 *
 *           +------------[;]<----------+
 *           |                          |
 *         ->+-[d/wd[-wd2],hh:mm-hh:mm]-+
 *
 *         d       - delay (0-n)
 *         wd, wd2 - day of week (1-7)
 *         hh      - hours (0-24)
 *         mm      - minutes (0-59)
 *
 * @param int $seed						seed value applied to delay to spread item checks over the delay period
 * @param string $delay					default delay, can be overridden
 * @param array $flexible_intervals		array of flexible intervals
 * @param int $now						current timestamp
 *
 * @return int
 */
function calculateItemNextCheck($seed, $delay, $flexible_intervals, $now)
{
    /*
     * Try to find the nearest 'nextcheck' value with condition 'now' < 'nextcheck' < 'now' + SEC_PER_YEAR
     * If it is not possible to check the item within a year, fail.
     */
    $t = $now;
    $tMax = $now + SEC_PER_YEAR;
    $try = 0;
    while ($t < $tMax) {
        // Calculate 'nextcheck' value for the current interval.
        $currentDelay = getCurrentDelay($delay, $flexible_intervals, $t);
        if ($currentDelay != 0) {
            $nextCheck = $currentDelay * floor($t / $currentDelay) + $seed % $currentDelay;
            if ($try == 0) {
                while ($nextCheck <= $t) {
                    $nextCheck += $currentDelay;
                }
            } else {
                while ($nextCheck < $t) {
                    $nextCheck += $currentDelay;
                }
            }
        } else {
            $nextCheck = ZBX_JAN_2038;
        }
        /*
         * Is 'nextcheck' < end of the current interval and the end of the current interval
         * is the beginning of the next interval - 1.
         */
        if (getNextDelayInterval($flexible_intervals, $t, $nextInterval) && $nextCheck >= $nextInterval) {
            // 'nextcheck' is beyond the current interval.
            $t = $nextInterval;
            $try++;
        } else {
            break;
        }
    }
    return $nextCheck;
}