mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
"Disable alerting" on device disables alert rules check (not just alert transport) (#11015)
* Fix disable notify * Fix disable notify * Disable all alerting * fix db migration * fix db migration * fix db migration * Add autoclearing active alerts if disable alerting set * Add autoclearing active alerts if disable alerting set * fix check * Device in gray if disable_notify is set - not ignore tag
This commit is contained in:
@@ -44,7 +44,16 @@ class AlertRules
|
|||||||
|
|
||||||
//Check to see if under maintenance
|
//Check to see if under maintenance
|
||||||
if (AlertUtil::isMaintenance($device_id) > 0) {
|
if (AlertUtil::isMaintenance($device_id) > 0) {
|
||||||
echo "Under Maintenance, Skipping alerts.\r\n";
|
echo "Under Maintenance, skipping alert rules check.\r\n";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
//Check to see if disable alerting is set
|
||||||
|
if (AlertUtil::hasDisableNotify($device_id)) {
|
||||||
|
echo "Disable alerting is set, Clearing active alerts and skipping alert rules check\r\n";
|
||||||
|
$device_alert['state'] = 0;
|
||||||
|
$device_alert['alerted'] = 0;
|
||||||
|
$device_alert['open'] = 0;
|
||||||
|
dbUpdate($device_alert, 'alerts', '`device_id` = ?', array($device_id));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//Checks each rule.
|
//Checks each rule.
|
||||||
|
@@ -195,6 +195,17 @@ class AlertUtil
|
|||||||
return !is_null($device) && $device->isUnderMaintenance();
|
return !is_null($device) && $device->isUnderMaintenance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if device is set to ignore alerts
|
||||||
|
* @param int $device_id Device-ID
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function hasDisableNotify($device_id)
|
||||||
|
{
|
||||||
|
$device = Device::find($device_id);
|
||||||
|
return !is_null($device) && $device->disable_notify;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process Macros
|
* Process Macros
|
||||||
* @param string $rule Rule to process
|
* @param string $rule Rule to process
|
||||||
|
@@ -260,10 +260,6 @@ class RunAlerts
|
|||||||
*/
|
*/
|
||||||
public function issueAlert($alert)
|
public function issueAlert($alert)
|
||||||
{
|
{
|
||||||
if (dbFetchCell('SELECT attrib_value FROM devices_attribs WHERE attrib_type = "disable_notify" && device_id = ?', array($alert['device_id'])) == '1') {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Config::get('alert.fixed-contacts') == false) {
|
if (Config::get('alert.fixed-contacts') == false) {
|
||||||
if (empty($alert['query'])) {
|
if (empty($alert['query'])) {
|
||||||
$alert['query'] = AlertDB::genSQL($alert['rule'], $alert['builder']);
|
$alert['query'] = AlertDB::genSQL($alert['rule'], $alert['builder']);
|
||||||
|
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
|
||||||
|
class MigrateDevicesAttribsTable extends Migration
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('devices', function (Blueprint $table) {
|
||||||
|
$table->boolean('disable_notify')->default(0);
|
||||||
|
});
|
||||||
|
// migrate disable_notify data into devices table
|
||||||
|
\DB::statement("UPDATE devices d, devices_attribs da SET d.disable_notify=1 WHERE da.attrib_type='disable_notify' AND da.attrib_value=1 AND d.device_id = da.device_id;");
|
||||||
|
\DB::statement("DELETE FROM devices_attribs WHERE attrib_type='disable_notify' AND attrib_value=1;");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
// revert migrate disable_notify data into devices table
|
||||||
|
\DB::statement("INSERT INTO devices_attribs (device_id, attrib_type, attrib_value) SELECT DISTINCT d.device_id, 'disable_notify', 1 FROM devices_attribs da INNER JOIN devices d WHERE d.device_id = da.device_id AND d.disable_notify=1;");
|
||||||
|
Schema::table('devices', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('disable_notify');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@@ -680,7 +680,7 @@ function devclass($device)
|
|||||||
$class = 'list-device';
|
$class = 'list-device';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($device['ignore']) && $device['ignore'] == '1') {
|
if (isset($device['disable_notify']) && $device['disable_notify'] == '1') {
|
||||||
$class = 'list-device-ignored';
|
$class = 'list-device-ignored';
|
||||||
if (isset($device['status']) && $device['status'] == '1') {
|
if (isset($device['status']) && $device['status'] == '1') {
|
||||||
$class = 'list-device-ignored-up';
|
$class = 'list-device-ignored-up';
|
||||||
|
@@ -32,6 +32,7 @@ if ($_POST['editing']) {
|
|||||||
$device_model->purpose = $_POST['descr'];
|
$device_model->purpose = $_POST['descr'];
|
||||||
$device_model->ignore = (int)isset($_POST['ignore']);
|
$device_model->ignore = (int)isset($_POST['ignore']);
|
||||||
$device_model->disabled = (int)isset($_POST['disabled']);
|
$device_model->disabled = (int)isset($_POST['disabled']);
|
||||||
|
$device_model->disable_notify = (int)isset($_POST['disable_notify']);
|
||||||
$device_model->type = $_POST['type'];
|
$device_model->type = $_POST['type'];
|
||||||
|
|
||||||
if ($device_model->isDirty('type')) {
|
if ($device_model->isDirty('type')) {
|
||||||
@@ -70,8 +71,6 @@ if ($_POST['editing']) {
|
|||||||
$override_sysContact_string = mres($_POST['sysContact']);
|
$override_sysContact_string = mres($_POST['sysContact']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$disable_notify = mres($_POST['disable_notify']);
|
|
||||||
|
|
||||||
if ($override_sysContact_bool) {
|
if ($override_sysContact_bool) {
|
||||||
set_dev_attrib($device, 'override_sysContact_bool', '1');
|
set_dev_attrib($device, 'override_sysContact_bool', '1');
|
||||||
} else {
|
} else {
|
||||||
@@ -80,15 +79,7 @@ if ($_POST['editing']) {
|
|||||||
|
|
||||||
if (isset($override_sysContact_string)) {
|
if (isset($override_sysContact_string)) {
|
||||||
set_dev_attrib($device, 'override_sysContact_string', $override_sysContact_string);
|
set_dev_attrib($device, 'override_sysContact_string', $override_sysContact_string);
|
||||||
};
|
|
||||||
if ($disable_notify) {
|
|
||||||
set_dev_attrib($device, 'disable_notify', '1');
|
|
||||||
} else {
|
|
||||||
set_dev_attrib($device, 'disable_notify', '0');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//$update_message = 'Device alert settings updated.';
|
|
||||||
//$updated = 1;
|
|
||||||
} else {
|
} else {
|
||||||
include 'includes/html/error-no-perm.inc.php';
|
include 'includes/html/error-no-perm.inc.php';
|
||||||
}
|
}
|
||||||
@@ -249,12 +240,11 @@ $disable_notify = get_dev_attrib($device, 'disable_notify');
|
|||||||
<label for="disable_notify" class="col-sm-2 control-label">Disable alerting:</label>
|
<label for="disable_notify" class="col-sm-2 control-label">Disable alerting:</label>
|
||||||
<div class="col-sm-6">
|
<div class="col-sm-6">
|
||||||
<input id="disable_notify" type="checkbox" name="disable_notify" data-size="small"
|
<input id="disable_notify" type="checkbox" name="disable_notify" data-size="small"
|
||||||
<?php
|
<?php
|
||||||
if ($disable_notify) {
|
if ($device_model->disable_notify) {
|
||||||
echo ' checked="1"';
|
echo("checked=checked");
|
||||||
};
|
}
|
||||||
?>
|
?> />
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
@@ -497,6 +497,7 @@ devices:
|
|||||||
- { Field: notes, Type: text, 'Null': true, Extra: '' }
|
- { Field: notes, Type: text, 'Null': true, Extra: '' }
|
||||||
- { Field: port_association_mode, Type: int(11), 'Null': false, Extra: '', Default: '1' }
|
- { Field: port_association_mode, Type: int(11), 'Null': false, Extra: '', Default: '1' }
|
||||||
- { Field: max_depth, Type: int(11), 'Null': false, Extra: '', Default: '0' }
|
- { Field: max_depth, Type: int(11), 'Null': false, Extra: '', Default: '0' }
|
||||||
|
- { Field: disable_notify, Type: tinyint(1), 'Null': false, Extra: '', Default: '0' }
|
||||||
Indexes:
|
Indexes:
|
||||||
PRIMARY: { Name: PRIMARY, Columns: [device_id], Unique: true, Type: BTREE }
|
PRIMARY: { Name: PRIMARY, Columns: [device_id], Unique: true, Type: BTREE }
|
||||||
hostname: { Name: hostname, Columns: [hostname], Unique: false, Type: BTREE }
|
hostname: { Name: hostname, Columns: [hostname], Unique: false, Type: BTREE }
|
||||||
|
Reference in New Issue
Block a user