Apply fixes from StyleCI (#12120)

This commit is contained in:
Jellyfrog
2020-09-21 15:40:17 +02:00
committed by GitHub
parent 77c531527c
commit 82f43cb98d
1733 changed files with 18337 additions and 18540 deletions

View File

@@ -15,14 +15,14 @@
$where = ' `devices`.`disabled` = 0';
$param = [];
$alert_states = array(
$alert_states = [
// divined from librenms/alerts.php
'recovered' => 0,
'alerted' => 1,
'acknowledged' => 2,
'worse' => 3,
'better' => 4,
);
];
$show_recovered = false;
@@ -47,7 +47,7 @@ if (is_numeric($vars['state'])) {
}
if (isset($vars['min_severity'])) {
$where .= get_sql_filter_min_severity($vars['min_severity'], "alert_rules");
$where .= get_sql_filter_min_severity($vars['min_severity'], "alert_rules");
}
if (is_numeric($vars['group'])) {
@@ -55,11 +55,11 @@ if (is_numeric($vars['group'])) {
$param[] = $vars['group'];
}
if (!$show_recovered) {
if (! $show_recovered) {
$where .= " AND `alerts`.`state`!=" . $alert_states['recovered'];
}
if (isset($searchPhrase) && !empty($searchPhrase)) {
if (isset($searchPhrase) && ! empty($searchPhrase)) {
$where .= " AND (`timestamp` LIKE ? OR `rule` LIKE ? OR `name` LIKE ? OR `hostname` LIKE ? OR `sysName` LIKE ?)";
$param[] = "%$searchPhrase%";
$param[] = "%$searchPhrase%";
@@ -70,9 +70,9 @@ if (isset($searchPhrase) && !empty($searchPhrase)) {
$sql = ' FROM `alerts` LEFT JOIN `devices` ON `alerts`.`device_id`=`devices`.`device_id`';
if (!Auth::user()->hasGlobalRead()) {
if (! Auth::user()->hasGlobalRead()) {
$device_ids = Permissions::devicesForUser()->toArray() ?: [0];
$where .= " AND `devices`.`device_id` IN " .dbGenPlaceholders(count($device_ids));
$where .= " AND `devices`.`device_id` IN " . dbGenPlaceholders(count($device_ids));
$param = array_merge($param, $device_ids);
}
@@ -86,7 +86,7 @@ if (empty($total)) {
$total = 0;
}
if (!isset($vars['sort']) || empty($vars['sort'])) {
if (! isset($vars['sort']) || empty($vars['sort'])) {
$sort = 'timestamp DESC';
} else {
$sort = '`alert_rules`.`severity` DESC, timestamp DESC';
@@ -108,25 +108,25 @@ $sql = "SELECT `alerts`.*, `devices`.`hostname`, `devices`.`sysName`, `devices`.
$rulei = 0;
$format = $vars['format'];
foreach (dbFetchRows($sql, $param) as $alert) {
$log = dbFetchCell('SELECT details FROM alert_log WHERE rule_id = ? AND device_id = ? ORDER BY id DESC LIMIT 1', array($alert['rule_id'], $alert['device_id']));
$log = dbFetchCell('SELECT details FROM alert_log WHERE rule_id = ? AND device_id = ? ORDER BY id DESC LIMIT 1', [$alert['rule_id'], $alert['device_id']]);
$fault_detail = alert_details($log);
$info = json_decode($alert['info'], true);
$info = json_decode($alert['info'], true);
$alert_to_ack = '<button type="button" class="btn btn-danger command-ack-alert fa fa-eye" aria-hidden="true" title="Mark as acknowledged" data-target="ack-alert" data-state="' . $alert['state'] . '" data-alert_id="' . $alert['id'] . '" data-alert_state="' . $alert['state'] . '" name="ack-alert"></button>';
$alert_to_nack = '<button type="button" class="btn btn-primary command-ack-alert fa fa-eye-slash" aria-hidden="true" title="Mark as not acknowledged" data-target="ack-alert" data-state="' . $alert['state'] . '" data-alert_id="' . $alert['id'] . '" data-alert_state="' . $alert['state'] . '" name="ack-alert"></button>';
$alert_to_ack = '<button type="button" class="btn btn-danger command-ack-alert fa fa-eye" aria-hidden="true" title="Mark as acknowledged" data-target="ack-alert" data-state="' . $alert['state'] . '" data-alert_id="' . $alert['id'] . '" data-alert_state="' . $alert['state'] . '" name="ack-alert"></button>';
$alert_to_nack = '<button type="button" class="btn btn-primary command-ack-alert fa fa-eye-slash" aria-hidden="true" title="Mark as not acknowledged" data-target="ack-alert" data-state="' . $alert['state'] . '" data-alert_id="' . $alert['id'] . '" data-alert_state="' . $alert['state'] . '" name="ack-alert"></button>';
$alert_to_unack = '<button type="button" class="btn btn-primary command-ack-alert fa fa-eye" aria-hidden="true" title="Mark as not acknowledged" data-target="ack-alert" data-state="' . $alert['state'] . '" data-alert_id="' . $alert['id'] . '" data-alert_state="' . $alert['state'] . '" name="ack-alert"></button>';
$ack_ico = $alert_to_ack;
if ((int)$alert['state'] === 0) {
if ((int) $alert['state'] === 0) {
$msg = '';
} elseif ((int)$alert['state'] === 1 || (int)$alert['state'] === 3 || (int)$alert['state'] === 4) {
if ((int)$alert['state'] === 3) {
} elseif ((int) $alert['state'] === 1 || (int) $alert['state'] === 3 || (int) $alert['state'] === 4) {
if ((int) $alert['state'] === 3) {
$msg = '<i class="fa fa-angle-double-down" style="font-size:20px;" aria-hidden="true" title="Status got worse"></i>';
} elseif ((int)$alert['state'] === 4) {
} elseif ((int) $alert['state'] === 4) {
$msg = '<i class="fa fa-angle-double-up" style="font-size:20px;" aria-hidden="true" title="Status got better"></i>';
}
} elseif ((int)$alert['state'] === 2) {
} elseif ((int) $alert['state'] === 2) {
if ($info['until_clear'] === false) {
$ack_ico = $alert_to_unack;
} else {
@@ -145,15 +145,15 @@ foreach (dbFetchRows($sql, $param) as $alert) {
$severity .= ' <strong>-</strong>';
}
if ((int)$alert['state'] === 2) {
if ((int) $alert['state'] === 2) {
$severity_ico = '<span class="alert-status label-primary">&nbsp;</span>';
}
$proc = dbFetchCell('SELECT proc FROM alerts,alert_rules WHERE alert_rules.id = alerts.rule_id AND alerts.id = ?', array($alert['id']));
$proc = dbFetchCell('SELECT proc FROM alerts,alert_rules WHERE alert_rules.id = alerts.rule_id AND alerts.id = ?', [$alert['id']]);
if (($proc == "") || ($proc == "NULL")) {
$has_proc = '';
} else {
if (!preg_match('/^http[s]*:\/\//', $proc)) {
if (! preg_match('/^http[s]*:\/\//', $proc)) {
$has_proc = '';
} else {
$has_proc = '<a href="' . $proc . '" target="_blank"><button type="button" class="btn btn-info fa fa-external-link" aria-hidden="true"></button></a>';
@@ -166,12 +166,12 @@ foreach (dbFetchRows($sql, $param) as $alert) {
$note_class = 'warning';
}
$response[] = array(
$response[] = [
'id' => $rulei++,
'rule' => '<i title="' . htmlentities($alert['rule']) . '"><a href="' . generate_url(array('page' => 'alert-rules')) . '">' . htmlentities($alert['name']) . '</a></i>',
'rule' => '<i title="' . htmlentities($alert['rule']) . '"><a href="' . generate_url(['page' => 'alert-rules']) . '">' . htmlentities($alert['name']) . '</a></i>',
'details' => '<a class="fa fa-plus incident-toggle" style="display:none" data-toggle="collapse" data-target="#incident' . ($alert['id']) . '" data-parent="#alerts"></a>',
'hostname' => $hostname,
'location' => generate_link($alert['location'], array('page' => 'devices', 'location' => $alert['location'])),
'location' => generate_link($alert['location'], ['page' => 'devices', 'location' => $alert['location']]),
'timestamp' => ($alert['timestamp'] ? $alert['timestamp'] : 'N/A'),
'severity' => $severity_ico,
'state' => $alert['state'],
@@ -179,13 +179,13 @@ foreach (dbFetchRows($sql, $param) as $alert) {
'ack_ico' => $ack_ico,
'proc' => $has_proc,
'notes' => "<button type='button' class='btn btn-$note_class fa fa-sticky-note-o command-alert-note' aria-label='Notes' id='alert-notes' data-alert_id='{$alert['id']}'></button>",
);
];
}
$output = array(
$output = [
'current' => $current,
'rowCount' => $rowCount,
'rows' => $response,
'total' => $total,
);
];
echo _json_encode($output);