mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Added functions to shorten code
This commit is contained in:
@@ -38,11 +38,8 @@ foreach ($smokeping_files[$direction][$device['hostname']] as $source => $filena
|
||||
|
||||
$descr = rrdtool_escape($source, $descr_len);
|
||||
|
||||
if ($config['smokeping']['integration'] === true) {
|
||||
$filename = $config['smokeping']['dir'] .'/'. $device['type'] .'/'. $filename;
|
||||
} else {
|
||||
$filename = $config['smokeping']['dir'] . $filename;
|
||||
}
|
||||
$filename = generate_smokeping_file($device,$filename);
|
||||
|
||||
$rrd_options .= " DEF:median$i=".$filename.":median:AVERAGE ";
|
||||
$rrd_options .= " DEF:loss$i=".$filename.":loss:AVERAGE";
|
||||
$rrd_options .= " CDEF:ploss$i=loss$i,$pings,/,100,*";
|
||||
|
@@ -39,11 +39,8 @@ foreach ($smokeping_files[$direction][$device['hostname']] as $source => $filena
|
||||
|
||||
$descr = rrdtool_escape($source, $descr_len);
|
||||
|
||||
if ($config['smokeping']['integration'] === true) {
|
||||
$filename = $config['smokeping']['dir'] .'/'. $device['type'] .'/'. $filename;
|
||||
} else {
|
||||
$filename = $config['smokeping']['dir'] . $filename;
|
||||
}
|
||||
$filename = generate_smokeping_file($device,$filename);
|
||||
|
||||
$rrd_options .= " DEF:median$i=".$filename.":median:AVERAGE ";
|
||||
$rrd_options .= " CDEF:dm$i=median$i,UN,0,median$i,IF";
|
||||
$rrd_options .= " DEF:loss$i=".$filename.":loss:AVERAGE";
|
||||
|
@@ -33,11 +33,7 @@ if($width > "500")
|
||||
|
||||
if($src['hostname'] == $config['own_hostname'])
|
||||
{
|
||||
if ($config['smokeping']['integration'] === true) {
|
||||
$filename_dir = $config['smokeping']['dir'] .'/'. $device['type'] .'/';
|
||||
} else {
|
||||
$filename_dir = $config['smokeping']['dir'];
|
||||
}
|
||||
$filename_dir = generate_smokeping_dir($device);
|
||||
if (!file_exists($filename_dir.$device['hostname'].'.rrd'))
|
||||
{
|
||||
// Try with dots in hostname replaced by underscores
|
||||
|
@@ -751,11 +751,7 @@ function get_smokeping_files($device) {
|
||||
global $config;
|
||||
if (isset($config['smokeping']['dir'])) {
|
||||
$smokeping_files = array();
|
||||
if ($config['smokeping']['integration'] === true) {
|
||||
$smokeping_dir = $config['smokeping']['dir'] . "/" . $device['type'];
|
||||
} else {
|
||||
$smokeping_dir = $config['smokeping']['dir'];
|
||||
}
|
||||
$filename_dir = generate_smokeping_dir($device);
|
||||
if ($handle = opendir($smokeping_dir)) {
|
||||
while (false !== ($file = readdir($handle))) {
|
||||
if ($file != "." && $file != "..") {
|
||||
@@ -778,3 +774,22 @@ function get_smokeping_files($device) {
|
||||
}
|
||||
return $smokeping_files;
|
||||
}
|
||||
|
||||
function generate_smokeping_file($device,$file) {
|
||||
global $config;
|
||||
if ($config['smokeping']['integration'] === true) {
|
||||
return $config['smokeping']['dir'] .'/'. $device['type'] .'/'. $file;
|
||||
} else {
|
||||
return $config['smokeping']['dir'] . $file;
|
||||
}
|
||||
}
|
||||
|
||||
function generate_smokeping_dir($device) {
|
||||
global $config;
|
||||
if ($config['smokeping']['integration'] === true) {
|
||||
return $config['smokeping']['dir'] .'/'. $device['type'] .'/';
|
||||
} else {
|
||||
return $config['smokeping']['dir'];
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user