Networking

Unix and Linux network configuration. Multiple network interfaces. Bridged NICs. High-availability network configurations.

Applications

Reviews of latest Unix and Linux software. Helpful tips for application support admins. Automating application support.

Data

Disk partitioning, filesystems, directories, and files. Volume management, logical volumes, HA filesystems. Backups and disaster recovery.

Monitoring

Distributed server monitoring. Server performance and capacity planning. Monitoring applications, network status and user activity.

Commands & Shells

Cool Unix shell commands and options. Command-line tools and application. Things every Unix sysadmin needs to know.

Home » Commands & Shells, Monitoring, Networking

Verifying SNMP Connectivity on Multiple Hosts

Submitted by on December 19, 2019 – 9:50 pm

I needed to check if SNMP was accessible on whatever live servers that existed in a particular subnet. Here’s a quick script to do this.

You will need to specify subnet information and the SNMP community string. The script will use nmap to find live hosts and will use snmpwalk running via xargs to query multiple hosts at once. The end result should look something like this:

192.168.122.1  192.168.122.1       no
192.168.122.2  192.168.122.2       no
192.168.122.3  ncc1701.jedi.local  yes

And here’s the script

subnet=192.168.122.0; subnetmask=24
commstr="vvrblfcctcbhrgbhincdggrjhb"; export commstr
threads=$(grep -c processor /proc/cpuinfo) && (( threads = threads * 10 )) || threads=12
snmpcheck() {
  echo -ne "\t$(host -4 -t A -W1 -s  2>/dev/null | awk '{print $NF}' | \
  sed -r "s/.*DOMAIN.*//g")\t$(snmpwalk -c ${commstr} -v 2c  2>/dev/null | head -1 | wc -l)\n" | \
  awk '$3!=1 {print $1,$2,"no";next}; $3=1{print $1,$2,"yes";next};{print $0}'
} && export -f snmpcheck
nmap -sn ${subnet}/${subnetmask} -oG - | awk '$4=="Status:" && $5=="Up" {print $2}' | \
xargs -n1 -P${threads} bash -c 'snmpcheck "$@"' _ | sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4 | column -t

 

Print Friendly, PDF & Email

Leave a Reply