Skip to content

Commit

Permalink
Apply fixes from StyleCI (librenms#12124)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jellyfrog authored Sep 21, 2020
1 parent 0d56bbd commit 29f45ca
Show file tree
Hide file tree
Showing 816 changed files with 5,038 additions and 5,038 deletions.
18 changes: 9 additions & 9 deletions LibreNMS/Alert/AlertDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ public static function genSQLOld($rule)
//Pretty-print rule to dissect easier
$pretty = ['&&' => ' && ', '||' => ' || '];
$rule = str_replace(array_keys($pretty), $pretty, $rule);
$tmp = explode(" ", $rule);
$tmp = explode(' ', $rule);
$tables = [];
foreach ($tmp as $opt) {
if (strstr($opt, '%') && strstr($opt, '.')) {
$tmpp = explode(".", $opt, 2);
$tmpp[0] = str_replace("%", "", $tmpp[0]);
$tables[] = mres(str_replace("(", "", $tmpp[0]));
$tmpp = explode('.', $opt, 2);
$tmpp[0] = str_replace('%', '', $tmpp[0]);
$tables[] = mres(str_replace('(', '', $tmpp[0]));
$rule = str_replace($opt, $tmpp[0] . '.' . $tmpp[1], $rule);
}
}
Expand All @@ -81,16 +81,16 @@ public static function genSQLOld($rule)
}
$x = sizeof($tables) - 1;
$i = 0;
$join = "";
$join = '';
while ($i < $x) {
if (isset($tables[$i + 1])) {
$gtmp = ResolveGlues([$tables[$i + 1]], 'device_id');
if ($gtmp === false) {
//Cannot resolve glue-chain. Rule is invalid.
return false;
}
$last = "";
$qry = "";
$last = '';
$qry = '';
foreach ($gtmp as $glue) {
if (empty($last)) {
[$tmp,$last] = explode('.', $glue);
Expand All @@ -104,11 +104,11 @@ public static function genSQLOld($rule)
$tables[] = $tmp;
}
}
$join .= "( " . $qry . $tables[0] . ".device_id ) && ";
$join .= '( ' . $qry . $tables[0] . '.device_id ) && ';
}
$i++;
}
$sql = "SELECT * FROM " . implode(",", $tables) . " WHERE (" . $join . "" . str_replace("(", "", $tables[0]) . ".device_id = ?) && (" . str_replace(["%", "@", "!~", "~"], ["", ".*", "NOT REGEXP", "REGEXP"], $rule) . ")";
$sql = 'SELECT * FROM ' . implode(',', $tables) . ' WHERE (' . $join . '' . str_replace('(', '', $tables[0]) . '.device_id = ?) && (' . str_replace(['%', '@', '!~', '~'], ['', '.*', 'NOT REGEXP', 'REGEXP'], $rule) . ')';

return $sql;
}
Expand Down
2 changes: 1 addition & 1 deletion LibreNMS/Alert/AlertRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function runRules($device_id)
$doalert = false;
}

$current_state = dbFetchCell("SELECT state FROM alerts WHERE rule_id = ? AND device_id = ? ORDER BY id DESC LIMIT 1", [$rule['id'], $device_id]);
$current_state = dbFetchCell('SELECT state FROM alerts WHERE rule_id = ? AND device_id = ? ORDER BY id DESC LIMIT 1', [$rule['id'], $device_id]);
if ($doalert) {
if ($current_state == AlertState::ACKNOWLEDGED) {
c_echo('Status: %ySKIP');
Expand Down
30 changes: 15 additions & 15 deletions LibreNMS/Alert/AlertUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class AlertUtil
*/
private static function getRuleId($alert_id)
{
$query = "SELECT `rule_id` FROM `alerts` WHERE `id`=?";
$query = 'SELECT `rule_id` FROM `alerts` WHERE `id`=?';

return dbFetchCell($query, [$alert_id]);
}
Expand All @@ -66,7 +66,7 @@ public static function getAlertTransports($alert_id)
*/
public static function getDefaultAlertTransports()
{
$query = "SELECT transport_id, transport_type, transport_name FROM alert_transports WHERE is_default=true";
$query = 'SELECT transport_id, transport_type, transport_name FROM alert_transports WHERE is_default=true';

return dbFetchRows($query);
}
Expand All @@ -91,30 +91,30 @@ public static function getContacts($results)
$uids = [];
foreach ($results as $result) {
$tmp = null;
if (is_numeric($result["bill_id"])) {
$tmpa = dbFetchRows("SELECT user_id FROM bill_perms WHERE bill_id = ?", [$result["bill_id"]]);
if (is_numeric($result['bill_id'])) {
$tmpa = dbFetchRows('SELECT user_id FROM bill_perms WHERE bill_id = ?', [$result['bill_id']]);
foreach ($tmpa as $tmp) {
$uids[$tmp['user_id']] = $tmp['user_id'];
}
}
if (is_numeric($result["port_id"])) {
$tmpa = dbFetchRows("SELECT user_id FROM ports_perms WHERE port_id = ?", [$result["port_id"]]);
if (is_numeric($result['port_id'])) {
$tmpa = dbFetchRows('SELECT user_id FROM ports_perms WHERE port_id = ?', [$result['port_id']]);
foreach ($tmpa as $tmp) {
$uids[$tmp['user_id']] = $tmp['user_id'];
}
}
if (is_numeric($result["device_id"])) {
if (is_numeric($result['device_id'])) {
if (Config::get('alert.syscontact') == true) {
if (dbFetchCell("SELECT attrib_value FROM devices_attribs WHERE attrib_type = 'override_sysContact_bool' AND device_id = ?", [$result["device_id"]])) {
$tmpa = dbFetchCell("SELECT attrib_value FROM devices_attribs WHERE attrib_type = 'override_sysContact_string' AND device_id = ?", [$result["device_id"]]);
if (dbFetchCell("SELECT attrib_value FROM devices_attribs WHERE attrib_type = 'override_sysContact_bool' AND device_id = ?", [$result['device_id']])) {
$tmpa = dbFetchCell("SELECT attrib_value FROM devices_attribs WHERE attrib_type = 'override_sysContact_string' AND device_id = ?", [$result['device_id']]);
} else {
$tmpa = dbFetchCell("SELECT sysContact FROM devices WHERE device_id = ?", [$result["device_id"]]);
$tmpa = dbFetchCell('SELECT sysContact FROM devices WHERE device_id = ?', [$result['device_id']]);
}
if (! empty($tmpa)) {
$contacts[$tmpa] = '';
}
}
$tmpa = dbFetchRows("SELECT user_id FROM devices_perms WHERE device_id = ?", [$result["device_id"]]);
$tmpa = dbFetchRows('SELECT user_id FROM devices_perms WHERE device_id = ?', [$result['device_id']]);
foreach ($tmpa as $tmp) {
$uids[$tmp['user_id']] = $tmp['user_id'];
}
Expand Down Expand Up @@ -175,7 +175,7 @@ public static function getContacts($results)

public static function getRules($device_id)
{
$query = "SELECT DISTINCT a.* FROM alert_rules a
$query = 'SELECT DISTINCT a.* FROM alert_rules a
LEFT JOIN alert_device_map d ON a.id=d.rule_id AND (a.invert_map = 0 OR a.invert_map = 1 AND d.device_id = ?)
LEFT JOIN alert_group_map g ON a.id=g.rule_id AND (a.invert_map = 0 OR a.invert_map = 1 AND g.group_id IN (SELECT DISTINCT device_group_id FROM device_group_device WHERE device_id = ?))
LEFT JOIN alert_location_map l ON a.id=l.rule_id AND (a.invert_map = 0 OR a.invert_map = 1 AND l.location_id IN (SELECT DISTINCT location_id FROM devices WHERE device_id = ?))
Expand All @@ -184,7 +184,7 @@ public static function getRules($device_id)
(d.device_id IS NULL AND g.group_id IS NULL)
OR (a.invert_map = 0 AND (d.device_id=? OR dg.device_id=?))
OR (a.invert_map = 1 AND (d.device_id != ? OR d.device_id IS NULL) AND (dg.device_id != ? OR dg.device_id IS NULL))
)";
)';

$params = [$device_id, $device_id, $device_id, $device_id, $device_id, $device_id, $device_id, $device_id];

Expand Down Expand Up @@ -224,11 +224,11 @@ public static function runMacros($rule, $x = 1)
$macros = Config::get('alert.macros.rule', []) .
krsort($macros);
foreach ($macros as $macro => $value) {
if (! strstr($macro, " ")) {
if (! strstr($macro, ' ')) {
$rule = str_replace('%macros.' . $macro, '(' . $value . ')', $rule);
}
}
if (strstr($rule, "%macros.")) {
if (strstr($rule, '%macros.')) {
if (++$x < 30) {
$rule = self::runMacros($rule, $x);
} else {
Expand Down
10 changes: 5 additions & 5 deletions LibreNMS/Alert/RunAlerts.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public function timeFormat($secs)

public function clearStaleAlerts()
{
$sql = "SELECT `alerts`.`id` AS `alert_id`, `devices`.`hostname` AS `hostname` FROM `alerts` LEFT JOIN `devices` ON `alerts`.`device_id`=`devices`.`device_id` RIGHT JOIN `alert_rules` ON `alerts`.`rule_id`=`alert_rules`.`id` WHERE `alerts`.`state`!=" . AlertState::CLEAR . " AND `devices`.`hostname` IS NULL";
$sql = 'SELECT `alerts`.`id` AS `alert_id`, `devices`.`hostname` AS `hostname` FROM `alerts` LEFT JOIN `devices` ON `alerts`.`device_id`=`devices`.`device_id` RIGHT JOIN `alert_rules` ON `alerts`.`rule_id`=`alert_rules`.`id` WHERE `alerts`.`state`!=' . AlertState::CLEAR . ' AND `devices`.`hostname` IS NULL';
foreach (dbFetchRows($sql) as $alert) {
if (empty($alert['hostname']) && isset($alert['alert_id'])) {
dbDelete('alerts', '`id` = ?', [$alert['alert_id']]);
Expand Down Expand Up @@ -544,9 +544,9 @@ public function extTransports($obj)
public function alertLog($result, $obj, $transport)
{
$prefix = [
AlertState::RECOVERED => "recovery",
AlertState::ACTIVE => $obj['severity'] . " alert",
AlertState::ACKNOWLEDGED => "acknowledgment",
AlertState::RECOVERED => 'recovery',
AlertState::ACTIVE => $obj['severity'] . ' alert',
AlertState::ACKNOWLEDGED => 'acknowledgment',
];
$prefix[3] = &$prefix[0];
$prefix[4] = &$prefix[0];
Expand Down Expand Up @@ -581,7 +581,7 @@ public function alertLog($result, $obj, $transport)
*/
public function isParentDown($device)
{
$parent_count = dbFetchCell("SELECT count(*) from `device_relationships` WHERE `child_device_id` = ?", [$device]);
$parent_count = dbFetchCell('SELECT count(*) from `device_relationships` WHERE `child_device_id` = ?', [$device]);
if (! $parent_count) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion LibreNMS/Alert/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function bladeTitle($data)
try {
return view(['template' => $data['title']], $alert)->__toString();
} catch (\Exception $e) {
return $data['title'] ?: view(['template' => "Template " . $data['name']], $alert)->__toString();
return $data['title'] ?: view(['template' => 'Template ' . $data['name']], $alert)->__toString();
}
}

Expand Down
2 changes: 1 addition & 1 deletion LibreNMS/Alert/Transport.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ abstract class Transport implements TransportInterface
public function __construct($transport_id = null)
{
if (! empty($transport_id)) {
$sql = "SELECT `transport_config` FROM `alert_transports` WHERE `transport_id`=?";
$sql = 'SELECT `transport_config` FROM `alert_transports` WHERE `transport_id`=?';
$this->config = json_decode(dbFetchCell($sql, [$transport_id]), true);
}
}
Expand Down
6 changes: 3 additions & 3 deletions LibreNMS/Alert/Transport/Alerta.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ public function contactAlerta($obj, $opts)
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ($code != 201) {
var_dump("API '$host' returned Error");
var_dump("Params: " . $alert_message);
var_dump("Return: " . $ret);
var_dump("Headers: " . $headers);
var_dump('Params: ' . $alert_message);
var_dump('Return: ' . $ret);
var_dump('Headers: ' . $headers);

return 'HTTP Status code ' . $code;
}
Expand Down
2 changes: 1 addition & 1 deletion LibreNMS/Alert/Transport/Alertmanager.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static function contactAlertmanager($obj, $api)
$curl = curl_init();
$alertmanager_msg = strip_tags($obj['msg']);
$data = [[
$alertmanager_status => date("c"),
$alertmanager_status => date('c'),
'generatorURL' => $gen_url,
'annotations' => [
'summary' => $obj['name'],
Expand Down
20 changes: 10 additions & 10 deletions LibreNMS/Alert/Transport/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,23 @@ private function contactAPI($obj, $api, $options, $method, $auth, $headers, $bod
$query = [];

$method = strtolower($method);
$host = explode("?", $api, 2)[0]; //we don't use the parameter part, cause we build it out of options.
$host = explode('?', $api, 2)[0]; //we don't use the parameter part, cause we build it out of options.

//get each line of key-values and process the variables for Headers;
foreach (preg_split("/\\r\\n|\\r|\\n/", $headers, -1, PREG_SPLIT_NO_EMPTY) as $current_line) {
foreach (preg_split('/\\r\\n|\\r|\\n/', $headers, -1, PREG_SPLIT_NO_EMPTY) as $current_line) {
[$u_key, $u_val] = explode('=', $current_line, 2);
foreach ($obj as $p_key => $p_val) {
$u_val = str_replace("{{ $" . $p_key . ' }}', $p_val, $u_val);
$u_val = str_replace('{{ $' . $p_key . ' }}', $p_val, $u_val);
}
//store the parameter in the array for HTTP headers
$request_heads[$u_key] = $u_val;
}
//get each line of key-values and process the variables for Options;
foreach (preg_split("/\\r\\n|\\r|\\n/", $options, -1, PREG_SPLIT_NO_EMPTY) as $current_line) {
foreach (preg_split('/\\r\\n|\\r|\\n/', $options, -1, PREG_SPLIT_NO_EMPTY) as $current_line) {
[$u_key, $u_val] = explode('=', $current_line, 2);
// Replace the values
foreach ($obj as $p_key => $p_val) {
$u_val = str_replace("{{ $" . $p_key . ' }}', $p_val, $u_val);
$u_val = str_replace('{{ $' . $p_key . ' }}', $p_val, $u_val);
}
//store the parameter in the array for HTTP query
$query[$u_key] = $u_val;
Expand All @@ -76,10 +76,10 @@ private function contactAPI($obj, $api, $options, $method, $auth, $headers, $bod
if (count($request_heads) > 0) {
$request_opts['headers'] = $request_heads;
}
if ($method == "get") {
if ($method == 'get') {
$request_opts['query'] = $query;
$res = $client->request('GET', $host, $request_opts);
} elseif ($method == "put") {
} elseif ($method == 'put') {
$request_opts['query'] = $query;
$request_opts['body'] = $body;
$res = $client->request('PUT', $host, $request_opts);
Expand All @@ -91,11 +91,11 @@ private function contactAPI($obj, $api, $options, $method, $auth, $headers, $bod
$code = $res->getStatusCode();
if ($code != 200) {
var_dump("API '$host' returned Error");
var_dump("Params:");
var_dump('Params:');
var_dump($query);
var_dump("Response headers:");
var_dump('Response headers:');
var_dump($res->getHeaders());
var_dump("Return: " . $res->getReasonPhrase());
var_dump('Return: ' . $res->getReasonPhrase());

return 'HTTP Status code ' . $code;
}
Expand Down
20 changes: 10 additions & 10 deletions LibreNMS/Alert/Transport/Boxcar.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,22 @@ public static function contactBoxcar($obj, $api)
$data['user_credentials'] = $api['access_token'];
$data['notification[source_name]'] = Config::get('project_id', 'librenms');
switch ($obj['severity']) {
case "critical":
$severity = "Critical";
case 'critical':
$severity = 'Critical';
if (! empty($api['sound_critical'])) {
$data['notification[sound]'] = $api['sound_critical'];
}
break;
case "warning":
$severity = "Warning";
case 'warning':
$severity = 'Warning';
if (! empty($api['sound_warning'])) {
$data['notification[sound]'] = $api['sound_warning'];
}
break;
}
switch ($obj['state']) {
case AlertState::RECOVERED:
$title_text = "OK";
$title_text = 'OK';
if (! empty($api['sound_ok'])) {
$data['notification[sound]'] = $api['sound_ok'];
}
Expand All @@ -80,15 +80,15 @@ public static function contactBoxcar($obj, $api)
$title_text = $severity;
break;
case AlertState::ACKNOWLEDGED:
$title_text = "Acknowledged";
$title_text = 'Acknowledged';
break;
}
$data['notification[title]'] = $title_text . " - " . $obj['hostname'] . " - " . $obj['name'];
$message_text = "Timestamp: " . $obj['timestamp'];
$data['notification[title]'] = $title_text . ' - ' . $obj['hostname'] . ' - ' . $obj['name'];
$message_text = 'Timestamp: ' . $obj['timestamp'];
if (! empty($obj['faults'])) {
$message_text .= "\n\nFaults:\n";
foreach ($obj['faults'] as $k => $faults) {
$message_text .= "#" . $k . " " . $faults['string'] . "\n";
$message_text .= '#' . $k . ' ' . $faults['string'] . "\n";
}
}
$data['notification[long_message]'] = $message_text;
Expand All @@ -101,7 +101,7 @@ public static function contactBoxcar($obj, $api)
curl_exec($curl);
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ($code != 201) {
var_dump("Boxcar returned error"); //FIXME: proper debugging
var_dump('Boxcar returned error'); //FIXME: proper debugging

return false;
}
Expand Down
Loading

0 comments on commit 29f45ca

Please sign in to comment.