Issues (2963)

includes/html/table/processor.inc.php (1 issue)

1
<?php
2
/*
3
 * LibreNMS
4
 *
5
 * This program is free software: you can redistribute it and/or modify it
6
 * under the terms of the GNU General Public License as published by the
7
 * Free Software Foundation, either version 3 of the License, or (at your
8
 * option) any later version.  Please see LICENSE.txt at the top level of
9
 * the source code distribution for details.
10
 *
11
 * @package    LibreNMS
12
 * @subpackage webui
13
 * @link       https://www.librenms.org
14
 * @copyright  2018 LibreNMS
15
 * @author     LibreNMS Contributors
16
*/
17
18
$graph_type = 'processor_usage';
19
$where = 1;
20
$sql = ' FROM `processors` AS `P` LEFT JOIN `devices` AS `D` ON `P`.`device_id` = `D`.`device_id`';
21
$param = [];
22
23
if (! Auth::user()->hasGlobalRead()) {
0 ignored issues
show
The method hasGlobalRead() does not exist on Illuminate\Contracts\Auth\Authenticatable. It seems like you code against a sub-type of Illuminate\Contracts\Auth\Authenticatable such as Illuminate\Foundation\Auth\User. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

23
if (! Auth::user()->/** @scrutinizer ignore-call */ hasGlobalRead()) {
Loading history...
24
    $device_ids = Permissions::devicesForUser()->toArray() ?: [false];
25
    $where .= ' AND `P`.`device_id` IN ' . dbGenPlaceholders(count($device_ids));
26
    $param = array_merge($param, $device_ids);
27
}
28
29
$sql .= " WHERE $where";
30
if (isset($searchPhrase) && ! empty($searchPhrase)) {
31
    $sql .= ' AND (`hostname` LIKE ? OR `processor_descr` LIKE ?)';
32
    $param[] = "%$searchPhrase%";
33
    $param[] = "%$searchPhrase%";
34
}
35
36
$count_sql = "SELECT COUNT(`processor_id`) $sql";
37
$total = dbFetchCell($count_sql, $param);
38
if (empty($total)) {
39
    $total = 0;
40
}
41
42
if (! isset($sort) || empty($sort)) {
43
    $sort = '`D`.`hostname`, `P`.`processor_descr`';
44
}
45
46
$sql .= " ORDER BY $sort";
47
if (isset($current)) {
48
    $limit_low = (($current * $rowCount) - ($rowCount));
49
    $limit_high = $rowCount;
50
}
51
52
if ($rowCount != -1) {
53
    $sql .= " LIMIT $limit_low,$limit_high";
54
}
55
56
$sql = "SELECT * $sql";
57
foreach (dbFetchRows($sql, $param) as $processor) {
58
    $perc = round($processor['processor_usage'], 0);
59
    $graph_array['type'] = $graph_type;
60
    $graph_array['id'] = $processor['processor_id'];
61
    $graph_array['from'] = \LibreNMS\Config::get('time.day');
62
    $graph_array['to'] = \LibreNMS\Config::get('time.now');
63
    $graph_array['height'] = '20';
64
    $graph_array['width'] = '80';
65
    $graph_array_zoom = $graph_array;
66
    $graph_array_zoom['height'] = '150';
67
    $graph_array_zoom['width'] = '400';
68
    $link = 'graphs/id=' . $graph_array['id'] . '/type=' . $graph_array['type'] . '/from=' . $graph_array['from'] . '/to=' . $graph_array['to'] . '/';
69
    $mini_graph = \LibreNMS\Util\Url::overlibLink($link, \LibreNMS\Util\Url::graphTag($graph_array), \LibreNMS\Util\Url::graphTag($graph_array_zoom));
70
    $background = \LibreNMS\Util\Colors::percentage($perc, $processor['processor_perc_warn']);
71
    $bar_link = \LibreNMS\Util\Url::overlibLink($link, print_percentage_bar(400, 20, $perc, $perc . '%', 'ffffff', $background['left'], (100 - $perc) . '%', 'ffffff', $background['right']), \LibreNMS\Util\Url::graphTag($graph_array_zoom));
72
73
    $response[] = [
74
        'hostname'        => generate_device_link($processor),
75
        'processor_descr' => $processor['processor_descr'],
76
        'graph'           => $mini_graph,
77
        'processor_usage' => $bar_link,
78
    ];
79
    if ($vars['view'] == 'graphs') {
80
        $graph_array['height'] = '100';
81
        $graph_array['width'] = '216';
82
        $graph_array['to'] = \LibreNMS\Config::get('time.now');
83
        $graph_array['id'] = $processor['processor_id'];
84
        $graph_array['type'] = $graph_type;
85
        $return_data = true;
86
        include 'includes/html/print-graphrow.inc.php';
87
        unset($return_data);
88
        $response[] = [
89
            'hostname'        => $graph_data[0],
90
            'processor_descr' => $graph_data[1],
91
            'graph'           => $graph_data[2],
92
            'processor_usage' => $graph_data[3],
93
        ];
94
    } //end if
95
}//end foreach
96
97
$output = [
98
    'current'  => $current,
99
    'rowCount' => $rowCount,
100
    'rows'     => $response,
101
    'total'    => $total,
102
];
103
echo json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
104