• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP logfile函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中logfile函数的典型用法代码示例。如果您正苦于以下问题:PHP logfile函数的具体用法?PHP logfile怎么用?PHP logfile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了logfile函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: exec_query

/**
 * Execute an sql query in the database. The correct database connection
 * will be chosen and the query will be logged with the success status.
 * 
 * @param $query query to execute as string
 */
function exec_query($query)
{
    global $conn, $pdo_conn, $errors, $db_layer;
    $success = false;
    if ($db_layer == "pdo") {
        if (is_object($pdo_conn)) {
            $pdo_query = $pdo_conn->prepare($query);
            $success = $pdo_query->execute(array());
            $errorInfo = serialize($pdo_query->errorInfo());
        } else {
            $errorInfo = "No connection object.";
        }
    } else {
        if (is_object($conn)) {
            $success = $conn->Query($query);
            $errorInfo = serialize($conn->Error());
        } else {
            $errorInfo = "No connection object.";
        }
    }
    logfile($query);
    if (!$success) {
        logfile($errorInfo);
        $errors = true;
    }
}
开发者ID:pombredanne,项目名称:ArcherSys,代码行数:32,代码来源:install.php


示例2: error_log_print

function error_log_print($errno, $errstr, $errfile, $errline)
{
    $backtrace = (new Exception())->getTraceAsString();
    $err = "Error #{$errno}: '{$errstr}' at line {$errline} of file {$errfile}. Debug Backtrace:\r\n{$backtrace}\r\n";
    logfile('err', $err);
    //Printing out
    global $DEBUG_MODE;
    if ($DEBUG_MODE) {
        echo "An error occurred:<br><pre>{$err}</pre><br>(logged as above)";
    } else {
        echo getErrPage();
    }
}
开发者ID:t-web,项目名称:doeqs_new,代码行数:13,代码来源:errors.php


示例3: exec_query

/**
 * Execute an sql query in the database. The correct database connection
 * will be chosen and the query will be logged with the success status.
 * 
 * @param $query query to execute as string
 */
function exec_query($query)
{
    global $conn, $pdo_conn, $kga, $errors, $executed_queries;
    $success = false;
    if ($kga['server_conn'] == "pdo") {
        if (is_object($pdo_conn)) {
            $pdo_query = $pdo_conn->prepare($query);
            $success = $pdo_query->execute(array());
        } else {
            $errorInfo = "No connection object.";
        }
    } else {
        if (is_object($conn)) {
            $success = $conn->Query($query);
        } else {
            $errorInfo = "No connection object.";
        }
    }
    logfile($query);
    if (!$success) {
        logfile($errorInfo);
        $errors = true;
    }
}
开发者ID:pombredanne,项目名称:ArcherSys,代码行数:30,代码来源:db_restore.php


示例4: logfile

                logfile("cleanup.log", "Database cleanup for table {$table}: deleted {$count} entries");
            }
        } else {
            if ($prompt) {
                print_message("No orphaned rows found in table {$table}.");
            }
        }
    }
    // Cleanup duplicate entries in the device_graphs table
    foreach (dbFetchRows("SELECT * FROM `device_graphs`") as $entry) {
        $graphs[$entry['device_id']][$entry['graph']][] = $entry['device_graph_id'];
    }
    foreach ($graphs as $device_id => $device_graph) {
        foreach ($device_graph as $graph => $data) {
            if (count($data) > 1) {
                // More than one entry for a single graph type for this device, let's clean up.
                // Leave the first entry intact, chop it off the array
                $device_graph_ids = array_slice($data, 1);
                if ($prompt) {
                    $answer = print_prompt(count($device_graph_ids) . " duplicate graph rows of type {$graph} for device {$device_id} will be deleted");
                }
                if ($answer) {
                    $table_status = dbDelete('device_graphs', "`device_graph_id` IN (?)", array($device_graph_ids));
                    print_debug("Deleted " . count($device_graph_ids) . " duplicate graph rows of type {$graph} for device {$device_id}");
                    logfile("cleanup.log", "Deleted " . count($device_graph_ids) . " duplicate graph rows of type {$graph} for device {$device_id}");
                }
            }
        }
    }
}
// EOF
开发者ID:rhizalpatrax64bit,项目名称:StacksNetwork,代码行数:31,代码来源:db_cleanup.php


示例5: chdir

 * @copyright  (C) 2006-2015 Adam Armstrong
 *
 */
chdir(dirname($argv[0]));
$scriptname = basename($argv[0]);
include_once "includes/defaults.inc.php";
include_once "config.php";
$options = getopt("d");
if (isset($options['d'])) {
    array_shift($argv);
}
// for compatability
include_once "includes/definitions.inc.php";
include "includes/functions.inc.php";
$entry = explode(",", $argv[1]);
logfile('SNMPTRAP: ' . $argv[1]);
#print_vars($entry);
$device = @dbFetchRow("SELECT * FROM devices WHERE `hostname` = ?", array($entry['0']));
if (!$device['device_id']) {
    $device = @dbFetchRow("SELECT * FROM ipv4_addresses AS A, ports AS I WHERE A.ipv4_address = ? AND I.port_id = A.port_id", array($entry['0']));
}
if (!$device['device_id']) {
    exit;
}
$file = $config['install_dir'] . "/includes/snmptrap/" . $entry['1'] . ".inc.php";
if (is_file($file)) {
    include "{$file}";
} else {
    echo "未知的陷阱 ({$file})";
}
// EOF
开发者ID:rhizalpatrax64bit,项目名称:StacksNetwork,代码行数:31,代码来源:snmptrap.php


示例6: print_debug

                }
            }
            print_debug("Timing housekeeping: deleted {$rows} entries (per-device)");
            logfile("housekeeping.log", "Timing: deleted {$rows} entries older than " . format_unixtime($cutoff) . " (per-device)");
            $rows = dbDelete('perf_times', $where);
            if ($rows === FALSE) {
                // Use LIMIT with big tables
                print_debug("Performance table (per-run) is too big, using LIMIT for delete entries");
                $rows = 0;
                $i = 1000;
                while ($i && $rows < $count_run) {
                    $iter = dbDelete('perf_times', $where . ' LIMIT 1000000');
                    if ($iter === FALSE) {
                        break;
                    }
                    $rows += $iter;
                    $i--;
                }
            }
            print_debug("Timing housekeeping: deleted {$rows} entries (per-run)");
            logfile("housekeeping.log", "Timing: deleted {$rows} entries older than " . format_unixtime($cutoff) . " (per-run)");
        }
    } else {
        if ($prompt) {
            print_message("No perfomance entries found older than " . format_unixtime($cutoff));
        }
    }
} else {
    print_message("Timing housekeeping disabled in configuration or less than 24h.");
}
// EOF
开发者ID:skive,项目名称:observium,代码行数:31,代码来源:timing.inc.php


示例7: get_http_request

function get_http_request($request)
{
    global $config;
    if (OBS_HTTP_REQUEST === FALSE) {
        print_debug("HTTP requests skipped since previous request exit with timeout.");
        return FALSE;
    }
    $response = '';
    $opts = array('http' => array('timeout' => '15'));
    if (isset($config['http_proxy']) && $config['http_proxy']) {
        $opts['http']['proxy'] = 'tcp://' . $config['http_proxy'];
        $opts['http']['request_fulluri'] = TRUE;
    }
    // Basic proxy auth
    if (isset($config['proxy_user']) && $config['proxy_user'] && isset($config['proxy_password'])) {
        $auth = base64_encode($config['proxy_user'] . ':' . $config['proxy_password']);
        $opts['http']['header'] = 'Proxy-Authorization: Basic ' . $auth;
    }
    $start = utime();
    $context = stream_context_create($opts);
    $response = file_get_contents($request, FALSE, $context);
    $runtime = utime() - $start;
    if (OBS_DEBUG) {
        if (OBS_DEBUG < 2 && strpos($request, 'update.observium.org')) {
            $request = preg_replace('/&stats=.+/', '&stats=***', $request);
        }
        print_message(PHP_EOL . 'REQUEST[%y' . $request . '%n]' . PHP_EOL . 'RUNTIME[' . ($runtime > 3 ? '%r' : '%g') . round($runtime, 4) . 's%n]', 'console');
        if (OBS_DEBUG > 1) {
            print_message("RESPONSE[\n" . $response . "\n]", 'console', FALSE);
        }
    }
    // Set OBS_HTTP_REQUEST for skip all other requests
    if (!defined('OBS_HTTP_REQUEST')) {
        if ($response === FALSE) {
            define('OBS_HTTP_REQUEST', FALSE);
            print_debug(__FUNCTION__ . '() exit with timeout. Access to outside localnet is blocked by firewall or network problems. Check proxy settings.');
            logfile(__FUNCTION__ . '() exit with timeout. Access to outside localnet is blocked by firewall or network problems. Check proxy settings.');
        } else {
            define('OBS_HTTP_REQUEST', TRUE);
        }
    }
    // FIXME. what if first request fine, but second broken?
    //else if ($response === FALSE)
    //{
    //  if (function_exists('runkit_constant_redefine')) { runkit_constant_redefine('OBS_HTTP_REQUEST', FALSE); }
    //}
    return $response;
}
开发者ID:rhizalpatrax64bit,项目名称:StacksNetwork,代码行数:48,代码来源:common.inc.php


示例8: print_debug

             if ($file_data['mtime'] < $cutoff) {
                 print_debug("File modification time is " . format_unixtime($file_data['mtime']) . " - deleting");
                 logfile("housekeeping.log", "File {$file} modification time is " . format_unixtime($file_data['mtime']) . " - deleting");
                 unlink($file);
                 $count_notmodified++;
             }
         }
         // Not using finfo functions from PHP, whatever I tried always resulted in application/octet-stream. Dumb thing.
         if ($config['housekeeping']['rrd']['invalid'] && file_exists($file)) {
             if (!file_exists($config['file'])) {
                 print_debug("Magic 'file' binary not found in configured path!");
             } else {
                 $filetype = $this_data = trim(external_exec($config['file'] . " -b " . $file));
                 if (substr($filetype, 0, 10) != "RRDTool DB") {
                     print_debug("Invalid file type for {$file} ({$filetype}) - deleting");
                     logfile("housekeeping.log", "File {$file} has invalid type: {$filetype} - deleting");
                     unlink($file);
                     $count_notvalid++;
                 }
             }
         }
     }
 }
 if ($prompt && $cutoff) {
     if ($count_notmodified) {
         print_message("Deleted {$count_notmodified} not modified RRD files older than " . format_unixtime($cutoff));
     } else {
         print_message("No RRD files found last modified before " . format_unixtime($cutoff));
     }
 }
 if ($prompt && $config['housekeeping']['rrd']['invalid']) {
开发者ID:skive,项目名称:observium,代码行数:31,代码来源:rrd.inc.php


示例9: isPingable

/**
 * Checks device availability by icmp echo response
 * If flag OBS_PING_SKIP passed, pings skipped and returns 0.001 (1ms)
 *
 * @param string $hostname Device hostname or IP address
 * @param int Flags. Supported OBS_DNS_A, OBS_DNS_AAAA and OBS_PING_SKIP
 * @return float Average response time for used retries count (default retries is 3)
 */
function isPingable($hostname, $flags = OBS_DNS_ALL)
{
    global $config;
    $ping_debug = isset($config['ping']['debug']) && $config['ping']['debug'];
    $try_a = is_flag_set(OBS_DNS_A, $flags);
    if (is_flag_set(OBS_PING_SKIP, $flags)) {
        return 0.001;
        // Ping is skipped, just return 1ms
    }
    $timeout = isset($config['ping']['timeout']) ? (int) $config['ping']['timeout'] : 500;
    if ($timeout < 50) {
        $timeout = 50;
    } else {
        if ($timeout > 2000) {
            $timeout = 2000;
        }
    }
    $retries = isset($config['ping']['retries']) ? (int) $config['ping']['retries'] : 3;
    if ($retries < 1) {
        $retries = 3;
    } else {
        if ($retries > 10) {
            $retries = 10;
        }
    }
    $sleep = floor(1000000 / $retries);
    // interval between retries, max 1 sec
    if ($ip_version = get_ip_version($hostname)) {
        // Ping by IP
        if ($ip_version === 6) {
            $cmd = $config['fping6'] . " -t {$timeout} -c 1 -q {$hostname} 2>&1";
        } else {
            if (!$try_a) {
                if ($ping_debug) {
                    logfile('debug.log', __FUNCTION__ . "() | DEVICE: {$hostname} | Passed IPv4 address but device use IPv6 transport");
                }
                print_debug('Into function ' . __FUNCTION__ . '() passed IPv4 address (' . $hostname . 'but device use IPv6 transport');
                return 0;
            }
            // Forced check for actual IPv4 address
            $cmd = $config['fping'] . " -t {$timeout} -c 1 -q {$hostname} 2>&1";
        }
    } else {
        // First try IPv4
        $ip = $try_a ? gethostbyname($hostname) : FALSE;
        // Do not check IPv4 if transport IPv6
        if ($ip && $ip != $hostname) {
            $cmd = $config['fping'] . " -t {$timeout} -c 1 -q {$ip} 2>&1";
        } else {
            $ip = gethostbyname6($hostname, OBS_DNS_AAAA);
            // Second try IPv6
            if ($ip) {
                $cmd = $config['fping6'] . " -t {$timeout} -c 1 -q {$ip} 2>&1";
            } else {
                // No DNS records
                if ($ping_debug) {
                    logfile('debug.log', __FUNCTION__ . "() | DEVICE: {$hostname} | NO DNS record found");
                }
                return 0;
            }
        }
    }
    for ($i = 1; $i <= $retries; $i++) {
        $output = external_exec($cmd);
        if ($GLOBALS['exec_status']['exitcode'] === 0) {
            // normal $output = '8.8.8.8 : xmt/rcv/%loss = 1/1/0%, min/avg/max = 1.21/1.21/1.21'
            $tmp = explode('/', $output);
            $ping = $tmp[7];
            if (!$ping) {
                $ping = 0.001;
            }
            // Protection from zero (exclude false status)
        } else {
            $ping = 0;
        }
        if ($ping) {
            break;
        }
        if ($ping_debug) {
            logfile('debug.log', __FUNCTION__ . "() | DEVICE: {$hostname} | FPING OUT ({$i}): " . $output[0]);
            if ($i == $retries) {
                $mtr = $config['mtr'] . " -r -n -c 5 {$ip}";
                logfile('debug.log', __FUNCTION__ . "() | DEVICE: {$hostname} | MTR OUT:\n" . external_exec($mtr));
            }
        }
        if ($i < $retries) {
            usleep($sleep);
        }
    }
    return $ping;
}
开发者ID:Natolumin,项目名称:observium,代码行数:99,代码来源:functions.inc.php


示例10: zef_edit_comment

/**
 * Just edit the comment an entry. This is used for editing the comment
 * of a running entry.
 * 
 * @param $zef_ID id of the timesheet entry
 * @param $comment_type new type of the comment
 * @param $comment the comment text
 */
function zef_edit_comment($zef_ID, $comment_type, $comment)
{
    global $kga, $conn;
    $zef_ID = MySQL::SQLValue($zef_ID, MySQL::SQLVALUE_NUMBER);
    $comment_type = MySQL::SQLValue($comment_type);
    $comment = MySQL::SQLValue($comment);
    $table = $kga['server_prefix'] . "zef";
    $filter['zef_ID'] = $zef_ID;
    $values['zef_comment_type'] = $comment_type;
    $values['zef_comment'] = $comment;
    $query = MySQL::BuildSQLUpdate($table, $values, $filter);
    logfile($query);
    return $conn->Query($query);
}
开发者ID:pombredanne,项目名称:ArcherSys,代码行数:22,代码来源:db_layer_mysql.php


示例11: print_prompt

        if ($prompt) {
            $answer = print_prompt("{$count} eventlog entries older than " . format_unixtime($cutoff) . " will be deleted");
        }
        if ($answer) {
            $rows = dbDelete('eventlog', $where);
            if ($rows === FALSE) {
                // Use LIMIT with big tables
                print_debug("Event log table is too big, using LIMIT to delete entries");
                $rows = 0;
                $i = 1000;
                while ($i && $rows < $count) {
                    $iter = dbDelete('eventlog', $where . ' LIMIT 1000000');
                    if ($iter === FALSE) {
                        break;
                    }
                    $rows += $iter;
                    $i--;
                }
            }
            print_debug("Event log housekeeping: deleted {$rows} entries");
            logfile("housekeeping.log", "Event log: deleted {$rows} entries older than " . format_unixtime($cutoff));
        }
    } else {
        if ($prompt) {
            print_message("No event log entries found older than " . format_unixtime($cutoff));
        }
    }
} else {
    print_message("Event log housekeeping is disabled in configuration or less than 24h.");
}
// EOF
开发者ID:skive,项目名称:observium,代码行数:31,代码来源:eventlog.inc.php


示例12: age_to_unixtime

 * @package    observium
 * @subpackage housekeeping
 * @author     Adam Armstrong <[email protected]>
 * @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) {
            print_message("No ports found marked as deleted before " . format_unixtime($cutoff));
        }
    }
} else {
    print_message("Deleted ports housekeeping disabled in configuration.");
}
// EOF
开发者ID:Natolumin,项目名称:observium,代码行数:31,代码来源:ports.inc.php


示例13: get_dev_attrib

global $valid, $agent_sensors;
if ($device['os_group'] == "unix") {
    echo "Observium UNIX Agent: ";
    // Use port configured in config (or defaults)
    $agent_port = $config['unix-agent']['port'];
    // ... Unless user configured a port for this specific device, and it's valid (numeric and within 16-bit port range)
    $override_port = get_dev_attrib($device, 'agent_port');
    if (is_numeric($override_port) && $override_port < 65536) {
        $agent_port = $override_port;
    }
    $agent_start = utime();
    $agent_socket = "tcp://" . $device['hostname'] . ":" . $agent_port;
    $agent = @stream_socket_client($agent_socket, $errno, $errstr, 10);
    if (!$agent) {
        print_warning("Connection to UNIX agent on " . $agent_socket . " failed. ERROR: " . $errno . " " . $errstr);
        logfile("UNIX-AGENT: Connection on " . $agent_socket . " failed. ERROR: " . $errno . " " . $errstr);
    } else {
        $agent_raw = stream_get_contents($agent);
    }
    $agent_end = utime();
    $agent_time = round(($agent_end - $agent_start) * 1000);
    if (!empty($agent_raw)) {
        echo "execution time: " . $agent_time . "ms";
        rrdtool_update_ng($device, 'agent', array('time' => $agent_time));
        $graphs['agent'] = TRUE;
        foreach (explode("<<<", $agent_raw) as $section) {
            list($section, $data) = explode(">>>", $section);
            $sa = '';
            $sb = '';
            $sc = '';
            # DO -NOT- ADD NEW CASES BELOW -- use <<<app-$foo>>> in your application script
开发者ID:Natolumin,项目名称:observium,代码行数:31,代码来源:unix-agent.inc.php


示例14: array

$comment_types = array($kga['lang']['ctype0'], $kga['lang']['ctype1'], $kga['lang']['ctype2']);
// ==================
// = security check =
// ==================
if (isset($_REQUEST['axAction']) && !is_array($_REQUEST['axAction']) && $_REQUEST['axAction'] != "") {
    $axAction = strip_tags($_REQUEST['axAction']);
} else {
    $axAction = '';
}
$axValue = isset($_REQUEST['axValue']) ? strip_tags($_REQUEST['axValue']) : '';
$id = isset($_REQUEST['id']) ? strip_tags($_REQUEST['id']) : null;
// ============================================
// = initialize currently displayed timespace =
// ============================================
$timespace = get_timespace();
$in = $timespace[0];
$out = $timespace[1];
if (isset($_REQUEST['first_day'])) {
    $in = (int) $_REQUEST['first_day'];
}
if (isset($_REQUEST['last_day'])) {
    $out = mktime(23, 59, 59, date("n", $_REQUEST['last_day']), date("j", $_REQUEST['last_day']), date("Y", $_REQUEST['last_day']));
}
if ($axAction != "reloadLogfile") {
    logfile("KSPI axAction (" . (array_key_exists('customer', $kga) ? $kga['customer']['knd_name'] : $kga['usr']['usr_name']) . "): " . $axAction);
}
// prevent IE from caching the response
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
开发者ID:pombredanne,项目名称:ArcherSys,代码行数:31,代码来源:kspi.php


示例15: CollectData

function CollectData($bill_id)
{
    $port_list = dbFetchRows("SELECT * FROM `bill_ports` as P, `ports` as I, `devices` as D WHERE P.bill_id=? AND I.port_id = P.port_id AND D.device_id = I.device_id", array($bill_id));
    print_r($port_list);
    $now = dbFetchCell("SELECT NOW()");
    foreach ($port_list as $port_data) {
        $port_id = $port_data['port_id'];
        $host = $port_data['hostname'];
        $port = $port_data['port'];
        echo "\nPolling " . $port_data['ifDescr'] . " on " . $port_data['hostname'] . "\n";
        $port_data['in_measurement'] = getValue($port_data['hostname'], $port_data['port'], $port_data['ifIndex'], "In");
        $port_data['out_measurement'] = getValue($port_data['hostname'], $port_data['port'], $port_data['ifIndex'], "Out");
        $last_data = getLastPortCounter($port_id, in);
        if ($last_data['state'] == "ok") {
            $port_data['last_in_measurement'] = $last_data[counter];
            $port_data['last_in_delta'] = $last_data[delta];
            if ($port_data['in_measurement'] > $port_data['last_in_measurement']) {
                $port_data['in_delta'] = $port_data['in_measurement'] - $port_data['last_in_measurement'];
            } else {
                $port_data['in_delta'] = $port_data['last_in_delta'];
            }
        } else {
            $port_data['in_delta'] = '0';
        }
        dbInsert(array('port_id' => $port_id, 'timestamp' => $now, 'counter' => $port_data['in_measurement'], 'delta' => $port_data['in_delta']), 'port_in_measurements');
        $last_data = getLastPortCounter($port_id, out);
        if ($last_data[state] == "ok") {
            $port_data['last_out_measurement'] = $last_data[counter];
            $port_data['last_out_delta'] = $last_data[delta];
            if ($port_data['out_measurement'] > $port_data['last_out_measurement']) {
                $port_data['out_delta'] = $port_data['out_measurement'] - $port_data['last_out_measurement'];
            } else {
                $port_data['out_delta'] = $port_data['last_out_delta'];
            }
        } else {
            $port_data['out_delta'] = '0';
        }
        dbInsert(array('port_id' => $port_id, 'timestamp' => $now, 'counter' => $port_data['out_measurement'], 'delta' => $port_data['out_delta']), 'port_out_measurements');
        $delta = $delta + $port_data['in_delta'] + $port_data['out_delta'];
        $in_delta = $in_delta + $port_data['in_delta'];
        $out_delta = $out_delta + $port_data['out_delta'];
    }
    $last_data = getLastMeasurement($bill_id);
    if ($last_data[state] == "ok") {
        $prev_delta = $last_data[delta];
        $prev_in_delta = $last_data[in_delta];
        $prev_out_delta = $last_data[out_delta];
        $prev_timestamp = $last_data[timestamp];
        $period = dbFetchCell("SELECT UNIX_TIMESTAMP(CURRENT_TIMESTAMP()) - UNIX_TIMESTAMP('" . mres($prev_timestamp) . "')");
    } else {
        $prev_delta = '0';
        $period = '0';
        $prev_in_delta = '0';
        $prev_out_delta = '0';
    }
    if ($delta < '0') {
        $delta = $prev_delta;
        $in_delta = $prev_in_delta;
        $out_delta = $prev_out_delta;
    }
    if ($period < "0") {
        logfile("BILLING: negative period! id:{$bill_id} period:{$period} delta:{$delta} in_delta:{$in_delta} out_delta:{$out_delta}");
    } else {
        dbInsert(array('bill_id' => $bill_id, 'timestamp' => $now, 'period' => $period, 'delta' => $delta, 'in_delta' => $in_delta, 'out_delta' => $out_delta), 'bill_data');
    }
}
开发者ID:REAP720801,项目名称:librenms,代码行数:66,代码来源:poll-billing.php


示例16: logfile

                            logfile('update-errors.log', "====== 架构更新 " . sprintf("%03d", $db_rev) . " -> " . sprintf("%03d", $filename) . " ==============");
                            foreach ($errors as $error) {
                                logfile('update-errors.log', "查询: " . $error['query']);
                                logfile('update-errors.log', "错误: " . $error['error']);
                            }
                            fclose($fd);
                            unset($errors);
                        } else {
                            echo " 完成.\n";
                        }
                    }
                } else {
                    echo " 无法打开文件!\n";
                    // Critical errors, stop update
                    logfile('update-errors.log', "====== Schema update " . sprintf("%03d", $db_rev) . " -> " . sprintf("%03d", $filename) . " ==============");
                    logfile('update-errors.log', "Error: Could not open file {$filepath}!");
                    exit(1);
                }
            }
        }
        $updating++;
        $db_rev = $filename;
    }
}
if ($updating) {
    $GLOBALS['cache']['db_version'] = $db_rev;
    // Cache new db version
    if ($insert) {
        dbInsert(array('version' => $db_rev), 'dbSchema');
    } else {
        dbUpdate(array('version' => $db_rev), 'dbSchema');
开发者ID:rhizalpatrax64bit,项目名称:StacksNetwork,代码行数:31,代码来源:update.php


示例17: header

 *
 * Copyright (c) 2014 Neil Lathwood <https://github.com/laf/ http://www.lathwood.co.uk/fa>
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or (at your
 * option) any later version.  Please see LICENSE.txt at the top level of
 * the source code distribution for details.
*/
header('Content-type: application/json');
$status = 'error';
$descr = mres($_POST['descr']);
$device_id = mres($_POST['device_id']);
$ifName = mres($_POST['ifName']);
$port_id = mres($_POST['port_id']);
logfile($descr . ',' . $device_id . ',' . $ifName . ',' . $port_id);
if (!empty($ifName) && is_numeric($port_id)) {
    // We have ifName and  port id so update ifAlias
    if (empty($descr)) {
        $descr = 'repoll';
        // Set to repoll so we avoid using ifDescr on port poll
    }
    if (dbUpdate(array('ifAlias' => $descr), 'ports', '`port_id`=?', array($port_id)) > 0) {
        $device = device_by_id_cache($device_id);
        if ($descr === 'repoll') {
            del_dev_attrib($device, 'ifName:' . $ifName);
        } else {
            set_dev_attrib($device, 'ifName:' . $ifName, 1);
        }
        $status = 'ok';
    } else {
开发者ID:greggcz,项目名称:librenms,代码行数:31,代码来源:update-ifalias.inc.php


示例18: poll_bill

function poll_bill($bill)
{
    $ports = dbFetchRows("SELECT * FROM `bill_ports` as P, `ports` as I, `devices` as D WHERE P.bill_id=? AND I.port_id = P.port_id AND D.device_id = I.device_id", array($bill['bill_id']));
    if (isset($options['d'])) {
        print_r($ports);
    }
    foreach ($ports as $port) {
        echo "\nPolling " . $port['ifDescr'] . " on " . $port['hostname'] . "\n";
        $now = time();
        if (is_numeric($port['bill_port_polled'])) {
            $period = $now - $port['bill_port_polled'];
        }
        echo "time: " . $now . "|" . $port['bill_port_polled'] . " period:" . $period . "\n";
        if ($port['snmpver'] == "1") {
            // SNMPv1 - Use non 64-bit counters
            $oids = "IF-MIB::ifInOctets." . $port['ifIndex'] . " IF-MIB::ifOutOctets." . $port['ifIndex'];
            $data = snmp_get_multi($port, $oids, "-OQUs", "IF-MIB");
            $data = $data[$port['ifIndex']];
            $data = array('in' => $data['ifInOctets'], 'out' => $data['ifOutOctets']);
        } else {
            // Not SNMPv1 - Use 64-bit counters
            $oids = "IF-MIB::ifHCInOctets." . $port['ifIndex'] . " IF-MIB::ifHCOutOctets." . $port['ifIndex'];
            $data = snmp_get_multi($port, $oids, "-OQUs", "IF-MIB");
            $data = $data[$port['ifIndex']];
            $data = array('in' => $data['ifHCInOctets'], 'out' => $data['ifHCOutOctets']);
            // Fallback on 32-bit counters if 64-bit fails
            if (empty($data['in']) && empty($data['out'])) {
                $oids = "IF-MIB::ifInOctets." . $port['ifIndex'] . " IF-MIB::ifOutOctets." . $port['ifIndex'];
                $data = snmp_get_multi($port, $oids, "-OQUs", "IF-MIB");
                $data = $data[$port['ifIndex']];
                $data = array('in' => $data['ifInOctets'], 'out' => $data['ifOutOctets']);
            }
            if (isset($options['d'])) {
                print_r($data);
            }
        }
        if (is_numeric($data['in']) && is_numeric($data['out'])) {
            echo $period . "|" . $port['bill_port_counter_in'] . "|" . $port['bill_port_counter_out'] . "|" . $data['in'] . "|" . $port['bill_port_counter_in'] . "\n";
            // The port returned counters
            if (is_numeric($period) && is_numeric($port['bill_port_counter_in']) && is_numeric($port['bill_port_counter_out']) && $data['in'] >= $port['bill_port_counter_in'] && $data['out'] >= $port['bill_port_counter_out']) {
                // Counters are higher or equal to before, seems legit.
                $in_delta = $data['in'] - $port['bill_port_counter_in'];
                $out_delta = $data['out'] - $port['bill_port_counter_out'];
                echo "Counters valid, delta generated.\n";
            } elseif (is_numeric($period) && is_numeric($port['bill_port_counter_in']) && is_numeric($port['bill_port_counter_out'])) {
                // Counters are lower, we must have wrapped. We'll take the measurement as the amount for this period.
                $in_delta = $data['in'];
                $out_delta = $data['out'];
                echo "Counters wrapped, delta fudged.\n";
            } else {
                // First update. delta is zero, only insert counters.
                echo "No existing counters.\n";
                $in_delta = 0;
                $out_delta = 0;
            }
            if ($in_delta == $data['in'] || $in_delta == $data['in']) {
                // Deltas are equal to counters. Clearly fail.
                echo "Deltas equal counters. Resetting.";
                $in_delta = 0;
                $out_delta = 0;
            }
            $update = array('bill_port_polled' => $now, 'bill_port_period' => $period, 'bill_port_counter_in' => $data['in'], 'bill_port_counter_out' => $data['out'], 'bill_port_delta_in' => $in_delta, 'bill_port_delta_out' => $out_delta);
            dbUpdate($update, 'bill_ports', '`bill_id` = ? AND `port_id` = ?', array($port['bill_id'], $port['port_id']));
            echo "data:  in(N:" . $data['in'] . "|P:" . $port['bill_port_counter_in'] . ") delta:" . $in_delta . "\n";
            echo "      out(N:" . $data['out'] . "|P:" . $port['bill_port_counter_out'] . ") delta:" . $out_delta . "\n";
        } else {
            // No counters were returned
            // We don't need to update the database.
            echo "No data.\n";
        }
        dbInsert(array('port_id' => $port['port_id'], 'timestamp' => $now, 'counter' => $data['in'], 'delta' => $in_delta), 'bill_port_in_data');
        dbInsert(array('port_id' => $port['port_id'], 'timestamp' => $now, 'counter' => $data['out'], 'delta' => $out_delta), 'bill_port_out_data');
        $bill_delta += $in_delta + $out_delta;
        $bill_in_delta += $in_delta;
        $bill_out_delta += $out_delta;
        echo "deltas: i:" . $bill_in_delta . " o:" . $bill_out_delta . " t:" . $bill_delta . "\n";
    }
    echo "Bill processing...\n";
    $now = time();
    if (is_numeric($bill['bill_polled'])) {
        $period = $now - $bill['bill_polled'];
    }
    echo "time: " . $now . "|" . $bill['bill_polled'] . " period:" . $period . "\n\n\n";
    if ($period <= '0') {
        $bill_delta = '0';
        $bill_in_delta = '0';
        $bill_out_delta = '0';
    }
    dbUpdate(array('bill_polled' => $now), 'bills', '`bill_id` = ?', array($port['bill_id']));
    if ($period < "0" || !is_numeric($period)) {
        logfile("BILLING: negative period! id:" . $bill['bill_id'] . " period:{$period} delta:{$bill_delta} in_delta:{$bill_in_delta} out_delta:{$bill_out_delta}");
    } else {
        dbInsert(array('bill_id' => $bill['bill_id'], 'timestamp' => array("NOW()"), 'period' => $period, 'delta' => $bill_delta, 'in_delta' => $bill_in_delta, 'out_delta' => $bill_out_delta), 'bill_data');
    }
}
开发者ID:RomanBogachev,项目名称:observium,代码行数:95,代码来源:poll-billing.php


示例19: exec_query

 /**
  * Execute an sql query in the database. The correct database connection
  * will be chosen and the query will be logged with the success status.
  * 
  * As third parameter an alternative query can be passed, which should be
  * displayed instead of the executed query. This prevents leakage of
  * confidential information like password salts. The logfile will still
  * contain the executed query.
  * 
  * @param $query query to execute as string
  * @param $errorProcessing true if it's an error when the query fails.
  */
 function exec_query($query, $errorProcessing = false, $displayQuery = null)
 {
     global $conn, $pdo_conn, $kga, $errors, $executed_queries;
     $executed_queries++;
     echo "<tr>";
     if ($kga['server_conn'] == "pdo") {
         if (is_object($pdo_conn)) {
             $pdo_query = $pdo_conn->prepare($query);
             $success = $pdo_query->execute(array());
         }
     } else {
         if (is_object($conn)) {
             $success = $conn->Query($query);
         }
     }
     logfile($query, $success);
     if ($kga['server_conn'] == "pdo") {
         if (is_object($pdo_conn)) {
             $err = $pdo_query->errorInfo();
             $err = serialize($err);
         }
     } else {
         if (is_object($conn)) {
             $err = $conn->Error();
         }
     }
     $query = htmlspecialchars($query);
     $displayQuery = htmlspecialchars($displayQuery);
     echo "<td>" . ($displayQuery == null ? $query : $displayQuery) . "<br/>";
     echo "<span class='error_info'>" . $err . "</span>";
     echo "</td>";
     if ($success) {
         echo "<td class='green'>&nbsp;&nbsp;</td>";
     } else {
         if ($errorProcessing) {
             echo "<td class='red'>!</td>";
             $errors++;
         } else {
             echo "<td class='orange'>&nbsp;&nbsp;</td>";
         }
     }
     if (!$success) {
         logfile("An error has occured in query: {$query}");
         if ($kga['server_conn'] == "pdo") {
             if (is_object($pdo_conn)) {
                 $err = $pdo_query->errorInfo();
                 $err = serialize($err);
             }
         } else {
             if (is_object($conn)) {
                 $err = $conn->Error();
             }
         }
         logfile("Error text: {$err}");
     }
 }
开发者ID:pombredanne,项目名称:ArcherSys,代码行数:68,代码来源:updater.php


示例20: utime

 $agent_port = $config['unix-agent']['port'];
 // Try Official port
 $agent_start = utime();
 $agent_socket = "tcp://" . $device['h 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP logg函数代码示例发布时间:2022-05-15
下一篇:
PHP log_write函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap