mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Remove port association mode map from the database (#8941)
* Remove port association mode map from the database * Renamed sql file * Renamed sql file
This commit is contained in:
committed by
Neil Lathwood
parent
bd6c51e3ab
commit
50bb72f530
@@ -186,8 +186,7 @@ echo " </select>
|
||||
<select name='port_assoc_mode' id='port_assoc_mode' class='form-control input-sm'>
|
||||
";
|
||||
|
||||
foreach (get_port_assoc_modes() as $pam) {
|
||||
$pam_id = get_port_assoc_mode_id($pam);
|
||||
foreach (get_port_assoc_modes() as $pam_id => $pam) {
|
||||
echo " <option value='$pam_id'";
|
||||
|
||||
if ($pam_id == $device['port_association_mode']) {
|
||||
|
@@ -610,7 +610,7 @@ function format_si($value, $round = '2', $sf = '3')
|
||||
$value = $value * -1;
|
||||
}
|
||||
|
||||
return number_format(round($value, $round), $sf, '.', '').$ext;
|
||||
return number_format(round($value, $round), $sf, '.', '').$ext;
|
||||
}
|
||||
|
||||
function format_bi($value, $round = '2', $sf = '3')
|
||||
@@ -1026,7 +1026,7 @@ function object_is_cached($section, $obj)
|
||||
* attributes
|
||||
* @param array $attribs Device attributes
|
||||
* @return bool
|
||||
**/
|
||||
**/
|
||||
function can_ping_device($attribs)
|
||||
{
|
||||
if (Config::get('icmp_check') && !(isset($attribs['override_icmp_disable']) && $attribs['override_icmp_disable'] == "true")) {
|
||||
@@ -1103,7 +1103,7 @@ Set <code>$config[\'poller_modules\'][\'mib\'] = 1;</code> in <code>config.php</
|
||||
* Constructs the path to an RRD for the Ceph application
|
||||
* @param string $gtype The type of rrd we're looking for
|
||||
* @return string
|
||||
**/
|
||||
**/
|
||||
function ceph_rrd($gtype)
|
||||
{
|
||||
global $device;
|
||||
@@ -1122,7 +1122,7 @@ function ceph_rrd($gtype)
|
||||
* Parse location field for coordinates
|
||||
* @param string location The location field to look for coords in.
|
||||
* @return array Containing the lat and lng coords
|
||||
**/
|
||||
**/
|
||||
function parse_location($location)
|
||||
{
|
||||
preg_match('/(\[)(-?[0-9\. ]+),[ ]*(-?[0-9\. ]+)(\])/', $location, $tmp_loc);
|
||||
@@ -1172,10 +1172,10 @@ function version_info($remote = false)
|
||||
}//end version_info()
|
||||
|
||||
/**
|
||||
* Convert a MySQL binary v4 (4-byte) or v6 (16-byte) IP address to a printable string.
|
||||
* @param string $ip A binary string containing an IP address, as returned from MySQL's INET6_ATON function
|
||||
* @return string Empty if not valid.
|
||||
*/
|
||||
* Convert a MySQL binary v4 (4-byte) or v6 (16-byte) IP address to a printable string.
|
||||
* @param string $ip A binary string containing an IP address, as returned from MySQL's INET6_ATON function
|
||||
* @return string Empty if not valid.
|
||||
*/
|
||||
// Fuction is from http://uk3.php.net/manual/en/function.inet-ntop.php
|
||||
function inet6_ntop($ip)
|
||||
{
|
||||
@@ -1219,17 +1219,12 @@ function format_hostname($device, $hostname = null)
|
||||
*/
|
||||
function get_port_assoc_modes()
|
||||
{
|
||||
return dbFetchColumn("SELECT `name` FROM `port_association_mode` ORDER BY pom_id");
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate port_association_mode
|
||||
* @param string $port_assoc_mode
|
||||
* @return bool
|
||||
*/
|
||||
function is_valid_port_assoc_mode($port_assoc_mode)
|
||||
{
|
||||
return in_array($port_assoc_mode, get_port_assoc_modes());
|
||||
return [
|
||||
1 => 'ifIndex',
|
||||
2 => 'ifName',
|
||||
3 => 'ifDescr',
|
||||
4 => 'ifAlias',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1239,7 +1234,9 @@ function is_valid_port_assoc_mode($port_assoc_mode)
|
||||
*/
|
||||
function get_port_assoc_mode_id($port_assoc_mode)
|
||||
{
|
||||
return (int)dbFetchCell("SELECT `pom_id` FROM `port_association_mode` WHERE name = ?", array ($port_assoc_mode));
|
||||
$modes = array_flip(get_port_assoc_modes());
|
||||
|
||||
return isset($modes[$port_assoc_mode]) ? $modes[$port_assoc_mode] : false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1249,7 +1246,9 @@ function get_port_assoc_mode_id($port_assoc_mode)
|
||||
*/
|
||||
function get_port_assoc_mode_name($port_assoc_mode_id)
|
||||
{
|
||||
return dbFetchCell("SELECT `name` FROM `port_association_mode` WHERE pom_id = ?", array ($port_assoc_mode_id));
|
||||
$modes = get_port_assoc_modes();
|
||||
|
||||
return isset($modes[$port_assoc_mode_id]) ? $modes[$port_assoc_mode_id] : false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -608,7 +608,7 @@ function addHost($host, $snmp_version = '', $port = '161', $transport = 'udp', $
|
||||
}
|
||||
|
||||
// Valid port assoc mode
|
||||
if (!is_valid_port_assoc_mode($port_assoc_mode)) {
|
||||
if (!in_array($port_assoc_mode, get_port_assoc_modes())) {
|
||||
throw new InvalidPortAssocModeException("Invalid port association_mode '$port_assoc_mode'. Valid modes are: " . join(', ', get_port_assoc_modes()));
|
||||
}
|
||||
|
||||
|
@@ -1316,12 +1316,6 @@ ports_vlans:
|
||||
Indexes:
|
||||
PRIMARY: { Name: PRIMARY, Columns: [port_vlan_id], Unique: true, Type: BTREE }
|
||||
unique: { Name: unique, Columns: [device_id, port_id, vlan], Unique: true, Type: BTREE }
|
||||
port_association_mode:
|
||||
Columns:
|
||||
- { Field: pom_id, Type: int(11), 'Null': false, Extra: auto_increment }
|
||||
- { Field: name, Type: varchar(12), 'Null': false, Extra: '' }
|
||||
Indexes:
|
||||
PRIMARY: { Name: PRIMARY, Columns: [pom_id], Unique: true, Type: BTREE }
|
||||
processes:
|
||||
Columns:
|
||||
- { Field: device_id, Type: int(11), 'Null': false, Extra: '' }
|
||||
|
1
sql-schema/258.sql
Normal file
1
sql-schema/258.sql
Normal file
@@ -0,0 +1 @@
|
||||
DROP TABLE IF EXISTS `port_association_mode`;
|
@@ -222,4 +222,20 @@ class CommonFunctionsTest extends TestCase
|
||||
$this->assertEquals('Testing IP', format_hostname($device_ip, 'hostname.like'));
|
||||
$this->assertEquals('Testing IP', format_hostname($device_ip, '10.10.10.10'));
|
||||
}
|
||||
|
||||
public function testPortAssociation()
|
||||
{
|
||||
$modes = [
|
||||
1 => 'ifIndex',
|
||||
2 => 'ifName',
|
||||
3 => 'ifDescr',
|
||||
4 => 'ifAlias',
|
||||
];
|
||||
|
||||
$this->assertEquals($modes, get_port_assoc_modes());
|
||||
$this->assertEquals('ifIndex', get_port_assoc_mode_name(1));
|
||||
$this->assertEquals(1, get_port_assoc_mode_id('ifIndex'));
|
||||
$this->assertFalse(get_port_assoc_mode_name(666));
|
||||
$this->assertFalse(get_port_assoc_mode_id('lucifer'));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user