2014-11-30 17:49:52 +00:00
< ? php
/*
* LibreNMS
*
* Copyright (c) 2014 Neil Lathwood <https://github.com/laf/ http://www.lathwood.co.uk/fa>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version. Please see LICENSE.txt at the top level of
* the source code distribution for details.
*/
2020-09-21 15:40:17 +02:00
if ( ! Auth :: user () -> hasGlobalAdmin ()) {
2016-08-18 20:28:22 -05:00
header ( 'Content-type: text/plain' );
2020-09-21 15:40:17 +02:00
exit ( 'ERROR: You need to be admin' );
2014-11-30 17:49:52 +00:00
}
2018-10-25 22:31:12 +02:00
$template_id = $vars [ 'template_id' ];
$template_edit = is_numeric ( $template_id ) && $template_id > 0 ;
2014-11-30 17:49:52 +00:00
2018-10-25 22:31:12 +02:00
$rules = [];
2020-09-21 15:40:17 +02:00
$output = [
2018-10-25 22:31:12 +02:00
'template' => '' ,
'name' => '' ,
'title' => '' ,
'title_rec' => '' ,
'type' => '' ,
'rules' => $rules ,
2020-09-21 15:40:17 +02:00
];
2018-10-25 22:31:12 +02:00
if ( $template_edit ) {
$template = dbFetchRow ( 'SELECT * FROM `alert_templates` WHERE `id` = ? LIMIT 1' , [ $template_id ]);
$output = [
2015-08-30 18:05:57 +01:00
'template' => $template [ 'template' ],
'name' => $template [ 'name' ],
'title' => $template [ 'title' ],
'title_rec' => $template [ 'title_rec' ],
2020-09-21 15:40:17 +02:00
'type' => $template [ 'type' ],
2018-10-25 22:31:12 +02:00
];
}
2020-09-21 15:59:34 +02:00
foreach ( dbFetchRows ( 'SELECT `id`,`rule`,`name` FROM `alert_rules` order by `name`' , []) as $rule ) {
$is_selected = $template_edit ? dbFetchCell ( 'SELECT `alert_templates_id` FROM `alert_template_map` WHERE `alert_rule_id` = ? AND `alert_templates_id` = ?' , [ $rule [ 'id' ], $template_id ]) : null ;
$is_available = dbFetchCell ( 'SELECT `alert_templates_id` FROM `alert_template_map` WHERE `alert_rule_id` = ?' , [ $rule [ 'id' ]]);
2018-10-25 22:31:12 +02:00
$rules [] = [
'id' => $rule [ 'id' ],
'name' => $rule [ 'name' ],
'selected' => isset ( $is_selected ),
2020-09-21 15:59:34 +02:00
'used' => isset ( $is_available ) ? dbFetchCell ( 'SELECT `name` FROM `alert_templates` WHERE `id` = ?' , [ $is_available ]) : '' ,
2018-10-25 22:31:12 +02:00
];
2014-11-30 17:49:52 +00:00
}
2018-10-25 22:31:12 +02:00
$output [ 'rules' ] = $rules ;
header ( 'Content-type: application/json' );
2021-03-04 07:55:41 -06:00
echo json_encode ( $output , JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );