1 | <?php |
||||
2 | /** |
||||
3 | * alert-rules.inc.php |
||||
4 | * |
||||
5 | * LibreNMS alert-rules.inc.php for processor |
||||
6 | * |
||||
7 | * This program is free software: you can redistribute it and/or modify |
||||
8 | * it under the terms of the GNU General Public License as published by |
||||
9 | * the Free Software Foundation, either version 3 of the License, or |
||||
10 | * (at your option) any later version. |
||||
11 | * |
||||
12 | * This program is distributed in the hope that it will be useful, |
||||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the |
||||
15 | * GNU General Public License for more details. |
||||
16 | * |
||||
17 | * You should have received a copy of the GNU General Public License |
||||
18 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
||||
19 | * |
||||
20 | * @link https://www.librenms.org |
||||
21 | * |
||||
22 | * @copyright 2018 Neil Lathwood |
||||
23 | * @author Neil Lathwood <[email protected]> |
||||
24 | */ |
||||
25 | |||||
26 | use LibreNMS\Alerting\QueryBuilderParser; |
||||
27 | use LibreNMS\Config; |
||||
0 ignored issues
–
show
|
|||||
28 | |||||
29 | header('Content-type: application/json'); |
||||
30 | |||||
31 | if (! Auth::user()->hasGlobalAdmin()) { |
||||
0 ignored issues
–
show
The method
hasGlobalAdmin() 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
Loading history...
|
|||||
32 | exit(json_encode([ |
||||
33 | 'status' => 'error', |
||||
34 | 'message' => 'ERROR: You need to be admin', |
||||
35 | ])); |
||||
36 | } |
||||
37 | |||||
38 | $template_id = $vars['template_id']; |
||||
39 | |||||
40 | if (is_numeric($template_id)) { |
||||
41 | $rules = get_rules_from_json(); |
||||
42 | $rule = $rules[$template_id]; |
||||
43 | $default_extra = [ |
||||
44 | 'mute' => Config::get('alert_rule.mute_alerts'), |
||||
45 | 'count' => Config::get('alert_rule.max_alerts'), |
||||
46 | 'delay' => 60 * Config::get('alert_rule.delay'), |
||||
47 | 'invert' => Config::get('alert_rule.invert_rule_match'), |
||||
48 | 'interval' => 60 * Config::get('alert_rule.interval'), |
||||
49 | 'recovery' => Config::get('alert_rule.recovery_alerts'), |
||||
50 | ]; |
||||
51 | $output = [ |
||||
52 | 'status' => 'ok', |
||||
53 | 'name' => $rule['name'], |
||||
54 | 'builder' => $rule['builder'] ?: QueryBuilderParser::fromOld($rule['rule'])->toArray(), |
||||
55 | 'extra' => array_replace($default_extra, (array) $rule['extra']), |
||||
56 | 'severity' => $rule['severity'] ?: Config::get('alert_rule.severity'), |
||||
57 | 'invert_map' => Config::get('alert_rule.invert_map'), |
||||
58 | ]; |
||||
59 | } else { |
||||
60 | $output = [ |
||||
61 | 'status' => 'error', |
||||
62 | 'message' => 'Invalid template', |
||||
63 | ]; |
||||
64 | } |
||||
65 | |||||
66 | exit(json_encode($output)); |
||||
67 |
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: