Esempio n. 1
0
 /**
  * @dataProvider providerAgeToUnixtime
  */
 public function testAgeToUnixtime($value, $min_age, $result)
 {
     // We fudge this a little since it's difficult to mock time().
     // We simply make sure that we are not off by more than 2 secs.
     $this->assertLessThanOrEqual(2, age_to_unixtime($value, $min_age) - $result);
 }
Esempio n. 2
0
<?php

/**
 * Observium
 *
 *   This file is part of Observium.
 *
 * @package    observium
 * @subpackage housekeeping
 * @author     Adam Armstrong <*****@*****.**>
 * @copyright  (C) 2006-2014 Adam Armstrong
 *
 */
// Minimum allowed age for delete perfomance times is 24h
$cutoff = age_to_unixtime($config['housekeeping']['timing']['age'], age_to_seconds('24h'));
if ($cutoff) {
    $where = "`start` < {$cutoff}";
    $count_run = dbFetchCell("SELECT COUNT(*) FROM `perf_times` WHERE {$where};");
    $count_dev = dbFetchCell("SELECT COUNT(*) FROM `devices_perftimes` WHERE {$where};");
    if ($count_run || $count_dev) {
        if ($prompt) {
            $answer = print_prompt("Perfomance entries - {$count_run} (per-run) and {$count_dev} (per-device) older than " . format_unixtime($cutoff) . " will be deleted");
        }
        if ($answer) {
            $rows = dbDelete('devices_perftimes', $where);
            if ($rows === FALSE) {
                // Use LIMIT with big tables
                print_debug("Performance table (per-device) is too big, using LIMIT for delete entries");
                $rows = 0;
                $i = 1000;
                while ($i && $rows < $count_dev) {
Esempio n. 3
0
<?php

/**
 * Observium
 *
 *   This file is part of Observium.
 *
 * @package    observium
 * @subpackage housekeeping
 * @author     Adam Armstrong <*****@*****.**>
 * @copyright  (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited
 *
 */
$cutoff = age_to_unixtime($config['housekeeping']['deleted_ports']['age']);
if ($cutoff) {
    $where = "`deleted` = 1 AND UNIX_TIMESTAMP(`ifLastChange`) < {$cutoff}";
    $ports = dbFetchRows("SELECT `port_id` FROM `ports` WHERE {$where}");
    $count = count($ports);
    if ($count) {
        if ($prompt) {
            $answer = print_prompt("{$count} ports marked as deleted before " . format_unixtime($cutoff) . " will be deleted");
        }
        if ($answer) {
            foreach ($ports as $entry) {
                delete_port($entry['port_id']);
            }
            print_debug("Deleted ports housekeeping: deleted {$count} entries");
            logfile("housekeeping.log", "Deleted ports: deleted {$count} entries older than " . format_unixtime($cutoff));
        }
    } else {
        if ($prompt) {