Syslog name translation (#9463)

* Check to see if a host exists in a lookup table to translate received name to what LibreNMS knows

* Added some documentation on how this is configured

* Use \LibreNMS\Config instead of accessing $config directly

* Fix codeclimate finding: Additional blank lines after USE statement

* murrant suggested a much cleaner way of doing this!
This commit is contained in:
TylerSweet
2018-11-20 16:47:53 -06:00
committed by Tony Murray
parent 549f2fc50b
commit 8617f3e21d
2 changed files with 19 additions and 1 deletions

View File

@@ -289,3 +289,18 @@ $config['os']['screenos']['syslog_hook'][] = Array('regex' => '/System configura
$config['os']['awplus']['syslog_hook'][] = Array('regex' => '/IMI.+.Startup-config saved on/', 'script' => '/opt/librenms/scripts/syslog-notify-oxidized.php');
```
### Configuration Options
#### Matching syslogs to hosts with different names
In some cases, you may get logs that aren't being associated with the device in LibreNMS. For example, in LibreNMS the device is known as "ne-core-01", and that's how DNS resolves. However, the received syslogs are for "loopback.core-nw".
To fix this issue, you can configure LibreNMS to translate the incoming syslog hostname into another hostname, so that the logs get associated with the correct device.
Example:
```ssh
$config['syslog_xlate'] = array(
'loopback0.core7k1.noc.net' => 'n7k1-core7k1',
'loopback0.core7k2.noc.net' => 'n7k2-core7k2'
);
```

View File

@@ -3,7 +3,7 @@
// FIXME : use db functions properly
// $device_id_host = @dbFetchCell("SELECT device_id FROM devices WHERE `hostname` = '".mres($entry['host'])."' OR `sysName` = '".mres($entry['host'])."'");
// $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");
use LibreNMS\Config;
function get_cache($host, $value)
{
@@ -57,6 +57,9 @@ function process_syslog($entry, $update)
}
$entry['host'] = preg_replace("/^::ffff:/", "", $entry['host']);
if ($new_host = Config::get('syslog_xlate.' . $entry['host'])) {
$entry['host'] = $new_host;
}
$entry['device_id'] = get_cache($entry['host'], 'device_id');
if ($entry['device_id']) {
$os = get_cache($entry['host'], 'os');