-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterface_status
executable file
·58 lines (47 loc) · 1.76 KB
/
interface_status
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#! /usr/bin/env sh
# Query interface status of network devices.
#
# Copyright (C) 2012-2024 Erik Auerswald <[email protected]>
#
# Copying and distribution of this file, with or without modification,
# are permitted in any medium without royalty provided the copyright
# notice and this notice are preserved. This file is offered as-is,
# without any warranty.
#
# Usage: interface_status IP|NAME...
#
# Queries the specified devices for interface status and interface name via
# SNMP (using snmpwalk from Net-SNMP) using standard MIBs.
#
# Use snmp.conf (e.g. $HOME/.snmp/snmp.conf) to configure SNMP access.
# The script uses OID names, thus Net-SNMP needs to be configured to allow
# this. See snmp_config(4) and snmp.conf(4) man-pages.
#
# Currently tested with Enterasys Networks switches only.
#
# Version 2024-03-04-01
STATUS=$(mktemp ifOperStatus.$$.XXXXXX)
NAME=$(mktemp ifName.$$.XXXXXX)
trap 'rm -f "${STATUS}" "${NAME}"' 0
# Specify the snmpwalk executable to use.
# This can be overridden from the environment.
# 'snmpbulkwalk' is faster, but needs SNMPv2c or SNMPv3
# (you should always use SNMPv3).
# Comment the following line to disable use of 'snmpbulkwalk.'
SNMPWALK=${SNMPWALK:=snmpbulkwalk}
# Use 'snmpwalk' as executable, if SNMPWALK is not specified.
SNMPWALK=${SNMPWALK:=snmpwalk}
for SWITCH_IP in "$@"; do
echo "Interface status on ${SWITCH_IP}:"
{ "${SNMPWALK}" "${SWITCH_IP}" \
interfaces.ifTable.ifEntry.ifOperStatus | \
sed 's/^.*\.\([0-9]*\) .* \([a-z]*\).*$/\1 \2/' | \
sort > "${STATUS}"; } &
{ "${SNMPWALK}" "${SWITCH_IP}" \
ifMIB.ifMIBObjects.ifXTable.ifXEntry.ifName | \
sed 's/^.*\.\([0-9]*\) .* \([^ ]*\).*$/\1 \2/' | \
sort > "${NAME}"; } &
wait
join "${NAME}" "${STATUS}" | sort -n | sed 's/^[0-9]* / /'
done
exit 0