From f817ae8586fffc8fcf24936e621410ec82230510 Mon Sep 17 00:00:00 2001 From: Tim de Boer Date: Fri, 7 Oct 2022 22:10:37 +0200 Subject: [PATCH] Added Ubuntu and Raspbian to ifAlias script (#14399) * Added Ubuntu and Raspbian to ifAlias script * Improved to pass shellcheck and added support for "/etc/network/interfaces.d/*" * Last shellcheck type and updated docs * Last changes in docs * Tabs vs Spaces --- .../Interface-Description-Parsing.md | 12 ++++++---- scripts/ifAlias | 22 +++++++++---------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/doc/Extensions/Interface-Description-Parsing.md b/doc/Extensions/Interface-Description-Parsing.md index 5c36cd0066..ab52957b16 100644 --- a/doc/Extensions/Interface-Description-Parsing.md +++ b/doc/Extensions/Interface-Description-Parsing.md @@ -76,10 +76,14 @@ to support the parsing of interface information. to the Server and make it executable `chmod +x /path/to/ifAlias` - Add to `snmpd.conf` something like: ``pass .1.3.6.1.2.1.31.1.1.1.18 /path/to/ifAlias`` - Restart `snmpd` - `service snmpd restart` +- Add aliasses with + - `iproute2` package like: + ``ip link set eth0.427 alias 'Cust: CustomerA'`` + - in `/etc/network/interfaces` or `/etc/network/interfaces.d/*` with a comment like: + ``# eth0.427: Cust CustomerA`` + +- Restart `snmpd` - `systemctl restart snmpd` There are no changes to be made or additions to install for the polling librenms. -Now you can set up your [keywords](#keywords) in your `/etc/network/interfaces` - -``//Add more distributions than just Debian based`` +Now you can set up your [keywords](#keywords) in your aliases. diff --git a/scripts/ifAlias b/scripts/ifAlias index 9342396eee..fcd777bbfd 100755 --- a/scripts/ifAlias +++ b/scripts/ifAlias @@ -1,5 +1,5 @@ -#!/bin/sh -# (c) 2013-2017, f0o@devilcode.org, olb@nebkha.net +#!/bin/bash +# (c) 2013-2022, f0o@devilcode.org, olb@nebkha.net, tim@tim427.net # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or @@ -41,7 +41,7 @@ interface_id() { local N= local L= - local ID="${GET_OID#${BASE}.}" + local ID="${GET_OID#"${BASE}".}" case "$GET_TYPE" in -g) @@ -58,7 +58,7 @@ interface_id() # find the next iface_id for N in $(echo "$IP_LINK" | grep -oE "^[0-9]+:" | cut -d':' -f 1) do - if [ "$L" = "$ID" -o ! "$ID" ] + if [ "$L" = "$ID" ] || [ ! "$ID" ] then echo -n "$N" return 0 @@ -85,23 +85,23 @@ alias_from_interfaces_config_file() if [ -x "$DISTRO_BIN" ] then case "$("$DISTRO_BIN" | cut -d " " -f 1)" in - Debian) - CONFIG_FILE="/etc/network/interfaces" + Debian|Ubuntu|Raspbian) + CONFIG_FILE=("/etc/network/interfaces" "/etc/network/interfaces.d/"*) ;; Gentoo) - CONFIG_FILE="/etc/conf.d/net" + CONFIG_FILE=("/etc/conf.d/net") ;; CentOS|RedHat|SuSE|Mandriva|Mandrake) - CONFIG_FILE="/etc/sysconfig/network-scripts/ifcfg-$IFACE" + CONFIG_FILE=("/etc/sysconfig/network-scripts/ifcfg-$IFACE") ;; Archlinux) - CONFIG_FILE="/etc/conf.d/net-conf-$IFACE" + CONFIG_FILE=("/etc/conf.d/net-conf-$IFACE") ;; esac fi - if [ "$CONFIG_FILE" ] + if ((${#CONFIG_FILE[@]})) then - echo "$(grep -i "^# $IFACE:" $CONFIG_FILE | sed "s/^# $IFACE: //i")" + grep -hsi "^# $IFACE:" "${CONFIG_FILE[@]}" | sed "s/^# $IFACE: //i" fi }