Device groups rewrite (#10346)

* Device Groups rewrite
Updated web ui
Static or dynamic groups allowed
Alert rule query builder
Translation support
Permissions support

* cleanup, make relationship save, and validate it

* builder WIP

* rules builder and rules saving/loading

* Parse query builder to Laravel Fluent query

* Upgrade existing groups when editing.
Properly update only dynamic groups when polling.

* remove unused old code
Update API and other places to use Eloquent

* debug output in poller restored

* Fix up some things
creating static
improved validation
fix js error on creation
Fix static groups in polling

* hide pattern for static group

* Implement authorization
Use in the menu too

* update schema

* fix rollback

* Don't abort on invalid queries

* fixes to query builder

* add test data, looks like macros aren't handled (omitted them because groups don't use them generally)

* Add macro support for QueryBuilderFluentParser

* add test for macro that accepts value

* More space in forms
Retain rules when converted to static
no duplicate names allowed

* Better error feedback
Update related devices on save

* Add button icon

* format

* update docs

* fix tests

* Fix some QueryBuilderFluentParser issues with OR
updated/more test data

* Show device groups runtime
fix querybuilder.json format

* Store table joins in the rules to minimize polling time
Update group joins in daily.sh (and when they are saved)

* Update daily.php

* Add units to time
This commit is contained in:
Tony Murray
2019-06-19 16:01:53 -05:00
committed by GitHub
parent d8931e1946
commit 1a60c44eb0
38 changed files with 1065 additions and 1360 deletions

View File

@@ -1,53 +0,0 @@
<?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.
*/
use LibreNMS\Authentication\LegacyAuth;
if (!LegacyAuth::user()->hasGlobalAdmin()) {
die('ERROR: You need to be admin');
}
$pattern = $_POST['patterns'];
$group_id = $_POST['group_id'];
$name = mres($_POST['name']);
$desc = mres($_POST['desc']);
if (is_array($pattern)) {
$pattern = implode(' ', $pattern);
} elseif (!empty($_POST['pattern']) && !empty($_POST['condition']) && !empty($_POST['value'])) {
$pattern = '%'.$_POST['pattern'].' '.$_POST['condition'].' ';
if (is_numeric($_POST['value'])) {
$pattern .= $_POST['value'];
} else {
$pattern .= '"'.$_POST['value'].'"';
}
}
if (empty($pattern)) {
$update_message = 'ERROR: No group was generated';
} elseif (is_numeric($group_id) && $group_id > 0) {
if (EditDeviceGroup($group_id, $name, $desc, $pattern)) {
$update_message = "Edited Group: <i>$name: $pattern</i>";
} else {
$update_message = 'ERROR: Failed to edit Group: <i>'.$pattern.'</i>';
}
} else {
if (AddDeviceGroup($name, $desc, $pattern)) {
$update_message = "Added Group: <i>$name: $pattern</i>";
} else {
$update_message = 'ERROR: Failed to add Group: <i>'.$pattern.'</i>';
}
}
echo $update_message;

View File

@@ -1,36 +0,0 @@
<?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.
*/
use LibreNMS\Authentication\LegacyAuth;
header('Content-type: text/plain');
if (!LegacyAuth::user()->hasGlobalAdmin()) {
die('ERROR: You need to be admin');
}
if (!is_numeric($_POST['group_id'])) {
echo 'ERROR: No group selected';
exit;
} else {
if (dbDelete('device_groups', '`id` = ?', array($_POST['group_id']))) {
dbDelete('alert_group_map', 'group_id=?', [$_POST['group_id']]);
echo 'Group has been deleted.';
exit;
} else {
echo 'ERROR: Group has not been deleted.';
exit;
}
}

View File

@@ -1,41 +0,0 @@
<?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.
*/
use LibreNMS\Authentication\LegacyAuth;
if (!LegacyAuth::user()->hasGlobalAdmin()) {
header('Content-type: text/plain');
die('ERROR: You need to be admin');
}
$group_id = $_POST['group_id'];
if (is_numeric($group_id) && $group_id > 0) {
$group = dbFetchRow('SELECT * FROM `device_groups` WHERE `id` = ? LIMIT 1', array($group_id));
$group_split = preg_split('/([a-zA-Z0-9_\-\.\=\%\<\>\ \"\'\!\~\(\)\*\/\@\[\]\^\$]+[&&\|\|]+)/', $group['pattern'], -1, (PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY));
$count = (count($group_split) - 1);
if (preg_match('/\&\&$/', $group_split[$count]) == 1 || preg_match('/\|\|$/', $group_split[$count]) == 1) {
$group_split[$count] = $group_split[$count];
} else {
$group_split[$count] = $group_split[$count].' &&';
}
$output = array(
'name' => $group['name'],
'desc' => $group['desc'],
'pattern' => $group_split,
);
header('Content-type: application/json');
echo _json_encode($output);
}