1 | <?php |
||
2 | /** |
||
3 | * ack-alert.inc.php |
||
4 | * |
||
5 | * LibreNMS ack-alert.inc.php |
||
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\Config; |
||
0 ignored issues
–
show
|
|||
27 | |||
28 | header('Content-type: application/json'); |
||
29 | |||
30 | $alert_id = $vars['alert_id']; |
||
31 | $state = $vars['state']; |
||
32 | $ack_msg = $vars['ack_msg']; |
||
33 | $until_clear = $vars['ack_until_clear']; |
||
34 | |||
35 | $status = 'error'; |
||
36 | |||
37 | if (! is_numeric($alert_id)) { |
||
38 | $message = 'No alert selected'; |
||
39 | } elseif (! is_numeric($state)) { |
||
40 | $message = 'No state passed'; |
||
41 | } else { |
||
42 | if ($state == 2) { |
||
43 | $state = 1; |
||
44 | $state_descr = 'UnAck'; |
||
45 | $open = 1; |
||
46 | } elseif ($state >= 1) { |
||
47 | $state = 2; |
||
48 | $state_descr = 'Ack'; |
||
49 | $open = 1; |
||
50 | } |
||
51 | |||
52 | if ($until_clear === 'true') { |
||
53 | $until_clear = true; |
||
54 | } else { |
||
55 | $until_clear = false; |
||
56 | } |
||
57 | |||
58 | $info = json_encode([ |
||
59 | 'until_clear' => $until_clear, |
||
60 | ]); |
||
61 | |||
62 | $username = Auth::user()->username; |
||
63 | $data = [ |
||
64 | 'state' => $state, |
||
65 | 'open' => $open, |
||
66 | 'info' => $info, |
||
67 | ]; |
||
68 | |||
69 | $note = dbFetchCell('SELECT note FROM alerts WHERE id=?', [$alert_id]); |
||
70 | if (! empty($note)) { |
||
71 | $note .= PHP_EOL; |
||
72 | } |
||
73 | $data['note'] = $note . date(Config::get('dateformat.long')) . " - $state_descr ($username) $ack_msg"; |
||
74 | |||
75 | if (dbUpdate($data, 'alerts', 'id=?', [$alert_id]) >= 0) { |
||
76 | if (in_array($state, [2, 22])) { |
||
77 | $alert_info = dbFetchRow('SELECT `alert_rules`.`name`,`alerts`.`device_id` FROM `alert_rules` LEFT JOIN `alerts` ON `alerts`.`rule_id` = `alert_rules`.`id` WHERE `alerts`.`id` = ?', [$alert_id]); |
||
78 | log_event("$username acknowledged alert {$alert_info['name']} note: $ack_msg", $alert_info['device_id'], 'alert', 2, $alert_id); |
||
79 | } |
||
80 | $message = 'Alert acknowledged status changed.'; |
||
81 | $status = 'ok'; |
||
82 | } else { |
||
83 | $message = 'Alert has not been acknowledged.'; |
||
84 | } |
||
85 | }//end if |
||
86 | |||
87 | exit(json_encode([ |
||
88 | 'status' => $status, |
||
89 | 'message' => $message, |
||
90 | ])); |
||
91 |
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: