netflow: Fix incorrect interface index (#6490)

This commit is contained in:
Nicolas Thumann 2023-04-15 18:51:28 +02:00 committed by GitHub
parent b85f3d0ed1
commit 2ff2989f72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 6 deletions

View File

@ -69,7 +69,7 @@ netflow_setup_interface()
# determine (snmp) ifIndex
ifIndex=0
found=0
for item in $(/sbin/ifconfig -l); do
for item in $(/usr/local/sbin/ifinfo | awk '$1 == "Interface" { print $2 }'); do
let ifIndex = ifIndex + 1 > /dev/null 2>&1
if [ "$item" = "$interface" ]; then
found=1

View File

@ -30,6 +30,7 @@ import glob
import tempfile
import subprocess
import os
import re
from lib.flowparser import FlowParser
@ -40,11 +41,11 @@ class Interfaces(object):
""" construct local interface mapping
"""
self._if_index = dict()
sp = subprocess.run(['/sbin/ifconfig', '-l'], capture_output=True, text=True)
if_index = 1
for line in sp.stdout.split():
self._if_index["%s" % if_index] = line
if_index += 1
sp = subprocess.run(['/usr/local/sbin/ifinfo'], capture_output=True, text=True)
interfaces = re.findall(r"Interface ([^ ]+)", sp.stdout)
for index, interface in enumerate(interfaces, start=1):
self._if_index["%s" % index] = interface
def if_device(self, if_index):
""" convert index to device (if found)