From 330910b4e39ebe20fd3f363f4417d9b2a5ac7f9d Mon Sep 17 00:00:00 2001 From: vitalisator Date: Sun, 7 Aug 2016 17:47:25 +0200 Subject: [PATCH] Fix a bug in syslog since PR #3812 syslog writes to wrong device id in syslog table. this happens on all devices where inet_pton() returns false. --- includes/syslog.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/includes/syslog.php b/includes/syslog.php index ab4d1e2a12..fa0eacacae 100644 --- a/includes/syslog.php +++ b/includes/syslog.php @@ -13,7 +13,12 @@ function get_cache($host, $value) { case 'device_id': // Try by hostname $ip = inet_pton($host); - $dev_cache[$host]['device_id'] = dbFetchCell('SELECT `device_id` FROM devices WHERE `hostname` = ? OR `sysName` = ? OR `ip` = ?', array($host, $host, $ip)); + if (var_export(inet_ntop($ip),1) == '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));