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

Device_processor::buildRRDXport()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 30
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 21
nc 4
nop 1
dl 0
loc 30
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 App\Models\Processor;
29
use Settings;
30
31
class Device_processor 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...
32
{
33
34
    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...
35
        //FIXME Add support for PNG Graph
36
        return [
37
            'headers' => '',
38
            'defs' => '',
39
        ];
40
    }
41
42
    public function buildRRDXport($input)
43
    {
44
        $rrd_path = Settings::get('rrd_dir');
45
        $device_id = $input->{'device_id'};
46
        $device = Device::find($device_id);
47
        $hostname = $device->hostname;
48
        if (isset($input->id) && is_numeric($input->id)) {
49
            $proc_ids = explode(',', $input->id);
50
            $procs = $device->processors()->whereIn('processor_id', $proc_ids)->get();
51
        } else {
52
            $procs = $device->processors()->get();
53
        }
54
55
        $headers = [];
56
        $defs = '';
57
58
        foreach ($procs as $proc) {
59
            $proc_descr = format_proc_descr($proc->processor_descr);
60
            $headers[] = $proc_descr;
61
            $id = $proc->hrDeviceIndex;
62
63
            $defs .= "DEF:ds$id=$rrd_path/$hostname/processor-hr-$id.rrd:usage:AVERAGE \
64
                XPORT:ds$id:'$proc_descr' ";
65
        }
66
67
        return [
68
            'headers' => $headers,
69
            'defs' => $defs,
70
        ];
71
    }
72
}
73