Completed
Pull Request — develop (#184)
by Neil
25:03
created

Device_storage::buildRRDXport()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 31
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 22
nc 4
nop 1
dl 0
loc 31
rs 8.5806
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 Illuminate\Http\Request;
27
use App\Models\Device;
28
use Settings;
29
30
class Device_storage 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...
31
{
32
33
    public function buildRRDGraphParams($input) {
0 ignored issues
show
Unused Code introduced by
The parameter $input is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
34
        //FIXME Add support for PNG Graph
35
        return [
36
            'headers' => '',
37
            'defs' => '',
38
        ];
39
    }
40
41
    public function buildRRDXport($input)
42
    {
43
        $device_id = $input->{'device_id'};
44
        $device = Device::find($device_id);
45
46
        if (isset($input->id) && is_numeric($input->id)) {
47
            $disk_ids = explode(',', $input->id);
48
            $disks = $device->storage()->whereIn('storage_id', $disk_ids)->get();
49
        } else {
50
            $disks = $device->storage()->get();
51
        }
52
53
        $headers = [];
54
        $defs = '';
55
56
        foreach ($disks as $disk) {
57
            $id = $disk->storage_id;
58
            $descr = rrdtool_escape($disk->storage_descr, 12);
59
            $headers[] = $descr;
60
            $defs .= "DEF:dsused$id=" . rrd_name($device, array('storage', $disk->storage_mib, $disk->storage_descr)) . ":used:AVERAGE \
61
                DEF:dsfree$id=" . rrd_name($device, array('storage', $disk->storage_mib, $disk->storage_descr)) . ":free:AVERAGE \
62
                CDEF:dssize$id=dsused$id,dsfree$id,+ \
63
                CDEF:dsperc$id=dsused$id,dssize$id,/,100,* \
64
                XPORT:dsperc$id:'$descr' ";
65
        }
66
67
        return [
68
            'headers' => $headers,
69
            'defs' => $defs,
70
        ];
71
    }
72
}
73