From 4d78a0261e8417cc2c6c7f1a235feac57151ed73 Mon Sep 17 00:00:00 2001 From: Maximilian Wilhelm Date: Thu, 21 Jan 2016 22:04:33 +0100 Subject: [PATCH] Update graph and port pages to use new RRD naming schema. Signed-off-by: Maximilian Wilhelm --- html/includes/graphs/bill/bits.inc.php | 5 ++-- html/includes/graphs/customer/bits.inc.php | 5 ++-- html/includes/graphs/device/bits.inc.php | 2 +- html/includes/graphs/global/bits.inc.php | 2 +- html/includes/graphs/location/bits.inc.php | 5 ++-- html/includes/graphs/multiport/bits.inc.php | 7 ++--- .../graphs/multiport/bits_duo.inc.php | 18 +++++++------ .../graphs/multiport/bits_separate.inc.php | 5 ++-- .../graphs/multiport/bits_trio.inc.php | 27 ++++++++++--------- .../graphs/port/adsl_attainable.inc.php | 2 +- .../graphs/port/adsl_attenuation.inc.php | 2 +- html/includes/graphs/port/adsl_power.inc.php | 2 +- html/includes/graphs/port/adsl_snr.inc.php | 2 +- html/includes/graphs/port/adsl_speed.inc.php | 2 +- html/includes/graphs/port/auth.inc.php | 2 +- html/includes/graphs/port/etherlike.inc.php | 2 +- html/includes/graphs/port/nupkts.inc.php | 12 +++++---- html/includes/graphs/port/pagp_bits.inc.php | 5 ++-- html/includes/print-interface.inc.php | 4 +-- html/pages/device/port/adsl.inc.php | 2 +- html/pages/device/port/graphs.inc.php | 4 +-- html/pages/iftype.inc.php | 2 +- 22 files changed, 65 insertions(+), 54 deletions(-) diff --git a/html/includes/graphs/bill/bits.inc.php b/html/includes/graphs/bill/bits.inc.php index 2e80ef792..266fa86a2 100644 --- a/html/includes/graphs/bill/bits.inc.php +++ b/html/includes/graphs/bill/bits.inc.php @@ -4,8 +4,9 @@ $i = 0; foreach ($ports as $port) { - if (is_file($config['rrd_dir'].'/'.$port['hostname'].'/port-'.safename($port['ifIndex'].'.rrd'))) { - $rrd_list[$i]['filename'] = $config['rrd_dir'].'/'.$port['hostname'].'/port-'.safename($port['ifIndex'].'.rrd'); + $rrd_file = get_port_rrdfile_path ($port['hostname'], $port['port_id']); + if (is_file($rrd_file)) { + $rrd_list[$i]['filename'] = $rrd_file; $rrd_list[$i]['descr'] = $port['ifDescr']; $i++; } diff --git a/html/includes/graphs/customer/bits.inc.php b/html/includes/graphs/customer/bits.inc.php index f66f91df0..ee3d4a741 100644 --- a/html/includes/graphs/customer/bits.inc.php +++ b/html/includes/graphs/customer/bits.inc.php @@ -10,8 +10,8 @@ if (!is_array($config['customers_descr'])) { $descr_type = "'".implode("', '", $config['customers_descr'])."'"; foreach (dbFetchRows('SELECT * FROM `ports` AS I, `devices` AS D WHERE `port_descr_type` IN (?) AND `port_descr_descr` = ? AND D.device_id = I.device_id', array(array($descr_type), $vars['id'])) as $port) { - if (is_file($config['rrd_dir'].'/'.$port['hostname'].'/port-'.safename($port['ifIndex'].'.rrd'))) { - $rrd_filename = $config['rrd_dir'].'/'.$port['hostname'].'/port-'.safename($port['ifIndex'].'.rrd'); + $rrd_filename = get_port_rrdfile_path ($port['hostname'], $port['port_id']); // FIXME: Unification OK? + if (is_file($rrd_filename)) { $rrd_list[$i]['filename'] = $rrd_filename; $rrd_list[$i]['descr'] = $port['hostname'].'-'.$port['ifDescr']; $rrd_list[$i]['descr_in'] = shorthost($port['hostname']); @@ -20,7 +20,6 @@ foreach (dbFetchRows('SELECT * FROM `ports` AS I, `devices` AS D WHERE `port_des } } -// echo($config['rrd_dir'] . "/" . $port['hostname'] . "/port-" . safename($port['ifIndex'] . ".rrd")); $units = 'bps'; $total_units = 'B'; $colours_in = 'greens'; diff --git a/html/includes/graphs/device/bits.inc.php b/html/includes/graphs/device/bits.inc.php index eaeed92f4..f796490f2 100644 --- a/html/includes/graphs/device/bits.inc.php +++ b/html/includes/graphs/device/bits.inc.php @@ -22,7 +22,7 @@ foreach (dbFetchRows('SELECT * FROM `ports` WHERE `device_id` = ?', array($devic } } - $rrd_filename = $config['rrd_dir'].'/'.$device['hostname'].'/port-'.safename($port['ifIndex'].'.rrd'); + $rrd_filename = get_port_rrdfile_path ($device['hostname'], $port['port_id']); if ($ignore != 1 && is_file($rrd_filename)) { $port = ifLabel($port); // Fix Labels! ARGH. This needs to be in the bloody database! diff --git a/html/includes/graphs/global/bits.inc.php b/html/includes/graphs/global/bits.inc.php index 763a9d103..350d96f87 100644 --- a/html/includes/graphs/global/bits.inc.php +++ b/html/includes/graphs/global/bits.inc.php @@ -21,7 +21,7 @@ foreach (dbFetchRows('SELECT * FROM `ports` AS P, `devices` AS D WHERE D.device_ } } - $rrd_filename = $config['rrd_dir'].'/'.$port['hostname'].'/port-'.safename($port['ifIndex'].'.rrd'); + $rrd_filename = get_port_rrdfile_path ($port['hostname'], $port['port_id']); if (!$ignore && $i < 1100 && is_file($rrd_filename)) { $rrd_filenames[] = $rrd_filename; $rrd_list[$i]['filename'] = $rrd_filename; diff --git a/html/includes/graphs/location/bits.inc.php b/html/includes/graphs/location/bits.inc.php index 53b0a656e..7f77108a9 100644 --- a/html/includes/graphs/location/bits.inc.php +++ b/html/includes/graphs/location/bits.inc.php @@ -24,8 +24,9 @@ foreach ($devices as $device) { } } - if (is_file($config['rrd_dir'].'/'.$device['hostname'].'/port-'.safename($int['ifIndex'].'.rrd')) && $ignore != 1) { - $rrd_filename = $config['rrd_dir'].'/'.$device['hostname'].'/port-'.safename($int['ifIndex'].'.rrd'); + $rrd_file = get_port_rrdfile_path ($device['hostname'], $int['port_id']); + if (is_file($rrd_file) && $ignore != 1) { + $rrd_filename = $rrd_file; // FIXME: Can this be unified without side-effects? $rrd_list[$i]['filename'] = $rrd_filename; $rrd_list[$i]['descr'] = $port['label']; $rrd_list[$i]['descr_in'] = $device['hostname']; diff --git a/html/includes/graphs/multiport/bits.inc.php b/html/includes/graphs/multiport/bits.inc.php index de3206c23..e64e39b31 100644 --- a/html/includes/graphs/multiport/bits.inc.php +++ b/html/includes/graphs/multiport/bits.inc.php @@ -8,9 +8,10 @@ foreach (explode(',', $vars['id']) as $ifid) { $ifid = str_replace('!', '', $ifid); } - $int = dbFetchRow('SELECT `ifIndex`, `hostname` FROM `ports` AS I, devices as D WHERE I.port_id = ? AND I.device_id = D.device_id', array($ifid)); - if (is_file($config['rrd_dir'].'/'.$int['hostname'].'/port-'.safename($int['ifIndex'].'.rrd'))) { - $rrd_filenames[$i] = $config['rrd_dir'].'/'.$int['hostname'].'/port-'.safename($int['ifIndex'].'.rrd'); + $int = dbFetchRow('SELECT `hostname` FROM `ports` AS I, devices as D WHERE I.port_id = ? AND I.device_id = D.device_id', array($ifid)); + $rrd_file = get_port_rrdfile_path ($int['hostname'], $ifid); + if (is_file($rrd_file)) { + $rrd_filenames[$i] = $rrd_file; $i++; } } diff --git a/html/includes/graphs/multiport/bits_duo.inc.php b/html/includes/graphs/multiport/bits_duo.inc.php index 205ca3834..cc9892dde 100644 --- a/html/includes/graphs/multiport/bits_duo.inc.php +++ b/html/includes/graphs/multiport/bits_duo.inc.php @@ -13,10 +13,11 @@ if ($height < '99') { $i = 1; foreach (explode(',', $_GET['id']) as $ifid) { - $int = dbFetchRow('SELECT `ifIndex`, `hostname` FROM `ports` AS I, devices as D WHERE I.port_id = ? AND I.device_id = D.device_id', array($ifid)); - if (is_file($config['rrd_dir'].'/'.$int['hostname'].'/port-'.$int['ifIndex'].'.rrd')) { - $rrd_options .= ' DEF:inoctets'.$i.'='.$config['rrd_dir'].'/'.$int['hostname'].'/port-'.$int['ifIndex'].'.rrd:INOCTETS:AVERAGE'; - $rrd_options .= ' DEF:outoctets'.$i.'='.$config['rrd_dir'].'/'.$int['hostname'].'/port-'.$int['ifIndex'].'.rrd:OUTOCTETS:AVERAGE'; + $int = dbFetchRow('SELECT `hostname` FROM `ports` AS I, devices as D WHERE I.port_id = ? AND I.device_id = D.device_id', array($ifid)); + $rrd_file = get_port_rrdfile_path ($int['hostname'], $ifid); + if (is_file($rrd_file)) { + $rrd_options .= ' DEF:inoctets'.$i.'='.$rrd_file.':INOCTETS:AVERAGE'; + $rrd_options .= ' DEF:outoctets'.$i.'='.$rrd_file.':OUTOCTETS:AVERAGE'; $in_thing .= $seperator.'inoctets'.$i.',UN,0,'.'inoctets'.$i.',IF'; $out_thing .= $seperator.'outoctets'.$i.',UN,0,'.'outoctets'.$i.',IF'; $pluses .= $plus; @@ -30,10 +31,11 @@ unset($seperator); unset($plus); foreach (explode(',', $_GET['idb']) as $ifid) { - $int = dbFetchRow('SELECT `ifIndex`, `hostname` FROM `ports` AS I, devices as D WHERE I.port_id = ? AND I.device_id = D.device_id', array($ifid)); - if (is_file($config['rrd_dir'].'/'.$int['hostname'].'/port-'.$int['ifIndex'].'.rrd')) { - $rrd_options .= ' DEF:inoctetsb'.$i.'='.$config['rrd_dir'].'/'.$int['hostname'].'/port-'.$int['ifIndex'].'.rrd:INOCTETS:AVERAGE'; - $rrd_options .= ' DEF:outoctetsb'.$i.'='.$config['rrd_dir'].'/'.$int['hostname'].'/port-'.$int['ifIndex'].'.rrd:OUTOCTETS:AVERAGE'; + $int = dbFetchRow('SELECT `hostname` FROM `ports` AS I, devices as D WHERE I.port_id = ? AND I.device_id = D.device_id', array($ifid)); + $rrd_file = get_port_rrdfile_path ($int['hostname'], $ifid); + if (is_file($rrd_file)) { + $rrd_options .= ' DEF:inoctetsb'.$i.'='.$rrd_file.':INOCTETS:AVERAGE'; + $rrd_options .= ' DEF:outoctetsb'.$i.'='.$rrd_file.':OUTOCTETS:AVERAGE'; $in_thingb .= $seperator.'inoctetsb'.$i.',UN,0,'.'inoctetsb'.$i.',IF'; $out_thingb .= $seperator.'outoctetsb'.$i.',UN,0,'.'outoctetsb'.$i.',IF'; $plusesb .= $plus; diff --git a/html/includes/graphs/multiport/bits_separate.inc.php b/html/includes/graphs/multiport/bits_separate.inc.php index d54259d02..980386286 100644 --- a/html/includes/graphs/multiport/bits_separate.inc.php +++ b/html/includes/graphs/multiport/bits_separate.inc.php @@ -4,9 +4,10 @@ $i = 0; foreach (explode(',', $vars['id']) as $ifid) { $port = dbFetchRow('SELECT * FROM `ports` AS I, devices as D WHERE I.port_id = ? AND I.device_id = D.device_id', array($ifid)); - if (is_file($config['rrd_dir'].'/'.$port['hostname'].'/port-'.safename($port['ifIndex'].'.rrd'))) { + $rrd_file = get_port_rrdfile_path ($port['hostname'], $ifid); + if (is_file($rrd_file)) { $port = ifLabel($port); - $rrd_list[$i]['filename'] = $config['rrd_dir'].'/'.$port['hostname'].'/port-'.safename($port['ifIndex'].'.rrd'); + $rrd_list[$i]['filename'] = $rrd_file; $rrd_list[$i]['descr'] = $port['hostname'].' '.$port['ifDescr']; $rrd_list[$i]['descr_in'] = $port['hostname']; $rrd_list[$i]['descr_out'] = makeshortif($port['label']); diff --git a/html/includes/graphs/multiport/bits_trio.inc.php b/html/includes/graphs/multiport/bits_trio.inc.php index a1112a677..563ae1b9b 100644 --- a/html/includes/graphs/multiport/bits_trio.inc.php +++ b/html/includes/graphs/multiport/bits_trio.inc.php @@ -14,8 +14,9 @@ if ($height < '99') { $i = 1; foreach (explode(',', $_GET['id']) as $ifid) { - $int = dbFetchRow('SELECT `ifIndex`, `hostname` FROM `ports` AS I, devices as D WHERE I.port_id = ? AND I.device_id = D.device_id', array($ifid)); - if (is_file($config['rrd_dir'].'/'.$int['hostname'].'/port-'.$int['ifIndex'].'.rrd')) { + $int = dbFetchRow('SELECT `hostname` FROM `ports` AS I, devices as D WHERE I.port_id = ? AND I.device_id = D.device_id', array($ifid)); + $rrd_file = get_port_rrdfile_path ($int['hostname'], $ifid); + if (is_file($rrd_file)) { if (strstr($inverse, 'a')) { $in = 'OUT'; $out = 'IN'; @@ -25,8 +26,8 @@ foreach (explode(',', $_GET['id']) as $ifid) { $out = 'OUT'; } - $rrd_options .= ' DEF:inoctets'.$i.'='.$config['rrd_dir'].'/'.$int['hostname'].'/port-'.$int['ifIndex'].'.rrd:'.$in.'OCTETS:AVERAGE'; - $rrd_options .= ' DEF:outoctets'.$i.'='.$config['rrd_dir'].'/'.$int['hostname'].'/port-'.$int['ifIndex'].'.rrd:'.$out.'OCTETS:AVERAGE'; + $rrd_options .= ' DEF:inoctets'.$i.'='.$rrd_file.':'.$in.'OCTETS:AVERAGE'; + $rrd_options .= ' DEF:outoctets'.$i.'='.$rrd_file.':'.$out.'OCTETS:AVERAGE'; $in_thing .= $seperator.'inoctets'.$i.',UN,0,'.'inoctets'.$i.',IF'; $out_thing .= $seperator.'outoctets'.$i.',UN,0,'.'outoctets'.$i.',IF'; $pluses .= $plus; @@ -40,8 +41,9 @@ unset($seperator); unset($plus); foreach (explode(',', $_GET['idb']) as $ifid) { - $int = dbFetchRow('SELECT `ifIndex`, `hostname` FROM `ports` AS I, devices as D WHERE I.port_id = ? AND I.device_id = D.device_id', array($ifid)); - if (is_file($config['rrd_dir'].'/'.$int['hostname'].'/port-'.$int['ifIndex'].'.rrd')) { + $int = dbFetchRow('SELECT `hostname` FROM `ports` AS I, devices as D WHERE I.port_id = ? AND I.device_id = D.device_id', array($ifid)); + $rrd_file = get_port_rrdfile_path ($int['hostname'], $ifid); + if (is_file($rrd_file)) { if (strstr($inverse, 'b')) { $in = 'OUT'; $out = 'IN'; @@ -51,8 +53,8 @@ foreach (explode(',', $_GET['idb']) as $ifid) { $out = 'OUT'; } - $rrd_options .= ' DEF:inoctetsb'.$i.'='.$config['rrd_dir'].'/'.$int['hostname'].'/port-'.$int['ifIndex'].'.rrd:'.$in.'OCTETS:AVERAGE'; - $rrd_options .= ' DEF:outoctetsb'.$i.'='.$config['rrd_dir'].'/'.$int['hostname'].'/port-'.$int['ifIndex'].'.rrd:'.$out.'OCTETS:AVERAGE'; + $rrd_options .= ' DEF:inoctetsb'.$i.'='.$rrd_file.':'.$in.'OCTETS:AVERAGE'; + $rrd_options .= ' DEF:outoctetsb'.$i.'='.$rrd_file.':'.$out.'OCTETS:AVERAGE'; $in_thingb .= $seperator.'inoctetsb'.$i.',UN,0,'.'inoctetsb'.$i.',IF'; $out_thingb .= $seperator.'outoctetsb'.$i.',UN,0,'.'outoctetsb'.$i.',IF'; $plusesb .= $plus; @@ -66,8 +68,9 @@ unset($seperator); unset($plus); foreach (explode(',', $_GET['idc']) as $ifid) { - $int = dbFetchRow('SELECT `ifIndex`, `hostname` FROM `ports` AS I, devices as D WHERE I.port_id = ? AND I.device_id = D.device_id', array($ifid)); - if (is_file($config['rrd_dir'].'/'.$int['hostname'].'/port-'.$int['ifIndex'].'.rrd')) { + $int = dbFetchRow('SELECT `hostname` FROM `ports` AS I, devices as D WHERE I.port_id = ? AND I.device_id = D.device_id', array($ifid)); + $rrd_file = get_port_rrdfile_path ($int['hostname'], $ifid); + if (is_file($rrd_file)) { if (strstr($inverse, 'c')) { $in = 'OUT'; $out = 'IN'; @@ -77,8 +80,8 @@ foreach (explode(',', $_GET['idc']) as $ifid) { $out = 'OUT'; } - $rrd_options .= ' DEF:inoctetsc'.$i.'='.$config['rrd_dir'].'/'.$int['hostname'].'/port-'.$int['ifIndex'].'.rrd:'.$in.'OCTETS:AVERAGE'; - $rrd_options .= ' DEF:outoctetsc'.$i.'='.$config['rrd_dir'].'/'.$int['hostname'].'/port-'.$int['ifIndex'].'.rrd:'.$out.'OCTETS:AVERAGE'; + $rrd_options .= ' DEF:inoctetsc'.$i.'='.$rrd_file.':'.$in.'OCTETS:AVERAGE'; + $rrd_options .= ' DEF:outoctetsc'.$i.'='.$rrd_file.':'.$out.'OCTETS:AVERAGE'; $in_thingc .= $seperator.'inoctetsc'.$i.',UN,0,'.'inoctetsc'.$i.',IF'; $out_thingc .= $seperator.'outoctetsc'.$i.',UN,0,'.'outoctetsc'.$i.',IF'; $plusesc .= $plus; diff --git a/html/includes/graphs/port/adsl_attainable.inc.php b/html/includes/graphs/port/adsl_attainable.inc.php index ad84314a0..7f2e2f33a 100644 --- a/html/includes/graphs/port/adsl_attainable.inc.php +++ b/html/includes/graphs/port/adsl_attainable.inc.php @@ -1,6 +1,6 @@ '; // If we're showing graphs, generate the graph and print the img tags if ($graph_type == 'etherlike') { - $graph_file = $config['rrd_dir'].'/'.$device['hostname'].'/port-'.safename($port['ifIndex']).'-dot3.rrd'; + $graph_file = get_port_rrdfile_path ($device['hostname'], $if_id, 'dot3'); } else { - $graph_file = $config['rrd_dir'].'/'.$device['hostname'].'/port-'.safename($port['ifIndex']).'.rrd'; + $graph_file = get_port_rrdfile_path ($device['hostname'], $if_id); } if ($graph_type && is_file($graph_file)) { diff --git a/html/pages/device/port/adsl.inc.php b/html/pages/device/port/adsl.inc.php index 170f2a2c5..b9230ccfb 100644 --- a/html/pages/device/port/adsl.inc.php +++ b/html/pages/device/port/adsl.inc.php @@ -1,6 +1,6 @@ ADSL Line Speed'; $graph_type = 'port_adsl_speed'; diff --git a/html/pages/device/port/graphs.inc.php b/html/pages/device/port/graphs.inc.php index e56f24bf3..64fdde60a 100644 --- a/html/pages/device/port/graphs.inc.php +++ b/html/pages/device/port/graphs.inc.php @@ -1,6 +1,6 @@
@@ -41,7 +41,7 @@ if (file_exists($config['rrd_dir'].'/'.$device['hostname'].'/port-'.$port['ifInd include 'includes/print-interface-graphs.inc.php'; echo '
'; - if (is_file($config['rrd_dir'].'/'.$device['hostname'].'/port-'.$port['ifIndex'].'-dot3.rrd')) { + if (is_file(get_port_rrdfile_path ($device['hostname'], $port['port_id'], 'dot3'))) { echo '

Ethernet Errors

diff --git a/html/pages/iftype.inc.php b/html/pages/iftype.inc.php index 05cfa2217..266b98fb6 100644 --- a/html/pages/iftype.inc.php +++ b/html/pages/iftype.inc.php @@ -94,7 +94,7 @@ if ($if_list) { echo '
'; - if (file_exists($config['rrd_dir'].'/'.$port['hostname'].'/port-'.$port['ifIndex'].'.rrd')) { + if (file_exists(get_port_rrdfile_path ($port['hostname'], $port['port_id']))) { $graph_type = 'port_bits'; include 'includes/print-interface-graphs.inc.php';