本文整理汇总了PHP中device_by_id_cache函数的典型用法代码示例。如果您正苦于以下问题:PHP device_by_id_cache函数的具体用法?PHP device_by_id_cache怎么用?PHP device_by_id_cache使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了device_by_id_cache函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ifLabel
function ifLabel($interface, $device = NULL)
{
global $config;
if (!$device) {
$device = device_by_id_cache($interface['device_id']);
}
$os = strtolower($device['os']);
if (isset($config['os'][$os]['ifname'])) {
$interface['label'] = $interface['ifName'];
if ($interface['ifName'] == "") {
$interface['label'] = $interface['ifDescr'];
} else {
$interface['label'] = $interface['ifName'];
}
} elseif (isset($config['os'][$os]['ifalias'])) {
$interface['label'] = $interface['ifAlias'];
} else {
$interface['label'] = $interface['ifDescr'];
if (isset($config['os'][$os]['ifindex'])) {
$interface['label'] = $interface['label'] . " " . $interface['ifIndex'];
}
}
if ($device['os'] == "speedtouch") {
list($interface['label']) = explode("thomson", $interface['label']);
}
return $interface;
}
示例2: discover_new_device
function discover_new_device($hostname, $source = 'xdp')
{
global $config, $debug;
if ($config['autodiscovery'][$source]) {
echo "Discovering new host {$hostname}\n";
if (!empty($config['mydomain']) && isDomainResolves($hostname . "." . $config['mydomain'])) {
if ($debug) {
echo "appending " . $config['mydomain'] . "!\n";
}
$dst_host = $hostname . "." . $config['mydomain'];
} else {
$dst_host = $hostname;
}
$ip = gethostbyname($dst_host);
if ($debug) {
echo "resolving {$dst_host} to {$ip}\n";
}
if (match_network($config['autodiscovery']['ip_nets'], $ip)) {
if ($debug) {
echo "found {$ip} inside configured nets, adding!\n";
}
$remote_device_id = addHost($dst_host);
if ($remote_device_id) {
$remote_device = device_by_id_cache($remote_device_id, 1);
array_push($GLOBALS['devices'], $remote_device);
return $remote_device_id;
}
}
} else {
if ($debug) {
echo "{$source} autodiscovery disabled";
}
return FALSE;
}
}
示例3: discover_new_device
function discover_new_device($hostname, $device = '', $method = '', $interface = '')
{
global $config;
if (!empty($config['mydomain']) && isDomainResolves($hostname . '.' . $config['mydomain'])) {
$dst_host = $hostname . '.' . $config['mydomain'];
} else {
$dst_host = $hostname;
}
d_echo("discovering {$dst_host}\n");
$ip = gethostbyname($dst_host);
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === false && filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === false) {
// $ip isn't a valid IP so it must be a name.
if ($ip == $dst_host) {
d_echo("name lookup of {$dst_host} failed\n");
log_event("{$method} discovery of " . $dst_host . " failed - Check name lookup", $device['device_id'], 'discovery');
return false;
}
} elseif (filter_var($dst_host, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === true || filter_var($dst_host, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === true) {
// gethostbyname returned a valid $ip, was $dst_host an IP?
if ($config['discovery_by_ip'] === false) {
d_echo('Discovery by IP disabled, skipping ' . $dst_host);
log_event("{$method} discovery of " . $dst_host . " failed - Discovery by IP disabled", $device['device_id'], 'discovery');
return false;
}
}
d_echo("ip lookup result: {$ip}\n");
$dst_host = rtrim($dst_host, '.');
// remove trailing dot
if (match_network($config['autodiscovery']['nets-exclude'], $ip)) {
d_echo("{$ip} in an excluded network - skipping\n");
return false;
}
if (match_network($config['nets'], $ip)) {
try {
$remote_device_id = addHost($dst_host, '', '161', 'udp', $config['distributed_poller_group']);
$remote_device = device_by_id_cache($remote_device_id, 1);
echo '+[' . $remote_device['hostname'] . '(' . $remote_device['device_id'] . ')]';
discover_device($remote_device);
device_by_id_cache($remote_device_id, 1);
if ($remote_device_id && is_array($device) && !empty($method)) {
$extra_log = '';
$int = ifNameDescr($interface);
if (is_array($int)) {
$extra_log = ' (port ' . $int['label'] . ') ';
}
log_event('Device ' . $remote_device['hostname'] . " ({$ip}) {$extra_log} autodiscovered through {$method} on " . $device['hostname'], $remote_device_id, 'discovery');
} else {
log_event("{$method} discovery of " . $remote_device['hostname'] . " ({$ip}) failed - Check ping and SNMP access", $device['device_id'], 'discovery');
}
return $remote_device_id;
} catch (HostExistsException $e) {
// already have this device
} catch (Exception $e) {
log_event("{$method} discovery of " . $dst_host . " ({$ip}) failed - " . $e->getMessage());
}
} else {
d_echo("{$ip} not in a matched network - skipping\n");
}
//end if
}
示例4: discover_new_device
function discover_new_device($hostname, $device = '', $method = '', $interface = '')
{
global $config, $debug;
if (!empty($config['mydomain']) && isDomainResolves($hostname . '.' . $config['mydomain'])) {
$dst_host = $hostname . '.' . $config['mydomain'];
} else {
$dst_host = $hostname;
}
if ($debug) {
echo "discovering {$dst_host}\n";
}
$ip = gethostbyname($dst_host);
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === false && filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === false) {
// $ip isn't a valid IP so it must be a name.
if ($ip == $dst_host) {
if ($debug) {
echo "name lookup of {$dst_host} failed\n";
}
return false;
}
}
if ($debug) {
echo "ip lookup result: {$ip}\n";
}
$dst_host = rtrim($dst_host, '.');
// remove trailing dot
if (match_network($config['autodiscovery']['nets-exclude'], $ip)) {
if ($debug) {
echo "{$ip} in an excluded network - skipping\n";
}
return false;
}
if (match_network($config['nets'], $ip)) {
$remote_device_id = addHost($dst_host, '', '161', 'udp', '0', $config['distributed_poller_group']);
if ($remote_device_id) {
$remote_device = device_by_id_cache($remote_device_id, 1);
echo '+[' . $remote_device['hostname'] . '(' . $remote_device['device_id'] . ')]';
discover_device($remote_device);
device_by_id_cache($remote_device_id, 1);
if ($remote_device_id && is_array($device) && !empty($method)) {
$extra_log = '';
$int = ifNameDescr($interface);
if (is_array($int)) {
$extra_log = ' (port ' . $int['label'] . ') ';
}
log_event('Device $' . $remote_device['hostname'] . " ({$ip}) {$extra_log} autodiscovered through {$method} on " . $device['hostname'], $remote_device_id, 'system');
} else {
log_event("{$method} discovery of " . $remote_device['hostname'] . " ({$ip}) failed - check ping and SNMP access", $device['device_id'], 'system');
}
return $remote_device_id;
}
} else {
if ($debug) {
echo "{$ip} not in a matched network - skipping\n";
}
}
//end if
}
示例5: print_neighbours
/**
* Display neighbours.
*
* Display pages with device neighbours in some formats.
* Examples:
* print_neighbours() - display all neighbours from all devices
* print_neighbours(array('pagesize' => 99)) - display 99 neighbours from all device
* print_neighbours(array('pagesize' => 10, 'pageno' => 3, 'pagination' => TRUE)) - display 10 neighbours from page 3 with pagination header
* print_neighbours(array('pagesize' => 10, 'device' = 4)) - display 10 neighbours for device_id 4
*
* @param array $vars
* @return none
*
*/
function print_neighbours($vars)
{
// Get neighbours array
$neighbours = get_neighbours_array($vars);
if (!$neighbours['count']) {
// There have been no entries returned. Print the warning.
print_warning('<h4>No neighbours found!</h4>');
} else {
// Entries have been returned. Print the table.
$list = array('device' => FALSE);
if ($vars['page'] != 'device') {
$list['device'] = TRUE;
}
if (in_array($vars['graph'], array('bits', 'upkts', 'nupkts', 'pktsize', 'percent', 'errors', 'etherlike', 'fdb_count'))) {
$graph_types = array($vars['graph']);
} else {
$graph_types = array('bits', 'upkts', 'errors');
}
$string = generate_box_open($vars['header']);
$string .= '<table class="table table-striped table-hover table-condensed">' . PHP_EOL;
$cols = array(array(NULL, 'class="state-marker"'), 'device_a' => 'Local Device', 'port_a' => 'Local Port', 'NONE' => NULL, 'device_b' => 'Remote Device', 'port_b' => 'Remote Port', 'protocol' => 'Protocol');
if (!$list['device']) {
unset($cols[0], $cols['device_a']);
}
$string .= get_table_header($cols, $vars);
$string .= ' <tbody>' . PHP_EOL;
foreach ($neighbours['entries'] as $entry) {
$string .= ' <tr class="' . $entry['row_class'] . '">' . PHP_EOL;
if ($list['device']) {
$string .= ' <td class="state-marker"></td>';
$string .= ' <td class="entity">' . generate_device_link($entry, NULL, array('tab' => 'ports', 'view' => 'neighbours')) . '</td>' . PHP_EOL;
}
$string .= ' <td><span class="entity">' . generate_port_link($entry) . '</span><br />' . $entry['ifAlias'] . '</td>' . PHP_EOL;
$string .= ' <td><i class="icon-resize-horizontal text-success"></i></td>' . PHP_EOL;
if (is_numeric($entry['remote_port_id']) && $entry['remote_port_id']) {
$remote_port = get_port_by_id_cache($entry['remote_port_id']);
$remote_device = device_by_id_cache($remote_port['device_id']);
$string .= ' <td><span class="entity">' . generate_device_link($remote_device) . '</span><br />' . $remote_device['hardware'] . '</td>' . PHP_EOL;
$string .= ' <td><span class="entity">' . generate_port_link($remote_port) . '</span><br />' . $remote_port['ifAlias'] . '</td>' . PHP_EOL;
} else {
$string .= ' <td><span class="entity">' . $entry['remote_hostname'] . '</span><br />' . $entry['remote_platform'] . '</td>' . PHP_EOL;
$string .= ' <td><span class="entity">' . $entry['remote_port'] . '</span></td>' . PHP_EOL;
}
$string .= ' <td>' . strtoupper($entry['protocol']) . '</td>' . PHP_EOL;
$string .= ' </tr>' . PHP_EOL;
}
$string .= ' </tbody>' . PHP_EOL;
$string .= '</table>';
$string .= generate_box_close();
// Print pagination header
if ($neighbours['pagination_html']) {
$string = $neighbours['pagination_html'] . $string . $neighbours['pagination_html'];
}
// Print
echo $string;
}
}
示例6: add_service
function add_service($device, $type, $desc, $ip = 'localhost', $param = "", $ignore = 0)
{
if (!is_array($device)) {
$device = device_by_id_cache($device);
}
if (empty($ip)) {
$ip = $device['hostname'];
}
$insert = array('device_id' => $device['device_id'], 'service_ip' => $ip, 'service_type' => $type, 'service_changed' => array('UNIX_TIMESTAMP(NOW())'), 'service_desc' => $desc, 'service_param' => $param, 'service_ignore' => $ignore, 'service_status' => 3, 'service_message' => 'Service not yet checked');
return dbInsert($insert, 'services');
}
示例7: discover_new_device
function discover_new_device($hostname)
{
global $config, $debug;
if ($config['autodiscovery']['xdp']) {
if (isDomainResolves($hostname . "." . $config['mydomain'])) {
$dst_host = $hostname . "." . $config['mydomain'];
} else {
$dst_host = $hostname;
}
if ($debug) {
echo "discovering {$dst_host}\n";
}
$ip = gethostbyname($dst_host);
if ($ip == $dst_host) {
if ($debug) {
echo "name lookup of {$dst_host} failed\n";
}
return FALSE;
} else {
if ($debug) {
echo "ip lookup result: {$ip}\n";
}
}
$dst_host = rtrim($dst_host, '.');
// remove trailing dot
if (match_network($config['autodiscovery']['nets-exclude'], $ip)) {
if ($debug) {
echo "{$ip} in an excluded network - skipping\n";
}
return FALSE;
}
if (match_network($config['nets'], $ip)) {
$remote_device_id = addHost($dst_host);
if ($remote_device_id) {
$remote_device = device_by_id_cache($remote_device_id, 1);
echo "+[" . $remote_device['hostname'] . "(" . $remote_device['device_id'] . ")]";
discover_device($remote_device);
$remote_device = device_by_id_cache($remote_device_id, 1);
return $remote_device_id;
}
} else {
if ($debug) {
echo "{$ip} not in a matched network - skipping\n";
}
}
} else {
if ($debug) {
echo "autodiscovery disabled - skipping\n";
}
return FALSE;
}
}
示例8: discover_new_device
function discover_new_device($hostname)
{
global $config, $debug;
if (!empty($config['mydomain']) && isDomainResolves($hostname . "." . $config['mydomain'])) {
$dst_host = $hostname . "." . $config['mydomain'];
} else {
$dst_host = $hostname;
}
if ($debug) {
echo "discovering {$dst_host}\n";
}
$ip = gethostbyname($dst_host);
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === FALSE && filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === FALSE) {
// $ip isn't a valid IP so it must be a name.
if ($ip == $dst_host) {
if ($debug) {
echo "name lookup of {$dst_host} failed\n";
}
return FALSE;
}
}
if ($debug) {
echo "ip lookup result: {$ip}\n";
}
$dst_host = rtrim($dst_host, '.');
// remove trailing dot
if (match_network($config['autodiscovery']['nets-exclude'], $ip)) {
if ($debug) {
echo "{$ip} in an excluded network - skipping\n";
}
return FALSE;
}
if (match_network($config['nets'], $ip)) {
$remote_device_id = addHost($dst_host, '', '161', 'udp', '0', $config['distributed_poller_group']);
if ($remote_device_id) {
$remote_device = device_by_id_cache($remote_device_id, 1);
echo "+[" . $remote_device['hostname'] . "(" . $remote_device['device_id'] . ")]";
discover_device($remote_device);
device_by_id_cache($remote_device_id, 1);
return $remote_device_id;
}
} else {
if ($debug) {
echo "{$ip} not in a matched network - skipping\n";
}
}
}
示例9: ifLabel
function ifLabel($interface, $device = null)
{
global $config;
if (!$device) {
$device = device_by_id_cache($interface['device_id']);
}
$os = strtolower($device['os']);
if (isset($config['os'][$os]['ifname'])) {
$interface['label'] = $interface['ifName'];
if ($interface['ifName'] == '') {
$interface['label'] = $interface['ifDescr'];
} else {
$interface['label'] = $interface['ifName'];
}
} else {
if (isset($config['os'][$os]['ifalias'])) {
$interface['label'] = $interface['ifAlias'];
} else {
$interface['label'] = $interface['ifDescr'];
if (isset($config['os'][$os]['ifindex'])) {
$interface['label'] = $interface['label'] . ' ' . $interface['ifIndex'];
}
}
}
if ($device['os'] == 'speedtouch') {
list($interface['label']) = explode('thomson', $interface['label']);
}
if (is_array($config['rewrite_if'])) {
foreach ($config['rewrite_if'] as $src => $val) {
if (stristr($interface['label'], $src)) {
$interface['label'] = $val;
}
}
}
if (is_array($config['rewrite_if_regexp'])) {
foreach ($config['rewrite_if_regexp'] as $reg => $val) {
if (preg_match($reg . 'i', $interface['label'])) {
$interface['label'] = preg_replace($reg . 'i', $val, $interface['label']);
}
}
}
return $interface;
}
示例10: generate_port_popup
function generate_port_popup($port, $text = NULL, $type = NULL)
{
global $config;
if (!isset($port['os'])) {
$port = array_merge($port, device_by_id_cache($port['device_id']));
}
humanize_port($port);
if (!$text) {
$text = rewrite_ifname($port['label']);
}
if ($type) {
$port['graph_type'] = $type;
}
if (!isset($port['graph_type'])) {
$port['graph_type'] = 'port_bits';
}
$class = ifclass($port['ifOperStatus'], $port['ifAdminStatus']);
if (!isset($port['os'])) {
$port = array_merge($port, device_by_id_cache($port['device_id']));
}
$content = generate_device_popup_header($port);
$content .= generate_port_popup_header($port);
$content .= '<div style="width: 700px">';
$graph_array['type'] = $port['graph_type'];
$graph_array['legend'] = "yes";
$graph_array['height'] = "100";
$graph_array['width'] = "275";
$graph_array['to'] = $config['time']['now'];
$graph_array['from'] = $config['time']['day'];
$graph_array['id'] = $port['port_id'];
$content .= generate_graph_tag($graph_array);
$graph_array['from'] = $config['time']['week'];
$content .= generate_graph_tag($graph_array);
$graph_array['from'] = $config['time']['month'];
$content .= generate_graph_tag($graph_array);
$graph_array['from'] = $config['time']['year'];
$content .= generate_graph_tag($graph_array);
$content .= "</div>";
return $content;
}
示例11: dbFetchRow
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage graphs
* @copyright (C) 2006-2014 Adam Armstrong
*
*/
// $cbqos = dbFetchRows("SELECT * FROM `ports_cbqos` WHERE `port_id` = ?", array($port['port_id']));
if (is_numeric($vars['id'])) {
$cbqos = dbFetchRow("SELECT * FROM `ports_cbqos` WHERE `cbqos_id` = ?", array($vars['id']));
if (is_numeric($cbqos['device_id']) && ($auth || device_permitted($cbqos['device_id']))) {
$device = device_by_id_cache($cbqos['device_id']);
$rrd_filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("cbqos-" . $cbqos['policy_index'] . "-" . $cbqos['object_index'] . ".rrd");
$title = generate_device_link($device);
$title .= " :: CBQoS :: " . $cbqos['policy_index'] . "-" . $cbqos['object_index'];
$auth = TRUE;
$graph_return['rrds'][] = $rrd_filename;
}
}
示例12: device_by_id_cache
<?php
require 'memcached.inc.php';
require 'includes/graphs/common.inc.php';
$device = device_by_id_cache($vars['id']);
require 'includes/graphs/common.inc.php';
$scale_min = 0;
$ds = 'threads';
$colour_area = 'F6F6F6';
$colour_line = '555555';
$colour_area_max = 'FFEE99';
// $graph_max = 100;
$unit_text = 'Threads';
require 'includes/graphs/generic_simplex.inc.php';
示例13: add_service
function add_service($device, $service, $descr, $service_ip, $service_param = "", $service_ignore = 0)
{
if (!is_array($device)) {
$device = device_by_id_cache($device);
}
if (empty($service_ip)) {
$service_ip = $device['hostname'];
}
$insert = array('device_id' => $device['device_id'], 'service_ip' => $service_ip, 'service_type' => $service, 'service_changed' => array('UNIX_TIMESTAMP(NOW())'), 'service_desc' => $descr, 'service_param' => $service_param, 'service_ignore' => $service_ignore);
return dbInsert($insert, 'services');
}
示例14: humanize_port
/**
* Humanize port.
*
* Returns a the $port array with processed information:
* label, humans_speed, human_type, html_class and human_mac
* row_class, table_tab_colour
*
* @param array $ports
* @return array $ports
*
*/
function humanize_port(&$port)
{
global $config;
// Process port data to make it pretty for printing. EVOLUTION, BITCHES.
// Lots of hacky shit will end up here with if (os);
$device = device_by_id_cache($port['device_id']);
$os = $device['os'];
$port['human_speed'] = humanspeed($port['ifSpeed']);
$port['human_type'] = fixiftype($port['ifType']);
$port['html_class'] = ifclass($port['ifOperStatus'], $port['ifAdminStatus']);
$port['human_mac'] = formatMac($port['ifPhysAddress']);
if (isset($config['os'][$os]['ifname'])) {
$port['label'] = $port['ifName'];
if ($port['ifName'] == "") {
$port['label'] = $port['ifDescr'];
} else {
$port['label'] = $port['ifName'];
}
} elseif (isset($config['os'][$os]['ifalias'])) {
$port['label'] = $port['ifAlias'];
} else {
$port['label'] = $port['ifDescr'];
if (isset($config['os'][$os]['ifindex'])) {
$port['label'] = $port['label'] . " " . $port['ifIndex'];
}
}
if ($device['os'] == "speedtouch") {
list($port['label']) = explode("thomson", $port['label']);
}
if ($port['ifAdminStatus'] == "down") {
$port['table_tab_colour'] = "#aaaaaa";
$port['row_class'] = "";
} elseif ($port['ifAdminStatus'] == "up" && $port['ifOperStatus'] == "down") {
$port['table_tab_colour'] = "#cc0000";
$port['row_class'] = "error";
} elseif ($port['ifAdminStatus'] == "up" && $port['ifOperStatus'] == "lowerLayerDown") {
$port['table_tab_colour'] = "#ff6600";
$port['row_class'] = "warning";
} elseif ($port['ifAdminStatus'] == "up" && $port['ifOperStatus'] == "up") {
$port['table_tab_colour'] = "#194B7F";
$port['row_class'] = "";
}
$port['humanized'] = TRUE;
/// Set this so we can check it later.
}
示例15: dbFetchRow
<?php
if (is_numeric($vars['id'])) {
// $auth= TRUE;
$rserver = dbFetchRow('SELECT * FROM `loadbalancer_rservers` AS I, `devices` AS D WHERE I.rserver_id = ? AND I.device_id = D.device_id', array($vars['id']));
if (is_numeric($rserver['device_id']) && ($auth || device_permitted($rserver['device_id']))) {
$device = device_by_id_cache($rserver['device_id']);
$rrd_filename = $config['rrd_dir'] . '/' . $device['hostname'] . '/' . safename('rserver-' . $rserver['rserver_id'] . '.rrd');
$title = generate_device_link($device);
$title .= ' :: Rserver :: ' . htmlentities($rserver['farm_id']);
$auth = true;
}
}