mirror of
https://github.com/stylersnico/librenms.git
synced 2026-07-28 00:24:21 +02:00
More network map updates
This commit is contained in:
+79
-115
@@ -12,7 +12,10 @@
|
||||
* the source code distribution for details.
|
||||
*/
|
||||
|
||||
$tmp_devices = array();
|
||||
//Don't know where this should come from, but it is used later, so I just define it here.
|
||||
$row_colour="#ffffff";
|
||||
|
||||
$sql_array= array();
|
||||
if (!empty($device['hostname'])) {
|
||||
$sql = ' WHERE `devices`.`hostname`=?';
|
||||
$sql_array = array($device['hostname']);
|
||||
@@ -22,128 +25,89 @@ if (!empty($device['hostname'])) {
|
||||
$sql = ' WHERE 1';
|
||||
}
|
||||
|
||||
$sql .= ' AND `local_device_id` != 0 AND `remote_device_id` != 0';
|
||||
$sql .= ' AND `local_device_id` != 0 AND `remote_device_id` != 0 ';
|
||||
$sql .= ' AND `local_device_id` IS NOT NULL AND `remote_device_id` IS NOT NULL ';
|
||||
|
||||
$tmp_devices = array();
|
||||
$tmp_ids = array();
|
||||
foreach (dbFetchRows("SELECT DISTINCT least(`devices`.`device_id`, `remote_device_id`) AS `remote_device_id`, GREATEST(`remote_device_id`,`devices`.`device_id`) AS `local_device_id` FROM `links` LEFT JOIN `ports` ON `local_port_id`=`ports`.`port_id` LEFT JOIN `devices` ON `ports`.`device_id`=`devices`.`device_id` $sql", $sql_array) as $link_devices) {
|
||||
if (!in_array($link_devices['local_device_id'], $tmp_ids) && device_permitted($link_devices['local_device_id'])) {
|
||||
$link_dev = dbFetchRow("SELECT * FROM `devices` WHERE `device_id`=?",array($link_devices['local_device_id']));
|
||||
$tmp_devices[] = array('id'=>$link_devices['local_device_id'],'label'=>$link_dev['hostname'],'title'=>generate_device_link($link_dev,'',array(),'','','',0),'group'=>$link_dev['location'],'shape'=>'box');
|
||||
}
|
||||
if (!in_array($link_devices['remote_device_id'], $tmp_ids) && device_permitted($link_devices['remote_device_id'])) {
|
||||
$link_dev = dbFetchRow("SELECT * FROM `devices` WHERE `device_id`=?",array($link_devices['remote_device_id']));
|
||||
$tmp_devices[] = array('id'=>$link_devices['remote_device_id'],'label'=>$link_dev['hostname'],'title'=>generate_device_link($link_dev,'',array(),'','','',0),'group'=>$link_dev['location'],'shape'=>'box');
|
||||
}
|
||||
array_push($tmp_ids,$link_devices['local_device_id']);
|
||||
array_push($tmp_ids,$link_devices['remote_device_id']);
|
||||
}
|
||||
|
||||
$tmp_exp_ids = implode(',',$tmp_ids);
|
||||
|
||||
$port_ids = array();
|
||||
$port_devices = array();
|
||||
$tmp_links = array();
|
||||
foreach (dbFetchRows("SELECT DISTINCT LEAST(`M`.`port_id`, `P`.`port_id`) AS `remote_port_id`, GREATEST(`P`.`port_id`,`M`.`port_id`) AS `local_port_id` FROM `ipv4_mac` AS `M` LEFT JOIN `ports` AS `P` ON `M`.`mac_address` = `P`.`ifPhysAddress` LEFT JOIN `devices` AS `D` ON `P`.`device_id`=`D`.`device_id` WHERE `P`.`port_id` IS NOT NULL AND `M`.`port_id` IS NOT NULL AND `M`.`port_id` != 0 AND `P`.`port_id` != 0 $mac_sql", $mac_array) as $macs) {
|
||||
if (!in_array($macs['local_port_id'], $port_ids) && port_permitted($macs['local_port_id'])) {
|
||||
$port_det = dbFetchRow("SELECT * FROM `ports` WHERE `port_id`=?", array($macs['local_port_id']));
|
||||
$port_dev = dbFetchRow("SELECT * FROM `devices` WHERE `device_id`=?", array($port_det['device_id']));
|
||||
if (!in_array($port_dev['device_id'],$tmp_ids) && !in_array($port_dev['device_id'],$port_devices)) {
|
||||
$mac_devices[] = array('id'=>$port_dev['device_id'], 'label'=>$port_dev['hostname'], 'title'=>generate_device_link($port_dev,'',array(),'','','',0),'group'=>$port_dev['location'], 'shape'=>'box');
|
||||
array_push($port_ids, $port_det['port_id']);
|
||||
array_push($port_devices, $port_dev['device_id']);
|
||||
$port_data = $port_det;
|
||||
$from = $port_dev['device_id'];
|
||||
$port = shorten_interface_type($port_det['ifName']);
|
||||
$speed = $port_det['ifSpeed']/1000/1000;
|
||||
if ($speed == 100) {
|
||||
$width = 3;
|
||||
} elseif ($speed == 1000) {
|
||||
$width = 5;
|
||||
} elseif ($speed == 10000) {
|
||||
$width = 10;
|
||||
} elseif ($speed == 40000) {
|
||||
$width = 15;
|
||||
} elseif ($speed == 100000) {
|
||||
$width = 20;
|
||||
} else {
|
||||
$width = 1;
|
||||
}
|
||||
$link_in_used = ($port_det['ifInOctets_rate'] * 8) / $port_det['ifSpeed'] * 100;
|
||||
$link_out_used = ($port_det['ifOutOctets_rate'] * 8) / $port_det['ifSpeed'] * 100;
|
||||
if ($link_in_used > $link_out_used) {
|
||||
$link_used = $link_in_used;
|
||||
} else {
|
||||
$link_used = $link_out_used;
|
||||
}
|
||||
$link_used = round($link_used, -1);
|
||||
if ($link_used > 100) {
|
||||
$link_used = 100;
|
||||
}
|
||||
$link_color = $config['map_legend'][$link_used];
|
||||
}
|
||||
foreach (dbFetchRows("SELECT
|
||||
`D1`.`device_id` AS `local_device_id`,
|
||||
`D1`.`os` AS `local_os`,
|
||||
`D1`.`hostname` AS `local_hostname`,
|
||||
`D2`.`device_id` AS `remote_device_id`,
|
||||
`D2`.`os` AS `remote_os`,
|
||||
`D2`.`hostname` AS `remote_hostname`,
|
||||
`P1`.`port_id` AS `local_port_id`,
|
||||
`P1`.`device_id` AS `local_port_device_id`,
|
||||
`P1`.`ifName` AS `local_ifname`,
|
||||
`P1`.`ifSpeed` AS `local_ifspeed`,
|
||||
`P1`.`ifOperStatus` AS `local_ifoperstatus`,
|
||||
`P1`.`ifAdminStatus` AS `local_ifadminstatus`,
|
||||
`P1`.`ifInOctets_rate` AS `local_ifinoctets_rate`,
|
||||
`P1`.`ifOutOctets_rate` AS `local_ifoutoctets_rate`,
|
||||
`P2`.`port_id` AS `remote_port_id`,
|
||||
`P2`.`device_id` AS `remote_port_device_id`,
|
||||
`P2`.`ifName` AS `remote_ifname`,
|
||||
`P2`.`ifSpeed` AS `remote_ifspeed`,
|
||||
`P2`.`ifOperStatus` AS `remote_ifoperstatus`,
|
||||
`P2`.`ifAdminStatus` AS `remote_ifadminstatus`,
|
||||
`P2`.`ifInOctets_rate` AS `remote_ifinoctets_rate`,
|
||||
`P2`.`ifOutOctets_rate` AS `remote_ifoutoctets_rate`
|
||||
FROM `links`
|
||||
LEFT JOIN `devices` AS `D1` ON `D1`.`device_id`=`links`.`local_device_id`
|
||||
LEFT JOIN `devices` AS `D2` ON `D2`.`device_id`=`links`.`remote_device_id`
|
||||
LEFT JOIN `ports` AS `P1` ON `P1`.`port_id`=`links`.`local_port_id`
|
||||
LEFT JOIN `ports` AS `P2` ON `P2`.`port_id`=`links`.`remote_port_id`
|
||||
WHERE
|
||||
`active`=1
|
||||
AND `remote_device_id`!=0
|
||||
",$sql_array) as $items) {
|
||||
$local_device = array('device_id'=>$items['local_device_id'], 'os'=>$items['local_os'], 'hostname'=>$items['local_hostname']);
|
||||
$remote_device = array('device_id'=>$items['remote_device_id'], 'os'=>$items['remote_os'], 'hostname'=>$items['remote_hostname']);
|
||||
|
||||
$local_port = array('port_id'=>$items['local_port_id'],'device_id'=>$items['local_port_device_id'],'ifName'=>$items['local_ifname'],'ifSpeed'=>$items['local_ifspeed'],'ifOperStatus'=>$items['local_ifoperstatus'],'ifAdminStatus'=>$items['local_adminstatus']);
|
||||
$remote_port = array('port_id'=>$items['remote_port_id'],'device_id'=>$items['remote_port_device_id'],'ifName'=>$items['remote_ifname'],'ifSpeed'=>$items['remote_ifspeed'],'ifOperStatus'=>$items['remote_ifoperstatus'],'ifAdminStatus'=>$items['remote_adminstatus']);
|
||||
|
||||
if (!in_array($items['local_device_id'],$tmp_ids)) {
|
||||
$tmp_devices[] = array('id'=>$items['local_device_id'],'label'=>$items['local_hostname'],'title'=>generate_device_link($local_device,'',array(),'','','',0),'shape'=>'box');
|
||||
}
|
||||
if (!in_array($macs['remote_port_id'], $port_ids) && port_permitted($macs['remote_port_id'])) {
|
||||
$port_det = dbFetchRow("SELECT * FROM `ports` WHERE `port_id`=?", array($macs['remote_port_id']));
|
||||
$port_dev = dbFetchRow("SELECT * FROM `devices` WHERE `device_id`=?", array($port_det['device_id']));
|
||||
if (!in_array($port_dev['device_id'],$tmp_ids) && !in_array($port_dev['device_id'],$port_devices)) {
|
||||
$mac_devices[] = array('id'=>$port_dev['device_id'], 'label'=>$port_dev['hostname'], 'title'=>generate_device_link($port_dev,'',array(),'','','',0),'group'=>$port_dev['location'], 'shape'=>'box');
|
||||
array_push($port_ids, $port_det['port_id']);
|
||||
array_push($port_devices, $port_dev['device_id']);
|
||||
$to = $port_dev['device_id'];
|
||||
$port .= ' > ' . shorten_interface_type($port_det['ifName']);
|
||||
}
|
||||
if (!in_array($items['remote_device_id'],$tmp_ids)) {
|
||||
$tmp_devices[] = array('id'=>$items['remote_device_id'],'label'=>$items['remote_hostname'],'title'=>generate_device_link($remote_device,'',array(),'','','',0),'shape'=>'box');
|
||||
}
|
||||
$tmp_links[] = array('from'=>$from,'to'=>$to,'label'=>$port,'title'=>generate_port_link($port_data, "<img src='graph.php?type=port_bits&id=".$port_data['port_id']."&from=".$config['time']['day']."&to=".$config['time']['now']."&width=100&height=20&legend=no&bg=".str_replace("#","", $row_colour)."'>",'',0,1),'width'=>$width,'color'=>$link_color);
|
||||
unset($port);
|
||||
array_push($tmp_ids,$items['local_device_id']);
|
||||
array_push($tmp_ids,$items['remote_device_id']);
|
||||
$speed = $items['ifSpeed']/1000/1000;
|
||||
if ($speed == 100) {
|
||||
$width = 3;
|
||||
} elseif ($speed == 1000) {
|
||||
$width = 5;
|
||||
} elseif ($speed == 10000) {
|
||||
$width = 10;
|
||||
} elseif ($speed == 40000) {
|
||||
$width = 15;
|
||||
} elseif ($speed == 100000) {
|
||||
$width = 20;
|
||||
} else {
|
||||
$width = 1;
|
||||
}
|
||||
$link_in_used = ($items['local_ifinoctets_rate'] * 8) / $items['local_ifspeed'] * 100;
|
||||
$link_out_used = ($items['local_ifoutoctets_rate'] * 8) / $items['local_ifspeed'] * 100;
|
||||
if ($link_in_used > $link_out_used) {
|
||||
$link_used = $link_in_used;
|
||||
} else {
|
||||
$link_used = $link_out_used;
|
||||
}
|
||||
$link_used = round($link_used, -1);
|
||||
if ($link_used > 100) {
|
||||
$link_used = 100;
|
||||
}
|
||||
$link_color = $config['map_legend'][$link_used];
|
||||
$tmp_links[] = array('from'=>$items['local_device_id'],'to'=>$items['remote_device_id'],'label'=>shorten_interface_type($items['local_ifname']) . ' > ' . shorten_interface_type($items['remote_ifname']),'title'=>generate_port_link($local_port, "<img src='graph.php?type=port_bits&id=".$items['local_port_id']."&from=".$config['time']['day']."&to=".$config['time']['now']."&width=100&height=20&legend=no&bg=".str_replace("#","", $row_colour)."'>",'',0,1),'width'=>$width,'color'=>$link_color);
|
||||
}
|
||||
|
||||
$node_devices = array_merge($tmp_devices,$mac_devices);
|
||||
$node_devices = $tmp_devices;
|
||||
$nodes = json_encode($node_devices);
|
||||
|
||||
if (is_array($tmp_devices[0])) {
|
||||
foreach (dbFetchRows("SELECT local_device_id, remote_device_id, `remote_hostname`,`ports`.*, `remote_port` FROM `links` LEFT JOIN `ports` ON `local_port_id`=`ports`.`port_id` LEFT JOIN `devices` ON `ports`.`device_id`=`devices`.`device_id` WHERE (`local_device_id` IN ($tmp_exp_ids) AND `remote_device_id` IN ($tmp_exp_ids))") as $link_devices) {
|
||||
foreach ($tmp_devices as $k=>$v) {
|
||||
if ($v['id'] == $link_devices['local_device_id']) {
|
||||
$from = $v['id'];
|
||||
$port = shorten_interface_type($link_devices['ifName']);
|
||||
$port_data = $link_devices;
|
||||
}
|
||||
if ($v['id'] == $link_devices['remote_device_id']) {
|
||||
$to = $v['id'];
|
||||
$port .= ' > ' .shorten_interface_type($link_devices['remote_port']);
|
||||
}
|
||||
}
|
||||
$speed = $link_devices['ifSpeed']/1000/1000;
|
||||
if ($speed == 100) {
|
||||
$width = 3;
|
||||
} elseif ($speed == 1000) {
|
||||
$width = 5;
|
||||
} elseif ($speed == 10000) {
|
||||
$width = 10;
|
||||
} elseif ($speed == 40000) {
|
||||
$width = 15;
|
||||
} elseif ($speed == 100000) {
|
||||
$width = 20;
|
||||
} else {
|
||||
$width = 1;
|
||||
}
|
||||
$link_in_used = ($link_devices['ifInOctets_rate'] * 8) / $link_devices['ifSpeed'] * 100;
|
||||
$link_out_used = ($link_devices['ifOutOctets_rate'] * 8) / $link_devices['ifSpeed'] * 100;
|
||||
if ($link_in_used > $link_out_used) {
|
||||
$link_used = $link_in_used;
|
||||
} else {
|
||||
$link_used = $link_out_used;
|
||||
}
|
||||
$link_used = round($link_used, -1);
|
||||
if ($link_used > 100) {
|
||||
$link_used = 100;
|
||||
}
|
||||
$link_color = $config['map_legend'][$link_used];
|
||||
|
||||
$tmp_links[] = array('from'=>$from,'to'=>$to,'label'=>$port,'title'=>generate_port_link($port_data, "<img src='graph.php?type=port_bits&id=".$port['port_id']."&from=".$config['time']['day']."&to=".$config['time']['now']."&width=100&height=20&legend=no&bg=".str_replace("#","", $row_colour)."'>",'',0,1),'width'=>$width,'color'=>$link_color);
|
||||
}
|
||||
}
|
||||
|
||||
$edges = json_encode($tmp_links);
|
||||
|
||||
if (count($node_devices) > 1 && count($tmp_links) > 0) {
|
||||
|
||||
Reference in New Issue
Block a user