mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Do not update alert timestamp when updating a triggered alert (#10907)
* Do not update alert timestamp when updating a triggered alert * Only update alerts timestamp if alert is triggered or recovered * db schema * db schema * cleanup timestamp update
This commit is contained in:
@@ -112,7 +112,7 @@ class AlertRules
|
||||
if (is_null($current_state)) {
|
||||
dbInsert(array('state' => 1, 'device_id' => $device_id, 'rule_id' => $rule['id'], 'open' => 1,'alerted' => 0), 'alerts');
|
||||
} else {
|
||||
dbUpdate(['state' => 1, 'open' => 1], 'alerts', 'device_id = ? && rule_id = ?', [$device_id, $rule['id']]);
|
||||
dbUpdate(['state' => 1, 'open' => 1, 'timestamp' => array('NOW()')], 'alerts', 'device_id = ? && rule_id = ?', [$device_id, $rule['id']]);
|
||||
}
|
||||
c_echo(PHP_EOL . 'Status: %rALERT');
|
||||
}
|
||||
@@ -125,7 +125,7 @@ class AlertRules
|
||||
if (is_null($current_state)) {
|
||||
dbInsert(['state' => 0, 'device_id' => $device_id, 'rule_id' => $rule['id'], 'open' => 1, 'alerted' => 0], 'alerts');
|
||||
} else {
|
||||
dbUpdate(['state' => 0, 'open' => 1, 'note' => ''], 'alerts', 'device_id = ? && rule_id = ?', [$device_id, $rule['id']]);
|
||||
dbUpdate(['state' => 0, 'open' => 1, 'note' => '', 'timestamp' => array('NOW()')], 'alerts', 'device_id = ? && rule_id = ?', [$device_id, $rule['id']]);
|
||||
}
|
||||
|
||||
c_echo(PHP_EOL . 'Status: %gOK');
|
||||
|
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
class AlertsDisableOnUpdateCurrentTimestamp extends Migration
|
||||
{
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
\DB::statement("ALTER TABLE `alerts` CHANGE `timestamp` `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP;");
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
\DB::statement("ALTER TABLE `alerts` CHANGE `timestamp` `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP;");
|
||||
}
|
||||
}
|
@@ -28,7 +28,7 @@ alerts:
|
||||
- { Field: alerted, Type: int(11), 'Null': false, Extra: '' }
|
||||
- { Field: open, Type: int(11), 'Null': false, Extra: '' }
|
||||
- { Field: note, Type: text, 'Null': true, Extra: '' }
|
||||
- { Field: timestamp, Type: timestamp, 'Null': false, Extra: 'on update CURRENT_TIMESTAMP', Default: CURRENT_TIMESTAMP }
|
||||
- { Field: timestamp, Type: timestamp, 'Null': false, Extra: '', Default: CURRENT_TIMESTAMP }
|
||||
- { Field: info, Type: text, 'Null': false, Extra: '' }
|
||||
Indexes:
|
||||
PRIMARY: { Name: PRIMARY, Columns: [id], Unique: true, Type: BTREE }
|
||||
|
Reference in New Issue
Block a user