From 240b6c7598dd8bcf236c26c7fa17f252c99449bb Mon Sep 17 00:00:00 2001 From: laf Date: Sun, 29 Mar 2015 20:43:35 +0100 Subject: [PATCH] Updated ipsec polling to clean up data and check before inserting --- includes/polling/cipsec-tunnels.inc.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/includes/polling/cipsec-tunnels.inc.php b/includes/polling/cipsec-tunnels.inc.php index 6801a89d6..53f33a83c 100644 --- a/includes/polling/cipsec-tunnels.inc.php +++ b/includes/polling/cipsec-tunnels.inc.php @@ -6,7 +6,12 @@ $ipsec_array = snmpwalk_cache_oid($device, "cipSecTunnelEntry", array(), "CISCO- $ike_array = snmpwalk_cache_oid($device, "cikeTunnelEntry", array(), "CISCO-IPSEC-FLOW-MONITOR-MIB"); $tunnels_db = dbFetchRows("SELECT * FROM `ipsec_tunnels` WHERE `device_id` = ?", array($device['device_id'])); -foreach ($tunnels_db as $tunnel) { $tunnels[$tunnel['peer_addr']] = $tunnel;} +foreach ($tunnels_db as $tunnel) { + if (empty($tunnel['peer_addr']) && empty($tunnel['local_addr'])) { + dbDelete('ipsec_tunnels', '`tunnel_id` = ?', array($tunnel['tunnel_id'])); + } + $tunnels[$tunnel['peer_addr']] = $tunnel; +} foreach ($ipsec_array as $index => $tunnel) { @@ -42,7 +47,7 @@ foreach ($ipsec_array as $index => $tunnel) "cikeTunLocalName" => "tunnel_name", "cikeTunLocalValue" => "local_addr"); - if (!is_array($tunnels[$tunnel['cikeTunRemoteValue']])) + if (!is_array($tunnels[$tunnel['cikeTunRemoteValue']]) && !empty($tunnel['cikeTunRemoteValue'])) { $tunnel_id = dbInsert(array('device_id' => $device['device_id'], 'peer_addr' => $tunnel['cikeTunRemoteValue'], 'local_addr' => $tunnel['cikeTunLocalValue'], 'tunnel_name' => $tunnel['cikeTunLocalName']), 'ipsec_tunnels'); } else {