mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Maintenance Mode for a complete Location (#11089)
* Maintenance mode for a complete location * updatedatabase query * updatedatabase query * add missing select
This commit is contained in:
@@ -102,7 +102,7 @@ class AvailabilityMapController extends WidgetController
|
||||
$device_query->isNotDisabled();
|
||||
}
|
||||
$device_query->orderBy($settings['order_by']);
|
||||
$devices = $device_query->select('devices.device_id', 'hostname', 'sysName', 'status', 'uptime', 'disabled', 'disable_notify')->get();
|
||||
$devices = $device_query->select('devices.device_id', 'hostname', 'sysName', 'status', 'uptime', 'disabled', 'disable_notify', 'location_id')->get();
|
||||
|
||||
// process status
|
||||
$uptime_warn = Config::get('uptime_warning', 84600);
|
||||
|
||||
@@ -207,6 +207,13 @@ class Device extends BaseModel
|
||||
->whereIn('alert_schedulable_id', $this->groups->pluck('id'));
|
||||
});
|
||||
}
|
||||
|
||||
if ($this->location) {
|
||||
$query->orWhere(function ($query) {
|
||||
$query->where('alert_schedulable_type', 'location')
|
||||
->where('alert_schedulable_id', $this->location->id);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return $query->exists();
|
||||
|
||||
@@ -126,7 +126,10 @@ if ($sub_type == 'new-maintenance') {
|
||||
|
||||
foreach ($_POST['maps'] as $target) {
|
||||
$type = 'device';
|
||||
if (starts_with($target, 'g')) {
|
||||
if (starts_with($target, 'l')) {
|
||||
$type = 'location';
|
||||
$target = substr($target, 1);
|
||||
} elseif (starts_with($target, 'g')) {
|
||||
$type = 'device_group';
|
||||
$target = substr($target, 1);
|
||||
}
|
||||
@@ -170,7 +173,10 @@ if ($sub_type == 'new-maintenance') {
|
||||
$items = [];
|
||||
foreach (dbFetchRows('SELECT `alert_schedulable_type`, `alert_schedulable_id` FROM `alert_schedulables` WHERE `schedule_id`=?', [$schedule_id]) as $target) {
|
||||
$id = $target['alert_schedulable_id'];
|
||||
if ($target['alert_schedulable_type'] == 'device_group') {
|
||||
if ($target['alert_schedulable_type'] == 'location') {
|
||||
$text = dbFetchCell('SELECT location FROM locations WHERE id = ?', [$id]);
|
||||
$id = 'l' . $id;
|
||||
} elseif ($target['alert_schedulable_type'] == 'device_group') {
|
||||
$text = dbFetchCell('SELECT name FROM device_groups WHERE id = ?', [$id]);
|
||||
$id = 'g' . $id;
|
||||
} else {
|
||||
|
||||
46
includes/html/list/devices_groups_locations.inc.php
Normal file
46
includes/html/list/devices_groups_locations.inc.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
/**
|
||||
* devices_groups.inc.php
|
||||
*
|
||||
* List devices and groups in one
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @package LibreNMS
|
||||
* @link http://librenms.org
|
||||
* @copyright 2018 Tony Murray
|
||||
* @author Tony Murray <murraytony@gmail.com>
|
||||
*/
|
||||
|
||||
list($devices, $d_more) = include 'devices.inc.php';
|
||||
list($groups, $g_more) = include 'groups.inc.php';
|
||||
list($locations, $l_more) = include 'locations.inc.php';
|
||||
|
||||
$locations = array_map(function ($location) {
|
||||
$location['id'] = 'l' . $location['id'];
|
||||
return $location;
|
||||
}, $locations);
|
||||
|
||||
$groups = array_map(function ($group) {
|
||||
$group['id'] = 'g' . $group['id'];
|
||||
return $group;
|
||||
}, $groups);
|
||||
|
||||
$data = [
|
||||
['text' => 'Devices', 'children' => $devices],
|
||||
['text' => 'Groups', 'children' => $groups],
|
||||
['text' => 'Locations', 'children' => $locations]
|
||||
];
|
||||
|
||||
return [$data, $d_more || $g_more || $l_more];
|
||||
58
includes/html/list/locations.inc.php
Normal file
58
includes/html/list/locations.inc.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
/**
|
||||
* locations.inc.php
|
||||
*
|
||||
* List locations
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @package LibreNMS
|
||||
* @link http://librenms.org
|
||||
* @copyright 2020 Thomas Berberich
|
||||
* @author Thomas Berberich <sourcehhdoctor@gmail.com>
|
||||
*/
|
||||
|
||||
if (!Auth::user()->hasGlobalRead()) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$query = '';
|
||||
$params = [];
|
||||
|
||||
if (!empty($_REQUEST['search'])) {
|
||||
$query .= ' WHERE `location` LIKE ?';
|
||||
$params[] = '%' . mres($_REQUEST['search']) . '%';
|
||||
}
|
||||
|
||||
|
||||
$total = dbFetchCell("SELECT COUNT(*) FROM `locations` $query", $params);
|
||||
$more = false;
|
||||
|
||||
if (!empty($_REQUEST['limit'])) {
|
||||
$limit = (int) $_REQUEST['limit'];
|
||||
$page = isset($_REQUEST['page']) ? (int) $_REQUEST['page'] : 1;
|
||||
$offset = ($page - 1) * $limit;
|
||||
|
||||
$query .= " LIMIT $offset, $limit";
|
||||
} else {
|
||||
$offset = 0;
|
||||
}
|
||||
|
||||
|
||||
$sql = "SELECT `id`, `location` AS `text` FROM `locations` $query order by `location`";
|
||||
$locations = dbFetchRows($sql, $params);
|
||||
|
||||
$more = ($offset + count($locations)) < $total;
|
||||
|
||||
return [$locations, $more];
|
||||
@@ -264,13 +264,13 @@ $('#sched-submit').click('', function(e) {
|
||||
|
||||
$("#maps").select2({
|
||||
width: '100%',
|
||||
placeholder: "Devices or Groups",
|
||||
placeholder: "Devices, Groups or Locations",
|
||||
ajax: {
|
||||
url: 'ajax_list.php',
|
||||
delay: 250,
|
||||
data: function (params) {
|
||||
return {
|
||||
type: 'devices_groups',
|
||||
type: 'devices_groups_locations',
|
||||
search: params.term
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user