mirror of
https://github.com/librenms/librenms.git
synced 2024-09-21 10:28:13 +00:00
Apply fixes from StyleCI (#12124)
This commit is contained in:
parent
0d56bbd946
commit
29f45ca352
@ -64,13 +64,13 @@ class AlertDB
|
||||
//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);
|
||||
}
|
||||
}
|
||||
@ -81,7 +81,7 @@ class AlertDB
|
||||
}
|
||||
$x = sizeof($tables) - 1;
|
||||
$i = 0;
|
||||
$join = "";
|
||||
$join = '';
|
||||
while ($i < $x) {
|
||||
if (isset($tables[$i + 1])) {
|
||||
$gtmp = ResolveGlues([$tables[$i + 1]], 'device_id');
|
||||
@ -89,8 +89,8 @@ class AlertDB
|
||||
//Cannot resolve glue-chain. Rule is invalid.
|
||||
return false;
|
||||
}
|
||||
$last = "";
|
||||
$qry = "";
|
||||
$last = '';
|
||||
$qry = '';
|
||||
foreach ($gtmp as $glue) {
|
||||
if (empty($last)) {
|
||||
[$tmp,$last] = explode('.', $glue);
|
||||
@ -104,11 +104,11 @@ class AlertDB
|
||||
$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;
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ class AlertRules
|
||||
$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');
|
||||
|
@ -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]);
|
||||
}
|
||||
@ -66,7 +66,7 @@ class AlertUtil
|
||||
*/
|
||||
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);
|
||||
}
|
||||
@ -91,30 +91,30 @@ class AlertUtil
|
||||
$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'];
|
||||
}
|
||||
@ -175,7 +175,7 @@ class AlertUtil
|
||||
|
||||
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 = ?))
|
||||
@ -184,7 +184,7 @@ class AlertUtil
|
||||
(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];
|
||||
|
||||
@ -224,11 +224,11 @@ class AlertUtil
|
||||
$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 {
|
||||
|
@ -225,7 +225,7 @@ class RunAlerts
|
||||
|
||||
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']]);
|
||||
@ -544,9 +544,9 @@ class RunAlerts
|
||||
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];
|
||||
@ -581,7 +581,7 @@ class RunAlerts
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ class Template
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -73,9 +73,9 @@ class Alerta extends Transport
|
||||
$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;
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ class Alertmanager extends Transport
|
||||
$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'],
|
||||
|
@ -46,23 +46,23 @@ class Api extends Transport
|
||||
$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;
|
||||
@ -76,10 +76,10 @@ class Api extends Transport
|
||||
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);
|
||||
@ -91,11 +91,11 @@ class Api extends Transport
|
||||
$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;
|
||||
}
|
||||
|
@ -56,14 +56,14 @@ class Boxcar extends Transport
|
||||
$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'];
|
||||
}
|
||||
@ -71,7 +71,7 @@ class Boxcar extends Transport
|
||||
}
|
||||
switch ($obj['state']) {
|
||||
case AlertState::RECOVERED:
|
||||
$title_text = "OK";
|
||||
$title_text = 'OK';
|
||||
if (! empty($api['sound_ok'])) {
|
||||
$data['notification[sound]'] = $api['sound_ok'];
|
||||
}
|
||||
@ -80,15 +80,15 @@ class Boxcar extends Transport
|
||||
$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;
|
||||
@ -101,7 +101,7 @@ class Boxcar extends Transport
|
||||
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;
|
||||
}
|
||||
|
@ -22,12 +22,12 @@ class Canopsis extends Transport
|
||||
public function contactCanopsis($obj, $opts)
|
||||
{
|
||||
// Configurations
|
||||
$host = $opts["host"];
|
||||
$port = $opts["port"];
|
||||
$user = $opts["user"];
|
||||
$pass = $opts["pass"];
|
||||
$vhost = $opts["vhost"];
|
||||
$exchange = "canopsis.events";
|
||||
$host = $opts['host'];
|
||||
$port = $opts['port'];
|
||||
$user = $opts['user'];
|
||||
$pass = $opts['pass'];
|
||||
$vhost = $opts['vhost'];
|
||||
$exchange = 'canopsis.events';
|
||||
|
||||
// Connection
|
||||
$conn = new \PhpAmqpLib\Connection\AMQPConnection($host, $port, $user, $pass, $vhost);
|
||||
@ -39,37 +39,37 @@ class Canopsis extends Transport
|
||||
|
||||
// Create Canopsis event, see: https://github.com/capensis/canopsis/wiki/Event-specification
|
||||
switch ($obj['severity']) {
|
||||
case "ok":
|
||||
case 'ok':
|
||||
$state = 0;
|
||||
break;
|
||||
case "warning":
|
||||
case 'warning':
|
||||
$state = 2;
|
||||
break;
|
||||
case "critical":
|
||||
case 'critical':
|
||||
$state = 3;
|
||||
break;
|
||||
default:
|
||||
$state = 0;
|
||||
}
|
||||
$msg_body = [
|
||||
"timestamp" => time(),
|
||||
"connector" => "librenms",
|
||||
"connector_name" => "LibreNMS1",
|
||||
"event_type" => "check",
|
||||
"source_type" => "resource",
|
||||
"component" => $obj['hostname'],
|
||||
"resource" => $obj['name'],
|
||||
"state" => $state,
|
||||
"output" => $obj['msg'],
|
||||
"display_name" => "librenms",
|
||||
'timestamp' => time(),
|
||||
'connector' => 'librenms',
|
||||
'connector_name' => 'LibreNMS1',
|
||||
'event_type' => 'check',
|
||||
'source_type' => 'resource',
|
||||
'component' => $obj['hostname'],
|
||||
'resource' => $obj['name'],
|
||||
'state' => $state,
|
||||
'output' => $obj['msg'],
|
||||
'display_name' => 'librenms',
|
||||
];
|
||||
$msg_raw = json_encode($msg_body);
|
||||
|
||||
// Build routing key
|
||||
if ($msg_body['source_type'] == "resource") {
|
||||
$msg_rk = $msg_rk . "." . $msg_body['resource'];
|
||||
if ($msg_body['source_type'] == 'resource') {
|
||||
$msg_rk = $msg_rk . '.' . $msg_body['resource'];
|
||||
} else {
|
||||
$msg_rk = $msg_body['connector'] . "." . $msg_body['connector_name'] . "." . $msg_body['event_type'] . "." . $msg_body['source_type'] . "." . $msg_body['component'];
|
||||
$msg_rk = $msg_body['connector'] . '.' . $msg_body['connector_name'] . '.' . $msg_body['event_type'] . '.' . $msg_body['source_type'] . '.' . $msg_body['component'];
|
||||
}
|
||||
|
||||
// Publish Event
|
||||
|
@ -40,7 +40,7 @@ class Clickatell extends Transport
|
||||
|
||||
$curl = curl_init($url);
|
||||
set_curl_proxy($curl);
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET");
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'GET');
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
|
||||
$ret = curl_exec($curl);
|
||||
|
@ -89,8 +89,8 @@ class Discord extends Transport
|
||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
if ($code != 204) {
|
||||
var_dump("API '$host' returned Error"); //FIXME: propper debuging
|
||||
var_dump("Params: " . $alert_message); //FIXME: propper debuging
|
||||
var_dump("Return: " . $ret); //FIXME: propper debuging
|
||||
var_dump('Params: ' . $alert_message); //FIXME: propper debuging
|
||||
var_dump('Return: ' . $ret); //FIXME: propper debuging
|
||||
|
||||
return 'HTTP Status code ' . $code;
|
||||
}
|
||||
|
@ -38,21 +38,21 @@ class Elasticsearch extends Transport
|
||||
{
|
||||
$es_host = '127.0.0.1';
|
||||
$es_port = 9200;
|
||||
$index = strftime("librenms-%Y.%m.%d");
|
||||
$index = strftime('librenms-%Y.%m.%d');
|
||||
$type = 'alert';
|
||||
$severity = $obj['severity'];
|
||||
$device = device_by_id_cache($obj['device_id']); // for event logging
|
||||
|
||||
if (! empty($opts['es_host'])) {
|
||||
if (preg_match("/[a-zA-Z]/", $opts['es_host'])) {
|
||||
if (preg_match('/[a-zA-Z]/', $opts['es_host'])) {
|
||||
$es_host = gethostbyname($opts['es_host']);
|
||||
if ($es_host === $opts['es_host']) {
|
||||
return "Alphanumeric hostname found but does not resolve to an IP.";
|
||||
return 'Alphanumeric hostname found but does not resolve to an IP.';
|
||||
}
|
||||
} elseif (filter_var($opts['es_host'], FILTER_VALIDATE_IP)) {
|
||||
$es_host = $opts['es_host'];
|
||||
} else {
|
||||
return "Elasticsearch host is not a valid IP: " . $opts['es_host'];
|
||||
return 'Elasticsearch host is not a valid IP: ' . $opts['es_host'];
|
||||
}
|
||||
}
|
||||
|
||||
@ -68,40 +68,40 @@ class Elasticsearch extends Transport
|
||||
|
||||
switch ($obj['state']) {
|
||||
case AlertState::RECOVERED:
|
||||
$state = "ok";
|
||||
$state = 'ok';
|
||||
break;
|
||||
case AlertState::ACTIVE:
|
||||
$state = $severity;
|
||||
break;
|
||||
case AlertState::ACKNOWLEDGED:
|
||||
$state = "acknowledged";
|
||||
$state = 'acknowledged';
|
||||
break;
|
||||
case AlertState::WORSE:
|
||||
$state = "worse";
|
||||
$state = 'worse';
|
||||
break;
|
||||
case AlertState::BETTER:
|
||||
$state = "better";
|
||||
$state = 'better';
|
||||
break;
|
||||
}
|
||||
|
||||
$data = [
|
||||
'@timestamp' => date('c'),
|
||||
"host" => gethostname(),
|
||||
"location" => $obj['location'],
|
||||
"title" => $obj['name'],
|
||||
"message" => $obj['string'],
|
||||
"device_id" => $obj['device_id'],
|
||||
"device_name" => $obj['hostname'],
|
||||
"device_hardware" => $obj['hardware'],
|
||||
"device_version" => $obj['version'],
|
||||
"state" => $state,
|
||||
"severity" => $severity,
|
||||
"first_occurrence" => $obj['timestamp'],
|
||||
"entity_type" => "device",
|
||||
"entity_tab" => "overview",
|
||||
"entity_id" => $obj['device_id'],
|
||||
"entity_name" => $obj['hostname'],
|
||||
"entity_descr" => $obj['sysDescr'],
|
||||
'host' => gethostname(),
|
||||
'location' => $obj['location'],
|
||||
'title' => $obj['name'],
|
||||
'message' => $obj['string'],
|
||||
'device_id' => $obj['device_id'],
|
||||
'device_name' => $obj['hostname'],
|
||||
'device_hardware' => $obj['hardware'],
|
||||
'device_version' => $obj['version'],
|
||||
'state' => $state,
|
||||
'severity' => $severity,
|
||||
'first_occurrence' => $obj['timestamp'],
|
||||
'entity_type' => 'device',
|
||||
'entity_tab' => 'overview',
|
||||
'entity_id' => $obj['device_id'],
|
||||
'entity_name' => $obj['hostname'],
|
||||
'entity_descr' => $obj['sysDescr'],
|
||||
];
|
||||
|
||||
if (! empty($obj['faults'])) {
|
||||
|
@ -46,17 +46,17 @@ class Gitlab extends Transport
|
||||
|
||||
$project_id = $opts['project-id'];
|
||||
$project_key = $opts['key'];
|
||||
$details = "Librenms alert for: " . $obj['hostname'];
|
||||
$details = 'Librenms alert for: ' . $obj['hostname'];
|
||||
$description = $obj['msg'];
|
||||
$title = urlencode($details);
|
||||
$desc = urlencode($description);
|
||||
$url = $opts['host'] . "/api/v4/projects/$project_id/issues?title=$title&description=$desc";
|
||||
$curl = curl_init();
|
||||
|
||||
$data = ["title" => $details,
|
||||
"description" => $description,
|
||||
$data = ['title' => $details,
|
||||
'description' => $description,
|
||||
];
|
||||
$postdata = ["fields" => $data];
|
||||
$postdata = ['fields' => $data];
|
||||
$datastring = json_encode($postdata);
|
||||
|
||||
set_curl_proxy($curl);
|
||||
@ -65,7 +65,7 @@ class Gitlab extends Transport
|
||||
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($curl, CURLOPT_VERBOSE, 1);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $datastring);
|
||||
@ -74,11 +74,11 @@ class Gitlab extends Transport
|
||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
if ($code == 200) {
|
||||
$gitlabout = json_decode($ret, true);
|
||||
d_echo("Created Gitlab issue " . $gitlabout['key'] . " for " . $device);
|
||||
d_echo('Created Gitlab issue ' . $gitlabout['key'] . ' for ' . $device);
|
||||
|
||||
return true;
|
||||
} else {
|
||||
d_echo("Gitlab connection error: " . serialize($ret));
|
||||
d_echo('Gitlab connection error: ' . serialize($ret));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -41,50 +41,50 @@ class Hipchat extends Transport
|
||||
public function contactHipchat($obj, $option)
|
||||
{
|
||||
$version = 1;
|
||||
if (stripos($option['url'], "v2")) {
|
||||
if (stripos($option['url'], 'v2')) {
|
||||
$version = 2;
|
||||
}
|
||||
|
||||
// Generate our URL from the base URL + room_id and the auth token if the version is 2.
|
||||
$url = $option['url'];
|
||||
if ($version == 2) {
|
||||
$url .= "/" . urlencode($option["room_id"]) . "/notification?auth_token=" . urlencode($option["auth_token"]);
|
||||
$url .= '/' . urlencode($option['room_id']) . '/notification?auth_token=' . urlencode($option['auth_token']);
|
||||
}
|
||||
foreach ($obj as $key => $value) {
|
||||
$api = str_replace("%" . $key, $method == "get" ? urlencode($value) : $value, $api);
|
||||
$api = str_replace('%' . $key, $method == 'get' ? urlencode($value) : $value, $api);
|
||||
}
|
||||
$curl = curl_init();
|
||||
|
||||
if (empty($obj["msg"])) {
|
||||
return "Empty Message";
|
||||
if (empty($obj['msg'])) {
|
||||
return 'Empty Message';
|
||||
}
|
||||
|
||||
if (empty($option["message_format"])) {
|
||||
$option["message_format"] = 'text';
|
||||
if (empty($option['message_format'])) {
|
||||
$option['message_format'] = 'text';
|
||||
}
|
||||
|
||||
// Sane default of making the message color green if the message indicates
|
||||
// that the alert recovered. If it rebooted, make it yellow.
|
||||
if (stripos($obj["msg"], "recovered")) {
|
||||
$color = "green";
|
||||
} elseif (stripos($obj["msg"], "rebooted")) {
|
||||
$color = "yellow";
|
||||
if (stripos($obj['msg'], 'recovered')) {
|
||||
$color = 'green';
|
||||
} elseif (stripos($obj['msg'], 'rebooted')) {
|
||||
$color = 'yellow';
|
||||
} else {
|
||||
if (empty($option["color"]) || $option["color"] == 'u') {
|
||||
if (empty($option['color']) || $option['color'] == 'u') {
|
||||
$color = 'red';
|
||||
} else {
|
||||
$color = $option["color"];
|
||||
$color = $option['color'];
|
||||
}
|
||||
}
|
||||
|
||||
$data[] = "message=" . urlencode($obj["msg"]);
|
||||
$data[] = 'message=' . urlencode($obj['msg']);
|
||||
if ($version == 1) {
|
||||
$data[] = "room_id=" . urlencode($option["room_id"]);
|
||||
$data[] = 'room_id=' . urlencode($option['room_id']);
|
||||
}
|
||||
$data[] = "from=" . urlencode($option["from"]);
|
||||
$data[] = "color=" . urlencode($color);
|
||||
$data[] = "notify=" . urlencode($option["notify"]);
|
||||
$data[] = "message_format=" . urlencode($option["message_format"]);
|
||||
$data[] = 'from=' . urlencode($option['from']);
|
||||
$data[] = 'color=' . urlencode($color);
|
||||
$data[] = 'notify=' . urlencode($option['notify']);
|
||||
$data[] = 'message_format=' . urlencode($option['message_format']);
|
||||
|
||||
$data = implode('&', $data);
|
||||
set_curl_proxy($curl);
|
||||
@ -100,8 +100,8 @@ class Hipchat extends Transport
|
||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
if ($code != 200 && $code != 204) {
|
||||
var_dump("API '$url' returned Error");
|
||||
var_dump("Params: " . $message);
|
||||
var_dump("Return: " . $ret);
|
||||
var_dump('Params: ' . $message);
|
||||
var_dump('Return: ' . $ret);
|
||||
|
||||
return 'HTTP Status code ' . $code;
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ class Hue extends Transport
|
||||
$url = $opts['bridge'] . "/api/$hue_user/groups/0/action";
|
||||
$curl = curl_init();
|
||||
$duration = $opts['duration'];
|
||||
$data = ["alert" => $duration];
|
||||
$data = ['alert' => $duration];
|
||||
$datastring = json_encode($data);
|
||||
|
||||
set_curl_proxy($curl);
|
||||
@ -65,7 +65,7 @@ class Hue extends Transport
|
||||
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT');
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($curl, CURLOPT_VERBOSE, 1);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $datastring);
|
||||
@ -73,11 +73,11 @@ class Hue extends Transport
|
||||
$ret = curl_exec($curl);
|
||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
if ($code == 200) {
|
||||
d_echo("Sent alert to Phillips Hue Bridge " . $opts['host'] . " for " . $device);
|
||||
d_echo('Sent alert to Phillips Hue Bridge ' . $opts['host'] . ' for ' . $device);
|
||||
|
||||
return true;
|
||||
} else {
|
||||
d_echo("Hue bridge connection error: " . serialize($ret));
|
||||
d_echo('Hue bridge connection error: ' . serialize($ret));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -34,9 +34,9 @@ class Irc extends Transport
|
||||
|
||||
public function contactIrc($obj, $opts)
|
||||
{
|
||||
$f = Config::get('install_dir') . "/.ircbot.alert";
|
||||
if (file_exists($f) && filetype($f) == "fifo") {
|
||||
$f = fopen($f, "w+");
|
||||
$f = Config::get('install_dir') . '/.ircbot.alert';
|
||||
if (file_exists($f) && filetype($f) == 'fifo') {
|
||||
$f = fopen($f, 'w+');
|
||||
$r = fwrite($f, json_encode($obj) . "\n");
|
||||
$f = fclose($f);
|
||||
if ($r === false) {
|
||||
|
@ -52,16 +52,16 @@ class Jira extends Transport
|
||||
$password = $opts['password'];
|
||||
$prjkey = $opts['prjkey'];
|
||||
$issuetype = $opts['issuetype'];
|
||||
$details = "Librenms alert for: " . $obj['hostname'];
|
||||
$details = 'Librenms alert for: ' . $obj['hostname'];
|
||||
$description = $obj['msg'];
|
||||
$url = $opts['url'] . '/rest/api/latest/issue';
|
||||
$curl = curl_init();
|
||||
|
||||
$data = ["project" => ["key" => $prjkey],
|
||||
"summary" => $details,
|
||||
"description" => $description,
|
||||
"issuetype" => ["name" => $issuetype], ];
|
||||
$postdata = ["fields" => $data];
|
||||
$data = ['project' => ['key' => $prjkey],
|
||||
'summary' => $details,
|
||||
'description' => $description,
|
||||
'issuetype' => ['name' => $issuetype], ];
|
||||
$postdata = ['fields' => $data];
|
||||
$datastring = json_encode($postdata);
|
||||
|
||||
set_curl_proxy($curl);
|
||||
@ -71,7 +71,7 @@ class Jira extends Transport
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
|
||||
curl_setopt($curl, CURLOPT_USERPWD, "$username:$password");
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($curl, CURLOPT_VERBOSE, 1);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $datastring);
|
||||
@ -80,11 +80,11 @@ class Jira extends Transport
|
||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
if ($code == 200) {
|
||||
$jiraout = json_decode($ret, true);
|
||||
d_echo("Created jira issue " . $jiraout['key'] . " for " . $device);
|
||||
d_echo('Created jira issue ' . $jiraout['key'] . ' for ' . $device);
|
||||
|
||||
return true;
|
||||
} else {
|
||||
d_echo("Jira connection error: " . serialize($ret));
|
||||
d_echo('Jira connection error: ' . serialize($ret));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ class Kayako extends Transport
|
||||
|
||||
public function contactKayako($host, $kayako)
|
||||
{
|
||||
$url = $kayako['url'] . "/Tickets/Ticket";
|
||||
$url = $kayako['url'] . '/Tickets/Ticket';
|
||||
$key = $kayako['key'];
|
||||
$secret = $kayako['secret'];
|
||||
$user = Config::get('email_from');
|
||||
@ -68,7 +68,7 @@ class Kayako extends Transport
|
||||
|
||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
if ($code != 200) {
|
||||
var_dump("Kayako returned Error, retry later");
|
||||
var_dump('Kayako returned Error, retry later');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -43,14 +43,14 @@ class Matrix extends Transport
|
||||
$txnid = rand(1111, 9999) . time();
|
||||
|
||||
$server = preg_replace('/\/$/', '', $server);
|
||||
$host = $server . "/_matrix/client/r0/rooms/" . urlencode($room) . "/send/m.room.message/" . $txnid;
|
||||
$host = $server . '/_matrix/client/r0/rooms/' . urlencode($room) . '/send/m.room.message/' . $txnid;
|
||||
|
||||
$request_heads['Authorization'] = "Bearer $authtoken";
|
||||
$request_heads['Content-Type'] = "application/json";
|
||||
$request_heads['Accept'] = "application/json";
|
||||
$request_heads['Content-Type'] = 'application/json';
|
||||
$request_heads['Accept'] = 'application/json';
|
||||
|
||||
foreach ($obj as $p_key => $p_val) {
|
||||
$message = str_replace("{{ $" . $p_key . ' }}', $p_val, $message);
|
||||
$message = str_replace('{{ $' . $p_key . ' }}', $p_val, $message);
|
||||
}
|
||||
|
||||
$body = ['body'=>$message, 'msgtype'=>'m.text'];
|
||||
@ -64,10 +64,10 @@ class Matrix extends Transport
|
||||
$code = $res->getStatusCode();
|
||||
if ($code != 200) {
|
||||
var_dump("Matrix '$host' returned Error");
|
||||
var_dump("Params:");
|
||||
var_dump("Response headers:");
|
||||
var_dump('Params:');
|
||||
var_dump('Response headers:');
|
||||
var_dump($res->getHeaders());
|
||||
var_dump("Return: " . $res->getReasonPhrase());
|
||||
var_dump('Return: ' . $res->getReasonPhrase());
|
||||
|
||||
return 'HTTP Status code ' . $code;
|
||||
}
|
||||
|
@ -77,11 +77,11 @@ class Mattermost extends Transport
|
||||
$ret = curl_exec($curl);
|
||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
if ($code != 200) {
|
||||
d_echo("Mattermost Connection Error: " . $ret);
|
||||
d_echo('Mattermost Connection Error: ' . $ret);
|
||||
|
||||
return 'HTTP Status code ' . $code;
|
||||
} else {
|
||||
d_echo("Mattermost message sent for " . $device);
|
||||
d_echo('Mattermost message sent for ' . $device);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ class Msteams extends Transport
|
||||
$ret = curl_exec($curl);
|
||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
if ($code != 200) {
|
||||
var_dump("Microsoft Teams returned Error, retry later");
|
||||
var_dump('Microsoft Teams returned Error, retry later');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -53,11 +53,11 @@ class Nagios extends Transport
|
||||
$format .= strtotime($obj['timestamp']) . "\t";
|
||||
$format .= $obj['hostname'] . "\t";
|
||||
$format .= md5($obj['rule']) . "\t"; //FIXME: Better entity
|
||||
$format .= ($obj['state'] ? $obj['severity'] : "ok") . "\t";
|
||||
$format .= ($obj['state'] ? $obj['severity'] : 'ok') . "\t";
|
||||
$format .= "0\t";
|
||||
$format .= "0\t";
|
||||
$format .= str_replace("\n", "", nl2br($obj['msg'])) . "\t";
|
||||
$format .= "NULL"; //FIXME: What's the HOSTPERFDATA equivalent for LibreNMS? Oo
|
||||
$format .= str_replace("\n", '', nl2br($obj['msg'])) . "\t";
|
||||
$format .= 'NULL'; //FIXME: What's the HOSTPERFDATA equivalent for LibreNMS? Oo
|
||||
$format .= "\n";
|
||||
|
||||
return file_put_contents($opts, $format);
|
||||
|
@ -43,7 +43,7 @@ class Opsgenie extends Transport
|
||||
|
||||
set_curl_proxy($curl);
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($obj));
|
||||
@ -52,7 +52,7 @@ class Opsgenie extends Transport
|
||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
|
||||
if ($code != 200) {
|
||||
var_dump("Error when sending post request to OpsGenie. Response code: " . $code . " Response body: " . $ret); //FIXME: proper debugging
|
||||
var_dump('Error when sending post request to OpsGenie. Response code: ' . $code . ' Response body: ' . $ret); //FIXME: proper debugging
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ class Osticket extends Transport
|
||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
|
||||
if ($code != 201) {
|
||||
var_dump("osTicket returned Error, retry later");
|
||||
var_dump('osTicket returned Error, retry later');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ class Pagerduty extends Transport
|
||||
|
||||
return $result->getReasonPhrase();
|
||||
} catch (GuzzleException $e) {
|
||||
return "Request to PagerDuty API failed. " . $e->getMessage();
|
||||
return 'Request to PagerDuty API failed. ' . $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -39,15 +39,15 @@ class Playsms extends Transport
|
||||
|
||||
public static function contactPlaysms($obj, $opts)
|
||||
{
|
||||
$data = ["u" => $opts['user'], "h" => $opts['token'], "to" => implode(',', $opts['to']), "msg" => $obj['title']];
|
||||
$data = ['u' => $opts['user'], 'h' => $opts['token'], 'to' => implode(',', $opts['to']), 'msg' => $obj['title']];
|
||||
if (! empty($opts['from'])) {
|
||||
$data["from"] = $opts['from'];
|
||||
$data['from'] = $opts['from'];
|
||||
}
|
||||
$url = $opts['url'] . '&op=pv&' . http_build_query($data);
|
||||
$curl = curl_init($url);
|
||||
|
||||
set_curl_proxy($curl);
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET");
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'GET');
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
|
||||
$ret = curl_exec($curl);
|
||||
|
@ -39,12 +39,12 @@ class Pushbullet extends Transport
|
||||
{
|
||||
// Note: At this point it might be useful to iterate through $obj['contacts'] and send each of them a note ?
|
||||
|
||||
$data = ["type" => "note", "title" => $obj['title'], "body" => $obj['msg']];
|
||||
$data = ['type' => 'note', 'title' => $obj['title'], 'body' => $obj['msg']];
|
||||
$data = json_encode($data);
|
||||
|
||||
$curl = curl_init('https://api.pushbullet.com/v2/pushes');
|
||||
set_curl_proxy($curl);
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, [
|
||||
|
@ -55,13 +55,13 @@ class Pushover extends Transport
|
||||
$data['token'] = $api['appkey'];
|
||||
$data['user'] = $api['userkey'];
|
||||
switch ($obj['severity']) {
|
||||
case "critical":
|
||||
case 'critical':
|
||||
$data['priority'] = 1;
|
||||
if (! empty($api['options']['sound_critical'])) {
|
||||
$data['sound'] = $api['options']['sound_critical'];
|
||||
}
|
||||
break;
|
||||
case "warning":
|
||||
case 'warning':
|
||||
$data['priority'] = 1;
|
||||
if (! empty($api['options']['sound_warning'])) {
|
||||
$data['sound'] = $api['options']['sound_warning'];
|
||||
@ -90,7 +90,7 @@ class Pushover extends Transport
|
||||
$ret = curl_exec($curl);
|
||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
if ($code != 200) {
|
||||
var_dump("Pushover returned error"); //FIXME: proper debugging
|
||||
var_dump('Pushover returned error'); //FIXME: proper debugging
|
||||
|
||||
return 'HTTP Status code ' . $code;
|
||||
}
|
||||
|
@ -66,8 +66,8 @@ class Rocket extends Transport
|
||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
if ($code != 200) {
|
||||
var_dump("API '$host' returned Error"); //FIXME: propper debuging
|
||||
var_dump("Params: " . $alert_message); //FIXME: propper debuging
|
||||
var_dump("Return: " . $ret); //FIXME: propper debuging
|
||||
var_dump('Params: ' . $alert_message); //FIXME: propper debuging
|
||||
var_dump('Return: ' . $ret); //FIXME: propper debuging
|
||||
|
||||
return 'HTTP Status code ' . $code;
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ class Sensu extends Transport
|
||||
try {
|
||||
return $this->contactSensu($obj, $sensu_opts);
|
||||
} catch (GuzzleException $e) {
|
||||
return "Sending event to Sensu failed: " . $e->getMessage();
|
||||
return 'Sending event to Sensu failed: ' . $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -67,8 +67,8 @@ class Slack extends Transport
|
||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
if ($code != 200) {
|
||||
var_dump("API '$host' returned Error"); //FIXME: propper debuging
|
||||
var_dump("Params: " . $alert_message); //FIXME: propper debuging
|
||||
var_dump("Return: " . $ret); //FIXME: propper debuging
|
||||
var_dump('Params: ' . $alert_message); //FIXME: propper debuging
|
||||
var_dump('Return: ' . $ret); //FIXME: propper debuging
|
||||
|
||||
return 'HTTP Status code ' . $code;
|
||||
}
|
||||
|
@ -50,11 +50,11 @@ class Smseagle extends Transport
|
||||
$curl = curl_init($url);
|
||||
|
||||
set_curl_proxy($curl);
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET");
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'GET');
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
|
||||
$ret = curl_exec($curl);
|
||||
if (substr($ret, 0, 2) == "OK") {
|
||||
if (substr($ret, 0, 2) == 'OK') {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
@ -49,11 +49,11 @@ class Smsfeedback extends Transport
|
||||
$curl = curl_init($url);
|
||||
|
||||
set_curl_proxy($curl);
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET");
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'GET');
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
|
||||
$ret = curl_exec($curl);
|
||||
if (substr($ret, 0, 8) == "accepted") {
|
||||
if (substr($ret, 0, 8) == 'accepted') {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -40,34 +40,34 @@ class Splunk extends Transport
|
||||
$device = device_by_id_cache($obj['device_id']); // for event logging
|
||||
|
||||
if (! empty($opts['splunk_host'])) {
|
||||
if (preg_match("/[a-zA-Z]/", $opts['splunk_host'])) {
|
||||
if (preg_match('/[a-zA-Z]/', $opts['splunk_host'])) {
|
||||
$splunk_host = gethostbyname($opts['splunk_host']);
|
||||
if ($splunk_host === $opts['splunk_host']) {
|
||||
log_event("Alphanumeric hostname found but does not resolve to an IP.", $device, 'poller', 5);
|
||||
log_event('Alphanumeric hostname found but does not resolve to an IP.', $device, 'poller', 5);
|
||||
|
||||
return false;
|
||||
}
|
||||
} elseif (filter_var($opts['splunk_host'], FILTER_VALIDATE_IP)) {
|
||||
$splunk_host = $opts['splunk_host'];
|
||||
} else {
|
||||
log_event("Splunk host is not a valid IP: " . $opts['splunk_host'], $device, 'poller', 5);
|
||||
log_event('Splunk host is not a valid IP: ' . $opts['splunk_host'], $device, 'poller', 5);
|
||||
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
log_event("Splunk host is empty.", $device, 'poller');
|
||||
log_event('Splunk host is empty.', $device, 'poller');
|
||||
}
|
||||
if (! empty($opts['splunk_port']) && preg_match("/^\d+$/", $opts['splunk_port'])) {
|
||||
$splunk_port = $opts['splunk_port'];
|
||||
} else {
|
||||
log_event("Splunk port is not an integer.", $device, 'poller', 5);
|
||||
log_event('Splunk port is not an integer.', $device, 'poller', 5);
|
||||
}
|
||||
|
||||
switch ($obj['severity']) {
|
||||
case "critical":
|
||||
case 'critical':
|
||||
$severity = 2;
|
||||
break;
|
||||
case "warning":
|
||||
case 'warning':
|
||||
$severity = 4;
|
||||
break;
|
||||
}
|
||||
@ -81,7 +81,7 @@ class Splunk extends Transport
|
||||
break;
|
||||
}
|
||||
|
||||
$ignore = ["template", "contacts", "rule", "string", "debug", "faults", "builder", "transport", "alert", "msg", "transport_name"];
|
||||
$ignore = ['template', 'contacts', 'rule', 'string', 'debug', 'faults', 'builder', 'transport', 'alert', 'msg', 'transport_name'];
|
||||
$splunk_prefix = '<' . $severity . '> ';
|
||||
foreach ($obj as $key => $val) {
|
||||
if (in_array($key, $ignore)) {
|
||||
@ -91,7 +91,7 @@ class Splunk extends Transport
|
||||
$splunk_prefix .= $key . '="' . $val . '", ';
|
||||
}
|
||||
|
||||
$ignore = ["attribs", "vrf_lite_cisco", "community", "authlevel", "authname", "authpass", "authalgo", "cryptopass", "cryptoalgo", "snmpver", "port"];
|
||||
$ignore = ['attribs', 'vrf_lite_cisco', 'community', 'authlevel', 'authname', 'authpass', 'authalgo', 'cryptopass', 'cryptoalgo', 'snmpver', 'port'];
|
||||
foreach ($device as $key => $val) {
|
||||
if (in_array($key, $ignore)) {
|
||||
continue;
|
||||
@ -102,7 +102,7 @@ class Splunk extends Transport
|
||||
$splunk_prefix = substr($splunk_prefix, 0, -1);
|
||||
|
||||
if (($socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP)) === false) {
|
||||
log_event("socket_create() failed: reason: " . socket_strerror(socket_last_error()), $device, 'poller', 5);
|
||||
log_event('socket_create() failed: reason: ' . socket_strerror(socket_last_error()), $device, 'poller', 5);
|
||||
|
||||
return false;
|
||||
} else {
|
||||
|
@ -37,62 +37,62 @@ class Syslog extends Transport
|
||||
{
|
||||
$syslog_host = '127.0.0.1';
|
||||
$syslog_port = 514;
|
||||
$state = "Unknown";
|
||||
$state = 'Unknown';
|
||||
$facility = 24; // Default facility is 3 * 8 (daemon)
|
||||
$severity = 6; // Default severity is 6 (Informational)
|
||||
$sev_txt = "OK";
|
||||
$sev_txt = 'OK';
|
||||
$device = device_by_id_cache($obj['device_id']); // for event logging
|
||||
|
||||
if (! empty($opts['syslog_facility']) && preg_match("/^\d+$/", $opts['syslog_facility'])) {
|
||||
$facility = (int) $opts['syslog_facility'] * 8;
|
||||
} else {
|
||||
log_event("Syslog facility is not an integer: " . $opts['syslog_facility'], $device, 'poller', 5);
|
||||
log_event('Syslog facility is not an integer: ' . $opts['syslog_facility'], $device, 'poller', 5);
|
||||
}
|
||||
if (! empty($opts['syslog_host'])) {
|
||||
if (preg_match("/[a-zA-Z]/", $opts['syslog_host'])) {
|
||||
if (preg_match('/[a-zA-Z]/', $opts['syslog_host'])) {
|
||||
$syslog_host = gethostbyname($opts['syslog_host']);
|
||||
if ($syslog_host === $opts['syslog_host']) {
|
||||
log_event("Alphanumeric hostname found but does not resolve to an IP.", $device, 'poller', 5);
|
||||
log_event('Alphanumeric hostname found but does not resolve to an IP.', $device, 'poller', 5);
|
||||
|
||||
return false;
|
||||
}
|
||||
} elseif (filter_var($opts['syslog_host'], FILTER_VALIDATE_IP)) {
|
||||
$syslog_host = $opts['syslog_host'];
|
||||
} else {
|
||||
log_event("Syslog host is not a valid IP: " . $opts['syslog_host'], $device, 'poller', 5);
|
||||
log_event('Syslog host is not a valid IP: ' . $opts['syslog_host'], $device, 'poller', 5);
|
||||
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
log_event("Syslog host is empty.", $device, 'poller');
|
||||
log_event('Syslog host is empty.', $device, 'poller');
|
||||
}
|
||||
if (! empty($opts['syslog_port']) && preg_match("/^\d+$/", $opts['syslog_port'])) {
|
||||
$syslog_port = $opts['syslog_port'];
|
||||
} else {
|
||||
log_event("Syslog port is not an integer.", $device, 'poller', 5);
|
||||
log_event('Syslog port is not an integer.', $device, 'poller', 5);
|
||||
}
|
||||
|
||||
switch ($obj['severity']) {
|
||||
case "critical":
|
||||
case 'critical':
|
||||
$severity = 2;
|
||||
$sev_txt = "Critical";
|
||||
$sev_txt = 'Critical';
|
||||
break;
|
||||
case "warning":
|
||||
case 'warning':
|
||||
$severity = 4;
|
||||
$sev_txt = "Warning";
|
||||
$sev_txt = 'Warning';
|
||||
break;
|
||||
}
|
||||
|
||||
switch ($obj['state']) {
|
||||
case AlertState::RECOVERED:
|
||||
$state = "OK";
|
||||
$state = 'OK';
|
||||
$severity = 6;
|
||||
break;
|
||||
case AlertState::ACTIVE:
|
||||
$state = $sev_txt;
|
||||
break;
|
||||
case AlertState::ACKNOWLEDGED:
|
||||
$state = "Acknowledged";
|
||||
$state = 'Acknowledged';
|
||||
$severity = 6;
|
||||
break;
|
||||
}
|
||||
@ -115,7 +115,7 @@ class Syslog extends Transport
|
||||
. $obj['name'];
|
||||
|
||||
if (($socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP)) === false) {
|
||||
log_event("socket_create() failed: reason: " . socket_strerror(socket_last_error()), $device, 'poller', 5);
|
||||
log_event('socket_create() failed: reason: ' . socket_strerror(socket_last_error()), $device, 'poller', 5);
|
||||
|
||||
return false;
|
||||
} else {
|
||||
|
@ -42,11 +42,11 @@ class Telegram extends Transport
|
||||
$curl = curl_init();
|
||||
set_curl_proxy($curl);
|
||||
$text = urlencode($obj['msg']);
|
||||
$format = "";
|
||||
$format = '';
|
||||
if ($data['format']) {
|
||||
$format = "&parse_mode=" . $data['format'];
|
||||
$format = '&parse_mode=' . $data['format'];
|
||||
if ($data['format'] == 'Markdown') {
|
||||
$text = urlencode(preg_replace("/([a-z0-9]+)_([a-z0-9]+)/", "$1\_$2", $obj['msg']));
|
||||
$text = urlencode(preg_replace('/([a-z0-9]+)_([a-z0-9]+)/', "$1\_$2", $obj['msg']));
|
||||
}
|
||||
}
|
||||
curl_setopt($curl, CURLOPT_URL, ("https://api.telegram.org/bot{$data['token']}/sendMessage?chat_id={$data['chat_id']}&text=$text{$format}"));
|
||||
@ -55,8 +55,8 @@ class Telegram extends Transport
|
||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
if ($code != 200) {
|
||||
var_dump("API '$host' returned Error"); //FIXME: propper debuging
|
||||
var_dump("Params: " . $api); //FIXME: propper debuging
|
||||
var_dump("Return: " . $ret); //FIXME: propper debuging
|
||||
var_dump('Params: ' . $api); //FIXME: propper debuging
|
||||
var_dump('Return: ' . $ret); //FIXME: propper debuging
|
||||
|
||||
return 'HTTP Status code ' . $code;
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ class Twilio extends Transport
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
|
||||
curl_setopt($curl, CURLOPT_USERPWD, $params["sid"] . ":" . $params["token"]);
|
||||
curl_setopt($curl, CURLOPT_USERPWD, $params['sid'] . ':' . $params['token']);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
|
||||
|
||||
curl_exec($curl);
|
||||
|
@ -69,7 +69,7 @@ class Victorops extends Transport
|
||||
$ret = curl_exec($curl);
|
||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
if ($code != 200) {
|
||||
var_dump("VictorOps returned Error, retry later"); //FIXME: propper debuging
|
||||
var_dump('VictorOps returned Error, retry later'); //FIXME: propper debuging
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -41,24 +41,24 @@ class QueryBuilderParser implements \JsonSerializable
|
||||
'>=' => 'greater_or_equal',
|
||||
];
|
||||
protected static $operators = [
|
||||
'equal' => "=",
|
||||
'not_equal' => "!=",
|
||||
'less' => "<",
|
||||
'less_or_equal' => "<=",
|
||||
'greater' => ">",
|
||||
'greater_or_equal' => ">=",
|
||||
'equal' => '=',
|
||||
'not_equal' => '!=',
|
||||
'less' => '<',
|
||||
'less_or_equal' => '<=',
|
||||
'greater' => '>',
|
||||
'greater_or_equal' => '>=',
|
||||
'between' => 'BETWEEN',
|
||||
'not_between' => 'NOT BETWEEN',
|
||||
'begins_with' => "LIKE",
|
||||
'not_begins_with' => "NOT LIKE",
|
||||
'contains' => "LIKE",
|
||||
'not_contains' => "NOT LIKE",
|
||||
'ends_with' => "LIKE",
|
||||
'not_ends_with' => "NOT LIKE",
|
||||
'is_empty' => "=",
|
||||
'is_not_empty' => "!=",
|
||||
'is_null' => "IS NULL",
|
||||
'is_not_null' => "IS NOT NULL",
|
||||
'begins_with' => 'LIKE',
|
||||
'not_begins_with' => 'NOT LIKE',
|
||||
'contains' => 'LIKE',
|
||||
'not_contains' => 'NOT LIKE',
|
||||
'ends_with' => 'LIKE',
|
||||
'not_ends_with' => 'NOT LIKE',
|
||||
'is_empty' => '=',
|
||||
'is_not_empty' => '!=',
|
||||
'is_null' => 'IS NULL',
|
||||
'is_not_null' => 'IS NOT NULL',
|
||||
'regex' => 'REGEXP',
|
||||
'not_regex' => 'NOT REGEXP',
|
||||
'in' => 'IN',
|
||||
@ -66,16 +66,16 @@ class QueryBuilderParser implements \JsonSerializable
|
||||
];
|
||||
|
||||
protected static $values = [
|
||||
'between' => "? AND ?",
|
||||
'not_between' => "? AND ?",
|
||||
'between' => '? AND ?',
|
||||
'not_between' => '? AND ?',
|
||||
'begins_with' => "'?%'",
|
||||
'not_begins_with' => "'?%'",
|
||||
'contains' => "'%?%'",
|
||||
'not_contains' => "'%?%'",
|
||||
'ends_with' => "'%?'",
|
||||
'not_ends_with' => "'%?'",
|
||||
'is_null' => "",
|
||||
'is_not_null' => "",
|
||||
'is_null' => '',
|
||||
'is_not_null' => '',
|
||||
'is_empty' => "''",
|
||||
'is_not_empty' => "''",
|
||||
];
|
||||
|
@ -71,7 +71,7 @@ class ActiveDirectoryAuthorizer extends AuthorizerBase
|
||||
$connection,
|
||||
Config::get('auth_ad_base_dn'),
|
||||
$search_filter,
|
||||
["cn"]
|
||||
['cn']
|
||||
);
|
||||
$result = ldap_get_entries($connection, $search);
|
||||
|
||||
@ -90,19 +90,19 @@ class ActiveDirectoryAuthorizer extends AuthorizerBase
|
||||
throw new AuthenticationException();
|
||||
}
|
||||
|
||||
$group_dn = $result[0]["dn"];
|
||||
$group_dn = $result[0]['dn'];
|
||||
|
||||
$search = ldap_search(
|
||||
$connection,
|
||||
Config::get('auth_ad_base_dn'),
|
||||
// add 'LDAP_MATCHING_RULE_IN_CHAIN to the user filter to search for $username in nested $group_dn
|
||||
// limiting to "DN" for shorter array
|
||||
"(&" . $this->userFilter($username) . "(memberOf:1.2.840.113556.1.4.1941:=$group_dn))",
|
||||
["DN"]
|
||||
'(&' . $this->userFilter($username) . "(memberOf:1.2.840.113556.1.4.1941:=$group_dn))",
|
||||
['DN']
|
||||
);
|
||||
$entries = ldap_get_entries($connection, $search);
|
||||
|
||||
return $entries["count"] > 0;
|
||||
return $entries['count'] > 0;
|
||||
}
|
||||
|
||||
public function userExists($username, $throw_exception = false)
|
||||
|
@ -157,7 +157,7 @@ trait ActiveDirectoryCommon
|
||||
foreach ($ldap_groups as $ldap_group) {
|
||||
$search_filter = "(&(memberOf:1.2.840.113556.1.4.1941:=$ldap_group)(!(userAccountControl:1.2.840.113556.1.4.803:=2)))";
|
||||
if (Config::get('auth_ad_user_filter')) {
|
||||
$search_filter = "(&" . Config::get('auth_ad_user_filter') . $search_filter . ")";
|
||||
$search_filter = '(&' . Config::get('auth_ad_user_filter') . $search_filter . ')';
|
||||
}
|
||||
$attributes = ['samaccountname', 'displayname', 'objectsid', 'mail'];
|
||||
$search = ldap_search($connection, Config::get('auth_ad_base_dn'), $search_filter, $attributes);
|
||||
|
@ -9,7 +9,7 @@ use LibreNMS\Exceptions\LdapMissingException;
|
||||
class LdapAuthorizer extends AuthorizerBase
|
||||
{
|
||||
protected $ldap_connection;
|
||||
private $userloginname = "";
|
||||
private $userloginname = '';
|
||||
|
||||
public function authenticate($credentials)
|
||||
{
|
||||
@ -100,15 +100,15 @@ class LdapAuthorizer extends AuthorizerBase
|
||||
$group_names = array_keys($groups);
|
||||
$ldap_group_filter = '';
|
||||
foreach ($group_names as $group_name) {
|
||||
$ldap_group_filter .= "(cn=" . trim($group_name) . ")";
|
||||
$ldap_group_filter .= '(cn=' . trim($group_name) . ')';
|
||||
}
|
||||
if (count($group_names) > 1) {
|
||||
$ldap_group_filter = "(|{$ldap_group_filter})";
|
||||
}
|
||||
if (Config::get('auth_ldap_userdn') === true) {
|
||||
$filter = "(&{$ldap_group_filter}(" . trim(Config::get('auth_ldap_groupmemberattr', 'memberUid')) . "=" . $this->getFullDn($username) . "))";
|
||||
$filter = "(&{$ldap_group_filter}(" . trim(Config::get('auth_ldap_groupmemberattr', 'memberUid')) . '=' . $this->getFullDn($username) . '))';
|
||||
} else {
|
||||
$filter = "(&{$ldap_group_filter}(" . trim(Config::get('auth_ldap_groupmemberattr', 'memberUid')) . "=" . $this->getMembername($username) . "))";
|
||||
$filter = "(&{$ldap_group_filter}(" . trim(Config::get('auth_ldap_groupmemberattr', 'memberUid')) . '=' . $this->getMembername($username) . '))';
|
||||
}
|
||||
$search = ldap_search($connection, Config::get('auth_ldap_groupbase'), $filter);
|
||||
$entries = ldap_get_entries($connection, $search);
|
||||
@ -292,14 +292,14 @@ class LdapAuthorizer extends AuthorizerBase
|
||||
{
|
||||
$connection = $this->getLdapConnection();
|
||||
$filter = '(' . Config::get('auth_ldap_attr.uid') . '=' . $username . ')';
|
||||
$base_dn = preg_replace("/,ou=[^,]+,/", ",", Config::get('auth_ldap_suffix'));
|
||||
$base_dn = preg_replace('/,ou=[^,]+,/', ',', Config::get('auth_ldap_suffix'));
|
||||
$base_dn = trim($base_dn, ',');
|
||||
$search = ldap_search($connection, $base_dn, $filter);
|
||||
foreach (ldap_get_entries($connection, $search) as $entry) {
|
||||
if ($entry['uid'][0] == $username) {
|
||||
preg_match('~,ou=([^,]+),~', $entry['dn'], $matches);
|
||||
$user_ou = $matches[1];
|
||||
$new_auth_ldap_suffix = preg_replace("/,ou=[^,]+,/", ",ou=" . $user_ou . ",", Config::get('auth_ldap_suffix'));
|
||||
$new_auth_ldap_suffix = preg_replace('/,ou=[^,]+,/', ',ou=' . $user_ou . ',', Config::get('auth_ldap_suffix'));
|
||||
Config::set('auth_ldap_suffix', $new_auth_ldap_suffix);
|
||||
|
||||
return true;
|
||||
@ -404,7 +404,7 @@ class LdapAuthorizer extends AuthorizerBase
|
||||
ldap_set_option($this->ldap_connection, LDAP_OPT_NETWORK_TIMEOUT, -1); // restore timeout
|
||||
|
||||
if (Config::get('auth_ldap_debug')) {
|
||||
echo "Bind result: " . ldap_error($this->ldap_connection) . PHP_EOL;
|
||||
echo 'Bind result: ' . ldap_error($this->ldap_connection) . PHP_EOL;
|
||||
}
|
||||
|
||||
if ($bind_result) {
|
||||
@ -417,7 +417,7 @@ class LdapAuthorizer extends AuthorizerBase
|
||||
ldap_set_option($this->ldap_connection, LDAP_OPT_NETWORK_TIMEOUT, -1); // restore timeout
|
||||
|
||||
if (Config::get('auth_ldap_debug')) {
|
||||
echo "Anonymous bind result: " . ldap_error($this->ldap_connection) . PHP_EOL;
|
||||
echo 'Anonymous bind result: ' . ldap_error($this->ldap_connection) . PHP_EOL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -50,44 +50,44 @@ class TwoFactor
|
||||
* Base32 Decoding dictionary
|
||||
*/
|
||||
private static $base32 = [
|
||||
"A" => 0,
|
||||
"B" => 1,
|
||||
"C" => 2,
|
||||
"D" => 3,
|
||||
"E" => 4,
|
||||
"F" => 5,
|
||||
"G" => 6,
|
||||
"H" => 7,
|
||||
"I" => 8,
|
||||
"J" => 9,
|
||||
"K" => 10,
|
||||
"L" => 11,
|
||||
"M" => 12,
|
||||
"N" => 13,
|
||||
"O" => 14,
|
||||
"P" => 15,
|
||||
"Q" => 16,
|
||||
"R" => 17,
|
||||
"S" => 18,
|
||||
"T" => 19,
|
||||
"U" => 20,
|
||||
"V" => 21,
|
||||
"W" => 22,
|
||||
"X" => 23,
|
||||
"Y" => 24,
|
||||
"Z" => 25,
|
||||
"2" => 26,
|
||||
"3" => 27,
|
||||
"4" => 28,
|
||||
"5" => 29,
|
||||
"6" => 30,
|
||||
"7" => 31,
|
||||
'A' => 0,
|
||||
'B' => 1,
|
||||
'C' => 2,
|
||||
'D' => 3,
|
||||
'E' => 4,
|
||||
'F' => 5,
|
||||
'G' => 6,
|
||||
'H' => 7,
|
||||
'I' => 8,
|
||||
'J' => 9,
|
||||
'K' => 10,
|
||||
'L' => 11,
|
||||
'M' => 12,
|
||||
'N' => 13,
|
||||
'O' => 14,
|
||||
'P' => 15,
|
||||
'Q' => 16,
|
||||
'R' => 17,
|
||||
'S' => 18,
|
||||
'T' => 19,
|
||||
'U' => 20,
|
||||
'V' => 21,
|
||||
'W' => 22,
|
||||
'X' => 23,
|
||||
'Y' => 24,
|
||||
'Z' => 25,
|
||||
'2' => 26,
|
||||
'3' => 27,
|
||||
'4' => 28,
|
||||
'5' => 29,
|
||||
'6' => 30,
|
||||
'7' => 31,
|
||||
];
|
||||
|
||||
/**
|
||||
* Base32 Encoding dictionary
|
||||
*/
|
||||
private static $base32_enc = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
|
||||
private static $base32_enc = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
|
||||
|
||||
/**
|
||||
* Generate Secret Key
|
||||
@ -97,20 +97,20 @@ class TwoFactor
|
||||
{
|
||||
// RFC 4226 recommends 160bits Secret Keys, that's 20 Bytes for the lazy ones.
|
||||
$crypto = false;
|
||||
$raw = "";
|
||||
$raw = '';
|
||||
$x = -1;
|
||||
while ($crypto == false || ++$x < 10) {
|
||||
$raw = openssl_random_pseudo_bytes(20, $crypto);
|
||||
}
|
||||
// RFC 4648 Base32 Encoding without padding
|
||||
$len = strlen($raw);
|
||||
$bin = "";
|
||||
$bin = '';
|
||||
$x = -1;
|
||||
while (++$x < $len) {
|
||||
$bin .= str_pad(base_convert(ord($raw[$x]), 10, 2), 8, '0', STR_PAD_LEFT);
|
||||
}
|
||||
$bin = str_split($bin, 5);
|
||||
$ret = "";
|
||||
$ret = '';
|
||||
$x = -1;
|
||||
while (++$x < sizeof($bin)) {
|
||||
$ret .= self::$base32_enc[base_convert(str_pad($bin[$x], 5, '0'), 2, 10)];
|
||||
@ -173,7 +173,7 @@ class TwoFactor
|
||||
$length = strlen($key);
|
||||
$x = -1;
|
||||
$y = $z = 0;
|
||||
$kbin = "";
|
||||
$kbin = '';
|
||||
while (++$x < $length) {
|
||||
$y <<= 5;
|
||||
$y += self::$base32[$key[$x]];
|
||||
@ -202,7 +202,7 @@ class TwoFactor
|
||||
*/
|
||||
public static function generateUri($username, $key, $counter = false)
|
||||
{
|
||||
$title = "LibreNMS:" . urlencode($username);
|
||||
$title = 'LibreNMS:' . urlencode($username);
|
||||
|
||||
return $counter ?
|
||||
"otpauth://hotp/$title?issuer=LibreNMS&counter=1&secret=$key" : // counter based
|
||||
|
@ -57,10 +57,10 @@ class Component
|
||||
public function getComponentType($TYPE = null)
|
||||
{
|
||||
if (is_null($TYPE)) {
|
||||
$SQL = "SELECT DISTINCT `type` as `name` FROM `component` ORDER BY `name`";
|
||||
$SQL = 'SELECT DISTINCT `type` as `name` FROM `component` ORDER BY `name`';
|
||||
$row = dbFetchRow($SQL, []);
|
||||
} else {
|
||||
$SQL = "SELECT DISTINCT `type` as `name` FROM `component` WHERE `type` = ? ORDER BY `name`";
|
||||
$SQL = 'SELECT DISTINCT `type` as `name` FROM `component` WHERE `type` = ? ORDER BY `name`';
|
||||
$row = dbFetchRow($SQL, [$TYPE]);
|
||||
}
|
||||
|
||||
@ -121,13 +121,13 @@ class Component
|
||||
|
||||
public function getComponentStatus($device = null)
|
||||
{
|
||||
$sql_query = "SELECT status, count(status) as count FROM component WHERE";
|
||||
$sql_query = 'SELECT status, count(status) as count FROM component WHERE';
|
||||
$sql_param = [];
|
||||
$add = 0;
|
||||
|
||||
if (! is_null($device)) {
|
||||
// Add a device filter to the SQL query.
|
||||
$sql_query .= " `device_id` = ?";
|
||||
$sql_query .= ' `device_id` = ?';
|
||||
$sql_param[] = $device;
|
||||
$add++;
|
||||
}
|
||||
@ -136,8 +136,8 @@ class Component
|
||||
// No filters, remove " WHERE" -6
|
||||
$sql_query = substr($sql_query, 0, strlen($sql_query) - 6);
|
||||
}
|
||||
$sql_query .= " GROUP BY status";
|
||||
d_echo("SQL Query: " . $sql_query);
|
||||
$sql_query .= ' GROUP BY status';
|
||||
d_echo('SQL Query: ' . $sql_query);
|
||||
|
||||
// $service is not null, get only what we want.
|
||||
$result = dbFetchRows($sql_query, $sql_param);
|
||||
@ -149,7 +149,7 @@ class Component
|
||||
$count[$v['status']] = $v['count'];
|
||||
}
|
||||
|
||||
d_echo("Component Count by Status: " . print_r($count, true) . "\n");
|
||||
d_echo('Component Count by Status: ' . print_r($count, true) . "\n");
|
||||
|
||||
return $count;
|
||||
}
|
||||
@ -158,7 +158,7 @@ class Component
|
||||
{
|
||||
if (($component_id == null) || ($start == null) || ($end == null)) {
|
||||
// Error...
|
||||
d_echo("Required arguments are missing. Component ID: " . $component_id . ", Start: " . $start . ", End: " . $end . "\n");
|
||||
d_echo('Required arguments are missing. Component ID: ' . $component_id . ', Start: ' . $start . ', End: ' . $end . "\n");
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -167,7 +167,7 @@ class Component
|
||||
$return = [];
|
||||
|
||||
// 1. find the previous value, this is the value when $start occurred.
|
||||
$sql_query = "SELECT status FROM `component_statuslog` WHERE `component_id` = ? AND `timestamp` < ? ORDER BY `id` desc LIMIT 1";
|
||||
$sql_query = 'SELECT status FROM `component_statuslog` WHERE `component_id` = ? AND `timestamp` < ? ORDER BY `id` desc LIMIT 1';
|
||||
$sql_param = [$component_id, $start];
|
||||
$result = dbFetchRow($sql_query, $sql_param);
|
||||
if ($result == false) {
|
||||
@ -177,11 +177,11 @@ class Component
|
||||
}
|
||||
|
||||
// 2. Then we just need a list of all the entries for the time period.
|
||||
$sql_query = "SELECT status, `timestamp`, message FROM `component_statuslog` WHERE `component_id` = ? AND `timestamp` >= ? AND `timestamp` < ? ORDER BY `timestamp`";
|
||||
$sql_query = 'SELECT status, `timestamp`, message FROM `component_statuslog` WHERE `component_id` = ? AND `timestamp` >= ? AND `timestamp` < ? ORDER BY `timestamp`';
|
||||
$sql_param = [$component_id, $start, $end];
|
||||
$return['data'] = dbFetchRows($sql_query, $sql_param);
|
||||
|
||||
d_echo("Status Log Data: " . print_r($return, true) . "\n");
|
||||
d_echo('Status Log Data: ' . print_r($return, true) . "\n");
|
||||
|
||||
return $return;
|
||||
}
|
||||
@ -202,7 +202,7 @@ class Component
|
||||
try {
|
||||
return ComponentStatusLog::create(['component_id' => $component_id, 'status' => $status, 'message' => $message])->id;
|
||||
} catch (\Exception $e) {
|
||||
Log::debug("Failed to create component status log");
|
||||
Log::debug('Failed to create component status log');
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -235,7 +235,7 @@ class Component
|
||||
|
||||
// If the Status has changed we need to add a log entry
|
||||
if ($component->isDirty('status')) {
|
||||
Log::debug("Status Changed - Old: " . $component->getOriginal('status') . ", New: $component->status\n");
|
||||
Log::debug('Status Changed - Old: ' . $component->getOriginal('status') . ", New: $component->status\n");
|
||||
$this->createStatusLogEntry($component->id, $component->status, $component->error);
|
||||
}
|
||||
$component->save();
|
||||
|
@ -129,18 +129,18 @@ class Eloquent
|
||||
public static function setConnection($name, $db_host = null, $db_user = '', $db_pass = '', $db_name = '', $db_port = null, $db_socket = null)
|
||||
{
|
||||
\Config::set("database.connections.$name", [
|
||||
"driver" => "mysql",
|
||||
"host" => $db_host,
|
||||
"port" => $db_port,
|
||||
"database" => $db_name,
|
||||
"username" => $db_user,
|
||||
"password" => $db_pass,
|
||||
"unix_socket" => $db_socket,
|
||||
"charset" => "utf8",
|
||||
"collation" => "utf8_unicode_ci",
|
||||
"prefix" => "",
|
||||
"strict" => true,
|
||||
"engine" => null,
|
||||
'driver' => 'mysql',
|
||||
'host' => $db_host,
|
||||
'port' => $db_port,
|
||||
'database' => $db_name,
|
||||
'username' => $db_user,
|
||||
'password' => $db_pass,
|
||||
'unix_socket' => $db_socket,
|
||||
'charset' => 'utf8',
|
||||
'collation' => 'utf8_unicode_ci',
|
||||
'prefix' => '',
|
||||
'strict' => true,
|
||||
'engine' => null,
|
||||
]);
|
||||
\Config::set('database.default', $name);
|
||||
}
|
||||
|
@ -202,10 +202,10 @@ class Schema
|
||||
{
|
||||
$relationships = $this->getTableRelationships();
|
||||
|
||||
d_echo("Starting Tables: " . json_encode($tables) . PHP_EOL);
|
||||
d_echo('Starting Tables: ' . json_encode($tables) . PHP_EOL);
|
||||
if (! empty($history)) {
|
||||
$tables = array_diff($tables, $history);
|
||||
d_echo("Filtered Tables: " . json_encode($tables) . PHP_EOL);
|
||||
d_echo('Filtered Tables: ' . json_encode($tables) . PHP_EOL);
|
||||
}
|
||||
|
||||
foreach ($tables as $table) {
|
||||
|
@ -102,13 +102,13 @@ class Graphite extends BaseDatastore
|
||||
$measurement = preg_replace('/\|/', '.', $measurement);
|
||||
$measurement_name = preg_replace('/\./', '_', $tags['rrd_name']);
|
||||
if (is_array($measurement_name)) {
|
||||
$ms_name = implode(".", $measurement_name);
|
||||
$ms_name = implode('.', $measurement_name);
|
||||
} else {
|
||||
$ms_name = $measurement_name;
|
||||
}
|
||||
// remove the port-id tags from the metric
|
||||
if (preg_match('/^port-id\d+/', $ms_name)) {
|
||||
$ms_name = "";
|
||||
$ms_name = '';
|
||||
}
|
||||
|
||||
foreach ($fields as $k => $v) {
|
||||
@ -116,7 +116,7 @@ class Graphite extends BaseDatastore
|
||||
if (empty($v)) {
|
||||
$v = 0;
|
||||
}
|
||||
$metric = implode(".", array_filter([$this->prefix, $hostname, $measurement, $ms_name, $k]));
|
||||
$metric = implode('.', array_filter([$this->prefix, $hostname, $measurement, $ms_name, $k]));
|
||||
$this->writeData($metric, $v, $timestamp);
|
||||
}
|
||||
}
|
||||
@ -134,7 +134,7 @@ class Graphite extends BaseDatastore
|
||||
// Further sanitize the full metric before sending, whitespace isn't allowed
|
||||
$metric = preg_replace('/\s+/', '_', $metric);
|
||||
|
||||
$line = implode(" ", [$metric, $value, $timestamp]);
|
||||
$line = implode(' ', [$metric, $value, $timestamp]);
|
||||
Log::debug("Sending to Graphite: $line\n");
|
||||
$this->connection->write("$line\n");
|
||||
|
||||
|
@ -83,12 +83,12 @@ class OpenTSDB extends BaseDatastore
|
||||
|
||||
$flag = Config::get('opentsdb.co');
|
||||
$timestamp = Carbon::now()->timestamp;
|
||||
$tmp_tags = "hostname=" . $device['hostname'];
|
||||
$tmp_tags = 'hostname=' . $device['hostname'];
|
||||
|
||||
foreach ($tags as $k => $v) {
|
||||
$v = str_replace([' ', ',', '='], '_', $v);
|
||||
if (! empty($v)) {
|
||||
$tmp_tags = $tmp_tags . " " . $k . "=" . $v;
|
||||
$tmp_tags = $tmp_tags . ' ' . $k . '=' . $v;
|
||||
}
|
||||
}
|
||||
|
||||
@ -96,7 +96,7 @@ class OpenTSDB extends BaseDatastore
|
||||
foreach ($fields as $k => $v) {
|
||||
$measurement = $k;
|
||||
if ($flag == true) {
|
||||
$measurement = $measurement . "." . $device['co'];
|
||||
$measurement = $measurement . '.' . $device['co'];
|
||||
}
|
||||
|
||||
$this->putData('port.' . $measurement, $timestamp, $v, $tmp_tags);
|
||||
@ -107,7 +107,7 @@ class OpenTSDB extends BaseDatastore
|
||||
}
|
||||
|
||||
foreach ($fields as $k => $v) {
|
||||
$tmp_tags_key = $tmp_tags . " " . "key" . "=" . $k;
|
||||
$tmp_tags_key = $tmp_tags . ' ' . 'key' . '=' . $k;
|
||||
$this->putData($measurement, $timestamp, $v, $tmp_tags_key);
|
||||
}
|
||||
}
|
||||
|
@ -76,8 +76,8 @@ class Prometheus extends BaseDatastore
|
||||
}
|
||||
|
||||
try {
|
||||
$vals = "";
|
||||
$promtags = "/measurement/" . $measurement;
|
||||
$vals = '';
|
||||
$promtags = '/measurement/' . $measurement;
|
||||
|
||||
foreach ($fields as $k => $v) {
|
||||
if ($v !== null) {
|
||||
@ -87,7 +87,7 @@ class Prometheus extends BaseDatastore
|
||||
|
||||
foreach ($tags as $t => $v) {
|
||||
if ($v !== null) {
|
||||
$promtags .= (Str::contains($v, "/") ? "/$t@base64/" . base64_encode($v) : "/$t/$v");
|
||||
$promtags .= (Str::contains($v, '/') ? "/$t@base64/" . base64_encode($v) : "/$t/$v");
|
||||
}
|
||||
}
|
||||
$options = $this->getDefaultOptions();
|
||||
@ -97,7 +97,7 @@ class Prometheus extends BaseDatastore
|
||||
if (Config::get('prometheus.attach_sysname', false)) {
|
||||
$promurl .= '/sysName/' . $device['sysName'];
|
||||
}
|
||||
$promurl = str_replace(" ", "-", $promurl); // Prometheus doesn't handle tags with spaces in url
|
||||
$promurl = str_replace(' ', '-', $promurl); // Prometheus doesn't handle tags with spaces in url
|
||||
|
||||
Log::debug("Prometheus put $promurl: ", [
|
||||
'measurement' => $measurement,
|
||||
@ -114,7 +114,7 @@ class Prometheus extends BaseDatastore
|
||||
Log::error('Prometheus Error: ' . $result->getReasonPhrase());
|
||||
}
|
||||
} catch (GuzzleException $e) {
|
||||
Log::error("Prometheus Exception: " . $e->getMessage());
|
||||
Log::error('Prometheus Exception: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -247,7 +247,7 @@ class Rrd extends BaseDatastore
|
||||
];
|
||||
}
|
||||
if (count($fields) > 0) {
|
||||
$options = "--maximum " . implode(":$max --maximum ", $fields) . ":$max";
|
||||
$options = '--maximum ' . implode(":$max --maximum ", $fields) . ":$max";
|
||||
$this->command('tune', $filename, $options);
|
||||
}
|
||||
|
||||
@ -301,11 +301,11 @@ class Rrd extends BaseDatastore
|
||||
$newrrd = self::name($device['hostname'], $newname);
|
||||
if (is_file($oldrrd) && ! is_file($newrrd)) {
|
||||
if (rename($oldrrd, $newrrd)) {
|
||||
log_event("Renamed $oldrrd to $newrrd", $device, "poller", 1);
|
||||
log_event("Renamed $oldrrd to $newrrd", $device, 'poller', 1);
|
||||
|
||||
return true;
|
||||
} else {
|
||||
log_event("Failed to rename $oldrrd to $newrrd", $device, "poller", 5);
|
||||
log_event("Failed to rename $oldrrd to $newrrd", $device, 'poller', 5);
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -323,11 +323,11 @@ class Rrd extends BaseDatastore
|
||||
* @param string $extension File extension (default is .rrd)
|
||||
* @return string the name of the rrd file for $host's $extra component
|
||||
*/
|
||||
public function name($host, $extra, $extension = ".rrd")
|
||||
public function name($host, $extra, $extension = '.rrd')
|
||||
{
|
||||
$filename = self::safeName(is_array($extra) ? implode("-", $extra) : $extra);
|
||||
$filename = self::safeName(is_array($extra) ? implode('-', $extra) : $extra);
|
||||
|
||||
return implode("/", [$this->dirFromHost($host), $filename . $extension]);
|
||||
return implode('/', [$this->dirFromHost($host), $filename . $extension]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -340,7 +340,7 @@ class Rrd extends BaseDatastore
|
||||
{
|
||||
$host = str_replace(':', '_', trim($host, '[]'));
|
||||
|
||||
return implode("/", [$this->rrd_dir, $host]);
|
||||
return implode('/', [$this->rrd_dir, $host]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -192,7 +192,7 @@ class Sensor implements DiscoveryModule, PollerModule
|
||||
|
||||
$sensor = dbFetchRow(
|
||||
"SELECT * FROM `$table` " .
|
||||
"WHERE `device_id`=? AND `sensor_class`=? AND `sensor_type`=? AND `sensor_index`=?",
|
||||
'WHERE `device_id`=? AND `sensor_class`=? AND `sensor_type`=? AND `sensor_index`=?',
|
||||
[$this->device_id, $this->type, $this->subtype, $this->index]
|
||||
);
|
||||
$this->sensor_id = $sensor['sensor_id'];
|
||||
@ -275,7 +275,7 @@ class Sensor implements DiscoveryModule, PollerModule
|
||||
|
||||
$submodules = Config::get('poller_submodules.wireless', []);
|
||||
if (! empty($submodules)) {
|
||||
$query .= " AND `sensor_class` IN " . dbGenPlaceholders(count($submodules));
|
||||
$query .= ' AND `sensor_class` IN ' . dbGenPlaceholders(count($submodules));
|
||||
$params = array_merge($params, $submodules);
|
||||
}
|
||||
|
||||
@ -648,7 +648,7 @@ class Sensor implements DiscoveryModule, PollerModule
|
||||
'sensor_current' => $sensor_value,
|
||||
'lastupdate' => ['NOW()'],
|
||||
];
|
||||
dbUpdate($update, static::$table, "`sensor_id` = ?", [$sensor['sensor_id']]);
|
||||
dbUpdate($update, static::$table, '`sensor_id` = ?', [$sensor['sensor_id']]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ class YamlDiscovery
|
||||
$class = get_class($class);
|
||||
}
|
||||
|
||||
d_echo("YAML Discovery Data: ");
|
||||
d_echo('YAML Discovery Data: ');
|
||||
d_echo($yaml_data);
|
||||
|
||||
foreach ($yaml_data as $first_key => $first_yaml) {
|
||||
@ -210,7 +210,7 @@ class YamlDiscovery
|
||||
}
|
||||
|
||||
if (! empty($device['dynamic_discovery']['modules'])) {
|
||||
echo "Caching data: ";
|
||||
echo 'Caching data: ';
|
||||
foreach ($device['dynamic_discovery']['modules'] as $module => $discovery_data) {
|
||||
echo "$module ";
|
||||
foreach ($discovery_data as $key => $data_array) {
|
||||
|
@ -28,7 +28,7 @@ class ApiException extends \Exception
|
||||
{
|
||||
private $output;
|
||||
|
||||
public function __construct($message = "", $output = [])
|
||||
public function __construct($message = '', $output = [])
|
||||
{
|
||||
parent::__construct($message, 0, null);
|
||||
$this->output = $output;
|
||||
|
@ -32,7 +32,7 @@ class UnserializableRouteCache extends \Exception implements UpgradeableExceptio
|
||||
protected $cli_php_version;
|
||||
protected $web_php_version;
|
||||
|
||||
public function __construct($message = "", $code = 0, Throwable $previous = null, $cli_php_version = null, $web_php_version = null)
|
||||
public function __construct($message = '', $code = 0, Throwable $previous = null, $cli_php_version = null, $web_php_version = null)
|
||||
{
|
||||
$this->cli_php_version = $cli_php_version;
|
||||
$this->web_php_version = $web_php_version;
|
||||
|
@ -174,7 +174,7 @@ class IRCBot
|
||||
$inactive_seconds = time() - $this->last_activity;
|
||||
$max_inactive = $this->config['irc_conn_timeout'];
|
||||
if ($inactive_seconds > $max_inactive) {
|
||||
$this->log("No data from server since " . $max_inactive . " seconds. Restarting.");
|
||||
$this->log('No data from server since ' . $max_inactive . ' seconds. Restarting.');
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -309,49 +309,49 @@ class IRCBot
|
||||
}
|
||||
}
|
||||
|
||||
if (($this->config['irc_ctcp']) && (preg_match("/^:" . chr(1) . ".*/", $ex[3]))) {
|
||||
if (($this->config['irc_ctcp']) && (preg_match('/^:' . chr(1) . '.*/', $ex[3]))) {
|
||||
// Handle CTCP
|
||||
$ctcp = trim(preg_replace("/[^A-Z]/", "", $ex[3]));
|
||||
$ctcp = trim(preg_replace('/[^A-Z]/', '', $ex[3]));
|
||||
$ctcp_reply = null;
|
||||
$this->log("Received irc CTCP: " . $ctcp . " from " . $this->getUser($this->data));
|
||||
$this->log('Received irc CTCP: ' . $ctcp . ' from ' . $this->getUser($this->data));
|
||||
switch ($ctcp) {
|
||||
case 'VERSION':
|
||||
$ctcp_reply = chr(1) . "$ctcp " . $this->config['irc_ctcp_version'] . chr(1);
|
||||
break;
|
||||
case 'PING':
|
||||
$ctcp_reply = chr(1) . "$ctcp " . $ex[4] . " " . $ex[5] . chr(1);
|
||||
$ctcp_reply = chr(1) . "$ctcp " . $ex[4] . ' ' . $ex[5] . chr(1);
|
||||
break;
|
||||
case 'TIME':
|
||||
$ctcp_reply = chr(1) . "$ctcp " . date('c') . chr(1);
|
||||
break;
|
||||
}
|
||||
if ($ctcp_reply !== null) {
|
||||
$this->log("Sending irc CTCP: " . 'NOTICE ' . $this->getUser($this->data) . " :" . $ctcp_reply);
|
||||
$this->log('Sending irc CTCP: ' . 'NOTICE ' . $this->getUser($this->data) . ' :' . $ctcp_reply);
|
||||
|
||||
return $this->ircRaw('NOTICE ' . $this->getUser($this->data) . " :" . $ctcp_reply);
|
||||
return $this->ircRaw('NOTICE ' . $this->getUser($this->data) . ' :' . $ctcp_reply);
|
||||
}
|
||||
}
|
||||
|
||||
if (($ex[1] == 'NICK') && (preg_replace("/^:/", "", $ex[2]) == $this->nick)) {
|
||||
if (($ex[1] == 'NICK') && (preg_replace('/^:/', '', $ex[2]) == $this->nick)) {
|
||||
// Nickname changed successfully
|
||||
if ($this->debug) {
|
||||
$this->log("Regained our real nick");
|
||||
$this->log('Regained our real nick');
|
||||
}
|
||||
unset($this->tempnick);
|
||||
}
|
||||
if (($ex[1] == 433) || ($ex[1] == 437)) {
|
||||
// Nickname already in use / temp unavailable
|
||||
if ($this->debug) {
|
||||
$this->log("Nickname already in use...");
|
||||
$this->log('Nickname already in use...');
|
||||
}
|
||||
if ($ex[2] != "*") {
|
||||
if ($ex[2] != '*') {
|
||||
$this->tempnick = $ex[2];
|
||||
}
|
||||
if (! isset($this->tempnick)) {
|
||||
$this->tempnick = $this->nick . rand(0, 99);
|
||||
}
|
||||
if ($this->debug) {
|
||||
$this->log("Using temp nick " . $this->tempnick);
|
||||
$this->log('Using temp nick ' . $this->tempnick);
|
||||
}
|
||||
|
||||
return $this->ircRaw('NICK ' . $this->tempnick);
|
||||
@ -577,7 +577,7 @@ class IRCBot
|
||||
global $authorizer;
|
||||
foreach ($this->config['irc_auth'] as $nms_user => $hosts) {
|
||||
foreach ($hosts as $host) {
|
||||
$host = preg_replace("/\*/", ".*", $host);
|
||||
$host = preg_replace("/\*/", '.*', $host);
|
||||
if (preg_match("/$host/", $this->getUserHost($this->data))) {
|
||||
$user_id = LegacyAuth::get()->getUserid(mres($nms_user));
|
||||
$user = LegacyAuth::get()->getUser($user_id);
|
||||
@ -685,7 +685,7 @@ class IRCBot
|
||||
private function _quit($params)
|
||||
{
|
||||
if ($this->user['level'] == 10) {
|
||||
$this->ircRaw("QUIT :Requested");
|
||||
$this->ircRaw('QUIT :Requested');
|
||||
|
||||
return exit();
|
||||
} else {
|
||||
@ -896,8 +896,8 @@ class IRCBot
|
||||
$status_counts = [];
|
||||
$status_colors = [0 => 'green', 3 => 'lightblue', 1 => 'yellow', 2 => 'red'];
|
||||
$srvcount = dbFetchCell('SELECT COUNT(*) FROM services' . $d_w);
|
||||
$srvign = dbFetchCell("SELECT COUNT(*) FROM services WHERE service_ignore = 1" . $d_a);
|
||||
$srvdis = dbFetchCell("SELECT COUNT(*) FROM services WHERE service_disabled = 1" . $d_a);
|
||||
$srvign = dbFetchCell('SELECT COUNT(*) FROM services WHERE service_ignore = 1' . $d_a);
|
||||
$srvdis = dbFetchCell('SELECT COUNT(*) FROM services WHERE service_disabled = 1' . $d_a);
|
||||
$service_status = dbFetchRows("SELECT `service_status`, COUNT(*) AS `count` FROM `services` WHERE `service_disabled`=0 AND `service_ignore`=0 $d_a GROUP BY `service_status`");
|
||||
$service_status = array_column($service_status, 'count', 'service_status'); // key by status
|
||||
|
||||
@ -926,28 +926,28 @@ class IRCBot
|
||||
private function _color($text, $fg_color, $bg_color = null, $other = null)
|
||||
{
|
||||
$colors = [
|
||||
'white' => "00",
|
||||
'black' => "01",
|
||||
'blue' => "02",
|
||||
'green' => "03",
|
||||
'red' => "04",
|
||||
'brown' => "05",
|
||||
'purple' => "06",
|
||||
'orange' => "07",
|
||||
'yellow' => "08",
|
||||
'lightgreen' => "09",
|
||||
'cyan' => "10",
|
||||
'lightcyan' => "11",
|
||||
'lightblue' => "12",
|
||||
'pink' => "13",
|
||||
'grey' => "14",
|
||||
'lightgrey' => "15",
|
||||
'white' => '00',
|
||||
'black' => '01',
|
||||
'blue' => '02',
|
||||
'green' => '03',
|
||||
'red' => '04',
|
||||
'brown' => '05',
|
||||
'purple' => '06',
|
||||
'orange' => '07',
|
||||
'yellow' => '08',
|
||||
'lightgreen' => '09',
|
||||
'cyan' => '10',
|
||||
'lightcyan' => '11',
|
||||
'lightblue' => '12',
|
||||
'pink' => '13',
|
||||
'grey' => '14',
|
||||
'lightgrey' => '15',
|
||||
];
|
||||
$ret = chr(3);
|
||||
if (array_key_exists($fg_color, $colors)) {
|
||||
$ret .= $colors[$fg_color];
|
||||
if (array_key_exists($bg_color, $colors)) {
|
||||
$ret .= "," . $colors[$fg_color];
|
||||
$ret .= ',' . $colors[$fg_color];
|
||||
}
|
||||
}
|
||||
switch ($other) {
|
||||
|
@ -92,7 +92,7 @@ class OS implements Module
|
||||
|
||||
$device->icon = basename(Url::findOsImage($device->os, $device->features, null, 'images/os/'));
|
||||
|
||||
echo trans("device.attributes.location") . ": $device->location\n";
|
||||
echo trans('device.attributes.location') . ": $device->location\n";
|
||||
foreach (['hardware', 'version', 'features', 'serial'] as $attribute) {
|
||||
echo \App\Observers\DeviceObserver::attributeChangedMessage($attribute, $device->$attribute, $device->getOriginal($attribute)) . PHP_EOL;
|
||||
}
|
||||
|
@ -229,7 +229,7 @@ class OS implements ProcessorDiscovery, OSDiscovery
|
||||
|
||||
$rf = new \ReflectionClass($this);
|
||||
$name = $rf->getShortName();
|
||||
preg_match_all("/[A-Z][a-z]*/", $name, $segments);
|
||||
preg_match_all('/[A-Z][a-z]*/', $name, $segments);
|
||||
|
||||
return implode('-', array_map('strtolower', $segments[0]));
|
||||
}
|
||||
|
@ -35,13 +35,13 @@ class Aix extends OS implements OSDiscovery
|
||||
$aix_descr = explode("\n", $device->sysDescr);
|
||||
// AIX standard snmp deamon
|
||||
if ($aix_descr[1]) {
|
||||
$device->serial = explode("Processor id: ", $aix_descr[1])[1];
|
||||
$aix_long_version = explode(" version: ", $aix_descr[2])[1];
|
||||
[$device->version, $aix_version_min] = array_map('intval', explode(".", $aix_long_version));
|
||||
$device->serial = explode('Processor id: ', $aix_descr[1])[1];
|
||||
$aix_long_version = explode(' version: ', $aix_descr[2])[1];
|
||||
[$device->version, $aix_version_min] = array_map('intval', explode('.', $aix_long_version));
|
||||
// AIX net-snmp
|
||||
} else {
|
||||
[, , $aix_version_min, $device->version, $device->serial] = explode(" ", $aix_descr[0]);
|
||||
[, , $aix_version_min, $device->version, $device->serial] = explode(' ', $aix_descr[0]);
|
||||
}
|
||||
$device->version .= "." . $aix_version_min;
|
||||
$device->version .= '.' . $aix_version_min;
|
||||
}
|
||||
}
|
||||
|
@ -39,12 +39,12 @@ class ArrisC4 extends OS implements OSDiscovery
|
||||
preg_match("/CMTS_V([\d.]+),/", $device->sysDescr, $match);
|
||||
$device->version = $match[1];
|
||||
|
||||
$data = explode(".", $device->sysObjectID);
|
||||
$data = explode('.', $device->sysObjectID);
|
||||
$id = end($data);
|
||||
if ($id == "1") {
|
||||
$device->hardware = "C4";
|
||||
} elseif ($id == "2") {
|
||||
$device->hardware = "C4c";
|
||||
if ($id == '1') {
|
||||
$device->hardware = 'C4';
|
||||
} elseif ($id == '2') {
|
||||
$device->hardware = 'C4c';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -202,7 +202,7 @@ class ArubaInstant extends OS implements
|
||||
public function discoverWirelessPower()
|
||||
{
|
||||
// instant
|
||||
return $this->discoverInstantRadio('power', 'aiRadioTransmitPower', "%s Radio %s: Tx Power");
|
||||
return $this->discoverInstantRadio('power', 'aiRadioTransmitPower', '%s Radio %s: Tx Power');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -155,7 +155,7 @@ class Arubaos extends OS implements
|
||||
public function discoverWirelessPower()
|
||||
{
|
||||
// instant
|
||||
return $this->discoverInstantRadio('power', 'aiRadioTransmitPower', "Radio %s: Tx Power");
|
||||
return $this->discoverInstantRadio('power', 'aiRadioTransmitPower', 'Radio %s: Tx Power');
|
||||
}
|
||||
|
||||
protected function decodeChannel($channel)
|
||||
|
@ -61,7 +61,7 @@ class Awplus extends OS implements OSDiscovery
|
||||
}
|
||||
}
|
||||
|
||||
$device->version = snmp_get($this->getDeviceArray(), "currSoftVersion.0", "-OQv", "AT-SETUP-MIB");
|
||||
$device->version = snmp_get($this->getDeviceArray(), 'currSoftVersion.0', '-OQv', 'AT-SETUP-MIB');
|
||||
$device->serial = $serial;
|
||||
$device->hardware = $hardware;
|
||||
$device->features = $features ?? null;
|
||||
|
@ -36,7 +36,7 @@ class Beagleboard extends OS implements
|
||||
{
|
||||
$oids = ['NET-SNMP-EXTEND-MIB::nsExtendOutputFull."distro"', 'NET-SNMP-EXTEND-MIB::nsExtendOutputFull."hardware"'];
|
||||
$info = snmp_get_multi($this->getDeviceArray(), $oids);
|
||||
$device->version = str_replace("BeagleBoard.org ", "", $info['"distro"']['nsExtendOutputFull']);
|
||||
$device->version = str_replace('BeagleBoard.org ', '', $info['"distro"']['nsExtendOutputFull']);
|
||||
$device->hardware = $info['"hardware"']['nsExtendOutputFull'];
|
||||
}
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ class Boss extends OS implements OSDiscovery, ProcessorDiscovery
|
||||
$count = 1;
|
||||
foreach ($data as $index => $entry) {
|
||||
$processors[] = Processor::discover(
|
||||
"avaya-ers",
|
||||
'avaya-ers',
|
||||
$this->getDeviceId(),
|
||||
".1.3.6.1.4.1.45.1.6.3.8.1.1.6.$index",
|
||||
zeropad($count),
|
||||
|
@ -62,7 +62,7 @@ class Ceraos extends OS implements OSDiscovery, WirelessXpiDiscovery, WirelessFr
|
||||
}
|
||||
}
|
||||
|
||||
$device->features = $num_radios . " radios in unit";
|
||||
$device->features = $num_radios . ' radios in unit';
|
||||
}
|
||||
|
||||
public function discoverWirelessXpi()
|
||||
@ -151,7 +151,7 @@ class Ceraos extends OS implements OSDiscovery, WirelessXpiDiscovery, WirelessFr
|
||||
'.1.3.6.1.4.1.2281.10.7.4.1.1.7.' . $index,
|
||||
'ceraos-tx',
|
||||
$index,
|
||||
$ifNames[$index] . " TX Bitrate",
|
||||
$ifNames[$index] . ' TX Bitrate',
|
||||
$data['genEquipRadioMRMCCurrTxBitrate'],
|
||||
1000
|
||||
);
|
||||
@ -165,7 +165,7 @@ class Ceraos extends OS implements OSDiscovery, WirelessXpiDiscovery, WirelessFr
|
||||
'.1.3.6.1.4.1.2281.10.7.4.1.1.11.' . $index,
|
||||
'ceraos-rx',
|
||||
$index,
|
||||
$ifNames[$index] . " RX Bitrate",
|
||||
$ifNames[$index] . ' RX Bitrate',
|
||||
$data['genEquipRadioMRMCCurrRxBitrate'],
|
||||
1000
|
||||
);
|
||||
@ -194,7 +194,7 @@ class Ceraos extends OS implements OSDiscovery, WirelessXpiDiscovery, WirelessFr
|
||||
'.1.3.6.1.4.1.2281.10.7.1.1.3.' . $index,
|
||||
'ceraos',
|
||||
$index,
|
||||
$ifNames[$index] . " Defected Blocks",
|
||||
$ifNames[$index] . ' Defected Blocks',
|
||||
$data['genEquipRadioStatusDefectedBlocks']
|
||||
);
|
||||
}
|
||||
@ -253,7 +253,7 @@ class Ceraos extends OS implements OSDiscovery, WirelessXpiDiscovery, WirelessFr
|
||||
'.1.3.6.1.4.1.2281.10.5.1.1.3.' . $index,
|
||||
'ceraos-tx',
|
||||
$index,
|
||||
$ifNames[$index] . " TX Level",
|
||||
$ifNames[$index] . ' TX Level',
|
||||
$data['genEquipRfuStatusTxLevel']
|
||||
);
|
||||
}
|
||||
@ -266,7 +266,7 @@ class Ceraos extends OS implements OSDiscovery, WirelessXpiDiscovery, WirelessFr
|
||||
'.1.3.6.1.4.1.2281.10.5.1.1.2.' . $index,
|
||||
'ceraos-rx',
|
||||
$index,
|
||||
$ifNames[$index] . " RX Level",
|
||||
$ifNames[$index] . ' RX Level',
|
||||
$data['genEquipRfuStatusRxLevel']
|
||||
);
|
||||
}
|
||||
|
@ -160,7 +160,7 @@ class Ewc extends OS implements
|
||||
'.1.3.6.1.4.1.4329.15.3.5.2.5.1.18.' . $index,
|
||||
'ewc',
|
||||
$index . 'Retx',
|
||||
"Retransmits ($name radio " . explode('.', $index)[1] . ")"
|
||||
"Retransmits ($name radio " . explode('.', $index)[1] . ')'
|
||||
);
|
||||
}
|
||||
|
||||
@ -248,7 +248,7 @@ class Ewc extends OS implements
|
||||
'.1.3.6.1.4.1.4329.15.3.5.2.5.1.9.' . $index,
|
||||
'ewc',
|
||||
$index,
|
||||
"RSS ($name radio " . explode('.', $index)[1] . ")"
|
||||
"RSS ($name radio " . explode('.', $index)[1] . ')'
|
||||
);
|
||||
}
|
||||
|
||||
@ -275,7 +275,7 @@ class Ewc extends OS implements
|
||||
'.1.3.6.1.4.1.4329.15.3.5.2.5.1.13.' . $index,
|
||||
'ewc',
|
||||
$index,
|
||||
"SNR ($name radio " . explode('.', $index)[1] . ")"
|
||||
"SNR ($name radio " . explode('.', $index)[1] . ')'
|
||||
);
|
||||
}
|
||||
|
||||
@ -302,7 +302,7 @@ class Ewc extends OS implements
|
||||
'.1.3.6.1.4.1.4329.15.3.5.2.5.1.5.' . $index,
|
||||
'ewc',
|
||||
$index,
|
||||
"Utilization ($name radio " . explode('.', $index)[1] . ")"
|
||||
"Utilization ($name radio " . explode('.', $index)[1] . ')'
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ class Exa extends OS implements OSDiscovery
|
||||
$info = snmp_getnext_multi($this->getDeviceArray(), ['e7CardSoftwareVersion', 'e7CardSerialNumber'], '-OQUs', 'E7-Calix-MIB');
|
||||
$device->version = $info['e7CardSoftwareVersion'];
|
||||
$device->serial = $info['e7CardSerialNumber'];
|
||||
$device->hardware = "Calix " . $device->sysDescr;
|
||||
$device->hardware = 'Calix ' . $device->sysDescr;
|
||||
|
||||
$cards = explode("\n", snmp_walk($this->getDeviceArray(), 'e7CardProvType', '-OQv', 'E7-Calix-MIB'));
|
||||
$card_count = [];
|
||||
|
@ -45,11 +45,11 @@ class FsSwitch extends OS implements ProcessorDiscovery
|
||||
|
||||
foreach ($processors_data as $index => $entry) {
|
||||
$processors[] = Processor::discover(
|
||||
"fs-SWITCHMIB",
|
||||
'fs-SWITCHMIB',
|
||||
$this->getDeviceId(),
|
||||
'.1.3.6.1.4.1.27975.1.2.11.' . $index,
|
||||
$index,
|
||||
"CPU",
|
||||
'CPU',
|
||||
-1,
|
||||
100 - $entry['ssCpuIdle']
|
||||
);
|
||||
|
@ -44,7 +44,7 @@ class Ifotec extends OS implements OSDiscovery
|
||||
];
|
||||
$data = snmp_get_multi($this->getDeviceArray(), $oids, ['-OQUs'], 'IFOTEC-SMI');
|
||||
|
||||
$device->version = $data[1]['ifoSysFirmware'] . " (Bootloader " . $data[1]['ifoSysBootloader'] . ")";
|
||||
$device->version = $data[1]['ifoSysFirmware'] . ' (Bootloader ' . $data[1]['ifoSysBootloader'] . ')';
|
||||
$device->serial = $data[1]['ifoSysSerialNumber'];
|
||||
}
|
||||
}
|
||||
|
@ -223,7 +223,7 @@ class Lcos extends OS implements
|
||||
'.1.3.6.1.4.1.2356.11.1.3.44.1.10.' . Rewrite::oidMac($bssid) . '.0',
|
||||
'lcos',
|
||||
$bssid,
|
||||
"CCQ " . $entry['lcsStatusWlanCompetingNetworksEntryInterpointPeerName'] . " $bssid",
|
||||
'CCQ ' . $entry['lcsStatusWlanCompetingNetworksEntryInterpointPeerName'] . " $bssid",
|
||||
$entry['lcsStatusWlanCompetingNetworksEntryPhySigal']
|
||||
);
|
||||
}
|
||||
@ -256,7 +256,7 @@ class Lcos extends OS implements
|
||||
'.1.3.6.1.4.1.2356.11.1.3.44.1.35.' . Rewrite::oidMac($bssid) . '.0',
|
||||
'lcos-tx',
|
||||
$bssid,
|
||||
"TX Rate " . $entry['lcsStatusWlanCompetingNetworksEntryInterpointPeerName'] . " $bssid",
|
||||
'TX Rate ' . $entry['lcsStatusWlanCompetingNetworksEntryInterpointPeerName'] . " $bssid",
|
||||
$entry['lcsStatusWlanCompetingNetworksEntryEffRate'],
|
||||
1000000
|
||||
);
|
||||
@ -291,7 +291,7 @@ class Lcos extends OS implements
|
||||
'.1.3.6.1.4.1.2356.11.1.3.44.1.26.' . Rewrite::oidMac($bssid) . '.0',
|
||||
'lcos',
|
||||
$bssid,
|
||||
"RSSI " . $entry['lcsStatusWlanCompetingNetworksEntryInterpointPeerName'] . " $bssid",
|
||||
'RSSI ' . $entry['lcsStatusWlanCompetingNetworksEntryInterpointPeerName'] . " $bssid",
|
||||
$entry['lcsStatusWlanCompetingNetworksEntrySignalLevel']
|
||||
);
|
||||
}
|
||||
|
@ -82,9 +82,9 @@ class Pmp extends OS implements
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (Str::contains($device->sysDescr, "AP")) {
|
||||
if (Str::contains($device->sysDescr, 'AP')) {
|
||||
$hardware .= ' AP';
|
||||
} elseif (Str::contains($device->sysDescr, "SM")) {
|
||||
} elseif (Str::contains($device->sysDescr, 'SM')) {
|
||||
$hardware .= ' SM';
|
||||
}
|
||||
}
|
||||
@ -121,7 +121,7 @@ class Pmp extends OS implements
|
||||
$this->enableGraph('canopy_generic_crcErrors');
|
||||
}
|
||||
|
||||
$jitter = snmp_get($this->getDeviceArray(), "jitter.0", "-Ovqn", "WHISP-SM-MIB");
|
||||
$jitter = snmp_get($this->getDeviceArray(), 'jitter.0', '-Ovqn', 'WHISP-SM-MIB');
|
||||
if (is_numeric($jitter)) {
|
||||
$rrd_def = RrdDefinition::make()->addDataset('jitter', 'GAUGE', 0, 20);
|
||||
$fields = [
|
||||
@ -133,10 +133,10 @@ class Pmp extends OS implements
|
||||
unset($rrd_filename, $jitter);
|
||||
}
|
||||
|
||||
$multi_get_array = snmp_get_multi($this->getDeviceArray(), ['regCount.0', 'regFailureCount.0'], "-OQU", "WHISP-APS-MIB");
|
||||
$multi_get_array = snmp_get_multi($this->getDeviceArray(), ['regCount.0', 'regFailureCount.0'], '-OQU', 'WHISP-APS-MIB');
|
||||
d_echo($multi_get_array);
|
||||
$registered = $multi_get_array[0]["WHISP-APS-MIB::regCount"];
|
||||
$failed = $multi_get_array[0]["WHISP-APS-MIB::regFailureCount"];
|
||||
$registered = $multi_get_array[0]['WHISP-APS-MIB::regCount'];
|
||||
$failed = $multi_get_array[0]['WHISP-APS-MIB::regFailureCount'];
|
||||
|
||||
if (is_numeric($registered) && is_numeric($failed)) {
|
||||
$rrd_def = RrdDefinition::make()
|
||||
@ -152,8 +152,8 @@ class Pmp extends OS implements
|
||||
unset($rrd_filename, $registered, $failed);
|
||||
}
|
||||
|
||||
$visible = str_replace('"', "", snmp_get($this->getDeviceArray(), ".1.3.6.1.4.1.161.19.3.4.4.7.0", "-Ovqn", ""));
|
||||
$tracked = str_replace('"', "", snmp_get($this->getDeviceArray(), ".1.3.6.1.4.1.161.19.3.4.4.8.0", "-Ovqn", ""));
|
||||
$visible = str_replace('"', '', snmp_get($this->getDeviceArray(), '.1.3.6.1.4.1.161.19.3.4.4.7.0', '-Ovqn', ''));
|
||||
$tracked = str_replace('"', '', snmp_get($this->getDeviceArray(), '.1.3.6.1.4.1.161.19.3.4.4.8.0', '-Ovqn', ''));
|
||||
if (is_numeric($visible) && is_numeric($tracked)) {
|
||||
$rrd_def = RrdDefinition::make()
|
||||
->addDataset('visible', 'GAUGE', 0, 1000)
|
||||
@ -200,7 +200,7 @@ class Pmp extends OS implements
|
||||
$this->enableGraph('canopy_generic_450_linkRadioDbm');
|
||||
}
|
||||
|
||||
$lastLevel = str_replace('"', "", snmp_get($this->getDeviceArray(), "lastPowerLevel.2", "-Ovqn", "WHISP-APS-MIB"));
|
||||
$lastLevel = str_replace('"', '', snmp_get($this->getDeviceArray(), 'lastPowerLevel.2', '-Ovqn', 'WHISP-APS-MIB'));
|
||||
if (is_numeric($lastLevel)) {
|
||||
$rrd_def = RrdDefinition::make()->addDataset('last', 'GAUGE', -100, 0);
|
||||
$fields = [
|
||||
@ -211,9 +211,9 @@ class Pmp extends OS implements
|
||||
$this->enableGraph('canopy_generic_450_powerlevel');
|
||||
}
|
||||
|
||||
$vertical = str_replace('"', "", snmp_get($this->getDeviceArray(), ".1.3.6.1.4.1.161.19.3.2.2.117.0", "-Ovqn", ""));
|
||||
$horizontal = str_replace('"', "", snmp_get($this->getDeviceArray(), ".1.3.6.1.4.1.161.19.3.2.2.118.0", "-Ovqn", ""));
|
||||
$combined = snmp_get($this->getDeviceArray(), "1.3.6.1.4.1.161.19.3.2.2.21.0", "-Ovqn", "");
|
||||
$vertical = str_replace('"', '', snmp_get($this->getDeviceArray(), '.1.3.6.1.4.1.161.19.3.2.2.117.0', '-Ovqn', ''));
|
||||
$horizontal = str_replace('"', '', snmp_get($this->getDeviceArray(), '.1.3.6.1.4.1.161.19.3.2.2.118.0', '-Ovqn', ''));
|
||||
$combined = snmp_get($this->getDeviceArray(), '1.3.6.1.4.1.161.19.3.2.2.21.0', '-Ovqn', '');
|
||||
if (is_numeric($vertical) && is_numeric($horizontal) && is_numeric($combined)) {
|
||||
$rrd_def = RrdDefinition::make()
|
||||
->addDataset('vertical', 'GAUGE', -150, 0)
|
||||
@ -230,8 +230,8 @@ class Pmp extends OS implements
|
||||
unset($rrd_filename, $vertical, $horizontal, $combined);
|
||||
}
|
||||
|
||||
$horizontal = str_replace('"', "", snmp_get($this->getDeviceArray(), "radioDbmHorizontal.0", "-Ovqn", "WHISP-SM-MIB"));
|
||||
$vertical = str_replace('"', "", snmp_get($this->getDeviceArray(), "radioDbmVertical.0", "-Ovqn", "WHISP-SM-MIB"));
|
||||
$horizontal = str_replace('"', '', snmp_get($this->getDeviceArray(), 'radioDbmHorizontal.0', '-Ovqn', 'WHISP-SM-MIB'));
|
||||
$vertical = str_replace('"', '', snmp_get($this->getDeviceArray(), 'radioDbmVertical.0', '-Ovqn', 'WHISP-SM-MIB'));
|
||||
if (is_numeric($horizontal) && is_numeric($vertical)) {
|
||||
$rrd_def = RrdDefinition::make()
|
||||
->addDataset('horizontal', 'GAUGE', -100, 100)
|
||||
|
@ -54,7 +54,7 @@ class Powerconnect extends OS implements ProcessorDiscovery, ProcessorPolling
|
||||
'.1.3.6.1.4.1.674.10895.3030',
|
||||
'.1.3.6.1.4.1.674.10895.3031',
|
||||
])) {
|
||||
d_echo("Dell Powerconnect 55xx");
|
||||
d_echo('Dell Powerconnect 55xx');
|
||||
|
||||
return [
|
||||
Processor::discover(
|
||||
|
@ -108,8 +108,8 @@ class Ptp250 extends OS implements
|
||||
$receive = '.1.3.6.1.4.1.17713.250.11.1.0'; //"CAMBIUM-PTP250-MIB::receiveDataRate.0"
|
||||
$transmit = '.1.3.6.1.4.1.17713.250.11.2.0'; //"CAMBIUM-PTP250-MIB::transmitDataRate.0"
|
||||
$aggregate = '.1.3.6.1.4.1.17713.250.11.3.0'; //"CAMBIUM-PTP250-MIB::aggregateDataRate.0"
|
||||
$txModulation = ".1.3.6.1.4.1.17713.250.5.9.0";
|
||||
$rxModulation = ".1.3.6.1.4.1.17713.250.5.8.0";
|
||||
$txModulation = '.1.3.6.1.4.1.17713.250.5.9.0';
|
||||
$rxModulation = '.1.3.6.1.4.1.17713.250.5.8.0';
|
||||
|
||||
return [
|
||||
new WirelessSensor(
|
||||
|
@ -83,8 +83,8 @@ class Ptp650 extends OS implements
|
||||
$receive = '.1.3.6.1.4.1.17713.7.20.1.0'; //CAMBIUM-PTP650-MIB::receiveDataRate.0
|
||||
$transmit = '.1.3.6.1.4.1.17713.7.20.2.0'; //CAMBIUM-PTP650-MIB::transmitDataRate.0
|
||||
$aggregate = '.1.3.6.1.4.1.17713.7.20.3.0'; //CAMBIUM-PTP650-MIB::aggregateDataRate.0
|
||||
$txModulation = ".1.3.6.1.4.1.17713.7.12.15.0";
|
||||
$rxModulation = ".1.3.6.1.4.1.17713.7.12.14.0";
|
||||
$txModulation = '.1.3.6.1.4.1.17713.7.12.15.0';
|
||||
$rxModulation = '.1.3.6.1.4.1.17713.7.12.14.0';
|
||||
|
||||
return [
|
||||
new WirelessSensor(
|
||||
|
@ -83,8 +83,8 @@ class Ptp670 extends OS implements
|
||||
$receive = '.1.3.6.1.4.1.17713.11.20.1.0'; //CAMBIUM-PTP670-MIB::receiveDataRate.0
|
||||
$transmit = '.1.3.6.1.4.1.17713.11.20.2.0'; //CAMBIUM-PTP670-MIB::transmitDataRate.0
|
||||
$aggregate = '.1.3.6.1.4.1.17713.11.20.3.0'; //CAMBIUM-PTP670-MIB::aggregateDataRate.0
|
||||
$txModulation = ".1.3.6.1.4.1.17713.11.12.15.0";
|
||||
$rxModulation = ".1.3.6.1.4.1.17713.11.12.14.0";
|
||||
$txModulation = '.1.3.6.1.4.1.17713.11.12.15.0';
|
||||
$rxModulation = '.1.3.6.1.4.1.17713.11.12.14.0';
|
||||
|
||||
return [
|
||||
new WirelessSensor(
|
||||
|
@ -14,12 +14,12 @@ class RuckuswirelessSz extends OS implements
|
||||
{
|
||||
public function discoverOS(Device $device): void
|
||||
{
|
||||
$device->hardware = snmp_getnext($this->getDeviceArray(), '.1.3.6.1.4.1.25053.1.8.1.1.1.1.1.1.3', "-OQv");
|
||||
$device->version = snmp_getnext($this->getDeviceArray(), '.1.3.6.1.4.1.25053.1.8.1.1.1.1.1.1.9', "-OQv");
|
||||
$device->serial = snmp_get($this->getDeviceArray(), '.1.3.6.1.4.1.25053.1.4.1.1.1.15.13.0', "-OQv");
|
||||
$device->features = "Licenses: " . snmp_get($this->getDeviceArray(), '.1.3.6.1.4.1.25053.1.4.1.1.1.15.1.0', "-OQv") . "/" . snmp_getnext($this->getDeviceArray(), '.1.3.6.1.4.1.25053.1.8.1.1.1.1.1.1.10', "-OQv");
|
||||
$device->hardware = snmp_getnext($this->getDeviceArray(), '.1.3.6.1.4.1.25053.1.8.1.1.1.1.1.1.3', '-OQv');
|
||||
$device->version = snmp_getnext($this->getDeviceArray(), '.1.3.6.1.4.1.25053.1.8.1.1.1.1.1.1.9', '-OQv');
|
||||
$device->serial = snmp_get($this->getDeviceArray(), '.1.3.6.1.4.1.25053.1.4.1.1.1.15.13.0', '-OQv');
|
||||
$device->features = 'Licenses: ' . snmp_get($this->getDeviceArray(), '.1.3.6.1.4.1.25053.1.4.1.1.1.15.1.0', '-OQv') . '/' . snmp_getnext($this->getDeviceArray(), '.1.3.6.1.4.1.25053.1.8.1.1.1.1.1.1.10', '-OQv');
|
||||
|
||||
$ruckuscountry = snmp_getnext($this->getDeviceArray(), '.1.3.6.1.4.1.25053.1.8.1.1.1.1.3.1.4', "-OQv");
|
||||
$ruckuscountry = snmp_getnext($this->getDeviceArray(), '.1.3.6.1.4.1.25053.1.8.1.1.1.1.3.1.4', '-OQv');
|
||||
if (! empty($ruckuscountry)) {
|
||||
$device->version .= " ($ruckuscountry)";
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ class Schleifenbauer extends \LibreNMS\OS
|
||||
{
|
||||
public function discoverOS(Device $device): void
|
||||
{
|
||||
$master_unit = snmp_get($this->getDeviceArray(), ".1.3.6.1.4.1.31034.12.1.1.1.2.4.1.2.1", '-Oqv');
|
||||
$master_unit = snmp_get($this->getDeviceArray(), '.1.3.6.1.4.1.31034.12.1.1.1.2.4.1.2.1', '-Oqv');
|
||||
|
||||
$oids = [
|
||||
'hardware' => ".1.3.6.1.4.1.31034.12.1.1.2.1.1.1.5.$master_unit",
|
||||
|
@ -61,12 +61,12 @@ class Cisco extends OS implements OSDiscovery, ProcessorDiscovery, NacPolling
|
||||
$device->version = $regexp_result[2];
|
||||
} elseif (preg_match('/^Cisco IOS Software \[([^\]]+)\],.+Software \(([^\)]+)\), Version ([^, ]+)/', $device->sysDescr, $regexp_result)) {
|
||||
$device->features = $regexp_result[1];
|
||||
$device->version = $regexp_result[2] . " " . $regexp_result[3];
|
||||
$device->version = $regexp_result[2] . ' ' . $regexp_result[3];
|
||||
} elseif (preg_match('/^Cisco IOS Software.*?, .+? Software(\, )?([\s\w\d]+)? \([^\-]+-([\w\d]+)-\w\), Version ([^,]+)/', $device->sysDescr, $regexp_result)) {
|
||||
$device->features = $regexp_result[3];
|
||||
$device->version = $regexp_result[4];
|
||||
$hardware = $regexp_result[2];
|
||||
$tmp = preg_split("/\\r\\n|\\r|\\n/", $device->version);
|
||||
$tmp = preg_split('/\\r\\n|\\r|\\n/', $device->version);
|
||||
if (! empty($tmp[0])) {
|
||||
$device->version = $tmp[0];
|
||||
}
|
||||
|
@ -49,25 +49,25 @@ class Unix extends \LibreNMS\OS
|
||||
preg_match('/ (\d+\.\d\S*) /', $device->sysDescr, $matches);
|
||||
$device->version = $matches[1] ?? $device->version;
|
||||
if (preg_match('/i[3-6]86/', $device->sysDescr)) {
|
||||
$device->hardware = "Generic x86";
|
||||
} elseif (Str::contains($device->sysDescr, "x86_64")) {
|
||||
$device->hardware = "Generic x86 64-bit";
|
||||
} elseif (Str::contains($device->sysDescr, "sparc32")) {
|
||||
$device->hardware = "Generic SPARC 32-bit";
|
||||
} elseif (Str::contains($device->sysDescr, "sparc64")) {
|
||||
$device->hardware = "Generic SPARC 64-bit";
|
||||
} elseif (Str::contains($device->sysDescr, "mips")) {
|
||||
$device->hardware = "Generic MIPS";
|
||||
} elseif (Str::contains($device->sysDescr, "armv5")) {
|
||||
$device->hardware = "Generic ARMv5";
|
||||
} elseif (Str::contains($device->sysDescr, "armv6")) {
|
||||
$device->hardware = "Generic ARMv6";
|
||||
} elseif (Str::contains($device->sysDescr, "armv7")) {
|
||||
$device->hardware = "Generic ARMv7";
|
||||
} elseif (Str::contains($device->sysDescr, "aarch64")) {
|
||||
$device->hardware = "Generic ARMv8 64-bit";
|
||||
} elseif (Str::contains($device->sysDescr, "armv")) {
|
||||
$device->hardware = "Generic ARM";
|
||||
$device->hardware = 'Generic x86';
|
||||
} elseif (Str::contains($device->sysDescr, 'x86_64')) {
|
||||
$device->hardware = 'Generic x86 64-bit';
|
||||
} elseif (Str::contains($device->sysDescr, 'sparc32')) {
|
||||
$device->hardware = 'Generic SPARC 32-bit';
|
||||
} elseif (Str::contains($device->sysDescr, 'sparc64')) {
|
||||
$device->hardware = 'Generic SPARC 64-bit';
|
||||
} elseif (Str::contains($device->sysDescr, 'mips')) {
|
||||
$device->hardware = 'Generic MIPS';
|
||||
} elseif (Str::contains($device->sysDescr, 'armv5')) {
|
||||
$device->hardware = 'Generic ARMv5';
|
||||
} elseif (Str::contains($device->sysDescr, 'armv6')) {
|
||||
$device->hardware = 'Generic ARMv6';
|
||||
} elseif (Str::contains($device->sysDescr, 'armv7')) {
|
||||
$device->hardware = 'Generic ARMv7';
|
||||
} elseif (Str::contains($device->sysDescr, 'aarch64')) {
|
||||
$device->hardware = 'Generic ARMv8 64-bit';
|
||||
} elseif (Str::contains($device->sysDescr, 'armv')) {
|
||||
$device->hardware = 'Generic ARM';
|
||||
}
|
||||
|
||||
$this->discoverDellHardware();
|
||||
@ -77,9 +77,9 @@ class Unix extends \LibreNMS\OS
|
||||
protected function discoverDellHardware()
|
||||
{
|
||||
// Detect Dell hardware via OpenManage SNMP
|
||||
$hw = snmp_get($this->getDeviceArray(), ".1.3.6.1.4.1.674.10892.1.300.10.1.9.1", "-Oqv", "MIB-Dell-10892");
|
||||
$hw = snmp_get($this->getDeviceArray(), '.1.3.6.1.4.1.674.10892.1.300.10.1.9.1', '-Oqv', 'MIB-Dell-10892');
|
||||
if ($hw) {
|
||||
$this->getDevice()->hardware = "Dell " . $hw;
|
||||
$this->getDevice()->hardware = 'Dell ' . $hw;
|
||||
} else {
|
||||
$hw = trim(snmp_get($this->getDeviceArray(), 'cpqSiProductName.0', '-Oqv', 'CPQSINFO-MIB', 'hp'), '"');
|
||||
if (! empty($hw)) {
|
||||
|
@ -53,7 +53,7 @@ class Smartax extends OS implements ProcessorDiscovery
|
||||
if ($value != -1) {
|
||||
$proc_desc = $descr_data[$index];
|
||||
$processors[] = Processor::discover(
|
||||
"smartax",
|
||||
'smartax',
|
||||
$this->getDeviceId(),
|
||||
"$proc_oid.$index",
|
||||
$index,
|
||||
|
@ -36,23 +36,23 @@ class Terra extends OS implements ProcessorDiscovery, OSDiscovery
|
||||
public function discoverOS(Device $device): void
|
||||
{
|
||||
$models = [
|
||||
"sda410C" => "5",
|
||||
"sta410C" => "6",
|
||||
"saa410C" => "7",
|
||||
"sdi410C" => "8",
|
||||
"sti410C" => "9",
|
||||
"sai410C" => "10",
|
||||
"ttd440" => "14",
|
||||
"ttx410C" => "15",
|
||||
"tdx410C" => "16",
|
||||
"sdi480" => "17",
|
||||
"sti440" => "18",
|
||||
'sda410C' => '5',
|
||||
'sta410C' => '6',
|
||||
'saa410C' => '7',
|
||||
'sdi410C' => '8',
|
||||
'sti410C' => '9',
|
||||
'sai410C' => '10',
|
||||
'ttd440' => '14',
|
||||
'ttx410C' => '15',
|
||||
'tdx410C' => '16',
|
||||
'sdi480' => '17',
|
||||
'sti440' => '18',
|
||||
];
|
||||
|
||||
foreach ($models as $model => $index) {
|
||||
if (Str::contains($device->sysDescr, $model)) {
|
||||
$oid_terra = ".1.3.6.1.4.1.30631.1.";
|
||||
$oid = [$oid_terra . $index . ".4.1.0", $oid_terra . $index . ".4.2.0"];
|
||||
$oid_terra = '.1.3.6.1.4.1.30631.1.';
|
||||
$oid = [$oid_terra . $index . '.4.1.0', $oid_terra . $index . '.4.2.0'];
|
||||
|
||||
$data = snmp_get_multi_oid($device, $oid);
|
||||
$device->hardware = $model;
|
||||
@ -74,12 +74,12 @@ class Terra extends OS implements ProcessorDiscovery, OSDiscovery
|
||||
$device = $this->getDeviceArray();
|
||||
|
||||
$query = [
|
||||
"sti410C" => ".1.3.6.1.4.1.30631.1.9.1.1.3.0",
|
||||
"sti440" => ".1.3.6.1.4.1.30631.1.18.1.326.3.0",
|
||||
'sti410C' => '.1.3.6.1.4.1.30631.1.9.1.1.3.0',
|
||||
'sti440' => '.1.3.6.1.4.1.30631.1.18.1.326.3.0',
|
||||
];
|
||||
|
||||
foreach ($query as $decr => $oid) {
|
||||
if (strpos($device["sysDescr"], $decr) !== false) {
|
||||
if (strpos($device['sysDescr'], $decr) !== false) {
|
||||
return [
|
||||
Processor::discover(
|
||||
'cpu',
|
||||
|
@ -34,14 +34,14 @@ class ThreeCom extends OS implements OSDiscovery
|
||||
public function discoverOS(Device $device): void
|
||||
{
|
||||
if (Str::contains($device->sysDescr, 'Software')) {
|
||||
$device->hardware = str_replace("3Com ", '', substr($device->sysDescr, 0, strpos($device->sysDescr, 'Software')));
|
||||
$device->hardware = str_replace('3Com ', '', substr($device->sysDescr, 0, strpos($device->sysDescr, 'Software')));
|
||||
// Version is the last word in the sysDescr's first line
|
||||
[$device->version] = explode("\n", substr($device->sysDescr, (strpos($device->sysDescr, 'Version') + 8)));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$device->hardware = str_replace("3Com ", '', $device->sysDescr);
|
||||
$device->hardware = str_replace('3Com ', '', $device->sysDescr);
|
||||
// Old Stack Units
|
||||
if (Str::startsWith($device->sysObjectID, '.1.3.6.1.4.1.43.10.27.4.1.')) {
|
||||
$oids = ['stackUnitDesc.1', 'stackUnitPromVersion.1', 'stackUnitSWVersion.1', 'stackUnitSerialNumber.1', 'stackUnitCapabilities.1'];
|
||||
|
@ -100,7 +100,7 @@ class Timos extends OS implements MplsDiscovery, MplsPolling, WirelessPowerDisco
|
||||
private function nokiaEncap($tmnxEncapVal)
|
||||
{
|
||||
// implement other encapsulation values
|
||||
$map = sprintf("%032b", $tmnxEncapVal);
|
||||
$map = sprintf('%032b', $tmnxEncapVal);
|
||||
|
||||
if (substr($map, -32, 20) == '00000000000000000000') { // 12-bit IEEE 802.1Q VLAN ID
|
||||
if ($tmnxEncapVal == 4095) {
|
||||
@ -378,10 +378,10 @@ class Timos extends OS implements MplsDiscovery, MplsPolling, WirelessPowerDisco
|
||||
$lsp_path_id = $paths->firstWhere('mplsLspPathTunnelARHopListIndex', $mplsTunnelARHopListIndex)->lsp_path_id;
|
||||
$protection = intval($value['vRtrMplsTunnelARHopProtection'], 16);
|
||||
|
||||
$localLinkProtection = ($protection & $localAvailable) ? "true" : "false";
|
||||
$linkProtectionInUse = ($protection & $localInUse) ? "true" : "false";
|
||||
$bandwidthProtection = ($protection & $bandwidthProtected) ? "true" : "false";
|
||||
$nextNodeProtection = ($protection & $nodeProtected) ? "true" : "false";
|
||||
$localLinkProtection = ($protection & $localAvailable) ? 'true' : 'false';
|
||||
$linkProtectionInUse = ($protection & $localInUse) ? 'true' : 'false';
|
||||
$bandwidthProtection = ($protection & $bandwidthProtected) ? 'true' : 'false';
|
||||
$nextNodeProtection = ($protection & $nodeProtected) ? 'true' : 'false';
|
||||
|
||||
$ARHopRouterId = $value['vRtrMplsTunnelARHopRouterId'];
|
||||
if (isset($value['vRtrMplsTunnelARHopNgRouterId'])) {
|
||||
@ -725,10 +725,10 @@ class Timos extends OS implements MplsDiscovery, MplsPolling, WirelessPowerDisco
|
||||
$lsp_path_id = $paths->firstWhere('mplsLspPathTunnelARHopListIndex', $mplsTunnelARHopListIndex)->lsp_path_id;
|
||||
$protection = intval($value['vRtrMplsTunnelARHopProtection'], 16);
|
||||
|
||||
$localLinkProtection = ($protection & $localAvailable) ? "true" : "false";
|
||||
$linkProtectionInUse = ($protection & $localInUse) ? "true" : "false";
|
||||
$bandwidthProtection = ($protection & $bandwidthProtected) ? "true" : "false";
|
||||
$nextNodeProtection = ($protection & $nodeProtected) ? "true" : "false";
|
||||
$localLinkProtection = ($protection & $localAvailable) ? 'true' : 'false';
|
||||
$linkProtectionInUse = ($protection & $localInUse) ? 'true' : 'false';
|
||||
$bandwidthProtection = ($protection & $bandwidthProtected) ? 'true' : 'false';
|
||||
$nextNodeProtection = ($protection & $nodeProtected) ? 'true' : 'false';
|
||||
|
||||
$ARHopRouterId = $value['vRtrMplsTunnelARHopRouterId'];
|
||||
if (isset($value['vRtrMplsTunnelARHopNgRouterId'])) {
|
||||
|
@ -34,9 +34,9 @@ class Topvision extends \LibreNMS\OS implements OSPolling
|
||||
public function discoverOS(Device $device): void
|
||||
{
|
||||
parent::discoverOS($device); // yaml
|
||||
$device->serial = snmp_getnext($this->getDeviceArray(), ".1.3.6.1.4.1.32285.11.1.1.2.1.1.1.16", "-OQv") ?? null;
|
||||
$device->serial = snmp_getnext($this->getDeviceArray(), '.1.3.6.1.4.1.32285.11.1.1.2.1.1.1.16', '-OQv') ?? null;
|
||||
if (empty($device->hardware)) {
|
||||
$device->hardware = snmp_getnext($this->getDeviceArray(), ".1.3.6.1.4.1.32285.11.1.1.2.1.1.1.18", "-OQv") ?? null;
|
||||
$device->hardware = snmp_getnext($this->getDeviceArray(), '.1.3.6.1.4.1.32285.11.1.1.2.1.1.1.18', '-OQv') ?? null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ trait HostResources
|
||||
*/
|
||||
public function discoverProcessors()
|
||||
{
|
||||
echo "Host Resources: ";
|
||||
echo 'Host Resources: ';
|
||||
$processors = [];
|
||||
|
||||
try {
|
||||
|
@ -36,7 +36,7 @@ trait UcdResources
|
||||
*/
|
||||
public function discoverProcessors()
|
||||
{
|
||||
echo "UCD Resources: ";
|
||||
echo 'UCD Resources: ';
|
||||
|
||||
return [
|
||||
Processor::discover(
|
||||
|
@ -61,7 +61,7 @@ trait YamlOSDiscovery
|
||||
$flags = $numeric ? '-OUQn' : '-OUQ';
|
||||
$data = snmp_get_multi_oid($this->getDeviceArray(), $fetch_oids, $flags);
|
||||
|
||||
Log::debug("Yaml OS data:", $data);
|
||||
Log::debug('Yaml OS data:', $data);
|
||||
|
||||
foreach ($oids as $field => $oid_list) {
|
||||
if ($value = $this->findFirst($data, $oid_list, $numeric)) {
|
||||
|
@ -36,14 +36,14 @@ class Ucos extends \LibreNMS\OS
|
||||
$device->version = snmp_get($this->getDeviceArray(), 'SYSAPPL-MIB::sysApplInstallPkgVersion.1', '-Oqv') ?: null;
|
||||
|
||||
$applist = snmp_walk($this->getDeviceArray(), 'SYSAPPL-MIB::sysApplInstallPkgProductName', '-OQv');
|
||||
if (Str::contains($applist, "Cisco Unified CCX Database")) {
|
||||
$device->features = "UCCX";
|
||||
} elseif (Str::contains($applist, "Cisco CallManager")) {
|
||||
$device->features = "CUCM";
|
||||
} elseif (Str::contains($applist, "Cisco Emergency Responder")) {
|
||||
$device->features = "CER";
|
||||
} elseif (Str::contains($applist, "Connection System Agent")) {
|
||||
$device->features = "CUC";
|
||||
if (Str::contains($applist, 'Cisco Unified CCX Database')) {
|
||||
$device->features = 'UCCX';
|
||||
} elseif (Str::contains($applist, 'Cisco CallManager')) {
|
||||
$device->features = 'CUCM';
|
||||
} elseif (Str::contains($applist, 'Cisco Emergency Responder')) {
|
||||
$device->features = 'CER';
|
||||
} elseif (Str::contains($applist, 'Connection System Agent')) {
|
||||
$device->features = 'CUC';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -129,7 +129,7 @@ class Vrp extends OS implements
|
||||
foreach ($ap as $r_id => $radio) {
|
||||
$channel = $radio['hwWlanRadioWorkingChannel'];
|
||||
$mac = $radio['hwWlanRadioMac'];
|
||||
$name = $apTable[$ap_id]['hwWlanApName'] . " Radio " . $r_id;
|
||||
$name = $apTable[$ap_id]['hwWlanApName'] . ' Radio ' . $r_id;
|
||||
$radionum = $r_id;
|
||||
$txpow = $radio['hwWlanRadioActualEIRP'];
|
||||
$interference = $radio['hwWlanRadioChInterferenceRate'];
|
||||
@ -138,13 +138,13 @@ class Vrp extends OS implements
|
||||
|
||||
switch ($radio['hwWlanRadioFreqType']) {
|
||||
case 1:
|
||||
$type = "2.4Ghz";
|
||||
$type = '2.4Ghz';
|
||||
break;
|
||||
case 2:
|
||||
$type = "5Ghz";
|
||||
$type = '5Ghz';
|
||||
break;
|
||||
default:
|
||||
$type = "unknown (huawei " . $radio['hwWlanRadioFreqType'] . ")";
|
||||
$type = 'unknown (huawei ' . $radio['hwWlanRadioFreqType'] . ')';
|
||||
}
|
||||
|
||||
// TODO
|
||||
@ -362,7 +362,7 @@ class Vrp extends OS implements
|
||||
|
||||
foreach ($vapInfoTable as $a_index => $ap) {
|
||||
//Convert mac address (hh:hh:hh:hh:hh:hh) to dec OID (ddd.ddd.ddd.ddd.ddd.ddd)
|
||||
$a_index_oid = implode(".", array_map("hexdec", explode(":", $a_index)));
|
||||
$a_index_oid = implode('.', array_map('hexdec', explode(':', $a_index)));
|
||||
foreach ($ap as $r_index => $radio) {
|
||||
foreach ($radio as $s_index => $ssid) {
|
||||
$oid = '.1.3.6.1.4.1.2011.6.139.17.1.1.1.9.' . $a_index_oid . '.' . $r_index . '.' . $s_index;
|
||||
|
@ -34,7 +34,7 @@ class Zxdsl extends \LibreNMS\OS
|
||||
parent::discoverOS($device); // yaml
|
||||
|
||||
if (preg_match('/^\.1\.3\.6\.1\.4\.1\.3902\.(1004|1015)\.(?<model>[^.]+)\.(?<variant>.*\.)1\.1\.1/', $device->sysObjectID, $matches)) {
|
||||
$device->hardware = "ZXDSL " . $matches['model'] . $this->parseVariant($matches['variant']);
|
||||
$device->hardware = 'ZXDSL ' . $matches['model'] . $this->parseVariant($matches['variant']);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -62,9 +62,9 @@ class Proc
|
||||
public function __construct(
|
||||
$cmd,
|
||||
$descriptorspec = [
|
||||
0 => ["pipe", "r"],
|
||||
1 => ["pipe", "w"],
|
||||
2 => ["pipe", "w"],
|
||||
0 => ['pipe', 'r'],
|
||||
1 => ['pipe', 'w'],
|
||||
2 => ['pipe', 'w'],
|
||||
],
|
||||
$cwd = null,
|
||||
$env = null,
|
||||
@ -222,7 +222,7 @@ class Proc
|
||||
proc_close($this->_process);
|
||||
|
||||
if (! $killed && $this->isRunning()) {
|
||||
throw new Exception("Terminate failed!");
|
||||
throw new Exception('Terminate failed!');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ class RrdDefinition
|
||||
public function addDataset($name, $type, $min = null, $max = null, $heartbeat = null)
|
||||
{
|
||||
if (empty($name)) {
|
||||
d_echo("DS must be set to a non-empty string.");
|
||||
d_echo('DS must be set to a non-empty string.');
|
||||
}
|
||||
|
||||
$name = $this->escapeName($name);
|
||||
|
@ -37,7 +37,7 @@ class Dispatcher
|
||||
public static function handle(Trap $trap)
|
||||
{
|
||||
if (empty($trap->getDevice())) {
|
||||
Log::warning("Could not find device for trap", ['trap_text' => $trap->getRaw()]);
|
||||
Log::warning('Could not find device for trap', ['trap_text' => $trap->getRaw()]);
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -51,7 +51,7 @@ class Dispatcher
|
||||
$fallback = $handler instanceof Fallback;
|
||||
$logging = Config::get('snmptraps.eventlog', 'unhandled');
|
||||
if ($logging == 'all' || ($fallback && $logging == 'unhandled')) {
|
||||
Log::event("SNMP trap received: " . $trap->getTrapOid(), $trap->getDevice(), 'trap');
|
||||
Log::event('SNMP trap received: ' . $trap->getTrapOid(), $trap->getDevice(), 'trap');
|
||||
} else {
|
||||
$rules = new AlertRules;
|
||||
$rules->runRules($trap->getDevice()->device_id);
|
||||
|
@ -44,11 +44,11 @@ class AdvaAccThresholdCrossingAlert implements SnmptrapHandler
|
||||
*/
|
||||
public function handle(Device $device, Trap $trap)
|
||||
{
|
||||
$interval = $trap->getOidData($trap->findOid("CM-PERFORMANCE-MIB::cmEthernetAccPortThresholdInterval"));
|
||||
$ifName = $trap->getOidData($trap->findOid("IF-MIB::ifName"));
|
||||
$interval = $trap->getOidData($trap->findOid('CM-PERFORMANCE-MIB::cmEthernetAccPortThresholdInterval'));
|
||||
$ifName = $trap->getOidData($trap->findOid('IF-MIB::ifName'));
|
||||
|
||||
$thresholdMessage = $this->getThresholdMessage(
|
||||
$trap->getOidData($trap->findOid("CM-PERFORMANCE-MIB::cmEthernetAccPortThresholdVariable"))
|
||||
$trap->getOidData($trap->findOid('CM-PERFORMANCE-MIB::cmEthernetAccPortThresholdVariable'))
|
||||
);
|
||||
|
||||
Log::event("$ifName $thresholdMessage threshold exceeded for $interval", $device->device_id, 'trap', 2);
|
||||
|
@ -50,7 +50,7 @@ class AdvaAttributeChange implements SnmptrapHandler
|
||||
} elseif ($trap->findOid('CM-SYSTEM-MIB::aclEntry')) {
|
||||
$this->handleAclChg($device, $trap);
|
||||
} elseif ($trap->findOid('CM-SYSTEM-MIB::securityBanner')) {
|
||||
Log::event("MOTD/Banner modified", $device->device_id, 'trap', 2);
|
||||
Log::event('MOTD/Banner modified', $device->device_id, 'trap', 2);
|
||||
} elseif ($trap->findOid('CM-SYSTEM-MIB::sysTimeOfDayType')) {
|
||||
$this->handleTimeSrcChg($device, $trap);
|
||||
} elseif ($trap->findOid('F3-TIMEZONE-MIB::f3TimeZone')) {
|
||||
@ -121,7 +121,7 @@ class AdvaAttributeChange implements SnmptrapHandler
|
||||
} elseif ('false' === $enabled && $trap->findOid('F3-TIMEZONE-MIB::f3TimeZoneDstControlEnabled')) {
|
||||
Log::event('Daylight Savings Time disabled', $device->device_id, 'trap', 2);
|
||||
}
|
||||
if ($trap->findOid("F3-TIMEZONE-MIB::f3TimeZoneUtcOffset")) {
|
||||
if ($trap->findOid('F3-TIMEZONE-MIB::f3TimeZoneUtcOffset')) {
|
||||
$dstOffset = $trap->getOidData($trap->findOid('F3-TIMEZONE-MIB::f3TimeZoneUtcOffset'));
|
||||
Log::event("UTC offset (timezone) change to $dstOffset", $device->device_id, 'trap', 2);
|
||||
}
|
||||
@ -164,7 +164,7 @@ class AdvaAttributeChange implements SnmptrapHandler
|
||||
public static function handleNeChg($device, $trap)
|
||||
{
|
||||
if ($trap->findOid('CM-ENTITY-MIB::neName')) {
|
||||
$neName = $trap->getOidData($trap->findOid("CM-ENTITY-MIB::neName"));
|
||||
$neName = $trap->getOidData($trap->findOid('CM-ENTITY-MIB::neName'));
|
||||
Log::event("Network Element name changed to $neName", $device->device_id, 'trap', 2);
|
||||
}
|
||||
if ($trap->findOid('CM-ENTITY-MIB::neCmdPromptPrefix')) {
|
||||
@ -177,16 +177,16 @@ class AdvaAttributeChange implements SnmptrapHandler
|
||||
{
|
||||
$nteSDGEnable = $trap->getOidData($trap->findOid('CM-ENTITY-MIB::ethernetNTEGE114ProCardSnmpDyingGaspEnabled'));
|
||||
if ('true' === $nteSDGEnable && $trap->findOid('CM-ENTITY-MIB::ethernetNTEGE114ProCardSnmpDyingGaspEnabled')) {
|
||||
Log::event("SNMP Dying Gasp is enabled", $device->device_id, 'trap', 2);
|
||||
Log::event('SNMP Dying Gasp is enabled', $device->device_id, 'trap', 2);
|
||||
} elseif ('false' === $nteSDGEnable && $trap->findOid('CM-ENTITY-MIB::ethernetNTEGE114ProCardSnmpDyingGaspEnabled')) {
|
||||
Log::event("SNMP Dying Gasp is disabled", $device->device_id, 'trap', 2);
|
||||
Log::event('SNMP Dying Gasp is disabled', $device->device_id, 'trap', 2);
|
||||
}
|
||||
}
|
||||
|
||||
public static function handleNetPortChg($device, $trap)
|
||||
{
|
||||
$netPort = substr($trap->findOid('CM-FACILITY-MIB::cmEthernetNetPort'), -7);
|
||||
$netPort = str_replace(".", "-", $netPort);
|
||||
$netPort = str_replace('.', '-', $netPort);
|
||||
$neDefMessage = false;
|
||||
if ($trap->findOid('CM-FACILITY-MIB::cmEthernetNetPortConfigSpeed')) {
|
||||
$netSpeed = $trap->getOidData($trap->findOid('CM-FACILITY-MIB::cmEthernetNetPortConfigSpeed'));
|
||||
@ -232,7 +232,7 @@ class AdvaAttributeChange implements SnmptrapHandler
|
||||
public static function handleAccPortChg($device, $trap)
|
||||
{
|
||||
$accPort = substr($trap->findOid('CM-FACILITY-MIB::cmEthernetAccPort'), -7);
|
||||
$accPort = str_replace(".", "-", $accPort);
|
||||
$accPort = str_replace('.', '-', $accPort);
|
||||
$accDefMessage = false;
|
||||
if ($trap->findOid('CM-FACILITY-MIB::cmEthernetAccPortConfigSpeed')) {
|
||||
$accSpeed = $trap->getOidData($trap->findOid('CM-FACILITY-MIB::cmEthernetAccPortConfigSpeed'));
|
||||
@ -278,7 +278,7 @@ class AdvaAttributeChange implements SnmptrapHandler
|
||||
public static function handleFlowChg($device, $trap)
|
||||
{
|
||||
$flowID = substr($trap->findOid('CM-FACILITY-MIB::cmFlow'), -9);
|
||||
$flowID = str_replace(".", "-", $flowID);
|
||||
$flowID = str_replace('.', '-', $flowID);
|
||||
Log::event("Access Flow $flowID modified", $device->device_id, 'trap', 2);
|
||||
}
|
||||
|
||||
@ -291,21 +291,21 @@ class AdvaAttributeChange implements SnmptrapHandler
|
||||
public static function handleQosFlowChg($device, $trap)
|
||||
{
|
||||
$flowID = substr($trap->findOid('CM-FACILITY-MIB::cmQosFlow'), -13, 9);
|
||||
$flowID = str_replace(".", "-", $flowID);
|
||||
$flowID = str_replace('.', '-', $flowID);
|
||||
Log::event("QoS on flow $flowID modified", $device->device_id, 'trap', 2);
|
||||
}
|
||||
|
||||
public static function handleQosShaperChg($device, $trap)
|
||||
{
|
||||
$flowID = substr($trap->findOid('CM-FACILITY-MIB::cmQosShaper'), -13, 9);
|
||||
$flowID = str_replace(".", "-", $flowID);
|
||||
$flowID = str_replace('.', '-', $flowID);
|
||||
Log::event("QoS on flow $flowID modified", $device->device_id, 'trap', 2);
|
||||
}
|
||||
|
||||
public static function handleAccPortShaperChg($device, $trap)
|
||||
{
|
||||
$shaperID = substr($trap->findOid('CM-FACILITY-MIB::cmAccPort'), -9);
|
||||
$shaperID = str_replace(".", "-", $shaperID);
|
||||
$shaperID = str_replace('.', '-', $shaperID);
|
||||
Log::event("Shaper modified on access port $shaperID modified", $device->device_id, 'trap', 2);
|
||||
}
|
||||
}
|
||||
|
@ -44,10 +44,10 @@ class AdvaNetThresholdCrossingAlert implements SnmptrapHandler
|
||||
*/
|
||||
public function handle(Device $device, Trap $trap)
|
||||
{
|
||||
$interval = $trap->getOidData($trap->findOid("CM-PERFORMANCE-MIB::cmEthernetNetPortThresholdInterval"));
|
||||
$ifName = $trap->getOidData($trap->findOid("IF-MIB::ifName"));
|
||||
$interval = $trap->getOidData($trap->findOid('CM-PERFORMANCE-MIB::cmEthernetNetPortThresholdInterval'));
|
||||
$ifName = $trap->getOidData($trap->findOid('IF-MIB::ifName'));
|
||||
$threshMessage = $this->getThresholdMessage(
|
||||
$trap->getOidData($trap->findOid("CM-PERFORMANCE-MIB::cmEthernetNetPortThresholdVariable"))
|
||||
$trap->getOidData($trap->findOid('CM-PERFORMANCE-MIB::cmEthernetNetPortThresholdVariable'))
|
||||
);
|
||||
|
||||
Log::event("$ifName $threshMessage threshold exceeded for $interval", $device->device_id, 'trap', 2);
|
||||
|
@ -46,16 +46,16 @@ class AdvaNetworkElementAlmTrap implements SnmptrapHandler
|
||||
{
|
||||
$alSeverity = $trap->getOidData($trap->findOid('CM-ALARM-MIB::cmNetworkElementAlmNotifCode'));
|
||||
switch ($alSeverity) {
|
||||
case "critical":
|
||||
case 'critical':
|
||||
$logSeverity = 5;
|
||||
break;
|
||||
case "major":
|
||||
case 'major':
|
||||
$logSeverity = 4;
|
||||
break;
|
||||
case "minor":
|
||||
case 'minor':
|
||||
$logSeverity = 3;
|
||||
break;
|
||||
case "cleared":
|
||||
case 'cleared':
|
||||
$logSeverity = 1;
|
||||
break;
|
||||
default:
|
||||
|
@ -48,11 +48,11 @@ class AdvaObjectDeletion implements SnmptrapHandler
|
||||
$UserName = $trap->getOidData($trap_oid);
|
||||
Log::event("User object $UserName deleted", $device->device_id, 'trap', 2);
|
||||
} elseif ($trap_oid = $trap->findOid('CM-FACILITY-MIB::cmFlowIndex')) {
|
||||
$flowID = str_replace(".", "-", substr($trap_oid, 29));
|
||||
$flowID = str_replace('.', '-', substr($trap_oid, 29));
|
||||
Log::event("Flow $flowID deleted", $device->device_id, 'trap', 2);
|
||||
} elseif ($trap_oid = $trap->findOid('F3-LAG-MIB::f3LagPortIndex')) {
|
||||
$lagPortID = $trap->getOidData($trap_oid);
|
||||
$lagID = str_replace(".", "-", substr($trap_oid, -5, 3));
|
||||
$lagID = str_replace('.', '-', substr($trap_oid, -5, 3));
|
||||
Log::event("LAG member port $lagPortID removed from LAG $lagID", $device->device_id, 'trap', 2);
|
||||
} elseif ($trap_oid = $trap->findOid('F3-LAG-MIB::f3LagIndex')) {
|
||||
$lagID = $trap->getOidData($trap_oid);
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user