当前位置: 首页>>代码示例>>PHP>>正文


PHP inet6_ntop函数代码示例

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


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

示例1: device_by_id_cache

function device_by_id_cache($device_id, $refresh = '0')
{
    global $cache;
    if (!$refresh && isset($cache['devices']['id'][$device_id]) && is_array($cache['devices']['id'][$device_id])) {
        $device = $cache['devices']['id'][$device_id];
    } else {
        $device = dbFetchRow("SELECT * FROM `devices` WHERE `device_id` = ?", array($device_id));
        $device['ip'] = inet6_ntop($device['ip']);
        $cache['devices']['id'][$device_id] = $device;
    }
    return $device;
}
开发者ID:BillTheBest,项目名称:librenms,代码行数:12,代码来源:common.php

示例2: device_by_id_cache

function device_by_id_cache($device_id, $refresh = '0')
{
    global $cache;
    if (!$refresh && isset($cache['devices']['id'][$device_id]) && is_array($cache['devices']['id'][$device_id])) {
        $device = $cache['devices']['id'][$device_id];
    } else {
        $device = dbFetchRow("SELECT * FROM `devices` WHERE `device_id` = ?", array($device_id));
        //order vrf_lite_cisco with context, this will help to get the vrf_name and instance_name all the time
        $vrfs_lite_cisco = dbFetchRows("SELECT * FROM `vrf_lite_cisco` WHERE `device_id` = ?", array($device_id));
        $device['vrf_lite_cisco'] = array();
        if (!empty($vrfs_lite_cisco)) {
            foreach ($vrfs_lite_cisco as $vrf) {
                $device['vrf_lite_cisco'][$vrf['context_name']] = $vrf;
            }
        }
        $device['ip'] = inet6_ntop($device['ip']);
        $cache['devices']['id'][$device_id] = $device;
    }
    return $device;
}
开发者ID:gottaloveit,项目名称:librenms,代码行数:20,代码来源:common.php

示例3: list_devices

function list_devices()
{
    // This will return a list of devices
    global $config;
    $app = \Slim\Slim::getInstance();
    $order = $_GET['order'];
    $type = $_GET['type'];
    $query = mres($_GET['query']);
    $param = array();
    $join = '';
    if (empty($order)) {
        $order = 'hostname';
    }
    if (stristr($order, ' desc') === false && stristr($order, ' asc') === false) {
        $order = '`' . $order . '` ASC';
    }
    if ($type == 'all' || empty($type)) {
        $sql = '1';
    } elseif ($type == 'ignored') {
        $sql = "`ignore`='1' AND `disabled`='0'";
    } elseif ($type == 'up') {
        $sql = "`status`='1' AND `ignore`='0' AND `disabled`='0'";
    } elseif ($type == 'down') {
        $sql = "`status`='0' AND `ignore`='0' AND `disabled`='0'";
    } elseif ($type == 'disabled') {
        $sql = "`disabled`='1'";
    } elseif ($type == 'mac') {
        $join = " LEFT JOIN `ports` ON `devices`.`device_id`=`ports`.`device_id` LEFT JOIN `ipv4_mac` ON `ports`.`port_id`=`ipv4_mac`.`port_id` ";
        $sql = "`ipv4_mac`.`mac_address`=?";
        $param[] = $query;
    } elseif ($type == 'ipv4') {
        $join = " LEFT JOIN `ports` ON `devices`.`device_id`=`ports`.`device_id` LEFT JOIN `ipv4_addresses` ON `ports`.`port_id`=`ipv4_addresses`.`port_id` ";
        $sql = "`ipv4_addresses`.`ipv4_address`=?";
        $param[] = $query;
    } elseif ($type == 'ipv6') {
        $join = " LEFT JOIN `ports` ON `devices`.`device_id`=`ports`.`device_id` LEFT JOIN `ipv6_addresses` ON `ports`.`port_id`=`ipv6_addresses`.`port_id` ";
        $sql = "`ipv6_addresses`.`ipv6_address`=? OR `ipv6_addresses`.`ipv6_compressed`=?";
        $param = array($query, $query);
    } else {
        $sql = '1';
    }
    $devices = array();
    foreach (dbFetchRows("SELECT * FROM `devices` {$join} WHERE {$sql} ORDER by {$order}", $param) as $device) {
        $device['ip'] = inet6_ntop($device['ip']);
        $devices[] = $device;
    }
    $count = count($devices);
    $output = array('status' => 'ok', 'count' => $count, 'devices' => $devices);
    $app->response->headers->set('Content-Type', 'application/json');
    echo _json_encode($output);
}
开发者ID:wiad,项目名称:librenms,代码行数:51,代码来源:api_functions.inc.php

示例4: poll_device

function poll_device($device, $options)
{
    global $config, $device, $polled_devices, $db_stats, $memcache;
    $attribs = get_dev_attribs($device['device_id']);
    $status = 0;
    unset($array);
    $device_start = microtime(true);
    // Start counting device poll time
    echo $device['hostname'] . ' ' . $device['device_id'] . ' ' . $device['os'] . ' ';
    $ip = dnslookup($device);
    if (!empty($ip) && $ip != inet6_ntop($device['ip'])) {
        log_event('Device IP changed to ' . $ip, $device, 'system');
        $db_ip = inet_pton($ip);
        dbUpdate(array('ip' => $db_ip), 'devices', 'device_id=?', array($device['device_id']));
    }
    if ($config['os'][$device['os']]['group']) {
        $device['os_group'] = $config['os'][$device['os']]['group'];
        echo '(' . $device['os_group'] . ')';
    }
    echo "\n";
    unset($poll_update);
    unset($poll_update_query);
    unset($poll_separator);
    $poll_update_array = array();
    $update_array = array();
    $host_rrd = $config['rrd_dir'] . '/' . $device['hostname'];
    if (!is_dir($host_rrd)) {
        mkdir($host_rrd);
        echo "Created directory : {$host_rrd}\n";
    }
    $address_family = snmpTransportToAddressFamily($device['transport']);
    $ping_response = isPingable($device['hostname'], $address_family, $attribs);
    $device_perf = $ping_response['db'];
    $device_perf['device_id'] = $device['device_id'];
    $device_perf['timestamp'] = array('NOW()');
    if (can_ping_device($attribs) === true && is_array($device_perf)) {
        dbInsert($device_perf, 'device_perf');
    }
    $device['pingable'] = $ping_response['result'];
    $ping_time = $ping_response['last_ping_timetaken'];
    $response = array();
    $status_reason = '';
    if ($device['pingable']) {
        $device['snmpable'] = isSNMPable($device);
        if ($device['snmpable']) {
            $status = '1';
            $response['status_reason'] = '';
        } else {
            echo 'SNMP Unreachable';
            $status = '0';
            $response['status_reason'] = 'snmp';
        }
    } else {
        echo 'Unpingable';
        $status = '0';
        $response['status_reason'] = 'icmp';
    }
    if ($device['status'] != $status) {
        $poll_update .= $poll_separator . "`status` = '{$status}'";
        $poll_separator = ', ';
        dbUpdate(array('status' => $status, 'status_reason' => $response['status_reason']), 'devices', 'device_id=?', array($device['device_id']));
        log_event('Device status changed to ' . ($status == '1' ? 'Up' : 'Down'), $device, $status == '1' ? 'up' : 'down');
    }
    if ($status == '1') {
        $graphs = array();
        $oldgraphs = array();
        // we always want the core module to be included
        include 'includes/polling/core.inc.php';
        if ($options['m']) {
            foreach (explode(',', $options['m']) as $module) {
                if (is_file('includes/polling/' . $module . '.inc.php')) {
                    include 'includes/polling/' . $module . '.inc.php';
                }
            }
        } else {
            foreach ($config['poller_modules'] as $module => $module_status) {
                if ($attribs['poll_' . $module] || $module_status && !isset($attribs['poll_' . $module])) {
                    $module_start = microtime(true);
                    include 'includes/polling/' . $module . '.inc.php';
                    $module_time = microtime(true) - $module_start;
                    echo "Runtime for polling module '{$module}': {$module_time}\n";
                    // save per-module poller stats
                    $tags = array('module' => $module, 'rrd_def' => 'DS:poller:GAUGE:600:0:U', 'rrd_name' => array('poller-perf', $module));
                    $fields = array('poller' => $module_time);
                    data_update($device, 'poller-perf', $tags, $fields);
                    // remove old rrd
                    $oldrrd = rrd_name($device['hostname'], array('poller', $module, 'perf'));
                    if (is_file($oldrrd)) {
                        unlink($oldrrd);
                    }
                } else {
                    if (isset($attribs['poll_' . $module]) && $attribs['poll_' . $module] == '0') {
                        echo "Module [ {$module} ] disabled on host.\n";
                    } else {
                        echo "Module [ {$module} ] disabled globally.\n";
                    }
                }
            }
        }
        //end if
//.........这里部分代码省略.........
开发者ID:vpsman,项目名称:librenms,代码行数:101,代码来源:functions.inc.php

示例5: formatCiscoHardware

}
echo '</div>
      <table class="table table-hover table-condensed table-striped">';
$uptime = $device['uptime'];
if ($device['os'] == 'ios') {
    formatCiscoHardware($device);
}
if ($device['features']) {
    $device['features'] = '(' . $device['features'] . ')';
}
$device['os_text'] = $config['os'][$device['os']]['text'];
echo '<tr>
        <td>System Name</td>
        <td>' . $device['sysName'] . ' </td>
      </tr>';
if ($ip = inet6_ntop($device['ip'])) {
    echo '<tr>
             <td>Resolved IP</td>
             <td>' . $ip . '</td>
         </tr>';
}
if ($device['hardware']) {
    echo '<tr>
        <td>Hardware</td>
        <td>' . $device['hardware'] . '</td>
      </tr>';
}
echo '<tr>
        <td>Operating System</td>
        <td>' . $device['os_text'] . ' ' . $device['version'] . ' ' . $device['features'] . ' </td>
      </tr>';
开发者ID:holmie,项目名称:librenms,代码行数:31,代码来源:dev-overview-data.inc.php

示例6: RunRules

/**
 * Run all rules for a device
 * @param int $device Device-ID
 * @return void
 */
function RunRules($device)
{
    if (IsMaintenance($device) > 0) {
        echo "Under Maintenance, Skipping alerts.\r\n";
        return false;
    }
    foreach (GetRules($device) as $rule) {
        c_echo('Rule %p#' . $rule['id'] . ' (' . $rule['name'] . '):%n ');
        $inv = json_decode($rule['extra'], true);
        if (isset($inv['invert'])) {
            $inv = (bool) $inv['invert'];
        } else {
            $inv = false;
        }
        d_echo(PHP_EOL);
        $chk = dbFetchRow("SELECT state FROM alerts WHERE rule_id = ? && device_id = ? ORDER BY id DESC LIMIT 1", array($rule['id'], $device));
        $sql = GenSQL($rule['rule']);
        $qry = dbFetchRows($sql, array($device));
        if (isset($qry[0]['ip'])) {
            $qry[0]['ip'] = inet6_ntop($qry[0]['ip']);
        }
        $s = sizeof($qry);
        if ($s == 0 && $inv === false) {
            $doalert = false;
        } elseif ($s > 0 && $inv === false) {
            $doalert = true;
        } elseif ($s == 0 && $inv === true) {
            $doalert = true;
        } else {
            //( $s > 0 && $inv == false ) {
            $doalert = false;
        }
        if ($doalert) {
            if ($chk['state'] === "2") {
                c_echo('Status: %ySKIP');
            } elseif ($chk['state'] >= "1") {
                c_echo('Status: %bNOCHG');
            } else {
                $extra = gzcompress(json_encode(array('contacts' => GetContacts($qry), 'rule' => $qry)), 9);
                if (dbInsert(array('state' => 1, 'device_id' => $device, 'rule_id' => $rule['id'], 'details' => $extra), 'alert_log')) {
                    if (!dbUpdate(array('state' => 1, 'open' => 1), 'alerts', 'device_id = ? && rule_id = ?', array($device, $rule['id']))) {
                        dbInsert(array('state' => 1, 'device_id' => $device, 'rule_id' => $rule['id'], 'open' => 1, 'alerted' => 0), 'alerts');
                    }
                    c_echo(PHP_EOL . 'Status: %rALERT');
                }
            }
        } else {
            if ($chk['state'] === "0") {
                c_echo('Status: %bNOCHG');
            } else {
                if (dbInsert(array('state' => 0, 'device_id' => $device, 'rule_id' => $rule['id']), 'alert_log')) {
                    if (!dbUpdate(array('state' => 0, 'open' => 1), 'alerts', 'device_id = ? && rule_id = ?', array($device, $rule['id']))) {
                        dbInsert(array('state' => 0, 'device_id' => $device, 'rule_id' => $rule['id'], 'open' => 1, 'alerted' => 0), 'alerts');
                    }
                    c_echo(PHP_EOL . 'Status: %gOK');
                }
            }
        }
        c_echo('%n' . PHP_EOL);
    }
}
开发者ID:arrmo,项目名称:librenms,代码行数:66,代码来源:alerts.inc.php


注:本文中的inet6_ntop函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。