本文整理汇总了PHP中dbFetchColumn函数的典型用法代码示例。如果您正苦于以下问题:PHP dbFetchColumn函数的具体用法?PHP dbFetchColumn怎么用?PHP dbFetchColumn使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dbFetchColumn函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generate_query_permitted
$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 {
示例2: array
$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);
示例3: explode
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']);
示例4: foreach
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'];
示例5: get_locations
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;
}
示例6: collect_table
/**
* 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)
//.........这里部分代码省略.........
示例7: array
$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[] = '事件日志';
示例8: generate_query_values
* @subpackage webui
* @author Adam Armstrong <adama@observium.org>
* @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
示例9: array
}
// 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;
示例10: snmpwalk_cache_oid
<?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']);
}
}
}
}
}
示例11: generate_query_values
$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 -->
示例12: dbDelete
/**
* 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";
}
}
示例13: get_bgp_array
/**
* 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'];
//.........这里部分代码省略.........
示例14: unset
*
* @package observium
* @subpackage webui
* @author Adam Armstrong <adama@memetic.org>
* @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
示例15: cache_alert_rules
<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