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
This commit is contained in:
Tim de Boer 2022-10-07 22:10:37 +02:00 committed by GitHub
parent 840c3210e6
commit f817ae8586
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 15 deletions

View File

@ -76,10 +76,14 @@ to support the parsing of interface information.
to the Server and make it executable `chmod +x /path/to/ifAlias` to the Server and make it executable `chmod +x /path/to/ifAlias`
- Add to `snmpd.conf` something like: - Add to `snmpd.conf` something like:
``pass .1.3.6.1.2.1.31.1.1.1.18 /path/to/ifAlias`` ``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. 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` Now you can set up your [keywords](#keywords) in your aliases.
``//Add more distributions than just Debian based``

View File

@ -1,5 +1,5 @@
#!/bin/sh #!/bin/bash
# (c) 2013-2017, f0o@devilcode.org, olb@nebkha.net # (c) 2013-2022, f0o@devilcode.org, olb@nebkha.net, tim@tim427.net
# This program is free software: you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or # the Free Software Foundation, either version 3 of the License, or
@ -41,7 +41,7 @@ interface_id()
{ {
local N= local N=
local L= local L=
local ID="${GET_OID#${BASE}.}" local ID="${GET_OID#"${BASE}".}"
case "$GET_TYPE" in case "$GET_TYPE" in
-g) -g)
@ -58,7 +58,7 @@ interface_id()
# find the next iface_id # find the next iface_id
for N in $(echo "$IP_LINK" | grep -oE "^[0-9]+:" | cut -d':' -f 1) for N in $(echo "$IP_LINK" | grep -oE "^[0-9]+:" | cut -d':' -f 1)
do do
if [ "$L" = "$ID" -o ! "$ID" ] if [ "$L" = "$ID" ] || [ ! "$ID" ]
then then
echo -n "$N" echo -n "$N"
return 0 return 0
@ -85,23 +85,23 @@ alias_from_interfaces_config_file()
if [ -x "$DISTRO_BIN" ] if [ -x "$DISTRO_BIN" ]
then then
case "$("$DISTRO_BIN" | cut -d " " -f 1)" in case "$("$DISTRO_BIN" | cut -d " " -f 1)" in
Debian) Debian|Ubuntu|Raspbian)
CONFIG_FILE="/etc/network/interfaces" CONFIG_FILE=("/etc/network/interfaces" "/etc/network/interfaces.d/"*)
;; ;;
Gentoo) Gentoo)
CONFIG_FILE="/etc/conf.d/net" CONFIG_FILE=("/etc/conf.d/net")
;; ;;
CentOS|RedHat|SuSE|Mandriva|Mandrake) CentOS|RedHat|SuSE|Mandriva|Mandrake)
CONFIG_FILE="/etc/sysconfig/network-scripts/ifcfg-$IFACE" CONFIG_FILE=("/etc/sysconfig/network-scripts/ifcfg-$IFACE")
;; ;;
Archlinux) Archlinux)
CONFIG_FILE="/etc/conf.d/net-conf-$IFACE" CONFIG_FILE=("/etc/conf.d/net-conf-$IFACE")
;; ;;
esac esac
fi fi
if [ "$CONFIG_FILE" ] if ((${#CONFIG_FILE[@]}))
then then
echo "$(grep -i "^# $IFACE:" $CONFIG_FILE | sed "s/^# $IFACE: //i")" grep -hsi "^# $IFACE:" "${CONFIG_FILE[@]}" | sed "s/^# $IFACE: //i"
fi fi
} }