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


PHP get_dev_attribs函数代码示例

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


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

示例1: discover_device

function discover_device($device, $options = null)
{
    global $config, $valid;
    $valid = array();
    // Reset $valid array
    $attribs = get_dev_attribs($device['device_id']);
    $device_start = utime();
    // Start counting device poll time
    echo $device['hostname'] . ' ' . $device['device_id'] . ' ' . $device['os'] . ' ';
    if ($device['os'] == 'generic') {
        // verify if OS has changed from generic
        $device['os'] = getHostOS($device);
        if ($device['os'] != 'generic') {
            echo "\nDevice os was updated to " . $device['os'] . '!';
            dbUpdate(array('os' => $device['os']), '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";
    // If we've specified modules, use them, else walk the modules array
    if ($options['m']) {
        foreach (explode(',', $options['m']) as $module) {
            if (is_file("includes/discovery/{$module}.inc.php")) {
                include "includes/discovery/{$module}.inc.php";
            }
        }
    } else {
        foreach ($config['discovery_modules'] as $module => $module_status) {
            if ($attribs['discover_' . $module] || $module_status && !isset($attribs['discover_' . $module])) {
                include 'includes/discovery/' . $module . '.inc.php';
            } else {
                if (isset($attribs['discover_' . $module]) && $attribs['discover_' . $module] == '0') {
                    echo "Module [ {$module} ] disabled on host.\n";
                } else {
                    echo "Module [ {$module} ] disabled globally.\n";
                }
            }
        }
    }
    // Set type to a predefined type for the OS if it's not already set
    if ($device['type'] == 'unknown' || $device['type'] == '') {
        if ($config['os'][$device['os']]['type']) {
            $device['type'] = $config['os'][$device['os']]['type'];
        }
    }
    $device_end = utime();
    $device_run = $device_end - $device_start;
    $device_time = substr($device_run, 0, 5);
    dbUpdate(array('last_discovered' => array('NOW()'), 'type' => $device['type'], 'last_discovered_timetaken' => $device_time), 'devices', '`device_id` = ?', array($device['device_id']));
    echo "Discovered in {$device_time} seconds\n";
    global $discovered_devices;
    echo "\n";
    $discovered_devices++;
}
开发者ID:rkojedzinszky,项目名称:librenms,代码行数:57,代码来源:functions.inc.php

示例2: 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 = utime();
    // Start counting device poll time
    echo $device['hostname'] . ' ' . $device['device_id'] . ' ' . $device['os'] . ' ';
    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']));
        dbInsert(array('importance' => '0', 'device_id' => $device['device_id'], 'message' => 'Device is ' . ($status == '1' ? 'up' : 'down')), 'alerts');
        log_event('Device status changed to ' . ($status == '1' ? 'Up' : 'Down'), $device, $status == '1' ? 'up' : 'down');
    }
    if ($status == '1') {
        $graphs = array();
        $oldgraphs = array();
        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])) {
                    // TODO per-module polling stats
                    include 'includes/polling/' . $module . '.inc.php';
                } 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
        if (!$options['m']) {
            // FIXME EVENTLOGGING -- MAKE IT SO WE DO THIS PER-MODULE?
            // This code cycles through the graphs already known in the database and the ones we've defined as being polled here
            // If there any don't match, they're added/deleted from the database.
            // Ideally we should hold graphs for xx days/weeks/polls so that we don't needlessly hide information.
            foreach (dbFetch('SELECT `graph` FROM `device_graphs` WHERE `device_id` = ?', array($device['device_id'])) as $graph) {
                if (isset($graphs[$graph['graph']])) {
                    $oldgraphs[$graph['graph']] = true;
                } else {
                    dbDelete('device_graphs', '`device_id` = ? AND `graph` = ?', array($device['device_id'], $graph['graph']));
                }
            }
            foreach ($graphs as $graph => $value) {
                if (!isset($oldgraphs[$graph])) {
                    echo '+';
                    dbInsert(array('device_id' => $device['device_id'], 'graph' => $graph), 'device_graphs');
                }
                echo $graph . ' ';
//.........这里部分代码省略.........
开发者ID:jcbailey2,项目名称:librenms,代码行数:101,代码来源:functions.inc.php

示例3: discover_device

function discover_device($device, $options = null)
{
    global $config, $valid;
    $valid = array();
    // Reset $valid array
    $attribs = get_dev_attribs($device['device_id']);
    $device['snmp_max_repeaters'] = $attribs['snmp_max_repeaters'];
    $device_start = microtime(true);
    // Start counting device poll time
    echo $device['hostname'] . ' ' . $device['device_id'] . ' ' . $device['os'] . ' ';
    if ($device['os'] == 'generic') {
        // verify if OS has changed from generic
        $device['os'] = getHostOS($device);
        if ($device['os'] != 'generic') {
            echo "\nDevice os was updated to " . $device['os'] . '!';
            dbUpdate(array('os' => $device['os']), 'devices', '`device_id` = ?', array($device['device_id']));
        }
    }
    // Set type to a predefined type for the OS if it's not already set
    if ($device['type'] == 'unknown' || $device['type'] == '') {
        if ($config['os'][$device['os']]['type']) {
            $device['type'] = $config['os'][$device['os']]['type'];
        }
    }
    if ($config['os'][$device['os']]['group']) {
        $device['os_group'] = $config['os'][$device['os']]['group'];
        echo ' (' . $device['os_group'] . ')';
    }
    echo "\n";
    // If we've specified modules, use them, else walk the modules array
    $force_module = false;
    if ($options['m']) {
        $config['discovery_modules'] = array();
        foreach (explode(',', $options['m']) as $module) {
            if (is_file("includes/discovery/{$module}.inc.php")) {
                $config['discovery_modules'][$module] = 1;
                $force_module = true;
            }
        }
    }
    foreach ($config['discovery_modules'] as $module => $module_status) {
        if ($force_module === true || $attribs['discover_' . $module] || $module_status && !isset($attribs['discover_' . $module])) {
            $module_start = microtime(true);
            echo "#### Load disco module {$module} ####\n";
            include "includes/discovery/{$module}.inc.php";
            $module_time = microtime(true) - $module_start;
            $module_time = substr($module_time, 0, 5);
            echo "\n>> Runtime for discovery module '{$module}': {$module_time} seconds\n";
            echo "#### Unload disco module {$module} ####\n\n";
        } elseif (isset($attribs['discover_' . $module]) && $attribs['discover_' . $module] == '0') {
            echo "Module [ {$module} ] disabled on host.\n\n";
        } else {
            echo "Module [ {$module} ] disabled globally.\n\n";
        }
    }
    if (is_mib_poller_enabled($device)) {
        $devicemib = array($device['sysObjectID'] => 'all');
        register_mibs($device, $devicemib, "includes/discovery/functions.inc.php");
    }
    $device_end = microtime(true);
    $device_run = $device_end - $device_start;
    $device_time = substr($device_run, 0, 5);
    dbUpdate(array('last_discovered' => array('NOW()'), 'type' => $device['type'], 'last_discovered_timetaken' => $device_time), 'devices', '`device_id` = ?', array($device['device_id']));
    echo "Discovered in {$device_time} seconds\n";
    global $discovered_devices;
    echo "\n";
    $discovered_devices++;
}
开发者ID:arrmo,项目名称:librenms,代码行数:68,代码来源:functions.inc.php

示例4: poll_device

function poll_device($device, $options)
{
    global $config, $device, $polled_devices, $memcache;
    $attribs = get_dev_attribs($device['device_id']);
    $device['snmp_max_repeaters'] = $attribs['snmp_max_repeaters'];
    $device['snmp_max_oid'] = $attribs['snmp_max_oid'];
    $status = 0;
    unset($array);
    $device_start = microtime(true);
    // Start counting device poll time
    echo 'Hostname: ' . $device['hostname'] . PHP_EOL;
    echo 'Device ID: ' . $device['device_id'] . PHP_EOL;
    echo 'OS: ' . $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 PHP_EOL . PHP_EOL;
    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 ($config['norrd'] !== true && !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') . ' from ' . $response['status_reason'] . ' check.', $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';
        $force_module = false;
        if ($options['m']) {
            $config['poller_modules'] = array();
            foreach (explode(',', $options['m']) as $module) {
                if (is_file('includes/polling/' . $module . '.inc.php')) {
                    $config['poller_modules'][$module] = 1;
                    $force_module = true;
                }
            }
        }
        foreach ($config['poller_modules'] as $module => $module_status) {
            $os_module_status = $config['os'][$device['os']]['poller_modules'][$module];
            d_echo("Modules status: Global" . (isset($module_status) ? $module_status ? '+ ' : '- ' : '  '));
            d_echo("OS" . (isset($os_module_status) ? $os_module_status ? '+ ' : '- ' : '  '));
            d_echo("Device" . (isset($attribs['poll_' . $module]) ? $attribs['poll_' . $module] ? '+ ' : '- ' : '  '));
            if ($force_module === true || $attribs['poll_' . $module] || $os_module_status && !isset($attribs['poll_' . $module]) || $module_status && !isset($os_module_status) && !isset($attribs['poll_' . $module])) {
                $module_start = 0;
                $module_time = 0;
                $module_start = microtime(true);
                echo "\n#### Load poller module {$module} ####\n";
                include "includes/polling/{$module}.inc.php";
                $module_time = microtime(true) - $module_start;
                printf("\n>> Runtime for poller module '%s': %.4f seconds\n", $module, $module_time);
                echo "#### Unload poller module {$module} ####\n\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);
//.........这里部分代码省略.........
开发者ID:Rosiak,项目名称:librenms,代码行数:101,代码来源:functions.inc.php

示例5: ksort

        if (in_array($mib, array_keys($mibs)) === FALSE) {
            $other_mibs[$mib]++;
        }
    }
}
// Sort alphabetically
ksort($other_mibs);
$attribs = get_dev_attribs($device['device_id']);
if ($_POST['toggle_mib'] && isset($mibs[$_POST['toggle_mib']])) {
    $mib = $_POST['toggle_mib'];
    if (isset($attribs['mib_' . $mib])) {
        del_dev_attrib($device, 'mib_' . $mib);
    } else {
        set_dev_attrib($device, 'mib_' . $mib, "0");
    }
    $attribs = get_dev_attribs($device['device_id']);
}
print_message("This page allows you to disable certain MIBs to be polled for a device. This configuration disables all discovery modules using this MIB.");
?>

<div class="row"> <!-- begin row -->

  <div class="col-md-6"> <!-- begin poller options -->

<fieldset>
  <legend>Device MIBs</legend>
</fieldset>

<table class="table table-bordered table-striped table-condensed table-rounded">
  <thead>
    <tr>
开发者ID:skive,项目名称:observium,代码行数:31,代码来源:mibs.inc.php

示例6: is_device_mib

function is_device_mib($device, $mib, $check_permissions = TRUE)
{
    global $config;
    $mib_permitted = in_array($mib, get_device_mibs($device));
    // Check if mib available for device
    if ($check_permissions && $mib_permitted && (!isset($config['mibs'][$mib]) || $config['mibs'][$mib])) {
        // Check if MIB permitted by config
        $mib_permitted = $mib_permitted && (!isset($config['mibs'][$mib]) || $config['mibs'][$mib]);
        // Check if MIB disabled by web interface or polling process
        $attribs = get_dev_attribs($device['device_id']);
        $mib_permitted = $mib_permitted && (!isset($attribs['mib_' . $mib]) || $attribs['mib_' . $mib] != 0);
    }
    return $mib_permitted;
}
开发者ID:skive,项目名称:observium,代码行数:14,代码来源:common.inc.php

示例7: discover_device

function discover_device($device, $options = NULL)
{
    global $config, $valid, $exec_status, $discovered_devices;
    $valid = array();
    // Reset $valid array
    $attribs = get_dev_attribs($device['device_id']);
    $device_start = utime();
    // Start counting device poll time
    echo $device['hostname'] . " " . $device['device_id'] . " " . $device['os'] . " ";
    $detect_os = TRUE;
    // Set TRUE or FALSE for module 'os' (exclude double os detection)
    if ($device['os'] == 'generic' || isset($options['h']) && $options['h'] == 'new') {
        $detect_os = FALSE;
        $old_os = $device['os'];
        $device['os'] = get_device_os($device);
        if ($device['os'] != $old_os) {
            print_warning("Device OS changed: {$old_os} -> " . $device['os'] . "!");
            log_event('OS changed: ' . $old_os . ' -> ' . $device['os'], $device, 'system');
            dbUpdate(array('os' => $device['os']), '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";
    // If we've specified a module, use that, else walk the modules array
    if ($options['m']) {
        foreach (explode(",", $options['m']) as $module) {
            if (is_file("includes/discovery/{$module}.inc.php")) {
                $m_start = utime();
                include "includes/discovery/{$module}.inc.php";
                $m_end = utime();
                $m_run = round($m_end - $m_start, 4);
                print_message("Module [ {$module} ] time: {$m_run}" . "s");
            }
        }
    } else {
        foreach ($config['discovery_modules'] as $module => $module_status) {
            if (in_array($device['os_group'], $config['os']['discovery_blacklist'])) {
                // Module is blacklisted for this OS.
                print_debug("Module [ {$module} ] is in the blacklist for " . $device['os_group']);
            } elseif (in_array($device['os'], $config['os']['discovery_blacklist'])) {
                // Module is blacklisted for this OS.
                print_debug("Module [ {$module} ] is in the blacklist for " . $device['os']);
            } else {
                if ($attribs['discover_' . $module] || $module_status && !isset($attribs['discover_' . $module])) {
                    $m_start = utime();
                    include "includes/discovery/{$module}.inc.php";
                    $m_end = utime();
                    $m_run = round($m_end - $m_start, 4);
                    print_message("Module [ {$module} ] time: {$m_run}" . "s");
                } elseif (isset($attribs['discover_' . $module]) && $attribs['discover_' . $module] == "0") {
                    print_debug("Module [ {$module} ] disabled on host.");
                } else {
                    print_debug("Module [ {$module} ] disabled globally.");
                }
            }
        }
    }
    // Set type to a predefined type for the OS if it's not already set
    if ($device['type'] == "unknown" || $device['type'] == "") {
        if ($config['os'][$device['os']]['type']) {
            $device['type'] = $config['os'][$device['os']]['type'];
        }
    }
    $device_end = utime();
    $device_run = $device_end - $device_start;
    $device_time = substr($device_run, 0, 5);
    dbUpdate(array('last_discovered' => array('NOW()'), 'type' => $device['type'], 'last_discovered_timetaken' => $device_time), 'devices', '`device_id` = ?', array($device['device_id']));
    // put performance into devices_perftimes
    dbInsert(array('device_id' => $device['device_id'], 'operation' => 'discover', 'start' => $device_start, 'duration' => $device_run), 'devices_perftimes');
    print_message("Discovered in {$device_time} seconds");
    // not worth putting discovery data into rrd. it's not done every 5 mins :)
    echo PHP_EOL;
    $discovered_devices++;
}
开发者ID:skive,项目名称:observium,代码行数:77,代码来源:functions.inc.php

示例8: poll_device

function poll_device($device, $options)
{
    global $config, $debug, $device, $polled_devices, $db_stats, $memcache;
    $old_device_state = unserialize($device['device_state']);
    $attribs = get_dev_attribs($device['device_id']);
    $status = 0;
    unset($array);
    $device_start = utime();
    // Start counting device poll time
    echo $device['hostname'] . " " . $device['device_id'] . " " . $device['os'] . " ";
    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();
    $host_rrd = $config['rrd_dir'] . "/" . $device['hostname'];
    if (!is_dir($host_rrd)) {
        mkdir($host_rrd);
        echo "Created directory : {$host_rrd}\n";
    }
    $device['pingable'] = isPingable($device['hostname']);
    if ($device['pingable']) {
        $device['snmpable'] = isSNMPable($device);
        if ($device['snmpable']) {
            $status = "1";
            $status_type = '';
        } else {
            echo "SNMP Unreachable";
            $status = "0";
            $status_type = ' (snmp)';
        }
    } else {
        echo "Unpingable";
        $status = "0";
        $status_type = ' (ping)';
    }
    if ($device['status'] != $status) {
        $poll_update .= $poll_separator . "`status` = '{$status}'";
        $poll_separator = ", ";
        dbUpdate(array('status' => $status), 'devices', 'device_id=?', array($device['device_id']));
        dbInsert(array('importance' => '0', 'device_id' => $device['device_id'], 'message' => "Device is " . ($status == '1' ? 'up' : 'down')), 'alerts');
        log_event('Device status changed to ' . ($status == '1' ? 'Up' : 'Down') . $status_type, $device, 'system');
        notify($device, "Device " . ($status == '1' ? 'Up' : 'Down') . ": " . $device['hostname'] . $status_type, "Device " . ($status == '1' ? 'up' : 'down') . ": " . $device['hostname']);
    }
    $rrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/status.rrd";
    if (!is_file($rrd)) {
        rrdtool_create($rrd, "DS:status:GAUGE:600:0:1 " . $config['rrd_rra']);
    }
    if ($status == "1" || $status == "0") {
        rrdtool_update($rrd, "N:" . $status);
    } else {
        rrdtool_update($rrd, "N:U");
    }
    // Ping response RRD database.
    $ping_rrd = $config['rrd_dir'] . '/' . $device['hostname'] . '/ping.rrd';
    if (!is_file($ping_rrd)) {
        rrdtool_create($ping_rrd, "DS:ping:GAUGE:600:0:65535 " . $config['rrd_rra']);
    }
    if ($device['pingable']) {
        rrdtool_update($ping_rrd, "N:" . $device['pingable']);
    } else {
        rrdtool_update($ping_rrd, "N:U");
    }
    // SNMP response RRD database.
    $ping_snmp_rrd = $config['rrd_dir'] . '/' . $device['hostname'] . '/ping_snmp.rrd';
    if (!is_file($ping_snmp_rrd)) {
        rrdtool_create($ping_snmp_rrd, "DS:ping_snmp:GAUGE:600:0:65535 " . $config['rrd_rra']);
    }
    if ($device['snmpable']) {
        rrdtool_update($ping_snmp_rrd, "N:" . $device['snmpable']);
    } else {
        rrdtool_update($ping_snmp_rrd, "N:U");
    }
    if ($status == "1") {
        $graphs = array();
        $oldgraphs = array();
        // Enable Ping graphs
        $graphs['ping'] = TRUE;
        // Enable SNMP graphs
        $graphs['ping_snmp'] = TRUE;
        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])) {
                    if ($debug) {
                        echo "including: includes/polling/{$module}.inc.php\n";
                    }
                    include 'includes/polling/' . $module . '.inc.php';
                } elseif (isset($attribs['poll_' . $module]) && $attribs['poll_' . $module] == "0") {
                    echo "Module [ {$module} ] disabled on host.\n";
                } else {
//.........这里部分代码省略.........
开发者ID:RomanBogachev,项目名称:observium,代码行数:101,代码来源:functions.inc.php

示例9: poll_device

function poll_device($device, $options)
{
    global $config, $debug, $device, $polled_devices, $db_stats, $memcache, $exec_status, $alert_rules, $alert_table;
    $oid_cache = array();
    $old_device_state = unserialize($device['device_state']);
    $attribs = get_dev_attribs($device['device_id']);
    $alert_rules = cache_alert_rules();
    $alert_table = cache_device_alert_table($device['device_id']);
    if ($debug && (count($alert_rules) || count($alert_table))) {
        print_vars($alert_rules);
        print_vars($alert_table);
    }
    $status = 0;
    unset($array);
    $device_start = utime();
    // Start counting device poll time
    echo $device['hostname'] . " " . $device['device_id'] . " " . $device['os'] . " ";
    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();
    $host_rrd = $config['rrd_dir'] . "/" . $device['hostname'];
    if (!is_dir($host_rrd)) {
        mkdir($host_rrd);
        echo "Created directory : {$host_rrd}\n";
    }
    $device['pingable'] = isPingable($device['hostname']);
    if ($device['pingable']) {
        $device['snmpable'] = isSNMPable($device);
        if ($device['snmpable']) {
            $status = "1";
            $status_type = '';
        } else {
            echo "SNMP Unreachable";
            $status = "0";
            $status_type = ' (snmp)';
        }
    } else {
        echo "Unpingable";
        $status = "0";
        $status_type = ' (ping)';
    }
    if ($device['status'] != $status) {
        $poll_update .= $poll_separator . "`status` = '{$status}'";
        $poll_separator = ", ";
        dbUpdate(array('status' => $status), 'devices', 'device_id=?', array($device['device_id']));
        dbInsert(array('importance' => '0', 'device_id' => $device['device_id'], 'message' => "Device is " . ($status == '1' ? 'up' : 'down')), 'alerts');
        log_event('Device status changed to ' . ($status == '1' ? 'Up' : 'Down') . $status_type, $device, 'system');
        notify($device, "Device " . ($status == '1' ? 'Up' : 'Down') . ": " . $device['hostname'] . $status_type, "Device " . ($status == '1' ? 'up' : 'down') . ": " . $device['hostname']);
    }
    $rrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/status.rrd";
    if (!is_file($rrd)) {
        rrdtool_create($rrd, "DS:status:GAUGE:600:0:1 ");
    }
    if ($status == "1" || $status == "0") {
        rrdtool_update($rrd, "N:" . $status);
    } else {
        rrdtool_update($rrd, "N:U");
    }
    // Ping response RRD database.
    $ping_rrd = $config['rrd_dir'] . '/' . $device['hostname'] . '/ping.rrd';
    if (!is_file($ping_rrd)) {
        rrdtool_create($ping_rrd, "DS:ping:GAUGE:600:0:65535 ");
    }
    if ($device['pingable']) {
        rrdtool_update($ping_rrd, "N:" . $device['pingable']);
    } else {
        rrdtool_update($ping_rrd, "N:U");
    }
    // SNMP response RRD database.
    $ping_snmp_rrd = $config['rrd_dir'] . '/' . $device['hostname'] . '/ping_snmp.rrd';
    if (!is_file($ping_snmp_rrd)) {
        rrdtool_create($ping_snmp_rrd, "DS:ping_snmp:GAUGE:600:0:65535 ");
    }
    if ($device['snmpable']) {
        rrdtool_update($ping_snmp_rrd, "N:" . $device['snmpable']);
    } else {
        rrdtool_update($ping_snmp_rrd, "N:U");
    }
    if ($status == "1") {
        $graphs = array();
        $oldgraphs = array();
        // Enable Ping graphs
        $graphs['ping'] = TRUE;
        // Enable SNMP graphs
        $graphs['ping_snmp'] = TRUE;
        // Run this base modules always and before all other modules!
        $poll_modules = array('system', 'os');
        if ($options['m']) {
            foreach (explode(',', $options['m']) as $module) {
                $module = trim($module);
                if (in_array($module, $poll_modules)) {
                    continue;
                }
                // Skip already added modules
//.........这里部分代码省略.........
开发者ID:rhizalpatrax64bit,项目名称:StacksNetwork,代码行数:101,代码来源:functions.inc.php

示例10: poll_device

function poll_device($device, $options)
{
    global $config, $device, $polled_devices, $db_stats, $memcache, $exec_status, $alert_rules, $alert_table, $graphs, $attribs;
    $alert_metrics = array();
    $oid_cache = array();
    $old_device_state = unserialize($device['device_state']);
    $attribs = get_dev_attribs($device['device_id']);
    $alert_rules = cache_alert_rules();
    $alert_table = cache_device_alert_table($device['device_id']);
    if (OBS_DEBUG > 1 && (count($alert_rules) || count($alert_table))) {
        print_vars($alert_rules);
        print_vars($alert_table);
    }
    $status = 0;
    unset($array);
    $device_start = utime();
    // Start counting device poll time
    echo $device['hostname'] . " " . $device['device_id'] . " " . $device['os'] . " ";
    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();
    $host_rrd_dir = $config['rrd_dir'] . "/" . $device['hostname'];
    if (!is_dir($host_rrd_dir)) {
        mkdir($host_rrd_dir);
        echo "创建的目录 : {$host_rrd_dir}\n";
    }
    $try_a = !($device['snmp_transport'] == 'udp6' || $device['snmp_transport'] == 'tcp6');
    // Use IPv6 only if transport 'udp6' or 'tcp6'
    $device['pingable'] = isPingable($device['hostname'], $try_a);
    if ($device['pingable']) {
        $device['snmpable'] = isSNMPable($device);
        if ($device['snmpable']) {
            $status = "1";
            $status_type = '';
        } else {
            echo "SNMP 无法访问";
            $status = "0";
            $status_type = 'snmp';
        }
    } else {
        echo "Unpingable";
        $status = "0";
        $status_type = 'ping';
    }
    if ($device['status'] != $status) {
        $poll_update .= $poll_separator . "`status` = '{$status}'";
        $poll_separator = ", ";
        dbUpdate(array('status' => $status), 'devices', 'device_id = ?', array($device['device_id']));
        dbInsert(array('importance' => '0', 'device_id' => $device['device_id'], 'message' => "设备的 " . ($status == '1' ? 'up' : 'down')), 'alerts');
        $event_msg = '设备状态变更为 ';
        if ($status == '1') {
            // Device Up, Severity Warning (4)
            $event_msg .= 'Up';
            $event_severity = 4;
        } else {
            // Device Down, Severity Error (3)!
            $event_msg .= 'Down';
            $event_severity = 3;
        }
        if ($status_type != '') {
            $event_msg .= ' (' . $status_type . ')';
        }
        log_event($event_msg, $device, 'device', $device['device_id'], $event_severity);
    }
    $rrd_filename = "status.rrd";
    rrdtool_create($device, $rrd_filename, "DS:status:GAUGE:600:0:1 ");
    if ($status == "1" || $status == "0") {
        rrdtool_update($device, $rrd_filename, "N:" . $status);
    } else {
        rrdtool_update($device, $rrd_filename, "N:U");
    }
    // Ping response RRD database.
    $ping_rrd = 'ping.rrd';
    rrdtool_create($device, $ping_rrd, "DS:ping:GAUGE:600:0:65535 ");
    if ($device['pingable']) {
        rrdtool_update($device, $ping_rrd, "N:" . $device['pingable']);
    } else {
        rrdtool_update($device, $ping_rrd, "N:U");
    }
    // SNMP response RRD database.
    $ping_snmp_rrd = 'ping_snmp.rrd';
    rrdtool_create($device, $ping_snmp_rrd, "DS:ping_snmp:GAUGE:600:0:65535 ");
    if ($device['snmpable']) {
        rrdtool_update($device, $ping_snmp_rrd, "N:" . $device['snmpable']);
    } else {
        rrdtool_update($device, $ping_snmp_rrd, "N:U");
    }
    $alert_metrics['device_status'] = $status;
    $alert_metrics['device_status_type'] = $status_type;
    $alert_metrics['device_ping'] = $device['pingable'];
    $alert_metrics['device_snmp'] = $device['snmpable'];
    if ($status == "1") {
        // Arrays for store and check enabled/disabled graphs
        $graphs = array();
//.........这里部分代码省略.........
开发者ID:rhizalpatrax64bit,项目名称:StacksNetwork,代码行数:101,代码来源:functions.inc.php

示例11: discover_device

function discover_device($device, $options = NULL)
{
    global $config, $valid, $exec_status, $discovered_devices;
    // Initialise variables
    $valid = array();
    // Reset $valid array
    $cache_discovery = array();
    // Specific discovery cache for exchange snmpwalk data betwen modules (memory/storage/sensors/etc)
    $attribs = get_dev_attribs($device['device_id']);
    $device_start = utime();
    // Start counting device poll time
    echo $device['hostname'] . " " . $device['device_id'] . " " . $device['os'] . " ";
    $detect_os = TRUE;
    // Set TRUE or FALSE for module 'os' (exclude double os detection)
    if ($device['os'] == 'generic' || isset($options['h']) && $options['h'] == 'new') {
        $detect_os = FALSE;
        $old_os = $device['os'];
        $device['os'] = get_device_os($device);
        if ($device['os'] != $old_os) {
            print_warning("设备OS更改: {$old_os} -> " . $device['os'] . "!");
            log_event('OS更改: ' . $old_os . ' -> ' . $device['os'], $device, 'device', $device['device_id'], 'warning');
            dbUpdate(array('os' => $device['os']), '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 PHP_EOL;
    // If we've specified a module, use that, else walk the modules array
    if ($options['m']) {
        foreach (explode(",", $options['m']) as $module) {
            if (is_file("includes/discovery/" . $module . ".inc.php")) {
                $m_start = utime();
                $GLOBALS['module_stats'][$module] = array();
                include "includes/discovery/" . $module . ".inc.php";
                $m_end = utime();
                $GLOBALS['module_stats'][$module]['time'] = round($m_end - $m_start, 4);
                print_module_stats($device, $module);
            }
        }
    } else {
        foreach ($config['discovery_modules'] as $module => $module_status) {
            if (in_array($device['os_group'], $config['os']['discovery_blacklist'])) {
                // Module is blacklisted for this OS.
                print_debug("模块 [ {$module} ] 被列入黑名单在 " . $device['os_group']);
            } elseif (in_array($device['os'], $config['os']['discovery_blacklist'])) {
                // Module is blacklisted for this OS.
                print_debug("模块 [ {$module} ] 被列入黑名单在 " . $device['os']);
            } else {
                if ($attribs['discover_' . $module] || $module_status && !isset($attribs['discover_' . $module])) {
                    $m_start = utime();
                    $GLOBALS['module_stats'][$module] = array();
                    include "includes/discovery/{$module}.inc.php";
                    $m_end = utime();
                    $GLOBALS['module_stats'][$module]['time'] = round($m_end - $m_start, 4);
                    print_module_stats($device, $module);
                } elseif (isset($attribs['discover_' . $module]) && $attribs['discover_' . $module] == "0") {
                    print_debug("模块 [ {$module} ] 在主机禁用.");
                } else {
                    print_debug("模块 [ {$module} ] 全局禁用.");
                }
            }
        }
    }
    // Set type to a predefined type for the OS if it's not already set
    if ($device['type'] == "unknown" || $device['type'] == "") {
        if ($config['os'][$device['os']]['type']) {
            $device['type'] = $config['os'][$device['os']]['type'];
        }
    }
    $device_end = utime();
    $device_run = $device_end - $device_start;
    $device_time = substr($device_run, 0, 5);
    dbUpdate(array('last_discovered' => array('NOW()'), 'type' => $device['type'], 'last_discovered_timetaken' => $device_time, 'force_discovery' => 0), 'devices', '`device_id` = ?', array($device['device_id']));
    // put performance into devices_perftimes
    dbInsert(array('device_id' => $device['device_id'], 'operation' => 'discover', 'start' => $device_start, 'duration' => $device_run), 'devices_perftimes');
    print_message("设备 [ " . $device['hostname'] . " ] 发现 {$device_time} 秒");
    // not worth putting discovery data into rrd. it's not done every 5 mins :)
    echo PHP_EOL;
    $discovered_devices++;
    // Clean
    unset($cache_discovery);
}
开发者ID:rhizalpatrax64bit,项目名称:StacksNetwork,代码行数:84,代码来源:functions.inc.php

示例12: discover_device

function discover_device($device, $options = NULL)
{
    global $config, $valid;
    $valid = array();
    // Reset $valid array
    $attribs = get_dev_attribs($device['device_id']);
    $device_start = utime();
    // Start counting device poll time
    echo $device['hostname'] . " " . $device['device_id'] . " " . $device['os'] . " ";
    if ($device['os'] == 'generic') {
        $device['os'] = getHostOS($device);
        if ($device['os'] != 'generic') {
            echo "\nDevice os was updated to " . $device['os'] . "!";
            dbUpdate(array('os' => $device['os']), '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";
    // If we've specified a module, use that, else walk the modules array
    if ($options['m']) {
        foreach (explode(",", $options['m']) as $module) {
            if (is_file("includes/discovery/" . $module . ".inc.php")) {
                include "includes/discovery/" . $module . ".inc.php";
            }
        }
    } else {
        foreach ($config['discovery_modules'] as $module => $module_status) {
            if (in_array($device['os_group'], $config['os']['discovery_blacklist'])) {
                // Module is blacklisted for this OS.
                debug("Module {$module} is in the blacklist for " . $device['os_group'] . "\n");
            } elseif (in_array($device['os'], $config['os']['discovery_blacklist'])) {
                // Module is blacklisted for this OS.
                debug("Module {$module} is in the blacklist for " . $device['os'] . "\n");
            } else {
                if ($attribs['discover_' . $module] || $module_status && !isset($attribs['discover_' . $module])) {
                    include 'includes/discovery/' . $module . '.inc.php';
                } elseif (isset($attribs['discover_' . $module]) && $attribs['discover_' . $module] == "0") {
                    echo "Module [ {$module} ] disabled on host.\n";
                } else {
                    echo "Module [ {$module} ] disabled globally.\n";
                }
            }
        }
    }
    // Set type to a predefined type for the OS if it's not already set
    if ($device['type'] == "unknown" || $device['type'] == "") {
        if ($config['os'][$device['os']]['type']) {
            $device['type'] = $config['os'][$device['os']]['type'];
        }
    }
    $device_end = utime();
    $device_run = $device_end - $device_start;
    $device_time = substr($device_run, 0, 5);
    dbUpdate(array('last_discovered' => array('NOW()'), 'type' => $device['type'], 'last_discovered_timetaken' => $device_time), 'devices', '`device_id` = ?', array($device['device_id']));
    // put performance into devices_perftimes
    dbInsert(array('device_id' => $device['device_id'], 'operation' => 'discover', 'start' => $device_start, 'duration' => $device_run), 'devices_perftimes');
    echo "Discovered in {$device_time} seconds\n";
    // not worth putting discovery data into rrd. it's not done every 5 mins :)
    global $discovered_devices;
    echo "\n";
    $discovered_devices++;
}
开发者ID:RomanBogachev,项目名称:observium,代码行数:65,代码来源:functions.inc.php


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