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; |
||
28 | |||
29 | header('Content-type: application/json'); |
||
30 | |||
31 | if (! Auth::user()->hasGlobalAdmin()) { |
||
0 ignored issues
–
show
Bug
introduced
by
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 |