mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Alert Rules use Carbon
Use carbon for time queries, need to be careful of timezone quirks. Timestamps won't have that issue
This commit is contained in:
@@ -34,6 +34,7 @@
|
||||
namespace LibreNMS\Alert;
|
||||
|
||||
use App\Models\Device;
|
||||
use Carbon\Carbon;
|
||||
use LibreNMS\Alert\AlertUtil;
|
||||
use LibreNMS\Alert\AlertDB;
|
||||
|
||||
@@ -112,7 +113,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, 'timestamp' => array('NOW()')], 'alerts', 'device_id = ? && rule_id = ?', [$device_id, $rule['id']]);
|
||||
dbUpdate(['state' => 1, 'open' => 1, 'timestamp' => Carbon::now()->timestamp], 'alerts', 'device_id = ? && rule_id = ?', [$device_id, $rule['id']]);
|
||||
}
|
||||
c_echo(PHP_EOL . 'Status: %rALERT');
|
||||
}
|
||||
@@ -125,7 +126,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' => '', 'timestamp' => array('NOW()')], 'alerts', 'device_id = ? && rule_id = ?', [$device_id, $rule['id']]);
|
||||
dbUpdate(['state' => 0, 'open' => 1, 'note' => '', 'timestamp' => Carbon::now()->timestamp], 'alerts', 'device_id = ? && rule_id = ?', [$device_id, $rule['id']]);
|
||||
}
|
||||
|
||||
c_echo(PHP_EOL . 'Status: %gOK');
|
||||
|
Reference in New Issue
Block a user