I was in need to count online hosts in a few networks and didn’t find any plugin to meet my needs os i have wrote my own plyugin i wish to share with all of you
The problem is that the simple ping wont show you the truth, the real online hosts count, because some nodes may ignore ping requests. In the other hand hosts can’t ignore arp requests (well… they actually can, but they won’t).
This plugin utilizes nmap’s arp scan ability (nmap -sS -PR ip_addresses) to count online hosts in your specified network, so yes, you do need nmap installed to use this plugin. You also need to edit you /etc/sudoers file to give nagios root access to nmap, becouse you need root privileges to run arp scan.
Edit /etc/sudoers file and add at least this:
nagios ALL = NOPASSWD: /usr/bin/nmap
And here’s the plugin (check_nmap_hosts_count_arp_scan.sh):
#!/bin/bash
################################################################################
# Count how much hosts are alive in the network (ARP ping) -sP -PR #
# #
# !!!You must allow user to invoke nmap as user root with NOPASS: #
# In /etc/sudoers file add: #
# nagios ALL = NOPASSWD: /usr/bin/nmap #
# #
################################################################################
VERSION="Version 1.0"
AUTHOR="2011, Edgaras Lukosevicius (edgaras@kauko.lt, admin@sysadmin.lt, edgaras.lukosevicius@gmail.com)"
NMAP="/usr/bin/nmap"
NMAP_OPTS="-sP -PR -T5" # FAST ARP ping scan
PROGNAME=$0
# Exit codes
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
result_count=
# Helper functions #############################################################
function print_revision {
# Print version number
echo "$VERSION"
}
function print_usage {
# Print a short usage statement
echo "Usage: $PROGNAME "
}
function print_help {
# Print detailed help information
print_revision
echo "$AUTHOR\n\nCount alive hosts in network\n\n"
print_usage
/bin/cat <