Completed
Pull Request — develop (#184)
by Tony
32:16
created

Device_bits::getHeaders()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 0
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
2
/**
3
 * BaseGraph.php
4
 *
5
 * This program is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 *
18
 * @package    LibreNMS
19
 * @link       http://librenms.org
20
 * @copyright  2016 Neil Lathwood
21
 * @author     Neil Lathwood <[email protected]>
22
 */
23
24
namespace App\Graphs;
25
26
use App\Data\RRD;
27
use Illuminate\Database\Query\Builder;
28
29
class Device_bits extends BaseGraph
0 ignored issues
show
Coding Style introduced by
This class is not in CamelCase format.

Classes in PHP are usually named in CamelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. The whole name starts with a capital letter as well.

Thus the name database provider becomes DatabaseProvider.

Loading history...
30
{
31
    protected function getRelation()
32
    {
33
        if ($this->hasIDs()) {
34
            return [
35
                'ports' => function (Builder $query) {
36
                    $query->whereIn('port_id', $this->getIDs());
37
                },
38
            ];
39
        }
40
41
        return 'ports';
42
    }
43
44
    protected function getData()
45
    {
46
        return $this->device->ports;
47
    }
48
49
    protected function getHeaders()
50
    {
51
        $headers = [];
52
        foreach ($this->getData() as $port) {
53
            $headers[] = 'In: '.$port['ifDescr'];
54
            $headers[] = 'Out: '.$port['ifDescr'];
55
        }
56
        return $headers;
57
    }
58
59
    protected function getRRDGraphDefinition()
60
    {
61
        $defs = " COMMENT:'              Now       Avg      Max' COMMENT:' \\n' ";
62
63
        foreach ($this->getData() as $port) {
64
            $port_id = $port->port_id;
65
            $rrd_file = RRD::getPortFileName($this->device, $port->port_id);
66
            $defs .= " DEF:outoctets$port_id=$rrd_file:OUTOCTETS:AVERAGE \
67
                DEF:inoctets$port_id=$rrd_file:INOCTETS:AVERAGE \
68
                DEF:outoctets_max$port_id=$rrd_file:OUTOCTETS:MAX \
69
                DEF:inoctets_max$port_id=$rrd_file:INOCTETS:MAX \
70
                CDEF:octets$port_id=inoctets$port_id,outoctets$port_id,+ \
71
                CDEF:doutoctets$port_id=outoctets$port_id,-1,* \
72
                CDEF:outbits$port_id=outoctets$port_id,8,* \
73
                CDEF:outbits_max$port_id=outoctets_max$port_id,8,* \
74
                CDEF:doutoctets_max$port_id=outoctets_max$port_id,-1,* \
75
                CDEF:doutbits$port_id=doutoctets$port_id,8,* \
76
                CDEF:doutbits_max$port_id=doutoctets_max$port_id,8,* \
77
                CDEF:inbits$port_id=inoctets$port_id,8,* \
78
                CDEF:inbits_max$port_id=inoctets_max$port_id,8,* \
79
                VDEF:totin$port_id=inoctets$port_id,TOTAL \
80
                VDEF:totout$port_id=outoctets$port_id,TOTAL \
81
                VDEF:tot$port_id=octets$port_id,TOTAL COMMENT:' \\n' \
82
                VDEF:95thin$port_id=inbits$port_id,95,PERCENT \
83
                VDEF:95thout$port_id=outbits$port_id,95,PERCENT \
84
                CDEF:d95thoutn$port_id=doutbits$port_id,-1,* \
85
                VDEF:d95thoutn95$port_id=d95thoutn$port_id,95,PERCENT \
86
                CDEF:d95thoutn95n$port_id=doutbits$port_id,doutbits$port_id,-,d95thoutn95$port_id,-1,*,+ \
87
                VDEF:d95thout$port_id=d95thoutn95n$port_id,FIRST  \
88
                AREA:inbits_max$port_id#D7FFC7: \
89
                AREA:inbits$port_id#90B040: \
90
                LINE:inbits$port_id#608720:'In ".str_pad($port['ifDescr'], 6)."' \
91
                GPRINT:inbits$port_id:LAST:%6.2lf%s \
92
                GPRINT:inbits$port_id:AVERAGE:%6.2lf%s \
93
                GPRINT:inbits_max$port_id:MAX:%6.2lf%s \
94
                AREA:doutbits_max$port_id#E0E0FF: \
95
                AREA:doutbits$port_id#8080C0:  COMMENT:' \\n' \
96
                LINE:doutbits$port_id#606090:'Out ' \
97
                GPRINT:outbits$port_id:LAST:%6.2lf%s \
98
                GPRINT:outbits$port_id:AVERAGE:%6.2lf%s \
99
                GPRINT:outbits_max$port_id:MAX:%6.2lf%s COMMENT:'\n' \
100
                LINE1:95thin$port_id#aa0000 \
101
                LINE1:d95thout$port_id#aa0000";
102
        }
103
        return $defs;
104
    }
105
106
    protected function getRRDXportDefinition()
107
    {
108
        $defs = '';
109
        foreach ($this->getData() as $port) {
110
            $port_id = $port->port_id;
111
            $rrd_file = get_port_rrdfile_path($this->device, $port->port_id);
112
            $defs .= "DEF:outoctets$port_id=$rrd_file:OUTOCTETS:AVERAGE \
113
                DEF:inoctets$port_id=$rrd_file:INOCTETS:AVERAGE \
114
                CDEF:doutoctets$port_id=outoctets$port_id,-1,* \
115
                CDEF:doutbits$port_id=doutoctets$port_id,8,* \
116
                CDEF:inbits$port_id=inoctets$port_id,8,* \
117
                XPORT:inbits$port_id:'In' \
118
                XPORT:doutbits$port_id:'Out' ";
119
        }
120
        return $defs;
121
    }
122
}
123