Apply fixes from StyleCI (#12117)

* Apply fixes from StyleCI

* Disable style check
This commit is contained in:
Jellyfrog
2020-09-21 14:54:51 +02:00
committed by GitHub
parent 8ec9183df5
commit 77c531527c
752 changed files with 6238 additions and 5833 deletions

View File

@@ -35,8 +35,8 @@ namespace LibreNMS\Alert;
use App\Models\Device;
use Carbon\Carbon;
use LibreNMS\Alert\AlertUtil;
use LibreNMS\Alert\AlertDB;
use LibreNMS\Alert\AlertUtil;
use LibreNMS\Enum\AlertState;
class AlertRules
@@ -47,6 +47,7 @@ class AlertRules
//Check to see if under maintenance
if (AlertUtil::isMaintenance($device_id) > 0) {
echo "Under Maintenance, skipping alert rules check.\r\n";
return false;
}
//Check to see if disable alerting is set
@@ -55,12 +56,13 @@ class AlertRules
$device_alert['state'] = AlertState::CLEAR;
$device_alert['alerted'] = 0;
$device_alert['open'] = 0;
dbUpdate($device_alert, 'alerts', '`device_id` = ?', array($device_id));
dbUpdate($device_alert, 'alerts', '`device_id` = ?', [$device_id]);
return false;
}
//Checks each rule.
foreach (AlertUtil::getRules($device_id) as $rule) {
c_echo('Rule %p#'.$rule['id'].' (' . $rule['name'] . '):%n ');
c_echo('Rule %p#' . $rule['id'] . ' (' . $rule['name'] . '):%n ');
$extra = json_decode($rule['extra'], true);
if (isset($extra['invert'])) {
$inv = (bool) $extra['invert'];
@@ -72,7 +74,7 @@ class AlertRules
$rule['query'] = AlertDB::genSQL($rule['rule'], $rule['builder']);
}
$sql = $rule['query'];
$qry = dbFetchRows($sql, array($device_id));
$qry = dbFetchRows($sql, [$device_id]);
$cnt = count($qry);
for ($i = 0; $i < $cnt; $i++) {
if (isset($qry[$i]['ip'])) {
@@ -99,20 +101,20 @@ class AlertRules
// NOCHG here doesn't mean no change full stop. It means no change to the alert state
// So we update the details column with any fresh changes to the alert output we might have.
$alert_log = dbFetchRow('SELECT alert_log.id, alert_log.details FROM alert_log,alert_rules WHERE alert_log.rule_id = alert_rules.id && alert_log.device_id = ? && alert_log.rule_id = ? && alert_rules.disabled = 0
ORDER BY alert_log.id DESC LIMIT 1', array($device_id, $rule['id']));
ORDER BY alert_log.id DESC LIMIT 1', [$device_id, $rule['id']]);
$details = [];
if (!empty($alert_log['details'])) {
$details = json_decode(gzuncompress($alert_log['details']), true);
if (! empty($alert_log['details'])) {
$details = json_decode(gzuncompress($alert_log['details']), true);
}
$details['contacts'] = AlertUtil::getContacts($qry);
$details['rule'] = $qry;
$details = gzcompress(json_encode($details), 9);
dbUpdate(array('details' => $details), 'alert_log', 'id = ?', array($alert_log['id']));
$details['rule'] = $qry;
$details = gzcompress(json_encode($details), 9);
dbUpdate(['details' => $details], 'alert_log', 'id = ?', [$alert_log['id']]);
} else {
$extra = gzcompress(json_encode(array('contacts' => AlertUtil::getContacts($qry), 'rule'=>$qry)), 9);
$extra = gzcompress(json_encode(['contacts' => AlertUtil::getContacts($qry), 'rule'=>$qry]), 9);
if (dbInsert(['state' => AlertState::ACTIVE, 'device_id' => $device_id, 'rule_id' => $rule['id'], 'details' => $extra], 'alert_log')) {
if (is_null($current_state)) {
dbInsert(array('state' => AlertState::ACTIVE, 'device_id' => $device_id, 'rule_id' => $rule['id'], 'open' => 1,'alerted' => 0), 'alerts');
dbInsert(['state' => AlertState::ACTIVE, 'device_id' => $device_id, 'rule_id' => $rule['id'], 'open' => 1, 'alerted' => 0], 'alerts');
} else {
dbUpdate(['state' => AlertState::ACTIVE, 'open' => 1, 'timestamp' => Carbon::now()], 'alerts', 'device_id = ? && rule_id = ?', [$device_id, $rule['id']]);
}
@@ -120,7 +122,7 @@ class AlertRules
}
}
} else {
if (!is_null($current_state) && $current_state == AlertState::RECOVERED) {
if (! is_null($current_state) && $current_state == AlertState::RECOVERED) {
c_echo('Status: %bNOCHG');
} else {
if (dbInsert(['state' => AlertState::RECOVERED, 'device_id' => $device_id, 'rule_id' => $rule['id']], 'alert_log')) {