Test Failed
Push — develop ( 55b248...7d9761 )
by Tony
21:25
created

Storage::getRRDXportDefinition()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 11
nc 2
nop 0
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Storage.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\Device;
25
26
use App\Data\RRD;
27
use App\Graphs\Graph;
28
use Illuminate\Database\Query\Builder;
29
30
class Storage extends Graph
31
{
32
    protected function getRelation()
33
    {
34
        if ($this->hasIDs()) {
35
            return [
36
                'storage' => function (Builder $query) {
37
                    $query->whereIn('storage_id', $this->getIDs());
38
                },
39
            ];
40
        }
41
42
        return 'storage';
43
    }
44
45
    protected function getData()
46
    {
47
        return $this->device->storage;
48
    }
49
50
    protected function getHeaders()
51
    {
52
        $headers = [];
53
        foreach ($this->getData() as $disk) {
54
            $headers[] = RRD::escape($disk->storage_descr, 12);
55
        }
56
        return $headers;
57
    }
58
59
    protected function getRRDGraphDefinition()
60
    {
61
        // TODO: Implement getRRDGraphDefinition() method.
62
    }
63
64
    protected function getRRDXportDefinition()
65
    {
66
        $defs = '';
67
        foreach ($this->getData() as $disk) {
68
            $id = $disk->storage_id;
69
            $rrd_file = RRD::getFileName($this->device, array('storage', $disk->storage_mib, $disk->storage_descr));
70
            $defs .= "DEF:dsused$id=$rrd_file:used:AVERAGE \
71
                DEF:dsfree$id=$rrd_file:free:AVERAGE \
72
                CDEF:dssize$id=dsused$id,dsfree$id,+ \
73
                CDEF:dsperc$id=dsused$id,dssize$id,/,100,* \
74
                XPORT:dsperc$id:'".RRD::escape($disk->storage_descr, 12)."' ";
75
        }
76
        return $defs;
77
    }
78
}
79