mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Revert "deduping type_where code, adding manual types to graph widgets "
This commit is contained in:
@@ -104,7 +104,6 @@ LibreNMS contributors:
|
||||
- Robert Verspuy <robert@exa.nl> (exarv)
|
||||
- Peter Tkatchenko <peter@flytrace.com> (Peter2121)
|
||||
- Marc Runkel <marc@runkel.org> (mrunkel)
|
||||
- Brandon Boudrias <bt.boudrias@gmail.com> (brandune)
|
||||
|
||||
[1]: http://observium.org/ "Observium web site"
|
||||
Observium was written by:
|
||||
|
@@ -495,10 +495,19 @@ function get_graph_by_portgroup() {
|
||||
$vars['width'] = $_GET['width'] ?: 1075;
|
||||
$vars['height'] = $_GET['height'] ?: 300;
|
||||
$auth = '1';
|
||||
$type_where = ' (';
|
||||
$or = '';
|
||||
$type_param = array();
|
||||
foreach (explode(',', $group) as $type) {
|
||||
$type_where .= " $or `port_descr_type` = ?";
|
||||
$or = 'OR';
|
||||
$type_param[] = $type;
|
||||
}
|
||||
|
||||
$ports = get_ports_from_type(explode(',', $group));
|
||||
$type_where .= ') ';
|
||||
$if_list = '';
|
||||
$seperator = '';
|
||||
$ports = dbFetchRows("SELECT * FROM `ports` as I, `devices` AS D WHERE $type_where AND I.device_id = D.device_id ORDER BY I.ifAlias", $type_param);
|
||||
foreach ($ports as $port) {
|
||||
$if_list .= $seperator.$port['port_id'];
|
||||
$seperator = ',';
|
||||
|
@@ -74,7 +74,6 @@ if( defined('show_settings') || empty($widget_settings) ) {
|
||||
<option value="peering"'.($widget_settings['graph_type'] == 'peering' ? ' selected' : '').'> Peering</option>
|
||||
<option value="core"'.($widget_settings['graph_type'] == 'core' ? ' selected' : '').'> Core</option>
|
||||
<option value="custom"'.($widget_settings['graph_type'] == 'custom' ? ' selected' : '').'> Custom Descr</option>
|
||||
<option value="manual"'.($widget_settings['graph_type'] == 'manual' ? ' selected' : '').'> Manual Descr</option>
|
||||
<option disabled></option>
|
||||
<option value="bill_bits"'.($widget_settings['graph_type'] == 'bill_bits' ? ' selected' : '').'>Bill</option>
|
||||
</select>
|
||||
@@ -151,14 +150,6 @@ if( defined('show_settings') || empty($widget_settings) ) {
|
||||
$common_output[] = ' </select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group input_'.$unique_id.'" id="input_'.$unique_id.'_manual">
|
||||
<div class="col-sm-2">
|
||||
<label for="graph_manual" class="control-label">Manual Port-Desc: </label>
|
||||
</div>
|
||||
<div class="col-sm-10">
|
||||
<input type="text" class="form-control input_'.$unique_id.'_manual" name="graph_manual" placeholder="Descr String" value="'.htmlspecialchars($widget_settings['graph_manual']).'">';
|
||||
$common_output[] = ' </div>
|
||||
</div>
|
||||
<div class="form-group input_'.$unique_id.'" id="input_'.$unique_id.'_bill">
|
||||
<div class="col-sm-2">
|
||||
<label for="graph_bill" class="control-label">Bill: </label>
|
||||
@@ -402,20 +393,39 @@ else {
|
||||
elseif ($type == 'munin') {
|
||||
$param = 'device='.$widget_settings['graph_'.$type]['device_id'].'&plugin='.$widget_settings['graph_'.$type]['name'];
|
||||
}
|
||||
elseif ($type == 'transit' || $type == 'peering' || $type == 'core' || $type == 'custom' || $type == 'manual') {
|
||||
if ( $type == 'custom' || $type == 'manual') {
|
||||
$type = $widget_settings['graph_'.$type];
|
||||
$type = explode(',', $type);
|
||||
elseif ($type == 'transit' || $type == 'peering' || $type == 'core') {
|
||||
$type_where = ' (';
|
||||
if (is_array($config[$type.'_descr']) === false) {
|
||||
$config[$type.'_descr'] = array($config[$type.'_descr']);
|
||||
}
|
||||
|
||||
$ports = get_ports_from_type($type);
|
||||
foreach ($ports as $port) {
|
||||
foreach ($config[$type.'_descr'] as $additional_type) {
|
||||
if (!empty($additional_type)) {
|
||||
$type_where .= " $or `port_descr_type` = ?";
|
||||
$or = 'OR';
|
||||
$type_param[] = $additional_type;
|
||||
}
|
||||
}
|
||||
$type_where .= " $or `port_descr_type` = ?";
|
||||
$or = 'OR';
|
||||
$type_param[] = $type;
|
||||
$type_where .= ') ';
|
||||
foreach (dbFetchRows("SELECT port_id FROM `ports` WHERE $type_where ORDER BY ifAlias", $type_param) as $port) {
|
||||
$tmp[] = $port['port_id'];
|
||||
}
|
||||
$param = 'id='.implode(',',$tmp);
|
||||
$widget_settings['graph_type'] = 'multiport_bits_separate';
|
||||
if (empty($widget_settings['title'])) {
|
||||
$widget_settings['title'] = 'Overall '.ucfirst(htmlspecialchars($type)).' Bits ('.$widget_settings['graph_range'].')';
|
||||
$widget_settings['title'] = 'Overall '.ucfirst($type).' Bits ('.$widget_settings['graph_range'].')';
|
||||
}
|
||||
}
|
||||
elseif ($type == 'custom') {
|
||||
foreach (dbFetchRows("SELECT port_id FROM `ports` WHERE `port_descr_type` = ? ORDER BY ifAlias", array($widget_settings['graph_custom'])) as $port) {
|
||||
$tmp[] = $port['port_id'];
|
||||
}
|
||||
$param = 'id='.implode(',',$tmp);
|
||||
$widget_settings['graph_type'] = 'multiport_bits_separate';
|
||||
if (empty($widget_settings['title'])) {
|
||||
$widget_settings['title'] = 'Overall '.ucfirst(htmlspecialchars($widget_settings['graph_custom'])).' Bits ('.$widget_settings['graph_range'].')';
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@@ -1283,58 +1283,3 @@ function get_ripe_api_whois_data_json($ripe_data_param, $ripe_query_param) {
|
||||
return json_decode(file_get_contents($ripe_whois_url) , true);
|
||||
}//end get_ripe_api_whois_data_json()
|
||||
|
||||
/**
|
||||
* Return the rows from 'ports' for all ports of a certain type as parsed by port_descr_parser.
|
||||
* One or an array of strings can be provided as an argument; if an array is passed, all ports matching
|
||||
* any of the types in the array are returned.
|
||||
* @param $types mixed String or strings matching 'port_descr_type's.
|
||||
* @return array Rows from the ports table for matching ports.
|
||||
*/
|
||||
function get_ports_from_type($given_types) {
|
||||
global $config;
|
||||
|
||||
# Make the arg an array if it isn't, so subsequent steps only have to handle arrays.
|
||||
if(!is_array($given_types)) {
|
||||
$given_types = array($given_types);
|
||||
}
|
||||
|
||||
# Check the config for a '_descr' entry for each argument. This is how a 'custom_descr' entry can
|
||||
# be key/valued to some other string that's actually searched for in the DB. Merge or append the
|
||||
# configured value if it's an array or a string. Or append the argument itself if there's no matching
|
||||
# entry in config.
|
||||
$search_types = array();
|
||||
foreach($given_types as $type) {
|
||||
if(isset($config[$type.'_descr']) === true) {
|
||||
if (is_array($config[$type.'_descr']) === true) {
|
||||
$search_types = array_merge($search_types, $config[$type.'_descr']);
|
||||
}
|
||||
else {
|
||||
$search_types[] = $config[$type.'_descr'];
|
||||
}
|
||||
}
|
||||
else {
|
||||
$search_types[] = $type;
|
||||
}
|
||||
}
|
||||
|
||||
# Using the full list of strings to search the DB for, build the 'where' portion of a query that
|
||||
# compares 'port_descr_type' with entry in the list. Also, since '@' is the convential wildcard,
|
||||
# replace it with '%' so it functions as a wildcard in the SQL query.
|
||||
$type_where = ' (';
|
||||
$or = '';
|
||||
$type_param = array();
|
||||
|
||||
foreach($search_types as $type) {
|
||||
if (!empty($type)) {
|
||||
$type = strtr($type, '@', '%');
|
||||
$type_where .= " $or `port_descr_type` LIKE ?";
|
||||
$or = 'OR';
|
||||
$type_param[] = $type;
|
||||
}
|
||||
}
|
||||
$type_where .= ') ';
|
||||
|
||||
# Run the query with the generated 'where' and necessary parameters, and send it back.
|
||||
$ports = dbFetchRows("SELECT * FROM `ports` as I, `devices` AS D WHERE $type_where AND I.device_id = D.device_id ORDER BY I.ifAlias", $type_param);
|
||||
return $ports;
|
||||
}
|
||||
|
@@ -16,8 +16,27 @@ else {
|
||||
$bg = '#ffffff';
|
||||
}
|
||||
|
||||
$types_array = explode(',', $vars['type']);
|
||||
$ports = get_ports_from_type($types_array);
|
||||
$type_where = ' (';
|
||||
foreach (explode(',', $vars['type']) as $type) {
|
||||
if (is_array($config[$type.'_descr']) === false) {
|
||||
$config[$type.'_descr'] = array($config[$type.'_descr']);
|
||||
}
|
||||
|
||||
foreach ($config[$type.'_descr'] as $additional_type) {
|
||||
if (!empty($additional_type)) {
|
||||
$type_where .= " $or `port_descr_type` = ?";
|
||||
$or = 'OR';
|
||||
$type_param[] = $additional_type;
|
||||
}
|
||||
}
|
||||
|
||||
$type_where .= " $or `port_descr_type` = ?";
|
||||
$or = 'OR';
|
||||
$type_param[] = $type;
|
||||
}
|
||||
|
||||
$type_where .= ') ';
|
||||
$ports = dbFetchRows("SELECT * FROM `ports` as I, `devices` AS D WHERE $type_where AND I.device_id = D.device_id ORDER BY I.ifAlias", $type_param);
|
||||
|
||||
foreach ($ports as $port) {
|
||||
$if_list .= $seperator.$port['port_id'];
|
||||
@@ -26,6 +45,7 @@ foreach ($ports as $port) {
|
||||
|
||||
unset($seperator);
|
||||
|
||||
$types_array = explode(',', $vars['type']);
|
||||
for ($i = 0; $i < count($types_array);
|
||||
$i++) {
|
||||
$types_array[$i] = ucfirst($types_array[$i]);
|
||||
|
Reference in New Issue
Block a user