From bd6e583b34dbc5c03e77aff5541c1caf5694c0a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Iranzo=20G=C3=B3mez?= Date: Thu, 24 Aug 2023 11:40:02 +0200 Subject: [PATCH] plugin(ifaceerrors): Reports errors on network interfaces --- .../plugins/core/network/interface-errors.sh | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100755 risuclient/plugins/core/network/interface-errors.sh diff --git a/risuclient/plugins/core/network/interface-errors.sh b/risuclient/plugins/core/network/interface-errors.sh new file mode 100755 index 00000000..5b13472f --- /dev/null +++ b/risuclient/plugins/core/network/interface-errors.sh @@ -0,0 +1,54 @@ +#!/bin/bash + +# Copyright (C) 2020-2023 Pablo Iranzo Gómez + +# 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 +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# long_name: Reports interfaces with errors +# description: Reports interfaces with errors +# priority: 900 +# kb: + +# Load common functions +[[ -f "${RISU_BASE}/common-functions.sh" ]] && . "${RISU_BASE}/common-functions.sh" + +if [[ ${RISU_LIVE} -eq "0" ]]; then + IP_ADDRESS_FILE=$(first_file_available "${RISU_ROOT}/sos_commands/networking/ip_-d_address" "${RISU_ROOT}/sos_commands/networking/ip_address") + is_required_file "${IP_ADDRESS_FILE}" +elif [[ ${RISU_LIVE} -eq "1" ]]; then + IP_ADDRESS_FILE=$(mktemp) + trap 'rm ${IP_ADDRESS_FILE}' EXIT + ip address >"${IP_ADDRESS_FILE}" 2>&1 +fi + +RC_STATUS=${RC_OKAY} + +IFACES_IN_SYSTEM=$(grep -i "state UP" ${IP_ADDRESS_FILE} | cut -f2 -d ":" | tr -d " ") + +# Check all interfaces +for iface in ${IFACES_IN_SYSTEM}; do + IFACEPATH=$(find ${RISU_ROOT}/sys | grep net | grep ${iface} | grep errors) + + for file in ${IFACEPATH}; do + CONTENT=$(cat ${file}) + if [ $CONTENT != "0" ]; then + echo "$iface detected errors on $file: $CONTENT" >&2 + RC_STATUS=${RC_FAILED} + + fi + done + +done + +exit ${RC_STATUS}