Exemplo n.º 1
0
             $params[] = '%' . $vars['query'] . '%';
         }
         $query .= ' ORDER BY `' . $ip_version . '_network`;';
         //print_vars($query);
         break;
     case 'ifspeed':
         $query_permitted = generate_query_permitted('ports');
         $query = 'SELECT `ifSpeed`, COUNT(ifSpeed) as `count` FROM `ports` WHERE `ifSpeed` > 0 ' . $query_permitted . ' GROUP BY ifSpeed ORDER BY `count` DESC';
         $call_function = 'formatRates';
         $call_params = array(4, 4);
         break;
     default:
         json_output('error', 'Search type unknown');
 }
 if (strlen($query)) {
     $options = dbFetchColumn($query, $params);
     if (count($options)) {
         if (isset($call_function)) {
             $call_options = array();
             foreach ($options as $option) {
                 $call_options[] = call_user_func_array($call_function, array_merge(array($option), $call_params));
             }
             $options = $call_options;
         }
         if ($vars['cache'] != 'no') {
             $_SESSION['cache']['options_' . $vars['field']] = $options;
             // Cache query data in session for speedup
         }
         header("Content-type: application/json; charset=utf-8");
         echo json_encode(array('options' => $options));
     } else {
Exemplo n.º 2
0
         $peer_device_id = array('NULL');
         foreach ($ip_array as $entry) {
             $as_array = dbFetchColumn('SELECT DISTINCT `bgpPeerRemoteAs` FROM `bgpPeers` WHERE `device_id` = ?', array($entry['device_id']));
             if (in_array($bgpLocalAs, $as_array)) {
                 $peer_device_id = $entry['device_id'];
                 $peer_device = device_by_id_cache($peer_device_id);
                 if ($peer_device['status'] && $entry['ifOperStatus'] == 'up') {
                     break;
                     // Stop on first UP device/port
                 }
             }
         }
     } else {
         if ($ip_array) {
             // It simple, only one device
             $as_array = dbFetchColumn('SELECT DISTINCT `bgpPeerRemoteAs` FROM `bgpPeers` WHERE `device_id` = ?', array($ip_array[0]['device_id']));
             if (in_array($bgpLocalAs, $as_array)) {
                 $peer_device_id = $ip_array[0]['device_id'];
             }
         } else {
             $peer_device_id = array('NULL');
         }
     }
 }
 if (is_numeric($peer_device_id)) {
     $peer_device = device_by_id_cache($peer_device_id);
 } else {
     unset($peer_device);
 }
 $table_rows[$peer['ip']] = array($peer['local_ip'], $peer['as'], $peer['ip'], '', $reverse_dns, truncate($peer_device['hostname'], 30));
 $params = array('device_id' => $device['device_id'], 'bgpPeerIdentifier' => $peer['id'], 'bgpPeerRemoteAddr' => $peer['ip'], 'bgpPeerLocalAddr' => $peer['local_ip'], 'bgpPeerRemoteAs' => $peer['as'], 'astext' => $astext, 'reverse_dns' => $reverse_dns, 'peer_device_id' => $peer_device_id);
Exemplo n.º 3
0
     if (count($key_val) != 2) {
         $key_val[] = '';
     }
     $key = $key_val[0];
     $value = $key_val[1];
     $prop_id = explode('.', $key);
     if (count($prop_id) != 2 || !ctype_digit($prop_id[1])) {
         continue;
     }
     $property = $prop_id[0];
     $id = intval($prop_id[1]);
     $sla_table[$id][$property] = trim($value);
 }
 // var_dump($sla_table);
 // Get existing SLAs
 $existing_slas = dbFetchColumn('SELECT `sla_id` FROM `slas` WHERE `device_id` = :device_id AND `deleted` = 0', array('device_id' => $device['device_id']));
 foreach ($sla_table as $sla_nr => $sla_config) {
     $query_data = array('device_id' => $device['device_id'], 'sla_nr' => $sla_nr);
     $sla_id = dbFetchCell('SELECT `sla_id` FROM `slas` WHERE `device_id` = :device_id AND `sla_nr` = :sla_nr', $query_data);
     $data = array('device_id' => $device['device_id'], 'sla_nr' => $sla_nr, 'owner' => $sla_config['rttMonCtrlAdminOwner'], 'tag' => $sla_config['rttMonCtrlAdminTag'], 'rtt_type' => $sla_config['rttMonCtrlAdminRttType'], 'status' => $sla_config['rttMonCtrlAdminStatus'] == 'active' ? 1 : 0, 'opstatus' => $sla_config['rttMonLatestRttOperSense'] == 'ok' ? 0 : 2, 'deleted' => 0);
     // Some fallbacks for when the tag is empty
     if (!$data['tag']) {
         switch ($data['rtt_type']) {
             case 'http':
                 $data['tag'] = $sla_config['rttMonEchoAdminURL'];
                 break;
             case 'dns':
                 $data['tag'] = $sla_config['rttMonEchoAdminTargetAddressString'];
                 break;
             case 'echo':
                 $parts = explode(' ', $sla_config['rttMonEchoAdminTargetAddress']);
Exemplo n.º 4
0
foreach (dbFetchColumn('SELECT DISTINCT `device_id` FROM `ports`' . $where) as $device_id) {
    if ($cache['devices']['id'][$device_id]['hostname']) {
        $form_items['devices'][$device_id] = $cache['devices']['id'][$device_id]['hostname'];
    }
}
natcasesort($form_items['devices']);
// If device IDs passed, limit ports to specified devices
if ($vars['device']) {
    $neighbours_ports = dbFetchColumn('SELECT DISTINCT `port_id` FROM `ports`' . $where . generate_query_values($vars['device'], 'device_id'));
    $where = ' WHERE 1 ';
    $where .= generate_query_values($neighbours_ports, 'port_id');
    //r($where);
}
$form_params = array('platforms' => 'remote_platform', 'versions' => 'remote_version', 'protocols' => 'protocol');
foreach ($form_params as $param => $column) {
    foreach (dbFetchColumn('SELECT DISTINCT `' . $column . '` FROM `neighbours`' . $where) as $entry) {
        if (!empty($entry)) {
            $form_items[$param][$entry] = $param == 'protocols' ? nicecase($entry) : escape_html($entry);
        }
    }
}
$form = array('type' => 'rows', 'space' => '5px', 'submit_by_key' => TRUE, 'url' => generate_url($vars));
$form['row'][0]['device'] = array('type' => 'multiselect', 'name' => 'Device', 'width' => '100%', 'value' => $vars['device'], 'values' => $form_items['devices']);
$form['row'][0]['protocol'] = array('type' => 'multiselect', 'name' => 'Protocol', 'width' => '100%', 'value' => $vars['protocol'], 'values' => $form_items['protocols']);
$form['row'][0]['platform'] = array('type' => 'multiselect', 'name' => 'Platform', 'width' => '100%', 'value' => $vars['platform'], 'values' => $form_items['platforms']);
$form['row'][0]['version'] = array('type' => 'multiselect', 'name' => 'Version', 'width' => '100%', 'value' => $vars['version'], 'values' => $form_items['versions']);
$form['row'][0]['remote_port_id'] = array('type' => 'select', 'name' => 'Version', 'width' => '100%', 'value' => escape_html($vars['remote_port_id']), 'values' => array('' => 'All Devices', '1' => 'Known Devices', '0' => 'Unknown Devices'));
// search button
$form['row'][0]['search'] = array('type' => 'submit', 'right' => TRUE);
$panel_form = array('type' => 'rows', 'title' => 'Search Neighbours', 'space' => '10px', 'submit_by_key' => TRUE, 'url' => generate_url($vars));
$panel_form['row'][0]['device'] = $form['row'][0]['device'];
Exemplo n.º 5
0
function get_locations($filter = array())
{
    foreach ($filter as $var => $value) {
        switch ($var) {
            case 'location_lat':
            case 'location_lon':
            case 'location_country':
            case 'location_state':
            case 'location_county':
            case 'location_city':
                // Check geo params only when GEO enabled globally
                if (!$GLOBALS['config']['geocoding']['enable']) {
                    break;
                }
            case 'location':
                $where_array[$var] = generate_query_values($value, $var);
                break;
        }
    }
    if (count($where_array)) {
        // Return only founded locations
        $where = implode('', $where_array) . $GLOBALS['cache']['where']['devices_permitted'];
        $locations = dbFetchColumn("SELECT DISTINCT `location` FROM `devices_locations` WHERE 1 {$where};");
    } else {
        $locations = array();
        foreach ($GLOBALS['cache']['device_locations'] as $location => $count) {
            $locations[] = $location;
        }
    }
    sort($locations);
    return $locations;
}
Exemplo n.º 6
0
/**
 * Poll a table or oids from SNMP and build an RRD based on an array of arguments.
 *
 * Current limitations:
 *  - single MIB and RRD file for all graphs
 *  - single table per MIB
 *  - if set definition 'call_function', than poll used specific function for snmp walk/get,
 *    else by default used snmpwalk_cache_oid()
 *  - allowed oids only with simple numeric index (oid.0, oid.33), NOT allowed (oid.1.2.23)
 *  - only numeric data
 *
 * Example of (full) args array:
 *  array(
 *   'file'          => 'someTable.rrd',              // [MANDATORY] RRD filename, but if not set used MIB_table.rrd as filename
 *   'call_function' => 'snmpwalk_cache_oid'          // [OPTIONAL] Which function to use for snmp poll, bu default snmpwalk_cache_oid()
 *   'mib'           => 'SOMETHING-MIB',              // [OPTIONAL] MIB or list of MIBs separated by a colon
 *   'mib_dir'       => 'something',                  // [OPTIONAL] OS MIB directory or array of directories
 *   'graphs'        => array('one','two'),           // [OPTIONAL] List of graph_types that this table provides
 *   'table'         => 'someTable',                  // [RECOMENDED] Table name for OIDs
 *   'numeric'       => '.1.3.6.1.4.1.555.4.1.1.48',  // [OPTIONAL] Numeric table OID
 *   'ds_rename'     => array('http' => ''),          // [OPTIONAL] Array for renaming OIDs to DSes
 *   'oids'          => array(                        // List of OIDs you can use as key: full OID name
 *     'someOid' => array(                                 // OID name (You can use OID name, like 'cpvIKECurrSAs')
 *       'descr'     => 'Current IKE SAs',                 // [OPTIONAL] Description of the OID contents
 *       'numeric'   => '.1.3.6.1.4.1.555.4.1.1.48.45',    // [OPTIONAL] Numeric OID
 *       'index'     => '0',                               // [OPTIONAL] OID index, if not set equals '0'
 *       'ds_name'   => 'IKECurrSAs',                      // [OPTIONAL] DS name, if not set used OID name truncated to 19 chars
 *       'ds_type'   => 'GAUGE',                           // [OPTIONAL] DS type, if not set equals 'COUNTER'
 *       'ds_min'    => '0',                               // [OPTIONAL] Min value for DS, if not set equals 'U'
 *       'ds_max'    => '30000'                            // [OPTIONAL] Max value for DS, if not set equals '100000000000'
 *    )
 *  )
 *
 */
function collect_table($device, $oids_def, &$graphs)
{
    $rrd = array();
    $mib = NULL;
    $mib_dirs = NULL;
    $use_walk = isset($oids_def['table']) && $oids_def['table'];
    // Use snmpwalk by default
    $call_function = strtolower($oids_def['call_function']);
    switch ($call_function) {
        case 'snmp_get_multi':
            $use_walk = FALSE;
            break;
        case 'snmpwalk_cache_oid':
        default:
            $call_function = 'snmpwalk_cache_oid';
            if (!$use_walk) {
                // Break because we should use snmpwalk, but walking table not set
                return FALSE;
            }
    }
    if (isset($oids_def['numeric'])) {
        $oids_def['numeric'] = '.' . trim($oids_def['numeric'], '. ');
    }
    // Remove trailing dot
    if (isset($oids_def['mib'])) {
        $mib = $oids_def['mib'];
    }
    if (isset($oids_def['mib_dir'])) {
        $mib_dirs = mib_dirs($oids_def['mib_dir']);
    }
    if (isset($oids_def['file'])) {
        $rrd_file = $oids_def['file'];
    } else {
        if ($mib && isset($oids_def['table'])) {
            // Try to use MIB & tableName as rrd_file
            $rrd_file = strtolower(safename($mib . '_' . $oids_def['table'])) . '.rrd';
        } else {
            print_debug("  WARNING, not have rrd filename.");
            return FALSE;
            // Not have RRD filename
        }
    }
    // Get MIBS/Tables/OIDs permissions
    if ($use_walk) {
        // if use table walk, than check only this table permission (not oids)
        if (dbFetchCell("SELECT COUNT(*) FROM `devices_mibs` WHERE `device_id` = ? AND `mib` = ? AND `table_name` = ?\n                    AND (`oid` = '' OR `oid` IS NULL) AND `disabled` = '1'", array($device['device_id'], $mib, $oids_def['table']))) {
            print_debug("  WARNING, table '" . $oids_def['table'] . "' for '{$mib}' disabled and skipped.");
            return FALSE;
            // table disabled, exit
        }
        $oids_ok = TRUE;
    } else {
        // if use multi_get, than get all disabled oids
        $oids_disabled = dbFetchColumn("SELECT `oid` FROM `devices_mibs` WHERE `device_id` = ? AND `mib` = ?\n                                   AND (`oid` != '' AND `oid` IS NOT NULL) AND `disabled` = '1'", array($device['device_id'], $mib));
        $oids_ok = empty($oids_disabled);
        // if empty disabled, than set to TRUE
    }
    $search = array();
    $replace = array();
    if (is_array($oids_def['ds_rename'])) {
        foreach ($oids_def['ds_rename'] as $s => $r) {
            $search[] = $s;
            $replace[] = $r;
        }
    }
    // rrd DS limit is 20 bytes (19 chars + NULL terminator)
    $ds_len = 19;
    $oids = array();
    $oids_index = array();
    foreach ($oids_def['oids'] as $oid => $entry) {
        if (is_numeric($entry['numeric']) && isset($oids_def['numeric'])) {
            $entry['numeric'] = $oids_def['numeric'] . '.' . $entry['numeric'];
            // Numeric oid, for future using
        }
        if (!isset($entry['index'])) {
            $entry['index'] = '0';
        }
        if (!isset($entry['ds_type'])) {
            $entry['ds_type'] = 'COUNTER';
        }
        if (!isset($entry['ds_min'])) {
            $entry['ds_min'] = 'U';
        }
        if (!isset($entry['ds_max'])) {
            $entry['ds_max'] = '100000000000';
        }
        if (!isset($entry['ds_name'])) {
            // Convert OID name to DS name
            $ds_name = $oid;
            if (is_array($oids_def['ds_rename'])) {
                $ds_name = str_replace($search, $replace, $ds_name);
            }
        } else {
            $ds_name = $entry['ds_name'];
        }
        if (strlen($ds_name) > $ds_len) {
            $ds_name = truncate($ds_name, $ds_len, '');
        }
        if (isset($oids_def['no_index']) && $oids_def['no_index'] == TRUE) {
            $oids[] = $oid;
        } else {
            $oids[] = $oid . '.' . $entry['index'];
        }
        $oids_index[] = array('index' => $entry['index'], 'oid' => $oid);
        if (!$use_walk) {
            // Check permissions for snmp_get_multi _ONLY_
            // if at least one oid missing in $oids_disabled than TRUE
            $oids_ok = $oids_ok || !in_array($oid, $oids_disabled);
        }
        $rrd['rrd_create'][] = ' DS:' . $ds_name . ':' . $entry['ds_type'] . ':600:' . $entry['ds_min'] . ':' . $entry['ds_max'];
        if ($GLOBALS['debug']) {
            $rrd['ds_list'][] = $ds_name;
        }
        // Make DS lists for compare with RRD file in debug
    }
    if (!$use_walk && !$oids_ok) {
        print_debug("  WARNING, oids '" . implode("', '", array_keys($oids_def['oids'])) . "' for '{$mib}' disabled and skipped.");
        return FALSE;
        // All oids disabled, exit
    }
    switch ($call_function) {
        case 'snmpwalk_cache_oid':
            $data = snmpwalk_cache_oid($device, $oids_def['table'], array(), $mib, $mib_dirs);
            break;
        case 'snmp_get_multi':
            $data = snmp_get_multi($device, $oids, "-OQUs", $mib, $mib_dirs);
            break;
    }
    if (isset($GLOBALS['exec_status']['exitcode']) && $GLOBALS['exec_status']['exitcode'] !== 0) {
        // Break because latest snmp walk/get return not good exitstatus (wrong mib/timeout/error/etc)
        print_debug("  WARNING, latest snmp walk/get return not good exitstatus for '{$mib}', RRD update skipped.");
        return FALSE;
    }
    if (isset($oids_def['no_index']) && $oids_def['no_index'] == TRUE) {
        $data[0] = $data[''];
    }
    foreach ($oids_index as $entry) {
        $index = $entry['index'];
        $oid = $entry['oid'];
        if (is_numeric($data[$index][$oid])) {
            $rrd['ok'] = TRUE;
            // We have any data for current rrd_file
            $rrd['rrd_update'][] = $data[$index][$oid];
        } else {
            $rrd['rrd_update'][] = 'U';
        }
    }
    // Ok, all previous checks done, update RRD, table/oids permissions, $graphs
    if (isset($rrd['ok']) && $rrd['ok']) {
        // Create/update RRD file
        $rrd_create = implode('', $rrd['rrd_create']);
        $rrd_update = 'N:' . implode(':', $rrd['rrd_update']);
        rrdtool_create($device, $rrd_file, $rrd_create);
        rrdtool_update($device, $rrd_file, $rrd_update);
        foreach ($oids_def['graphs'] as $graph) {
            $graphs[$graph] = TRUE;
            // Set all graphs to TRUE
        }
        // Compare DSes form RRD file with DSes from array
        if (OBS_DEBUG) {
            $graph_template = "\$config['graph_types']['device']['GRAPH_CHANGE_ME'] = array(\n";
            $graph_template .= "  'file'      => '{$rrd_file}',\n";
            $graph_template .= "  'ds'        => array(\n";
            $rrd_file_info = rrdtool_file_info(get_rrd_path($device, $rrd_file));
            foreach ($rrd_file_info['DS'] as $ds => $nothing) {
                $ds_list[] = $ds;
                $graph_template .= "    '{$ds}' => array('label' => '{$ds}'),\n";
            }
            $graph_template .= "  )\n);";
            $in_args = array_diff($rrd['ds_list'], $ds_list);
            if ($in_args) {
                print_message("%rWARNING%n, in file '%W" . $rrd_file_info['filename'] . "%n' different DS lists. NOT have: " . implode(', ', $in_args));
            }
            $in_file = array_diff($ds_list, $rrd['ds_list']);
            if ($in_file) {
                print_message("%rWARNING%n, in file '%W" . $rrd_file_info['filename'] . "%n' different DS lists. Excess: " . implode(', ', $in_file));
            }
            // Print example for graph template using rrd_file and ds list
            print_message($graph_template);
        }
    } else {
        if ($use_walk) {
            // Table NOT exist on device!
            // Disable polling table (only if table not enabled manually in DB)
            if (!dbFetchCell("SELECT COUNT(*) FROM `devices_mibs` WHERE `device_id` = ? AND `mib` = ?\n                     AND `table_name` = ? AND (`oid` = '' OR `oid` IS NULL)", array($device['device_id'], $mib, $oids_def['table']))) {
                dbInsert(array('device_id' => $device['device_id'], 'mib' => $mib, 'table_name' => $oids_def['table'], 'disabled' => '1'), 'devices_mibs');
            }
            print_debug("  WARNING, table '" . $oids_def['table'] . "' for '{$mib}' disabled.");
        } else {
            // OIDs NOT exist on device!
            // Disable polling oids (only if table not enabled manually in DB)
            foreach (array_keys($oids_def['oids']) as $oid) {
                if (!dbFetchCell("SELECT COUNT(*) FROM `devices_mibs` WHERE `device_id` = ? AND `mib` = ?\n                       AND `oid` = ?", array($device['device_id'], $mib, $oid))) {
                    dbInsert(array('device_id' => $device['device_id'], 'mib' => $mib, 'oid' => $oid, 'disabled' => '1'), 'devices_mibs');
                }
            }
            print_debug("  WARNING, oids '" . implode("', '", array_keys($oids_def['oids'])) . "' for '{$mib}' disabled.");
        }
    }
    // Return obtained snmp data
    return $data;
}
$search[] = array('type' => 'multiselect', 'name' => '设备', 'id' => 'device_id', 'width' => '125px', 'value' => $vars['device_id'], 'values' => $devices_array);
// Add device_id limit for other fields
if (isset($vars['device_id'])) {
    $where .= generate_query_values($vars['device_id'], 'device_id');
}
//Message field
$search[] = array('type' => 'text', 'name' => '信息', 'id' => 'message', 'width' => '150px', 'placeholder' => 'Message', 'value' => $vars['message']);
//Severity field
foreach (dbFetchColumn('SELECT DISTINCT `severity` FROM `eventlog`' . $where) as $severity) {
    $severities[$severity] = ucfirst($config['syslog']['priorities'][$severity]['name']);
}
krsort($severities);
$search[] = array('type' => 'multiselect', 'name' => '严重程度', 'id' => 'severity', 'width' => '110px', 'subtext' => TRUE, 'value' => $vars['severity'], 'values' => $severities);
//Types field
$types['device'] = '设备';
foreach (dbFetchColumn('SELECT DISTINCT `entity_type` FROM `eventlog` IGNORE INDEX (`type`)' . $where) as $type) {
    //$type = $data['type'];
    $types[$type] = ucfirst($type);
}
$search[] = array('type' => 'multiselect', 'name' => '类型', 'id' => 'type', 'width' => '100px', 'value' => $vars['type'], 'values' => $types);
// Newline
//$search[] = array('type'    => 'newline',
//                  'hr'      => TRUE);
// Datetime field
$search[] = array('type' => 'datetime', 'id' => 'timestamp', 'presets' => TRUE, 'min' => dbFetchCell('SELECT `timestamp` FROM `eventlog`' . $where . ' ORDER BY `timestamp` LIMIT 0,1;'), 'max' => dbFetchCell('SELECT `timestamp` FROM `eventlog`' . $where . ' ORDER BY `timestamp` DESC LIMIT 0,1;'), 'from' => $vars['timestamp_from'], 'to' => $vars['timestamp_to']);
print_search($search, '事件日志', 'search', 'eventlog/');
// Pagination
$vars['pagination'] = TRUE;
// Print events
print_events($vars);
$page_title[] = '事件日志';
Exemplo n.º 8
0
 * @subpackage webui
 * @author     Adam Armstrong <*****@*****.**>
 * @copyright  (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited
 *
 */
$where = ' WHERE 1 ' . generate_query_values($device['device_id'], 'device_id');
$timestamp_min = dbFetchCell('SELECT `timestamp` FROM `eventlog` ' . $where . ' ORDER BY `timestamp` LIMIT 0,1;');
$timestamp_max = dbFetchCell('SELECT `timestamp` FROM `eventlog` ' . $where . ' ORDER BY `timestamp` DESC LIMIT 0,1;');
// Note, this form have more complex grid and class elements for responsive datetime field
$form = array('type' => 'rows', 'space' => '5px', 'submit_by_key' => TRUE, 'url' => generate_url($vars));
// Message field
$form['row'][0]['message'] = array('type' => 'text', 'name' => 'Message', 'placeholder' => 'Message', 'width' => '100%', 'div_class' => 'col-lg-4 col-md-6 col-sm-6', 'value' => $vars['message']);
// Severities field
$form_filter = dbFetchColumn('SELECT DISTINCT `severity` FROM `eventlog`' . $where);
$form_items['severities'] = generate_form_values('eventlog', $form_filter, 'severity');
$form['row'][0]['severity'] = array('type' => 'multiselect', 'name' => 'Severities', 'width' => '100%', 'div_class' => 'col-lg-1 col-md-2 col-sm-2', 'subtext' => TRUE, 'value' => $vars['severity'], 'values' => $form_items['severities']);
// Types field
$form_filter = dbFetchColumn('SELECT DISTINCT `entity_type` FROM `eventlog` IGNORE INDEX (`type`)' . $where);
$form_items['types'] = generate_form_values('eventlog', $form_filter, 'type');
$form['row'][0]['type'] = array('type' => 'multiselect', 'name' => 'Types', 'width' => '100%', 'div_class' => 'col-lg-1 col-md-2 col-sm-2', 'size' => '15', 'value' => $vars['type'], 'values' => $form_items['types']);
// Datetime field
$form['row'][0]['timestamp'] = array('type' => 'datetime', 'div_class' => 'col-lg-5 col-md-7 col-sm-10', 'presets' => TRUE, 'min' => $timestamp_min, 'max' => $timestamp_max, 'from' => $vars['timestamp_from'], 'to' => $vars['timestamp_to']);
// search button
$form['row'][0]['search'] = array('type' => 'submit', 'div_class' => 'col-lg-1 col-md-5 col-sm-2', 'right' => TRUE);
print_form($form);
unset($form, $form_items, $form_devices);
/// Pagination
$vars['pagination'] = TRUE;
print_events($vars);
register_html_title("Events");
// EOF
Exemplo n.º 9
0
 }
 // Collect port IDs and ifIndexes who has adsl/cbqos/pagp/ip and other.
 $cache['ports_option'] = array();
 $ext_tables = array('ports_adsl', 'ports_cbqos', 'mac_accounting', 'neighbours');
 if ($port_details) {
     $ext_tables = array_merge($ext_tables, array('ipv4_addresses', 'ipv6_addresses', 'pseudowires'));
     // Here stored ifIndex!
     $cache['ports_option']['ports_pagp'] = dbFetchColumn("SELECT `pagpGroupIfIndex` FROM `ports`   WHERE `device_id` = ? GROUP BY `pagpGroupIfIndex`", array($device['device_id']));
     $cache['ports_option']['ports_stack_low'] = dbFetchColumn("SELECT `port_id_low`  FROM `ports_stack` WHERE `device_id` = ? AND `port_id_high` != 0 GROUP BY `port_id_low`", array($device['device_id']));
     $cache['ports_option']['ports_stack_high'] = dbFetchColumn("SELECT `port_id_high` FROM `ports_stack` WHERE `device_id` = ? AND `port_id_low`  != 0 GROUP BY `port_id_high`", array($device['device_id']));
 }
 //$where = ' IN ('.implode(',', array_keys($port_cache)).')';
 $where = generate_query_values(array_keys($port_cache), 'port_id');
 foreach ($ext_tables as $table) {
     // Here stored port_id!
     $cache['ports_option'][$table] = dbFetchColumn("SELECT DISTINCT `port_id` FROM `{$table}` WHERE 1 " . $where);
 }
 $cache['ports_vlan'] = array();
 // Cache port vlans
 foreach (dbFetchRows('SELECT * FROM `ports_vlans` AS PV LEFT JOIN vlans AS V ON PV.`vlan` = V.`vlan_vlan` AND PV.`device_id` = V.`device_id`
                WHERE PV.`device_id` = ? ORDER BY PV.`vlan`', array($device['device_id'])) as $entry) {
     $cache['ports_vlan'][$entry['port_id']][$entry['vlan']] = $entry;
 }
 echo generate_box_open();
 echo '<table class="' . $table_class . ' table-hover">' . PHP_EOL;
 $cols = array(array(NULL, 'class="state-marker"'), array(NULL), 'port' => array('Port'), array(NULL), 'traffic' => array('Traffic'), 'speed' => array('Speed'), 'mac' => array('MAC Address'), array(NULL));
 echo get_table_header($cols, $vars);
 echo '<tbody>' . PHP_EOL;
 foreach ($ports as $port) {
     if (is_filtered()) {
         continue;
Exemplo n.º 10
0
<?php

$dsktable_array = snmpwalk_cache_oid($device, 'dskTable', null, 'UCD-SNMP-MIB');
$sql = "SELECT `storage_descr` FROM `storage` WHERE `device_id`  = '" . $device['device_id'] . "' AND `storage_type` != 'dsk'";
$tmp_storage = dbFetchColumn($sql);
if (is_array($dsktable_array)) {
    foreach ($dsktable_array as $dsk) {
        if (isset($dsk['dskPath'])) {
            if (!in_array($dsk['dskPath'], $tmp_storage)) {
                $dsk['dskTotal'] = $dsk['dskTotal'] * 1024;
                $dsk['dskAvail'] = $entry['dskAvail'] * 1024;
                $dsk['dskUsed'] = $dsk['dskTotal'] - $dsk['dskAvail'];
                $deny = ignore_storage($dsk['dskPath']);
                if ($deny != 1) {
                    discover_storage($valid_storage, $device, $dsk['dskIndex'], 'dsk', 'ucd-dsktable', $dsk['dskPath'], $dsk['dskTotal'], 1024, $dsk['dskUsed']);
                }
            }
        }
    }
}
Exemplo n.º 11
0
    $where .= generate_query_values($vars['device_id'], 'device_id');
}
//Message field
$search[] = array('type' => 'text', 'name' => '信息', 'id' => 'message', 'placeholder' => 'Message', 'width' => '130px', 'value' => $vars['message']);
//Priority field
//$priorities[''] = '所有优先级';
foreach ($config['syslog']['priorities'] as $p => $priority) {
    if ($p > 7) {
        continue;
    }
    $priorities[$p] = ucfirst($priority['name']);
}
$search[] = array('type' => 'multiselect', 'name' => '优先级', 'id' => 'priority', 'width' => '125px', 'subtext' => TRUE, 'value' => $vars['priority'], 'values' => $priorities);
//Program field
//$programs[''] = '所有程序';
foreach (dbFetchColumn('SELECT `program` FROM `syslog` IGNORE INDEX (`program`)' . $where . 'GROUP BY `program`;') as $program) {
    $program = $program != '' ? $program : OBS_VAR_UNSET;
    $programs[$program] = $program;
}
$search[] = array('type' => 'multiselect', 'name' => '程序', 'id' => 'program', 'width' => '125px', 'size' => '15', 'value' => $vars['program'], 'values' => $programs);
//$search[] = array('type'    => 'newline',
//                  'hr'      => TRUE);
$search[] = array('type' => 'datetime', 'id' => 'timestamp', 'presets' => TRUE, 'min' => dbFetchCell('SELECT `timestamp` FROM `syslog`' . $where . ' ORDER BY `timestamp` LIMIT 0,1;'), 'max' => dbFetchCell('SELECT `timestamp` FROM `syslog`' . $where . ' ORDER BY `timestamp` DESC LIMIT 0,1;'), 'from' => $vars['timestamp_from'], 'to' => $vars['timestamp_to']);
print_search($search, '系统日志', 'search', 'syslog/');
// Pagination
$vars['pagination'] = TRUE;
// Print syslog
print_syslogs($vars);
$page_title[] = '系统日志';
?>
  </div> <!-- col-md-12 -->
Exemplo n.º 12
0
/**
 * Observium
 *
 *   This file is part of Observium.
 *
 * @package    observium
 * @subpackage update
 * @copyright  (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited
 *
 */
echo 'Clean incorrect syslog entries: ';
$entries_deteted = dbDelete('syslog', "`msg` = ''");
if ($entries_deteted) {
    echo "{$entries_deteted} deleted, ";
}
$devices_iosxr = dbFetchColumn('SELECT `device_id` FROM `devices` WHERE `os` = ?;', array('iosxr'));
if (count($devices_iosxr)) {
    // Fix old syslog entries for IOS-XR devices
    foreach (dbFetchRows("SELECT * FROM `syslog` WHERE `device_id` IN (" . implode(',', $devices_iosxr) . ");") as $entry) {
        if (is_numeric($entry['program'])) {
            $update_array = array('timestamp' => $entry['timestamp']);
            list(, $entry['program'], $update_array['msg']) = explode(' : ', $entry['msg'], 3);
            list(, $update_array['program']) = explode(' %', $entry['program'], 2);
            dbUpdate($update_array, 'syslog', '`seq` = ?', array($entry['seq']));
            $entries_fixed++;
        }
    }
    if ($entries_fixed) {
        echo "{$entries_fixed} fixed";
    }
}
Exemplo n.º 13
0
/**
 * Params:
 *
 * pagination, pageno, pagesize
 * device, type, adminstatus, state
 */
function get_bgp_array($vars)
{
    $array = array();
    // With pagination? (display page numbers in header)
    $array['pagination'] = isset($vars['pagination']) && $vars['pagination'];
    pagination($vars, 0, TRUE);
    // Get default pagesize/pageno
    $array['pageno'] = $vars['pageno'];
    $array['pagesize'] = $vars['pagesize'];
    $start = $array['pagesize'] * $array['pageno'] - $array['pagesize'];
    $pagesize = $array['pagesize'];
    // Require cached IDs from html/includes/cache-data.inc.php
    $cache_bgp =& $GLOBALS['cache']['bgp'];
    // Begin query generate
    $param = array();
    $where = ' WHERE 1 ';
    foreach ($vars as $var => $value) {
        if ($value != '') {
            switch ($var) {
                case 'device':
                case 'device_id':
                    $where .= generate_query_values($value, 'B.device_id');
                    break;
                case 'type':
                    if ($value == 'external' || $value == 'ebgp') {
                        $where .= generate_query_values($cache_bgp['external'], 'B.bgpPeer_id');
                    } else {
                        if ($value == 'internal' || $value == 'ibgp') {
                            $where .= generate_query_values($cache_bgp['internal'], 'B.bgpPeer_id');
                        }
                    }
                    break;
                case 'adminstatus':
                    if ($value == 'stop') {
                        $where .= generate_query_values($cache_bgp['start'], 'B.bgpPeer_id', '!=');
                        // NOT IN
                    } else {
                        if ($value == 'start') {
                            $where .= generate_query_values($cache_bgp['start'], 'B.bgpPeer_id');
                        }
                    }
                    break;
                case 'state':
                    if ($value == 'down') {
                        $where .= generate_query_values($cache_bgp['up'], 'B.bgpPeer_id', '!=');
                        // NOT IN
                    } else {
                        if ($value == 'up') {
                            $where .= generate_query_values($cache_bgp['up'], 'B.bgpPeer_id');
                        }
                    }
                    break;
            }
        }
    }
    // Cache IP array
    $cache_ip = dbFetchColumn("SELECT `ipv4_address` FROM `ipv4_addresses` WHERE `ipv4_address` NOT IN (?, ?)" . $GLOBALS['cache']['where']['ports_permitted'], array('127.0.0.1', '0.0.0.0'));
    $cache_ip = array_merge($cache_ip, dbFetchColumn("SELECT `ipv6_address` FROM `ipv6_addresses` WHERE `ipv6_compressed` NOT IN (?)" . $GLOBALS['cache']['where']['ports_permitted'], array('::1')));
    //r($cache_ip);
    // Show peers only for permitted devices
    $query_permitted = generate_query_values($cache_bgp['permitted'], 'B.bgpPeer_id');
    $query = 'FROM `bgpPeers` AS B';
    $query_count = 'SELECT COUNT(*) ' . $query . $where . $query_permitted;
    // Use only bgpPeer_id and device_id in query!
    $query .= ' LEFT JOIN `bgpPeers-state` AS S ON B.`bgpPeer_id` = S.`bgpPeer_id`';
    $query .= ' LEFT JOIN `devices` AS D ON B.`device_id` = D.`device_id`';
    $query .= $where . $query_permitted;
    $query = 'SELECT D.`hostname`, D.`bgpLocalAs`, B.*, S.* ' . $query;
    $query .= ' ORDER BY D.`hostname`, B.`bgpPeerRemoteAs`, B.`bgpPeerRemoteAddr`';
    $query .= " LIMIT {$start},{$pagesize}";
    // Query BGP
    foreach (dbFetchRows($query, $param) as $entry) {
        humanize_bgp($entry);
        $peer_addr = $entry['bgpPeerRemoteAddr'];
        $peer_devices[$entry['device_id']] = 1;
        // Collect devices for AFIs query
        if (!isset($cache_bgp['ips'][$peer_addr])) {
            $cache_bgp['ips'][$peer_addr] = array();
            if (in_array($peer_addr, $cache_ip)) {
                $peer_addr_type = get_ip_version($peer_addr);
                if ($peer_addr_type) {
                    $peer_addr_type = 'ipv' . $peer_addr_type;
                    $query_ip = 'SELECT `device_id`, `port_id`, `ifOperStatus`, `ifAdminStatus` FROM `' . $peer_addr_type . '_addresses`
                       JOIN `ports` USING (`port_id`) WHERE `' . $peer_addr_type . '_address` = ?;';
                    $ip_array = dbFetchRows($query_ip, array($peer_addr));
                    if (count($ip_array) > 1) {
                        // We have multiple ports for same IPs, complicated logic
                        foreach ($ip_array as $ip) {
                            $device_tmp = device_by_id_cache($ip['device_id']);
                            // Crazy logic, exclude down/disabled ports/devices
                            if (!$device_tmp['bgpLocalAs'] || $device_tmp['status'] == 0 || $ip['ifAdminStatus'] != 'up') {
                                continue;
                            }
                            $cache_bgp['ips'][$peer_addr]['device_id'] = $ip['device_id'];
                            $cache_bgp['ips'][$peer_addr]['port_id'] = $ip['port_id'];
                        }
                    } else {
                        $device_tmp = device_by_id_cache($ip_array[0]['device_id']);
                        if ($device_tmp['bgpLocalAs']) {
                            // We found device in DB by IP, but this device really have BGP?
                            $cache_bgp['ips'][$peer_addr]['device_id'] = $ip_array[0]['device_id'];
                            $cache_bgp['ips'][$peer_addr]['port_id'] = $ip_array[0]['port_id'];
                        }
                    }
                }
                //r($cache_bgp['ips'][$peer_addr]);
            }
        }
        $entry['peer_port_id'] = $cache_bgp['ips'][$peer_addr]['port_id'];
        //$entry['peer_port']      = get_port_by_id_cache($entry['peer_port_id']);
        $entry['peer_device_id'] = $cache_bgp['ips'][$peer_addr]['device_id'];
        //$entry['peer_device']    = device_by_id_cache($entry['peer_device_id']);
        $array['entries'][] = $entry;
    }
    // Query AFI/SAFI
    $query_afi = 'SELECT * FROM `bgpPeers_cbgp` WHERE 1' . generate_query_values(array_keys($peer_devices), 'device_id');
    //.generate_query_values(array_keys($cache_bgp['ips']), 'bgpPeerRemoteAddr');
    foreach (dbFetchRows($query_afi) as $entry) {
        $array['afisafi'][$entry['device_id']][$entry['bgpPeerRemoteAddr']][] = $entry['afi'] . '.' . $entry['safi'];
    }
    // Query BGP peers count
    if ($array['pagination']) {
        $array['count'] = dbFetchCell($query_count, $param);
        $array['pagination_html'] = pagination($vars, $array['count']);
    } else {
        $array['count'] = count($array['entries']);
    }
    return $array;
}
 *
 * @package    observium
 * @subpackage webui
 * @author     Adam Armstrong <*****@*****.**>
 * @copyright  (C) 2006-2014 Adam Armstrong
 *
 */
unset($search, $types);
//Message field
$search[] = array('type' => 'text', 'id' => 'message', 'placeholder' => '信息', 'name' => '信息', 'value' => $vars['message']);
//Severity field
foreach (dbFetchColumn('SELECT DISTINCT `severity` FROM `eventlog` WHERE `device_id` = ?;', array($vars['device'])) as $severity) {
    $severities[$severity] = ucfirst($config['syslog']['priorities'][$severity]['name']);
}
krsort($severities);
$search[] = array('type' => 'multiselect', 'name' => '严重程度', 'id' => 'severity', 'width' => '125px', 'subtext' => TRUE, 'value' => $vars['severity'], 'values' => $severities);
//Type field
$types['device'] = '设备';
foreach (dbFetchColumn('SELECT DISTINCT `entity_type` FROM `eventlog` IGNORE INDEX (`type`) WHERE `device_id` = ?;', array($vars['device'])) as $type) {
    $types[$type] = ucfirst($type);
}
$search[] = array('type' => 'multiselect', 'name' => '类型', 'id' => 'type', 'width' => '125px', 'value' => $vars['type'], 'values' => $types);
//$search[] = array('type'    => 'newline',
//                  'hr'      => TRUE);
$search[] = array('type' => 'datetime', 'id' => 'timestamp', 'presets' => TRUE, 'min' => dbFetchCell('SELECT `timestamp` FROM `eventlog` WHERE `device_id` = ? ORDER BY `timestamp` LIMIT 0,1;', array($vars['device'])), 'max' => dbFetchCell('SELECT `timestamp` FROM `eventlog` WHERE `device_id` = ? ORDER BY `timestamp` DESC LIMIT 0,1;', array($vars['device'])), 'from' => $vars['timestamp_from'], 'to' => $vars['timestamp_to']);
print_search($search, '事件日志');
/// Pagination
$vars['pagination'] = TRUE;
print_events($vars);
$page_title[] = "事件";
// EOF
Exemplo n.º 15
0
<div class="row">
<div class="col-md-12">

<?php 
if (!is_array($alert_rules)) {
    $alert_rules = cache_alert_rules();
}
// Note, this form have more complex grid and class elements for responsive datetime field
$form = array('type' => 'rows', 'space' => '5px', 'submit_by_key' => TRUE, 'url' => generate_url($vars));
$where = ' WHERE 1 ' . generate_query_values($device['device_id'], 'device_id');
// Checkers Field
$form_filter = dbFetchColumn('SELECT DISTINCT `alert_test_id` FROM `alert_log`' . $where);
$form_items['checkers'] = generate_form_values('alert_log', $form_filter, 'alert_test_id');
$form['row'][0]['alert_test_id'] = array('type' => 'multiselect', 'name' => 'Checkers', 'width' => '100%', 'div_class' => 'col-lg-2 col-md-2 col-sm-4', 'subtext' => TRUE, 'value' => $vars['alert_test_id'], 'values' => $form_items['checkers']);
// Status Type Field
$form_filter = dbFetchColumn('SELECT DISTINCT `log_type` FROM `alert_log`' . $where);
$form_items['statuses'] = generate_form_values('alert_log', $form_filter, 'log_type');
$form['row'][0]['log_type'] = array('type' => 'multiselect', 'name' => 'Status Type', 'width' => '100%', 'div_class' => 'col-lg-2 col-md-2 col-sm-4', 'size' => '15', 'value' => $vars['log_type'], 'values' => $form_items['statuses']);
// Datetime Field
$form['row'][0]['timestamp'] = array('type' => 'datetime', 'div_class' => 'col-lg-5 col-md-7 col-sm-9', 'presets' => TRUE, 'min' => dbFetchCell('SELECT `timestamp` FROM `alert_log`' . $where . ' ORDER BY `timestamp` LIMIT 0,1;'), 'max' => dbFetchCell('SELECT `timestamp` FROM `alert_log`' . $where . ' ORDER BY `timestamp` DESC LIMIT 0,1;'), 'from' => $vars['timestamp_from'], 'to' => $vars['timestamp_to']);
// Second row with timestamp for sm
//$form['row_options'][1]  = array('class' => 'hidden-lg hidden-md hidden-xs');
//$form['row'][1]['timestamp'] = $form['row'][0]['timestamp'];
//$form['row'][1]['timestamp']['div_class'] = 'text-nowrap col-sm-9';
// search button
$form['row'][0]['search'] = array('type' => 'submit', 'div_class' => 'col-lg-3 col-md-1 col-sm-3', 'right' => TRUE);
print_form($form);
unset($form, $form_items, $form_filter);
// Pagination
$vars['pagination'] = TRUE;
// Print Alert Log
Exemplo n.º 16
0
    $port['out_rate'] = $port['ifOutOctets_rate'] * 8;
    $in_perc = @round($port['in_rate'] / $port['ifSpeed'] * 100);
    $out_perc = @round($port['in_rate'] / $port['ifSpeed'] * 100);
    echo "<img src='images/16/arrow_left.png' align=absmiddle> <span style='color: " . percent_colour($in_perc) . "'>" . formatRates($port['in_rate']) . "<br />\n        <img align=absmiddle src='images/16/arrow_out.png'> <span style='color: " . percent_colour($out_perc) . "'>" . formatRates($port['out_rate']) . "<br />\n        <img src='images/icons/arrow_pps_in.png' align=absmiddle> " . format_bi($port['ifInUcastPkts_rate']) . "pps</span><br />\n        <img src='images/icons/arrow_pps_out.png' align=absmiddle> " . format_bi($port['ifOutUcastPkts_rate']) . 'pps</span>';
}
echo "</td><td width=75 onclick=\"location.href='" . generate_port_url($port) . "'\" >";
if ($port['ifSpeed']) {
    echo '<span class=box-desc>' . humanspeed($port['ifSpeed']) . '</span>';
}
echo '<br />';
if ($port[ifDuplex] != 'unknown') {
    echo '<span class=box-desc>' . $port['ifDuplex'] . '</span>';
} else {
    echo '-';
}
$vlans = dbFetchColumn('SELECT vlan FROM `ports_vlans` AS PV, vlans AS V ' . 'WHERE PV.`port_id`=? AND PV.`device_id`=? AND V.`vlan_vlan`=PV.vlan AND V.device_id = PV.device_id', array($port['port_id'], $device['device_id']));
$vlan_count = count($vlans);
if ($vlan_count > 1) {
    echo '<p class=box-desc><span class=purple><a href="';
    echo generate_device_url($device, array('tab' => 'vlans'));
    echo '" title="';
    echo implode(', ', $vlans);
    echo '">VLANs: ';
    echo $vlan_count;
    echo '</a></span></p>';
} elseif ($vlan_count == 1 || $port['ifVlan']) {
    echo '<p class=box-desc><span class=blue>VLAN: ';
    echo $vlans[0] ?: $port['ifVlan'];
    echo '</span></p>';
} elseif ($port['ifVrf']) {
    $vrf = dbFetchRow('SELECT * FROM vrfs WHERE vrf_id = ?', array($port['ifVrf']));
Exemplo n.º 17
0
/**
 * Observium
 *
 *   This file is part of Observium.
 *
 * @package    observium
 * @subpackage webui
 * @copyright  (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited
 *
 */
?>
<div class="row">
<div class="col-md-12">

<?php 
$form_devices = dbFetchColumn('SELECT DISTINCT `device_id` FROM `wifi_sessions`;');
$form_items['devices'] = generate_form_values('device', $form_devices);
$form = array('type' => 'rows', 'submit_by_key' => TRUE, 'url' => 'search/search=dot1x/');
//Device field
$form['row'][0]['device_id'] = array('type' => 'multiselect', 'name' => 'Device', 'width' => '100%', 'grid' => 3, 'value' => $vars['device_id'], 'groups' => array('', 'UP', 'DOWN', 'DISABLED'), 'values' => $form_items['devices']);
//Search by field
$form['row'][0]['searchby'] = array('type' => 'select', 'name' => 'Search By', 'width' => '100%', 'grid' => 2, 'onchange' => "\$('#address').prop('placeholder', \$('#searchby option:selected').text())", 'value' => $vars['searchby'], 'values' => array('mac' => 'MAC Address', 'ip' => 'IP Address', 'username' => 'Username'));
if ($vars['searchby'] == 'mac') {
    $name = 'MAC Address';
} else {
    if ($vars['searchby'] == 'ip') {
        $name = 'IP Address';
    } else {
        $name = 'Username';
    }
}
Exemplo n.º 18
0
 * Observium
 *
 *   This file is part of Observium.
 *
 * @package    observium
 * @subpackage webui
 * @copyright  (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited
 *
 */
?>
<div class="row">
<div class="col-md-12">

<?php 
// Select the devices only with ARP/NDP tables
$form_devices = dbFetchColumn('SELECT DISTINCT `device_id` FROM `ip_mac` LEFT JOIN `ports` USING(`port_id`)');
$form_items['devices'] = generate_form_values('device', $form_devices);
$form = array('type' => 'rows', 'space' => '5px', 'submit_by_key' => TRUE, 'url' => 'search/search=arp/');
$form['row'][0]['device_id'] = array('type' => 'multiselect', 'name' => 'Device', 'width' => '100%', 'value' => $vars['device_id'], 'groups' => array('', 'UP', 'DOWN', 'DISABLED'), 'values' => $form_items['devices']);
$form['row'][0]['ip_version'] = array('type' => 'select', 'name' => 'IP', 'width' => '100%', 'value' => $vars['ip_version'], 'values' => array('' => 'IPv4 & IPv6', '4' => 'IPv4 only', '6' => 'IPv6 only'));
$form['row'][0]['searchby'] = array('type' => 'select', 'name' => 'Search By', 'width' => '100%', 'onchange' => "\$('#address').prop('placeholder', \$('#searchby option:selected').text())", 'value' => $vars['searchby'], 'values' => array('mac' => 'MAC Address', 'ip' => 'IP Address'));
$form['row'][0]['address'] = array('type' => 'text', 'name' => $vars['searchby'] == 'ip' ? 'IP Address' : 'MAC Address', 'width' => '100%', 'grid' => 3, 'placeholder' => TRUE, 'submit_by_key' => TRUE, 'value' => escape_html($vars['address']));
// search button
$form['row'][0]['search'] = array('type' => 'submit', 'grid' => 3, 'value' => 'arp', 'right' => TRUE);
print_form($form);
unset($form, $form_items, $form_devices);
// Pagination
$vars['pagination'] = TRUE;
print_arptable($vars);
register_html_title('ARP/NDP Search');
?>
Exemplo n.º 19
0
function getRates($bill_id, $datefrom, $dateto)
{
    $data = array();
    $mq_text = 'SELECT count(delta) FROM bill_data ';
    $mq_text .= " WHERE bill_id = '" . mres($bill_id) . "'";
    $mq_text .= " AND timestamp > '" . mres($datefrom) . "' AND timestamp <= '" . mres($dateto) . "'";
    $measurements = dbFetchCell($mq_sql);
    $measurement_95th = round($measurements / 100 * 95) - 1;
    $q_95_sql = "SELECT delta FROM bill_data  WHERE bill_id = '" . mres($bill_id) . "'";
    $q_95_sql .= " AND timestamp > '" . mres($datefrom) . "' AND timestamp <= '" . mres($dateto) . "' ORDER BY delta ASC";
    $a_95th = dbFetchColumn($q_95_sql);
    $m_95th = $a_95th[$measurement_95th];
    $sum_data = getSum($bill_id, $datefrom, $dateto);
    $mtot = $sum_data['total'];
    $mtot_in = $sum_data['inbound'];
    $mtot_out = $sum_data['outbound'];
    $ptot = $sum_data['period'];
    $data['rate_95th_in'] = get95thIn($bill_id, $datefrom, $dateto);
    $data['rate_95th_out'] = get95thOut($bill_id, $datefrom, $dateto);
    if ($data['rate_95th_out'] > $data['rate_95th_in']) {
        $data['rate_95th'] = $data['rate_95th_out'];
        $data['dir_95th'] = 'out';
    } else {
        $data['rate_95th'] = $data['rate_95th_in'];
        $data['dir_95th'] = 'in';
    }
    $data['total_data'] = $mtot;
    $data['total_data_in'] = $mtot_in;
    $data['total_data_out'] = $mtot_out;
    $data['rate_average'] = $mtot / $ptot * 8;
    $data['rate_average_in'] = $mtot_in / $ptot * 8;
    $data['rate_average_out'] = $mtot_out / $ptot * 8;
    // print_r($data);
    return $data;
}
Exemplo n.º 20
0
// Show devices only with syslog messages
$form_devices = dbFetchColumn('SELECT DISTINCT `device_id` FROM `syslog`' . $where);
$form_items['devices'] = generate_form_values('device', $form_devices);
// Device field
$form['row'][0]['device_id'] = array('type' => 'multiselect', 'name' => 'Devices', 'width' => '100%', 'div_class' => 'col-lg-1 col-md-2 col-sm-2', 'value' => $vars['device_id'], 'groups' => array('', 'UP', 'DOWN', 'DISABLED'), 'values' => $form_items['devices']);
// Add device_id limit for other fields
if (isset($vars['device_id'])) {
    $where .= generate_query_values($vars['device_id'], 'device_id');
}
// Message field
$form['row'][0]['message'] = array('type' => 'text', 'name' => 'Message', 'placeholder' => 'Message', 'width' => '100%', 'div_class' => 'col-lg-3 col-md-4 col-sm-4', 'value' => $vars['message']);
// Priority field
$form_items['priorities'] = generate_form_values('syslog', NULL, 'priorities');
$form['row'][0]['priority'] = array('type' => 'multiselect', 'name' => 'Priorities', 'width' => '100%', 'div_class' => 'col-lg-1 col-md-2 col-sm-2', 'subtext' => TRUE, 'value' => $vars['priority'], 'values' => $form_items['priorities']);
// Program field
$form_filter = dbFetchColumn('SELECT DISTINCT `program` FROM `syslog` IGNORE INDEX (`program`)' . $where);
$form_items['programs'] = generate_form_values('syslog', $form_filter, 'programs');
$form['row'][0]['program'] = array('type' => 'multiselect', 'name' => 'Programs', 'width' => '100%', 'div_class' => 'col-lg-1 col-md-2 col-sm-2', 'size' => '15', 'value' => $vars['program'], 'values' => $form_items['programs']);
// Datetime Field
$form['row'][0]['timestamp'] = array('type' => 'datetime', 'div_class' => 'col-lg-5 col-md-7 col-sm-10 col-lg-push-0 col-md-push-2 col-sm-push-2', 'presets' => TRUE, 'min' => dbFetchCell('SELECT `timestamp` FROM `syslog`' . $where . ' ORDER BY `timestamp` LIMIT 0,1;'), 'max' => dbFetchCell('SELECT `timestamp` FROM `syslog`' . $where . ' ORDER BY `timestamp` DESC LIMIT 0,1;'), 'from' => $vars['timestamp_from'], 'to' => $vars['timestamp_to']);
// Second row with timestamp for md and sm
//$form['row_options'][1]  = array('class' => 'hidden-lg hidden-xs');
//$form['row'][1]['timestamp'] = $form['row'][0]['timestamp'];
//$form['row'][1]['timestamp']['div_class'] = 'text-nowrap col-md-7 col-sm-8 col-md-offset-2 col-sm-offset-2';
// search button
$form['row'][0]['search'] = array('type' => 'submit', 'div_class' => 'col-lg-1 col-md-5 col-sm-2', 'right' => TRUE);
print_form($form);
unset($form, $form_items, $form_devices);
// Pagination
$vars['pagination'] = TRUE;
// Print syslog
Exemplo n.º 21
0
function get_device_graphs($device)
{
    $query = 'SELECT `graph` FROM `device_graphs` WHERE `device_id` = ?';
    return dbFetchColumn($query, array($device['device_id']));
}
Exemplo n.º 22
0
/**
 * Observium
 *
 *   This file is part of Observium.
 *
 * @package    observium
 * @subpackage webui
 * @copyright  (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited
 *
 */
?>
<div class="row">
<div class="col-md-12">

<?php 
$form_devices = dbFetchColumn('SELECT DISTINCT `device_id` FROM `ipv4_addresses` LEFT JOIN `ports` USING(`port_id`);');
$form_items['devices'] = generate_form_values('device', $form_devices);
$form = array('type' => 'rows', 'space' => '5px', 'submit_by_key' => TRUE, 'url' => 'search/search=ipv4/');
$form['row'][0]['device'] = array('type' => 'multiselect', 'name' => 'Device', 'width' => '100%', 'value' => $vars['device'], 'groups' => array('', 'UP', 'DOWN', 'DISABLED'), 'values' => $form_items['devices']);
$form['row'][0]['interface'] = array('type' => 'select', 'name' => 'Interface', 'width' => '100%', 'value' => $vars['interface'], 'values' => array('' => 'All Interfaces', 'Lo' => 'Loopbacks', 'Vlan' => 'Vlans'));
$form['row'][0]['network'] = array('type' => 'text', 'name' => 'IP Network', 'width' => '100%', 'placeholder' => TRUE, 'ajax' => TRUE, 'ajax_vars' => array('field' => 'ipv4_network'), 'value' => escape_html($vars['network']));
$form['row'][0]['address'] = array('type' => 'text', 'name' => 'IP Address', 'width' => '100%', 'grid' => 3, 'placeholder' => TRUE, 'value' => escape_html($vars['address']));
// search button
$form['row'][0]['search'] = array('type' => 'submit', 'grid' => 3, 'value' => 'ipv4', 'right' => TRUE);
print_form($form);
unset($form, $form_items, $form_devices);
// Pagination
$vars['pagination'] = TRUE;
// Print addresses
print_addresses($vars);
register_html_title("IPv4 Addresses");
Exemplo n.º 23
0
/**
 * Get the Device Group IDs of a Device from the database
 * @param $device_id
 * @param int $extra Return extra info about the groups (name, desc, pattern)
 * @return array
 */
function GetGroupsFromDevice($device_id, $extra = 0)
{
    $ret = array();
    if ($extra === 0) {
        $ret = dbFetchColumn('SELECT `device_group_id` FROM `device_group_device` WHERE `device_id`=?', array($device_id));
    } else {
        $ret = dbFetchRows('SELECT `device_groups`.* FROM `device_group_device` LEFT JOIN `device_groups` ON `device_group_device`.`device_group_id`=`device_groups`.`id` WHERE `device_group_device`.`device_id`=?', array($device_id));
    }
    return $ret;
}
Exemplo n.º 24
0
    // Collect port IDs and ifIndexes who has adsl/cbqos/pagp/ip and other.
    $ports_has_ext = array();
    $ext_tables = array('ports_adsl', 'ports_cbqos', 'mac_accounting');
    if ($port_details) {
        $ext_tables = array_merge($ext_tables, array('ipv4_addresses', 'ipv6_addresses', 'pseudowires'));
        // Here stored ifIndex!
        $ports_has_ext['ports_pagp'] = dbFetchColumn("SELECT `pagpGroupIfIndex` FROM `ports`   WHERE `device_id` = ? GROUP BY `pagpGroupIfIndex`", array($device['device_id']));
        $ports_has_ext['ports_stack_low'] = dbFetchColumn("SELECT `port_id_low`  FROM `ports_stack` WHERE `device_id` = ? AND `port_id_high` != 0 GROUP BY `port_id_low`", array($device['device_id']));
        $ports_has_ext['ports_stack_high'] = dbFetchColumn("SELECT `port_id_high` FROM `ports_stack` WHERE `device_id` = ? AND `port_id_low`  != 0 GROUP BY `port_id_high`", array($device['device_id']));
    }
    $where = ' IN (' . implode(',', array_keys($port_cache)) . ')';
    foreach ($ext_tables as $table) {
        // Here stored port_id!
        $ports_has_ext[$table] = dbFetchColumn("SELECT `port_id` FROM `{$table}` WHERE `port_id` {$where} GROUP BY `port_id`");
    }
    $ports_has_ext['links'] = dbFetchColumn("SELECT `local_port_id` FROM `links` WHERE `local_port_id` {$where} AND `remote_port_id` != 0 GROUP BY `local_port_id`");
    $ports_vlan_cache = array();
    // Cache port vlans
    foreach (dbFetchRows('SELECT * FROM `ports_vlans` AS PV LEFT JOIN vlans AS V ON PV.`vlan` = V.`vlan_vlan` AND PV.`device_id` = V.`device_id`
                       WHERE PV.`device_id` = ? ORDER BY PV.`vlan`', array($device['device_id'])) as $entry) {
        $ports_vlan_cache[$entry['port_id']][$entry['vlan']] = $entry;
    }
    foreach ($ports as $port) {
        if (is_filtered()) {
            continue;
        }
        include "includes/print-interface.inc.php";
        $i++;
    }
    echo "</table>";
}
Exemplo n.º 25
0
/**
 * Observium
 *
 *   This file is part of Observium.
 *
 * @package    observium
 * @subpackage poller
 * @copyright  (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited
 *
 */
echo ' CISCO-RTTMON-MIB ';
$sla_states =& $GLOBALS['config']['mibs']['CISCO-RTTMON-MIB']['sla_states'];
// Events from MIB definitions
$sla_oids = array('jitter' => array('rttMonLatestJitterOperRTTMin', 'rttMonLatestJitterOperRTTMax', 'rttMonLatestJitterOperNumOfRTT', 'rttMonLatestJitterOperPacketLossSD', 'rttMonLatestJitterOperPacketLossDS'), 'icmpjitter' => array('rttMonLatestIcmpJitterRTTMin', 'rttMonLatestIcmpJitterRTTMax', 'rttMonLatestIcmpJitterNumRTT', 'rttMonLatestIcmpJitterPktLoss'));
$sla_poll = snmpwalk_cache_multi_oid($device, "rttMonLatestRttOperEntry", array(), 'CISCO-RTTMON-MIB');
foreach (dbFetchColumn("SELECT DISTINCT `rtt_type` FROM `slas` WHERE `device_id` = ? AND `rtt_type` != ? AND `deleted` = 0 AND `sla_status` = 'active';", array($device['device_id'], 'echo')) as $rtt_type) {
    switch ($rtt_type) {
        case 'jitter':
            // Additional data for Jitter
            $sla_poll = snmpwalk_cache_multi_oid($device, "rttMonLatestJitterOperEntry", $sla_poll, 'CISCO-RTTMON-MIB');
            break;
        case 'icmpjitter':
            // Additional data for ICMP jitter
            $sla_poll = snmpwalk_cache_multi_oid($device, "rttMonLatestIcmpJitterOperEntry", $sla_poll, 'CISCO-RTTMON-ICMP-MIB');
            break;
    }
}
// Uptime offset for timestamps
$uptime = timeticks_to_sec($poll_device['sysUpTime']);
$uptime_offset = time() - intval($uptime) / 100;
/// WARNING. System timezone BOMB
Exemplo n.º 26
0
$cache['where']['devices_permitted'] = generate_query_permitted(array('device'));
$cache['where']['ports_permitted'] = generate_query_permitted(array('port'));
// CEF
$routing['cef']['count'] = count(dbFetchColumn("SELECT `cef_switching_id` FROM `cef_switching` WHERE 1 " . $cache['where']['devices_permitted'] . " GROUP BY `device_id`, `afi`;"));
// VRF
$routing['vrf']['count'] = count(dbFetchColumn("SELECT DISTINCT `mplsVpnVrfRouteDistinguisher` FROM `vrfs` WHERE 1 " . $cache['where']['devices_permitted']));
// Status
$cache['status']['count'] = $statuses['count'];
//dbFetchCell("SELECT COUNT(`status_id`) FROM `status` WHERE 1 ".$cache['where']['devices_permitted']);
// Additional common counts
if ($config['enable_pseudowires']) {
    $cache['ports']['pseudowires'] = dbFetchColumn('SELECT DISTINCT `port_id` FROM `pseudowires` WHERE 1 ' . $cache['where']['ports_permitted']);
    $cache['pseudowires']['count'] = count($cache['ports']['pseudowires']);
}
if ($config['poller_modules']['cisco-cbqos'] || $config['discovery_modules']['cisco-cbqos']) {
    $cache['ports']['cbqos'] = dbFetchColumn('SELECT DISTINCT `port_id` FROM `ports_cbqos` WHERE 1 ' . $cache['where']['ports_permitted']);
    $cache['cbqos']['count'] = count($cache['ports']['cbqos']);
}
if ($config['poller_modules']['unix-agent']) {
    $cache['packages']['count'] = dbFetchCell("SELECT COUNT(*) FROM `packages` WHERE 1 " . $cache['where']['devices_permitted']);
}
if ($config['poller_modules']['applications']) {
    $cache['applications']['count'] = dbFetchCell("SELECT COUNT(*) FROM `applications` WHERE 1 " . $cache['where']['devices_permitted']);
}
if ($config['poller_modules']['wifi'] || $config['discovery_modules']['wifi']) {
    $cache['wifi_sessions']['count'] = dbFetchCell("SELECT COUNT(*) FROM `wifi_sessions` WHERE 1 " . $cache['where']['devices_permitted']);
}
if ($config['poller_modules']['printersupplies'] || $config['discovery_modules']['printersupplies']) {
    $cache['printersupplies']['count'] = dbFetchCell("SELECT COUNT(*) FROM `printersupplies` WHERE 1 " . $cache['where']['devices_permitted']);
}
$cache['neighbours']['count'] = dbFetchCell("SELECT COUNT(*) FROM `neighbours` WHERE `active` = 1 " . $cache['where']['ports_permitted']);
Exemplo n.º 27
0
$pagetitle[] = "Devices";
if ($vars['searchbar'] != "hide") {
    // Generate array with form elements
    $search_items = array();
    foreach (array('os', 'hardware', 'version', 'features', 'type') as $entry) {
        $query = "SELECT `{$entry}` FROM `devices`";
        if (isset($where_array[$entry])) {
            $tmp = $where_array[$entry];
            unset($where_array[$entry]);
            $query .= ' WHERE 1 ' . implode('', $where_array);
            $where_array[$entry] = $tmp;
        } else {
            $query .= $where;
        }
        $query .= " AND `{$entry}` != '' {$query_permitted} GROUP BY `{$entry}` ORDER BY `{$entry}`";
        foreach (dbFetchColumn($query) as $item) {
            if ($entry == 'os') {
                $name = $config['os'][$item]['text'];
            } else {
                $name = nicecase($item);
            }
            $search_items[$entry][$item] = $name;
        }
    }
    foreach (get_locations() as $entry) {
        $search_items['location'][$entry] = $entry == '' ? 'UNSET' : htmlspecialchars($entry);
    }
    foreach (get_type_groups('device') as $entry) {
        $search_items['group'][$entry['group_id']] = $entry['group_name'];
    }
    $search_items['sort'] = array('hostname' => 'Hostname', 'location' => 'Location', 'os' => 'Operating System', 'uptime' => 'Uptime');
Exemplo n.º 28
0
$form_items = array();
$form_devices = dbFetchColumn('SELECT DISTINCT `device_id` FROM `bgpPeers`;');
$form_items['devices'] = generate_form_values('device', $form_devices);
//r($form_items['devices']);
$param = 'peer_as';
$column = 'bgpPeerRemoteAs';
foreach (dbFetchRows('SELECT DISTINCT `' . $column . '`, `astext` FROM `bgpPeers` WHERE 1 ' . $cache['where']['devices_permitted'] . ' ORDER BY `' . $column . '`') as $entry) {
    if (empty($entry[$column])) {
        continue;
    }
    $form_items[$param][$entry[$column]]['name'] = 'AS' . $entry[$column];
    $form_items[$param][$entry[$column]]['subtext'] = $entry['astext'];
}
$form_params = array('local_ip' => 'bgpPeerLocalAddr', 'peer_ip' => 'bgpPeerRemoteAddr');
foreach ($form_params as $param => $column) {
    foreach (dbFetchColumn('SELECT DISTINCT `' . $column . '` FROM `bgpPeers` WHERE 1 ' . $cache['where']['devices_permitted'] . ' ORDER BY `' . $column . '`') as $entry) {
        if (empty($entry)) {
            continue;
        }
        if (strpos($entry, ':') !== FALSE) {
            $form_items[$param][$entry]['group'] = 'IPv6';
            $form_items[$param][$entry]['name'] = Net_IPv6::compress($entry);
        } else {
            $form_items[$param][$entry]['group'] = 'IPv4';
            $form_items[$param][$entry]['name'] = escape_html($entry);
        }
    }
}
$form = array('type' => 'rows', 'space' => '5px', 'submit_by_key' => TRUE, 'url' => generate_url($vars));
$form['row'][0]['device'] = array('type' => 'multiselect', 'name' => 'Local Device', 'width' => '100%', 'value' => $vars['device'], 'values' => $form_items['devices']);
$form['row'][0]['local_ip'] = array('type' => 'multiselect', 'name' => 'Local address', 'width' => '100%', 'value' => $vars['local_ip'], 'values' => $form_items['local_ip']);
Exemplo n.º 29
0
 // Show which other devices are on the same subnet as this interface
 if (!isset($ports_has_ext['ipv4_addresses']) || in_array($port['port_id'], $ports_has_ext['ipv4_addresses'])) {
     foreach (dbFetchColumn("SELECT A4.`ipv4_network_id` FROM `ipv4_addresses` AS A4\n        LEFT JOIN `ipv4_networks` AS N4 ON A4.`ipv4_network_id` = N4.`ipv4_network_id`\n        WHERE `port_id` = ? AND `ipv4_network` NOT IN (?) GROUP BY A4.`ipv4_network_id`", array($port['port_id'], $config['ignore_common_subnet'])) as $network_id) {
         $sql = "SELECT N.*, P.`port_id`, P.`device_id` FROM `ipv4_addresses` AS A, `ipv4_networks` AS N, `ports` AS P\n                WHERE A.`port_id` = P.`port_id` AND P.`device_id` != ?\n                AND A.`ipv4_network_id` = ? AND N.`ipv4_network_id` = A.`ipv4_network_id`\n                AND P.`ifAdminStatus` = 'up'";
         $params = array($device['device_id'], $network_id);
         foreach (dbFetchRows($sql, $params) as $new) {
             if ($cache['devices']['id'][$new['device_id']]['disabled'] && !$config['web_show_disabled']) {
                 continue;
             }
             $int_links[$new['port_id']] = $new['port_id'];
             $int_links_v4[$new['port_id']][] = $new['ipv4_network'];
         }
     }
 }
 if (!isset($ports_has_ext['ipv6_addresses']) || in_array($port['port_id'], $ports_has_ext['ipv6_addresses'])) {
     foreach (dbFetchColumn("SELECT A6.`ipv6_network_id` FROM `ipv6_addresses` AS A6\n         LEFT JOIN `ipv6_networks` AS N6 ON A6.`ipv6_network_id` = N6.`ipv6_network_id`\n         WHERE `port_id` = ? AND `ipv6_network` NOT IN (?) GROUP BY A6.`ipv6_network_id`", array($port['port_id'], $config['ignore_common_subnet'])) as $network_id) {
         $ipv6_network_id = $net['ipv6_network_id'];
         $sql = "SELECT P.`port_id`, P.`device_id` FROM `ipv6_addresses` AS A, `ipv6_networks` AS N, `ports` AS P\n                WHERE A.`port_id` = P.`port_id` AND P.device_id != ?\n                AND A.`ipv6_network_id` = ? AND N.`ipv6_network_id` = A.`ipv6_network_id`\n                AND P.`ifAdminStatus` = 'up' AND A.`ipv6_origin` != 'linklayer' AND A.`ipv6_origin` != 'wellknown'";
         $params = array($device['device_id'], $network_id);
         foreach (dbFetchRows($sql, $params) as $new) {
             if ($cache['devices']['id'][$new['device_id']]['disabled'] && !$config['web_show_disabled']) {
                 continue;
             }
             $int_links[$new['port_id']] = $new['port_id'];
             $int_links_v6[$new['port_id']][] = $new['port_id'];
         }
     }
 }
 foreach ($int_links as $int_link) {
     $link_if = get_port_by_id_cache($int_link);
     $link_dev = device_by_id_cache($link_if['device_id']);
Exemplo n.º 30
0
 if (dbFetchCell('SELECT COUNT(*) FROM `entPhysical` WHERE `device_id` = ?', array($device['device_id'])) > 0) {
     $navbar['options']['entphysical'] = array('text' => 'Inventory', 'icon' => 'oicon-wooden-box');
 } elseif (dbFetchCell('SELECT COUNT(*) FROM `hrDevice` WHERE `device_id` = ?', array($device['device_id'])) > 0) {
     $navbar['options']['hrdevice'] = array('text' => 'Inventory', 'icon' => 'oicon-wooden-box');
 }
 // Print service tab if show_services enabled and there are entries in the services table
 ## DEPRECATED
 if ($config['show_services'] && dbFetchCell('SELECT COUNT(*) FROM services WHERE device_id = ?', array($device['device_id'])) > 0) {
     $navbar['options']['services'] = array('text' => 'Services', 'icon' => 'oicon-target');
 }
 // Print printing tab if there are entries in the printersupplies table
 if (dbFetchCell('SELECT COUNT(*) FROM `printersupplies` WHERE device_id = ?', array($device['device_id'])) > 0) {
     $navbar['options']['printing'] = array('text' => 'Printing', 'icon' => 'oicon-printer-color');
     // $printing_tabs is used in device/printing/ to build the tabs menu. we build it here to save some queries
     /// FIXME. sid3windr, I not see what this query "save" here, must be moved to device/printing.inc.php
     $printing_tabs = dbFetchColumn("SELECT DISTINCT `supply_type` FROM `printersupplies` WHERE `device_id` = ?", array($device['device_id']));
 }
 // Always print logs tab
 $navbar['options']['logs'] = array('text' => 'Logs', 'icon' => 'oicon-clipboard-audit');
 // Print alerts tab
 $navbar['options']['alerts'] = array('text' => 'Alerts', 'icon' => 'oicon-bell');
 // If the user has secure global read privileges, check for a device config.
 if ($_SESSION['userlevel'] >= 7) {
     $device_config_file = get_rancid_filename($device['hostname']);
     // Print the config tab if we have a device config
     if ($device_config_file) {
         $navbar['options']['showconfig'] = array('text' => 'Config', 'icon' => 'oicon-application-terminal');
     }
 }
 /*
     // If the user has global read privileges, check for device notes.