本文整理汇总了PHP中zeropad函数的典型用法代码示例。如果您正苦于以下问题:PHP zeropad函数的具体用法?PHP zeropad怎么用?PHP zeropad使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了zeropad函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: getDates
function getDates($dayofmonth, $months = 0)
{
$dayofmonth = zeropad($dayofmonth);
$year = date('Y');
$month = date('m');
if (date('d') > $dayofmonth) {
// Billing day is past, so it is next month
$date_end = date_create($year . '-' . $month . '-' . $dayofmonth);
$date_start = date_create($year . '-' . $month . '-' . $dayofmonth);
date_add($date_end, date_interval_create_from_date_string('1 month'));
} else {
// Billing day will happen this month, therefore started last month
$date_end = date_create($year . '-' . $month . '-' . $dayofmonth);
$date_start = date_create($year . '-' . $month . '-' . $dayofmonth);
date_sub($date_start, date_interval_create_from_date_string('1 month'));
}
if ($months > 0) {
date_sub($date_start, date_interval_create_from_date_string($months . ' month'));
date_sub($date_end, date_interval_create_from_date_string($months . ' month'));
}
// date_sub($date_start, date_interval_create_from_date_string('1 month'));
date_sub($date_end, date_interval_create_from_date_string('1 day'));
$date_from = date_format($date_start, 'Ymd') . '000000';
$date_to = date_format($date_end, 'Ymd') . '235959';
date_sub($date_start, date_interval_create_from_date_string('1 month'));
date_sub($date_end, date_interval_create_from_date_string('1 month'));
$last_from = date_format($date_start, 'Ymd') . '000000';
$last_to = date_format($date_end, 'Ymd') . '235959';
$return = array();
$return['0'] = $date_from;
$return['1'] = $date_to;
$return['2'] = $last_from;
$return['3'] = $last_to;
return $return;
}
开发者ID:Tatermen,项目名称:librenms,代码行数:35,代码来源:billing.php
示例2: snmp_cache_cip
function snmp_cache_cip($oid, $device, $array, $mib = 0)
{
global $config;
$cmd = ($device['snmpver'] == 'v1' ? $config['snmpwalk'] : $config['snmpbulkwalk']) . " -O snQ -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . ":" . $device['port'] . " ";
if ($mib) {
$cmd .= "-m {$mib} ";
}
$cmd .= $oid;
$data = trim(shell_exec($cmd));
$device_id = $device['device_id'];
#echo("Caching: $oid\n");
foreach (explode("\n", $data) as $entry) {
list($this_oid, $this_value) = split("=", $entry);
$this_oid = trim($this_oid);
$this_value = trim($this_value);
$this_oid = substr($this_oid, 30);
list($ifIndex, $dir, $a, $b, $c, $d, $e, $f) = explode(".", $this_oid);
$h_a = zeropad(dechex($a));
$h_b = zeropad(dechex($b));
$h_c = zeropad(dechex($c));
$h_d = zeropad(dechex($d));
$h_e = zeropad(dechex($e));
$h_f = zeropad(dechex($f));
$mac = "{$h_a}{$h_b}{$h_c}{$h_d}{$h_e}{$h_f}";
if ($dir == "1") {
$dir = "input";
} elseif ($dir == "2") {
$dir = "output";
}
if ($mac && $dir) {
$array[$device_id][$ifIndex][$mac][$oid][$dir] = $this_value;
}
}
return $array;
}
开发者ID:kyrisu,项目名称:observernms,代码行数:35,代码来源:snmp.inc.php
示例3: getDates
function getDates($dayofmonth, $months = 0)
{
$dayofmonth = zeropad($dayofmonth);
$year = date('Y');
$month = date('m');
if (date('d') >= $dayofmonth) {
$date_end = date_create($year . '-' . $month . '-' . $dayofmonth);
$date_start = date_create($year . '-' . $month . '-' . $dayofmonth);
date_add($date_end, date_interval_create_from_date_string('1 月'));
} else {
// Billing day will happen this month, therefore started last month
$date_end = date_create($year . '-' . $month . '-' . $dayofmonth);
$date_start = date_create($year . '-' . $month . '-' . $dayofmonth);
date_sub($date_start, date_interval_create_from_date_string('1 月'));
}
if ($months > 0) {
date_sub($date_start, date_interval_create_from_date_string($months . ' 月'));
date_sub($date_end, date_interval_create_from_date_string($months . ' 月'));
}
# date_sub($date_start, date_interval_create_from_date_string('1 月'));
date_sub($date_end, date_interval_create_from_date_string('1 天'));
$date_from = date_format($date_start, 'Ymd') . "000000";
$date_to = date_format($date_end, 'Ymd') . "235959";
date_sub($date_start, date_interval_create_from_date_string('1 月'));
date_sub($date_end, date_interval_create_from_date_string('1 月'));
$last_from = date_format($date_start, 'Ymd') . "000000";
$last_to = date_format($date_end, 'Ymd') . "235959";
$return['0'] = $date_from;
$return['1'] = $date_to;
$return['2'] = $last_from;
$return['3'] = $last_to;
return $return;
}
开发者ID:rhizalpatrax64bit,项目名称:StacksNetwork,代码行数:33,代码来源:billing.inc.php
示例4: getHEXRGB
function getHEXRGB($string)
{
$matches = null;
$returnValue = preg_match('/rgba?\\(\\s*(?<red>[0-9A-F]{1,3})\\s*,\\s*(?<green>[0-9A-F]{1,3})\\s*,\\s*(?<blue>[0-9A-F]{1,3})/is', $string, $matches);
if ($returnValue) {
return zeropad(dechex(intval($matches["red"])), 2) . zeropad(dechex(intval($matches["green"])), 2) . zeropad(dechex(intval($matches["blue"])), 2);
}
return trim($string, "#");
}
开发者ID:zakaria340,项目名称:critique,代码行数:9,代码来源:front.php
示例5: snmpwalk_cache_cip
function snmpwalk_cache_cip($device, $oid, $array = array(), $mib = 0)
{
global $config, $debug;
$timeout = prep_snmp_setting($device, 'timeout');
$retries = prep_snmp_setting($device, 'retries');
if (!isset($device['transport'])) {
$device['transport'] = 'udp';
}
if ($device['snmpver'] == 'v1' || $config['os'][$device['os']]['nobulk']) {
$snmpcommand = $config['snmpwalk'];
} else {
$snmpcommand = $config['snmpbulkwalk'];
}
$cmd = $snmpcommand;
$cmd .= snmp_gen_auth($device);
$cmd .= ' -O snQ';
if ($mib) {
$cmd .= " -m {$mib}";
}
$cmd .= mibdir(null);
$cmd .= isset($timeout) ? ' -t ' . $timeout : '';
$cmd .= isset($retries) ? ' -r ' . $retries : '';
$cmd .= ' ' . $device['transport'] . ':' . $device['hostname'] . ':' . $device['port'] . ' ' . $oid;
if (!$debug) {
$cmd .= ' 2>/dev/null';
}
$data = trim(external_exec($cmd));
// echo("Caching: $oid\n");
foreach (explode("\n", $data) as $entry) {
list($this_oid, $this_value) = preg_split('/=/', $entry);
$this_oid = trim($this_oid);
$this_value = trim($this_value);
$this_oid = substr($this_oid, 30);
list($ifIndex, $dir, $a, $b, $c, $d, $e, $f) = explode('.', $this_oid);
$h_a = zeropad(dechex($a));
$h_b = zeropad(dechex($b));
$h_c = zeropad(dechex($c));
$h_d = zeropad(dechex($d));
$h_e = zeropad(dechex($e));
$h_f = zeropad(dechex($f));
$mac = "{$h_a}{$h_b}{$h_c}{$h_d}{$h_e}{$h_f}";
if ($dir == '1') {
$dir = 'input';
} else {
if ($dir == '2') {
$dir = 'output';
}
}
if ($mac && $dir) {
$array[$ifIndex][$mac][$oid][$dir] = $this_value;
}
}
//end foreach
return $array;
}
开发者ID:JamesonFinney,项目名称:librenms,代码行数:55,代码来源:snmp.inc.php
示例6: snmpwalk_cache_oid
// Copyright (c) 1986-2011 by Cisco Systems, Inc.
// Compiled Thu 22-Dec-11 00:46 by prod_rel_team
// mtxrNeighborPlatform.1 = STRING: cisco WS-C2960G-48TC-L
// mtxrNeighborIdentity.1 = STRING: switch.example.com
// mtxrNeighborSoftwareID.1 = STRING:
// mtxrNeighborInterfaceID.1 = INTEGER: 2
$mtxr_array = snmpwalk_cache_oid($device, "mtxrNeighbor", array(), "MIKROTIK-MIB", NULL, OBS_SNMP_ALL | OBS_SNMP_CONCAT);
if ($mtxr_array) {
if (OBS_DEBUG > 1) {
print_vars($mtxr_array);
}
foreach ($mtxr_array as $key => $entry) {
// Need to straighten out the MAC first for use later. Mikrotik does not pad the numbers! (i.e. 0:12:23:3:5c:6b)
// FIXME move this to a smarter function?
list($a, $b, $c, $d, $e, $f) = explode(':', $entry['mtxrNeighborMacAddress'], 6);
$entry['mtxrNeighborMacAddress'] = zeropad($a) . ':' . zeropad($b) . ':' . zeropad($c) . ':' . zeropad($d) . ':' . zeropad($e) . ':' . zeropad($f);
$ifIndex = $entry['mtxrNeighborInterfaceID'];
// Get the port using BRIDGE-MIB
$port = dbFetchRow("SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ? AND `ifDescr` NOT LIKE 'Vlan%'", array($device['device_id'], $ifIndex));
$remote_device_id = FALSE;
$remote_port_id = 0;
if (is_valid_hostname($entry['mtxrNeighborIdentity'])) {
if (isset($GLOBALS['cache']['discovery-protocols'][$entry['mtxrNeighborIdentity']])) {
// This hostname already checked, skip discover
$remote_device_id = $GLOBALS['cache']['discovery-protocols'][$entry['mtxrNeighborIdentity']];
} else {
$remote_device = dbFetchRow("SELECT `device_id`, `hostname` FROM `devices` WHERE `sysName` = ? OR `hostname` = ?", array($entry['mtxrNeighborIdentity'], $entry['mtxrNeighborIdentity']));
$remote_device_id = $remote_device['device_id'];
// If we don't know this device, try to discover it, as long as it's not matching our exclusion filters
if (!$remote_device_id && !is_bad_xdp($entry['mtxrNeighborIdentity'], $entry['mtxrNeighborPlatform'])) {
$remote_device_id = discover_new_device($entry['mtxrNeighborIdentity'], 'xdp', 'MNDP', $device, $port);
开发者ID:Natolumin,项目名称:observium,代码行数:31,代码来源:mikrotik-mib.inc.php
示例7: testZeropad
/**
* @dataProvider providerZeropad
*/
public function testZeropad($value, $result)
{
$this->assertSame($result, zeropad($value));
}
开发者ID:skive,项目名称:observium,代码行数:7,代码来源:IncludesCommonTest.php
示例8: snmpwalk_cache_cip
function snmpwalk_cache_cip($device, $oid, $array = array(), $mib = 0)
{
$cmd = gen_snmpwalk_cmd($device, $oid, ' -OsnQ', $mib);
$data = trim(external_exec($cmd));
// echo("Caching: $oid\n");
foreach (explode("\n", $data) as $entry) {
list($this_oid, $this_value) = preg_split('/=/', $entry);
$this_oid = trim($this_oid);
$this_value = trim($this_value);
$this_oid = substr($this_oid, 30);
list($ifIndex, $dir, $a, $b, $c, $d, $e, $f) = explode('.', $this_oid);
$h_a = zeropad(dechex($a));
$h_b = zeropad(dechex($b));
$h_c = zeropad(dechex($c));
$h_d = zeropad(dechex($d));
$h_e = zeropad(dechex($e));
$h_f = zeropad(dechex($f));
$mac = "{$h_a}{$h_b}{$h_c}{$h_d}{$h_e}{$h_f}";
if ($dir == '1') {
$dir = 'input';
} elseif ($dir == '2') {
$dir = 'output';
}
if ($mac && $dir) {
$array[$ifIndex][$mac][$oid][$dir] = $this_value;
}
}
//end foreach
return $array;
}
开发者ID:Rosiak,项目名称:librenms,代码行数:30,代码来源:snmp.inc.php
示例9: preg_match
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2014 Adam Armstrong
*
*/
// This could do with a rewrite.
echo " S5-CHASSIS-MIB ";
# Get major version number of running firmware
$fw_major_version = Null;
preg_match("/[0-9]\\.[0-9]/", $device['version'], $fw_major_version);
$fw_major_version = $fw_major_version[0];
# Temperature info only known to be present in firmware 6.1 or higher
if ($fw_major_version >= 6.1) {
$temps = snmp_walk($device, "1.3.6.1.4.1.45.1.6.3.7.1.1.5.5", "-Osqn");
$scale = 0.5;
foreach (explode("\n", $temps) as $i => $t) {
$t = explode(" ", $t);
$oid = $t[0];
$val = trim($t[1]);
discover_sensor($valid['sensor'], 'temperature', $device, $oid, zeropad($i + 1), 'avaya-ers', "Unit " . ($i + 1) . " temperature", $scale, $val * $scale);
}
}
// EOF
开发者ID:skive,项目名称:observium,代码行数:30,代码来源:s5-chassis-mib.inc.php
示例10: array
<?php
$mac_list = array();
// Disabled because we can do this better in poller now without performance hit
if ($device['os_group'] == "cisco" && FALSE) {
echo "Cisco MAC Accounting : ";
$datas = snmp_walk($device, "CISCO-IP-STAT-MIB::cipMacSwitchedBytes", "-OUqsX", "NS-ROOT-MIB");
foreach (explode("\n", $datas) as $data) {
list(, $ifIndex, $dir, $mac, ) = parse_oid2($data);
list($a_a, $a_b, $a_c, $a_d, $a_e, $a_f) = explode(":", $mac);
$ah_a = zeropad($a_a);
$ah_b = zeropad($a_b);
$ah_c = zeropad($a_c);
$ah_d = zeropad($a_d);
$ah_e = zeropad($a_e);
$ah_f = zeropad($a_f);
$clean_mac = "{$ah_a}{$ah_b}{$ah_c}{$ah_d}{$ah_e}{$ah_f}";
$mac_list[$ifIndex . '_' . $clean_mac] = array('ifIndex' => $ifIndex, 'mac' => $clean_mac);
}
foreach ($mac_list as $mac_entry) {
$port = dbFetchRow("SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ? LIMIT 1", array($device['device_id'], $mac_entry['ifIndex']));
if ($port) {
echo $port['ifDescr'] . ' (' . $mac_entry['ifIndex'] . ') -> ' . $mac_entry['mac'];
if (dbFetchCell("SELECT COUNT(*) from `mac_accounting` WHERE `port_id` = ? AND `mac` = ?", array($port['port_id'], $mac_entry['mac']))) {
echo ".";
} else {
$ma_id = dbInsert(array('port_id' => $port['port_id'], 'device_id' => $device['device_id'], 'mac' => $mac_entry['mac']), 'mac_accounting');
dbInsert(array('ma_id' => $ma_id), 'mac_accounting-state');
echo "+";
}
} else {
开发者ID:rhizalpatrax64bit,项目名称:StacksNetwork,代码行数:31,代码来源:mac-accounting.inc.php
示例11: char2hex
function char2hex($c)
{
return zeropad(dechex(ord($c)), 2);
}
开发者ID:rbauduin,项目名称:amiusingmptcp,代码行数:4,代码来源:mptcp.inc.php
示例12: preg_match
<?php
if ($device['os'] == 'avaya-ers') {
// Get major version number of running firmware
$fw_major_version = null;
preg_match('/[0-9]\\.[0-9]/', $device['version'], $fw_major_version);
$fw_major_version = $fw_major_version[0];
// Temperature info only known to be present in firmware 6.1 or higher
if ($fw_major_version >= 6.1) {
$temps = snmp_walk($device, '1.3.6.1.4.1.45.1.6.3.7.1.1.5.5', '-Osqn');
foreach (explode("\n", $temps) as $i => $t) {
$t = explode(' ', $t);
$oid = $t[0];
$val = $t[1];
// Sensors are reported as 2 * value
$val = trim($val) / 2;
discover_sensor($valid['sensor'], 'temperature', $device, $oid, zeropad($i + 1), 'avaya-ers', 'Unit ' . ($i + 1) . ' temperature', '2', '1', null, null, null, null, $val);
}
}
}
开发者ID:szatam,项目名称:librenms,代码行数:20,代码来源:avaya-ers.inc.php
示例13: convert_color
function convert_color($color)
{
$out = '';
// We only accept color in #rgb, #rrggbb, and rgb(r,g,b) formats
if (preg_match('/#(\\[0-9a-f])([0-9a-f])([0-9a-f])/i', $color, $matches)) {
$out = '#' . $matches[1] . $matches[1] . $matches[2] . $matches[2] . $matches[3] . $matches[3];
} else {
if (preg_match('/#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})/i', $color, $matches)) {
$out = '#' . $matches[1] . $matches[2] . $matches[3];
} else {
if (preg_match('/rgb\\((\\d+),\\s?(\\d+),\\s?(\\d+)\\)/', $color, $matches)) {
$out = '#' . zeropad(dechex($matches[1]), 2) . zeropad(dechex($matches[2]), 2) . zeropad(dechex($matches[3]), 2);
}
}
}
return $out;
}
开发者ID:0hyeah,项目名称:yurivn,代码行数:17,代码来源:utils.php
示例14: snmp_walk
<?php
if ($device['os'] == 'avaya-ers') {
// Processor information only know to work with 5500 and 5600 switches
if (preg_match('/5[56][0-9][0-9]/', $device['sysDescr'])) {
$procs = snmp_walk($device, '.1.3.6.1.4.1.45.1.6.3.8.1.1.6', '-Osqn');
foreach (explode("\n", $procs) as $i => $t) {
$t = explode(' ', $t);
$oid = $t[0];
$val = $t[1];
discover_processor($valid['processor'], $device, $oid, zeropad($i + 1), 'avaya-ers', 'Unit ' . ($i + 1) . ' processor', '1', $val, $i, null);
}
}
}
开发者ID:samyscoub,项目名称:librenms,代码行数:14,代码来源:avaya-ers.inc.php
示例15: shell_exec
$datas = shell_exec($config['snmpbulkwalk'] . " -m CISCO-IP-STAT-MIB -Oqn -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " cipMacSwitchedBytes");
#echo("$datas\n");
#echo("done\n");
foreach (explode("\n", $datas) as $data) {
list($oid) = explode(" ", $data);
$oid = str_replace(".1.3.6.1.4.1.9.9.84.1.2.1.1.4.", "", $oid);
list($if, $direction, $a_a, $a_b, $a_c, $a_d, $a_e, $a_f) = explode(".", $oid);
$oid = "{$a_a}.{$a_b}.{$a_c}.{$a_d}.{$a_e}.{$a_f}";
unset($interface);
$interface = mysql_fetch_array(mysql_query("SELECT * FROM ports WHERE device_id = '" . $device['device_id'] . "' AND ifIndex = '" . $if . "'"));
$ah_a = zeropad(dechex($a_a));
$ah_b = zeropad(dechex($a_b));
$ah_c = zeropad(dechex($a_c));
$ah_d = zeropad(dechex($a_d));
$ah_e = zeropad(dechex($a_e));
$ah_f = zeropad(dechex($a_f));
$mac = "{$ah_a}:{$ah_b}:{$ah_c}:{$ah_d}:{$ah_e}:{$ah_f}";
$mac_cisco = "{$ah_a}{$ah_b}.{$ah_c}{$ah_d}.{$ah_e}{$ah_f}";
$mac_cisco = $mac_table[$if][$mac]['ciscomac'];
$clean_mac = $mac_table[$if][$mac]['cleanmac'];
$ip = $mac_table[$if][$mac]['ip'];
if ($ip && $interface) {
$new_mac = str_replace(":", "", $mac);
#echo($interface['ifDescr'] . " ($if) -> $mac ($oid) -> $ip");
if (mysql_result(mysql_query("SELECT COUNT(*) from mac_accounting WHERE interface_id = '" . $interface['interface_id'] . "' AND mac = '{$clean_mac}'"), 0)) {
#$sql = "UPDATE `mac_accounting` SET `mac` = '$clean_mac' WHERE interface_id = '".$interface['interface_id']."' AND `mac` = '$clean_mac'";
#mysql_query($sql);
#if(mysql_affected_rows()) { echo(" UPDATED!"); }
#echo($sql);
echo ".";
} else {
开发者ID:kyrisu,项目名称:observernms,代码行数:31,代码来源:cisco-mac-accounting.inc.php
示例16: print_vars
if (OBS_DEBUG && count($sessions_db)) {
print_vars($sessions_db);
}
$radios_db = dbFetchRows("SELECT `wifi_radio_id`, `radio_number`,`ap_number`, `wifi_accesspoints`.`device_id` FROM `wifi_accesspoints`, `wifi_radios` WHERE `wifi_radios`.`radio_ap` = wifi_accesspoints.`wifi_accesspoint_id` AND wifi_accesspoints.`device_id` = ?", array($device['device_id']));
foreach ($radios_db as $radio_db) {
$radios_sorted_db[$radio_db['ap_number']][$radio_db['radio_number']] = $radio_db;
}
$sessions_array = snmpwalk_cache_multi_oid($device, "trpzClSessClientSessionTable", $sessions_array, "TRAPEZE-NETWORKS-CLIENT-SESSION-MIB", NULL, OBS_SNMP_ALL_NUMERIC_INDEX);
if (OBS_DEBUG > 1 && count($sessions_array)) {
print_vars($sessions_array);
}
$timestamp = date('Y-m-d H:i:s', strtotime("now"));
// Goes through the SNMP sessions data
foreach ($sessions_array as $index => $session) {
list($a_a, $a_b, $a_c, $a_d, $a_e, $a_f) = explode(".", $index);
$clean_mac = zeropad(dechex($a_a)) . zeropad(dechex($a_b)) . zeropad(dechex($a_c)) . zeropad(dechex($a_d)) . zeropad(dechex($a_e)) . zeropad(dechex($a_f));
// Mapping OIDs<>DB
$db_oids = array('trpzClSessClientSessSessionId' => 'session_id', 'trpzClSessClientSessUsername' => 'username', 'trpzClSessClientSessIpAddress' => 'ipv4_addr', 'trpzClSessClientSessSsid' => 'ssid', 'trpzClSessClientSessSessionState' => 'state');
$new_index = $clean_mac;
foreach ($db_oids as $db_oid => $db_value) {
$db_insert[$db_value] = $session[$db_oid];
}
$db_insert['device_id'] = $device['device_id'];
$db_insert['mac_addr'] = $clean_mac;
$db_insert['uptime'] = timeticks_to_sec($session['trpzClSessClientSessTimeStamp']);
// FIXME. There timestamp, not timetick!
$db_insert['timestamp'] = $timestamp;
if ($session['trpzClSessClientSessRadioNum'] == "radio-1") {
$radio_number = '1';
} else {
if ($session['trpzClSessClientSessradioNum'] == "radio-2") {
开发者ID:Natolumin,项目名称:observium,代码行数:31,代码来源:trapeze-networks-client-session-mib.inc.php
示例17: zeropad
} else {
// In principle the such shouldn't be.
continue;
}
$if = $matches[1];
$port_id = $interface[$if];
if ($ip & $port_id) {
if ($matches[3] === '' && $matches[4] === '') {
// Convert IPv4 to fake MAC for 6to4 tunnels
//ipNetToPhysicalPhysAddress[27][ipv6]["20:02:c0:58:63:01:00:00:00:00:00:00:00:00:00:00"] 0:0:c0:58
$matches[3] = 'ff';
$matches[4] = 'fe';
}
$mac = zeropad($matches[3]);
for ($i = 4; $i <= 8; $i++) {
$mac .= ':' . zeropad($matches[$i]);
}
$clean_mac = str_replace(':', '', $mac);
$mac_table[$if][$ip_version][$ip] = $clean_mac;
if (isset($old_table[$if][$ip_version][$ip])) {
$old_mac = $old_table[$if][$ip_version][$ip];
if ($clean_mac != $old_mac && $clean_mac != '00:00:00:00:00:00' && $old_mac != '00:00:00:00:00:00') {
print_debug("Changed MAC address for {$ip} from " . format_mac($old_mac) . " to " . format_mac($clean_mac));
log_event("MAC changed: {$ip} : " . format_mac($old_mac) . " -> " . format_mac($clean_mac), $device, "port", $port_id);
dbUpdate(array('mac_address' => $clean_mac), 'ip_mac', 'port_id = ? AND ip_address = ?', array($port_id, $ip));
echo "U";
} else {
echo ".";
}
} else {
$params = array('port_id' => $port_id, 'mac_address' => $clean_mac, 'ip_address' => $ip, 'ip_version' => $ip_version);
开发者ID:Natolumin,项目名称:observium,代码行数:31,代码来源:arp-table.inc.php
示例18: dbUpdate
dbUpdate($vlan_update, 'vlans', 'vlan_id = ?', array($vlans_db[$vtpdomain_id][$vlan_id]['vlan_id']));
$module_stats[$vlan_id]['V'] = 'U';
} elseif (is_array($vlans_db[$vtpdomain_id][$vlan_id])) {
$module_stats[$vlan_id]['V'] = '.';
//echo(".");
} else {
dbInsert(array('device_id' => $device['device_id'], 'vlan_domain' => $vtpdomain_id, 'vlan_vlan' => $vlan_id, 'vlan_name' => $vlan['dot1qVlanStaticName'], 'vlan_type' => array('NULL')), 'vlans');
$module_stats[$vlan_id]['V'] = '+';
}
$device['vlans'][$vtpdomain_id][$vlan_id] = $vlan_id;
//Set Q-BRIDGE ports Vlan table (not work on FTOS for now)
if ($device['os'] != 'ftos') {
$parts = explode(' ', $vlan['dot1qVlanStaticEgressPorts']);
$binary = '';
foreach ($parts as $part) {
$binary .= zeropad(decbin($part), 8);
}
$length = strlen($binary);
for ($i = 0; $i < $length; $i++) {
if ($binary[$i]) {
$port = get_port_by_index_cache($device, $i);
if (isset($ports_vlans_db[$port['port_id']][$vlan_id])) {
$ports_vlans[$port['port_id']][$vlan_id] = $ports_vlans_db[$port['port_id']][$vlan_id]['port_vlan_id'];
$module_stats[$vlan_id]['P'] = '.';
} else {
$db_w = array('device_id' => $device['device_id'], 'port_id' => $port['port_id'], 'vlan' => $vlan_id);
$id = dbInsert($db_w, 'ports_vlans');
$module_stats[$vlan_id]['P'] = '+';
$ports_vlans[$port['port_id']][$vlan_id] = $id;
}
}
开发者ID:skive,项目名称:observium,代码行数:31,代码来源:q-bridge-mib.inc.php
示例19: list
$this_port['ifOutUcastPkts'] = $airos_stats[1]['txValidUnicastFrames'];
$ports['update']['ifInOctets'] = $airos_stats[1]['rxOctetsOK'];
$ports['update']['ifOutOctets'] = $airos_stats[1]['txOctetsOK'];
$ports['update']['ifInErrors'] = $airos_stats[1]['rxErroredFrames'];
$ports['update']['ifOutErrors'] = $airos_stats[1]['txErroredFrames'];
$ports['update']['ifInBroadcastPkts'] = $airos_stats[1]['rxValidBroadcastFrames'];
$ports['update']['ifOutBroadcastPkts'] = $airos_stats[1]['txValidBroadcastFrames'];
$ports['update']['ifInMulticastPkts'] = $airos_stats[1]['rxValidMulticastFrames'];
$ports['update']['ifOutMulticastPkts'] = $airos_stats[1]['txValidMulticastFrames'];
$ports['update']['ifInUcastPkts'] = $airos_stats[1]['rxValidUnicastFrames'];
$ports['update']['ifOutUcastPkts'] = $airos_stats[1]['txValidUnicastFrames'];
}
// rewrite the ifPhysAddress
if (strpos($this_port['ifPhysAddress'], ':')) {
list($a_a, $a_b, $a_c, $a_d, $a_e, $a_f) = explode(':', $this_port['ifPhysAddress']);
$this_port['ifPhysAddress'] = zeropad($a_a) . zeropad($a_b) . zeropad($a_c) . zeropad($a_d) . zeropad($a_e) . zeropad($a_f);
}
if (is_numeric($this_port['ifHCInBroadcastPkts']) && is_numeric($this_port['ifHCOutBroadcastPkts']) && is_numeric($this_port['ifHCInMulticastPkts']) && is_numeric($this_port['ifHCOutMulticastPkts'])) {
echo 'HC ';
$this_port['ifInBroadcastPkts'] = $this_port['ifHCInBroadcastPkts'];
$this_port['ifOutBroadcastPkts'] = $this_port['ifHCOutBroadcastPkts'];
$this_port['ifInMulticastPkts'] = $this_port['ifHCInMulticastPkts'];
$this_port['ifOutMulticastPkts'] = $this_port['ifHCOutMulticastPkts'];
}
// Overwrite ifSpeed with ifHighSpeed if it's over 1G
if (is_numeric($this_port['ifHighSpeed']) && ($this_port['ifSpeed'] > '1000000000' || $this_port['ifSpeed'] == 0)) {
echo 'HighSpeed ';
$this_port['ifSpeed'] = $this_port['ifHighSpeed'] * 1000000;
}
// Overwrite ifDuplex with dot3StatsDuplexStatus if it exists
if (isset($this_port['dot3StatsDuplexStatus'])) {
开发者ID:MACscr,项目名称:librenms,代码行数:31,代码来源:ports.inc.php
示例20: snmpwalk_cache_cip
function snmpwalk_cache_cip($device, $oid, $array = array(), $mib = 0)
{
global $config;
if (is_numeric($device['timeout']) && $device['timeout'] > 0) {
$timeout = $device['timeout'];
} elseif (isset($config['snmp']['timeout'])) {
$timeout = $config['snmp']['timeout'];
}
if (is_numeric($device['retries']) && $device['retries'] > 0) {
$retries = $device['retries'];
} elseif (isset($config['snmp']['retries'])) {
$retries = $config['snmp']['retries'];
}
if (!isset($device['transport'])) {
$device['transport'] = "udp";
}
if ($device['snmpver'] == 'v1' || $config['os'][$device['os']]['nobulk']) {
$snmpcommand = $config['snmpwalk'];
} else {
$snmpcommand = $config['snmpbulkwalk'];
}
$cmd = $snmpcommand;
$cmd .= snmp_gen_auth($device);
$cmd .= " -O snQ";
if ($mib) {
$cmd .= " -m {$mib}";
}
$cmd .= mibdir(null);
if (isset($timeout)) {
$cmd .= " -t " . $timeout;
}
if (isset($retries)) {
$cmd .= " -r " . $retries;
}
$cmd .= " " . $device['transport'] . ":" . $device['hostname'] . ":" . $device['port'] . " " . $oid;
if (!$debug) {
$cmd .= " 2>/dev/null";
}
$data = trim(external_exec($cmd));
$device_id = $device['device_id'];
#echo("Caching: $oid\n");
foreach (explode("\n", $data) as $entry) {
list($this_oid, $this_value) = preg_split("/=/", $entry);
$this_oid = trim($this_oid);
$this_value = trim($this_value);
$this_oid = substr($this_oid, 30);
list($ifIndex, $dir, $a, $b, $c, $d, $e, $f) = explode(".", $this_oid);
$h_a = zeropad(dechex($a));
$h_b = zeropad(dechex($b));
$h_c = zeropad(dechex($c));
$h_d = zeropad(dechex($d));
$h_e = zeropad(dechex($e));
$h_f = zeropad(dechex($f));
$mac = "{$h_a}{$h_b}{$h_c}{$h_d}{$h_e}{$h_f}";
if ($dir == "1") {
$dir = "input";
} elseif ($dir == "2") {
$dir = "output";
}
if ($mac && $dir) {
$array[$ifIndex][$mac][$oid][$dir] = $this_value;
}
}
return $array;
}
开发者ID:REAP720801,项目名称:librenms,代码行数:65,代码来源:snmp.inc.php
注:本文中的zeropad函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论