Completed
Pull Request — master (#2676)
by Paul
27:01 queued 16:42
created

html/includes/graphs/smokeping/out.inc.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
$dest = device_by_id_cache($_GET['dest']);
4
5
// Dear Tobias. You write in Perl, this makes me hate you forever.
6
// This is my translation of Smokeping's graphing.
7
// Thanks to Bill Fenner for Perl->Human translation:>
8
$scale_min   = 0;
9
$scale_rigid = true;
10
11
require 'includes/graphs/common.inc.php';
12
require 'smokeping_common.inc.php';
13
14
$i         = 0;
15
$pings     = 20;
16
$iter      = 0;
17
$colourset = 'mixed';
18
19 View Code Duplication
if ($width > '500') {
20
    $descr_len = 18;
21
}
22
else {
23
    $descr_len = (12 + round(($width - 275) / 8));
24
}
25
26
if ($width > '500') {
27
    $rrd_options .= " COMMENT:'".substr(str_pad($unit_text, ($descr_len + 5)), 0, ($descr_len + 5))." RTT      Loss    SDev   RTT\:SDev                              \l'";
28
}
29
else {
30
    $rrd_options .= " COMMENT:'".substr(str_pad($unit_text, ($descr_len + 5)), 0, ($descr_len + 5))." RTT      Loss    SDev   RTT\:SDev                              \l'";
31
}
32
33
if ($device['hostname'] == $config['own_hostname']) {
34
    $filename = $config['smokeping']['dir'].$dest['hostname'].'.rrd';
35 View Code Duplication
    if (!file_exists($filename)) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
36
        // Try with dots in hostname replaced by underscores
37
        $filename = $config['smokeping']['dir'].str_replace('.', '_', $dest['hostname']).'.rrd';
38
    }
39
}
40
else {
41
    $filename = $config['smokeping']['dir'].$dest['hostname'].'~'.$device['hostname'].'.rrd';
42 View Code Duplication
    if (!file_exists($filename)) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
43
        // Try with dots in hostname replaced by underscores
44
        $filename = $config['smokeping']['dir'].str_replace('.', '_', $dest['hostname']).'~'.$device['hostname'].'.rrd';
45
    }
46
}
47
48
if (!isset($config['graph_colours'][$colourset][$iter])) {
49
    $iter = 0;
50
}
51
52
  $colour = $config['graph_colours'][$colourset][$iter];
53
  $iter++;
54
55
  $descr = rrdtool_escape($source, $descr_len);
56
57
  $rrd_options .= " DEF:median$i=".$filename.':median:AVERAGE ';
58
  $rrd_options .= " DEF:loss$i=".$filename.':loss:AVERAGE';
59
  $rrd_options .= " CDEF:ploss$i=loss$i,$pings,/,100,*";
60
  $rrd_options .= " CDEF:dm$i=median$i";
61
// $rrd_options .= " CDEF:dm$i=median$i,0,".$max->{$start}.",LIMIT";
62
  // start emulate Smokeping::calc_stddev
63 View Code Duplication
foreach (range(1, $pings) as $p) {
64
    $rrd_options .= ' DEF:pin'.$i.'p'.$p.'='.$filename.':ping'.$p.':AVERAGE';
65
    $rrd_options .= ' CDEF:p'.$i.'p'.$p.'=pin'.$i.'p'.$p.',UN,0,pin'.$i.'p'.$p.',IF';
66
}
67
68
  unset($pings_options, $m_options, $sdev_options);
69
70 View Code Duplication
foreach (range(2, $pings) as $p) {
71
    $pings_options .= ',p'.$i.'p'.$p.',UN,+';
72
    $m_options     .= ',p'.$i.'p'.$p.',+';
73
    $sdev_options  .= ',p'.$i.'p'.$p.',m'.$i.',-,DUP,*,+';
74
}
75
76
  $rrd_options .= ' CDEF:pings'.$i.'='.$pings.',p'.$i.'p1,UN'.$pings_options.',-';
77
  $rrd_options .= ' CDEF:m'.$i.'=p'.$i.'p1'.$m_options.',pings'.$i.',/';
78
  $rrd_options .= ' CDEF:sdev'.$i.'=p'.$i.'p1,m'.$i.',-,DUP,*'.$sdev_options.',pings'.$i.',/,SQRT';
79
  // end emulate Smokeping::calc_stddev
80
  $rrd_options .= " CDEF:dmlow$i=dm$i,sdev$i,2,/,-";
81
  $rrd_options .= " CDEF:s2d$i=sdev$i";
82
  $rrd_options .= " AREA:dmlow$i";
83
  $rrd_options .= " AREA:s2d$i#".$colour.'30::STACK';
84
  $rrd_options .= " LINE1:dm$i#".$colour.":'$descr'";
85
86
// $rrd_options .= " LINE1:sdev$i#000000:$descr";
87
  $rrd_options .= " VDEF:avmed$i=median$i,AVERAGE";
88
  $rrd_options .= " VDEF:avsd$i=sdev$i,AVERAGE";
89
  $rrd_options .= " CDEF:msr$i=median$i,POP,avmed$i,avsd$i,/";
90
  $rrd_options .= " VDEF:avmsr$i=msr$i,AVERAGE";
91
92
  $rrd_options .= " GPRINT:avmed$i:'%5.1lf%ss'";
93
  $rrd_options .= " GPRINT:ploss$i:AVERAGE:'%5.1lf%%'";
94
95
  $rrd_options .= " GPRINT:avsd$i:'%5.1lf%Ss'";
96
  $rrd_options .= " GPRINT:avmsr$i:'%5.1lf%s\\l'";
97
98
  $i++;
99