mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Update code in includes to be PSR-2 compliant (#4220)
refactor: Update code in /includes to be psr2 compliant #4220
This commit is contained in:
committed by
Neil Lathwood
parent
3c0fcdd46b
commit
9284bc60ff
@@ -5,45 +5,45 @@
|
||||
// $device_id_ip = @dbFetchCell("SELECT device_id FROM ipv4_addresses AS A, ports AS I WHERE A.ipv4_address = '" . $entry['host']."' AND I.port_id = A.port_id");
|
||||
|
||||
|
||||
function get_cache($host, $value) {
|
||||
function get_cache($host, $value)
|
||||
{
|
||||
global $dev_cache;
|
||||
|
||||
if (!isset($dev_cache[$host][$value])) {
|
||||
switch ($value) {
|
||||
case 'device_id':
|
||||
// Try by hostname
|
||||
$ip = inet_pton($host);
|
||||
if (inet_ntop($ip) === false) {
|
||||
$dev_cache[$host]['device_id'] = dbFetchCell('SELECT `device_id` FROM devices WHERE `hostname` = ? OR `sysName` = ?', array($host, $host));
|
||||
}
|
||||
else {
|
||||
$dev_cache[$host]['device_id'] = dbFetchCell('SELECT `device_id` FROM devices WHERE `hostname` = ? OR `sysName` = ? OR `ip` = ?', array($host, $host, $ip));
|
||||
}
|
||||
// If failed, try by IP
|
||||
if (!is_numeric($dev_cache[$host]['device_id'])) {
|
||||
$dev_cache[$host]['device_id'] = dbFetchCell('SELECT `device_id` FROM `ipv4_addresses` AS A, `ports` AS I WHERE A.ipv4_address = ? AND I.port_id = A.port_id', array($host));
|
||||
}
|
||||
break;
|
||||
case 'device_id':
|
||||
// Try by hostname
|
||||
$ip = inet_pton($host);
|
||||
if (inet_ntop($ip) === false) {
|
||||
$dev_cache[$host]['device_id'] = dbFetchCell('SELECT `device_id` FROM devices WHERE `hostname` = ? OR `sysName` = ?', array($host, $host));
|
||||
} else {
|
||||
$dev_cache[$host]['device_id'] = dbFetchCell('SELECT `device_id` FROM devices WHERE `hostname` = ? OR `sysName` = ? OR `ip` = ?', array($host, $host, $ip));
|
||||
}
|
||||
// If failed, try by IP
|
||||
if (!is_numeric($dev_cache[$host]['device_id'])) {
|
||||
$dev_cache[$host]['device_id'] = dbFetchCell('SELECT `device_id` FROM `ipv4_addresses` AS A, `ports` AS I WHERE A.ipv4_address = ? AND I.port_id = A.port_id', array($host));
|
||||
}
|
||||
break;
|
||||
|
||||
case 'os':
|
||||
$dev_cache[$host]['os'] = dbFetchCell('SELECT `os` FROM devices WHERE `device_id` = ?', array(get_cache($host, 'device_id')));
|
||||
break;
|
||||
case 'os':
|
||||
$dev_cache[$host]['os'] = dbFetchCell('SELECT `os` FROM devices WHERE `device_id` = ?', array(get_cache($host, 'device_id')));
|
||||
break;
|
||||
|
||||
case 'version':
|
||||
$dev_cache[$host]['version'] = dbFetchCell('SELECT `version` FROM devices WHERE `device_id`= ?', array(get_cache($host, 'device_id')));
|
||||
break;
|
||||
case 'version':
|
||||
$dev_cache[$host]['version'] = dbFetchCell('SELECT `version` FROM devices WHERE `device_id`= ?', array(get_cache($host, 'device_id')));
|
||||
break;
|
||||
|
||||
default:
|
||||
return null;
|
||||
default:
|
||||
return null;
|
||||
}//end switch
|
||||
}//end if
|
||||
|
||||
return $dev_cache[$host][$value];
|
||||
|
||||
}//end get_cache()
|
||||
|
||||
|
||||
function process_syslog($entry, $update) {
|
||||
function process_syslog($entry, $update)
|
||||
{
|
||||
global $config, $dev_cache;
|
||||
|
||||
foreach ($config['syslog_filter'] as $bi) {
|
||||
@@ -59,26 +59,24 @@ function process_syslog($entry, $update) {
|
||||
|
||||
if (in_array($os, array('ios', 'iosxe', 'catos'))) {
|
||||
// multipart message
|
||||
if(strpos($entry['msg'], ':') !== false) {
|
||||
if (strpos($entry['msg'], ':') !== false) {
|
||||
$matches = array();
|
||||
$timestamp_prefix = '([\*\.]?[A-Z][a-z]{2} \d\d? \d\d:\d\d:\d\d(.\d\d\d)?( [A-Z]{3})?: )?';
|
||||
$program_match = '(?<program>%?[A-Za-z\d\-_]+(:[A-Z]* %[A-Z\d\-_]+)?)';
|
||||
$message_match = '(?<msg>.*)';
|
||||
if(preg_match('/^' . $timestamp_prefix . $program_match . ': ?' . $message_match . '/', $entry['msg'], $matches)) {
|
||||
if (preg_match('/^' . $timestamp_prefix . $program_match . ': ?' . $message_match . '/', $entry['msg'], $matches)) {
|
||||
$entry['program'] = $matches['program'];
|
||||
$entry['msg'] = $matches['msg'];
|
||||
}
|
||||
unset($matches);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// if this looks like a program (no groups of 2 or more lowercase letters), move it to program
|
||||
if (!preg_match('/[(a-z)]{2,}/', $entry['msg'])) {
|
||||
$entry['program'] = $entry['msg'];
|
||||
unset($entry['msg']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ($os == 'linux' and get_cache($entry['host'], 'version') == 'Point') {
|
||||
} elseif ($os == 'linux' and get_cache($entry['host'], 'version') == 'Point') {
|
||||
// Cisco WAP200 and similar
|
||||
$matches = array();
|
||||
if (preg_match('#Log: \[(?P<program>.*)\] - (?P<msg>.*)#', $entry['msg'], $matches)) {
|
||||
@@ -87,8 +85,7 @@ function process_syslog($entry, $update) {
|
||||
}
|
||||
|
||||
unset($matches);
|
||||
}
|
||||
else if ($os == 'linux') {
|
||||
} elseif ($os == 'linux') {
|
||||
$matches = array();
|
||||
// pam_krb5(sshd:auth): authentication failure; logname=root uid=0 euid=0 tty=ssh ruser= rhost=123.213.132.231
|
||||
// pam_krb5[sshd:auth]: authentication failure; logname=root uid=0 euid=0 tty=ssh ruser= rhost=123.213.132.231
|
||||
@@ -104,20 +101,18 @@ function process_syslog($entry, $update) {
|
||||
// $entry['msg'] = substr($entry['msg'], $pos+1);
|
||||
// }
|
||||
// fallback, better than nothing...
|
||||
else if (empty($entry['program']) and !empty($entry['facility'])) {
|
||||
elseif (empty($entry['program']) and !empty($entry['facility'])) {
|
||||
$entry['program'] = $entry['facility'];
|
||||
}
|
||||
|
||||
unset($matches);
|
||||
}
|
||||
else if ($os == 'procurve') {
|
||||
} elseif ($os == 'procurve') {
|
||||
$matches = array();
|
||||
if (preg_match('/^(?P<program>[A-Za-z]+): {2}(?P<msg>.*)/', $entry['msg'], $matches)) {
|
||||
$entry['msg'] = $matches['msg']. " [". $entry['program']. "]";
|
||||
$entry['program'] = $matches['program'];
|
||||
}
|
||||
unset($matches);
|
||||
|
||||
}//end if
|
||||
|
||||
if (!isset($entry['program'])) {
|
||||
@@ -148,5 +143,4 @@ function process_syslog($entry, $update) {
|
||||
}//end if
|
||||
|
||||
return $entry;
|
||||
|
||||
}//end process_syslog()
|
||||
|
Reference in New Issue
Block a user