Pages

Thursday, April 14, 2016

check_nwc_health icinga2 service config script

This bash script lets you quickly generate configs for you switch for use with icinga2 monitoring command check_nwc_health as described here, https://gist.github.com/lazyfrosch/005c8becab82c712681c. It assumes you have already configured and installed check_nwc_health under /usr/bin/nagios/plugins/.

It's helpful if you have 100s of interfaces on your switches in MDFs or IDFs.

#!/bin/bash
host_addr="1.1.1.1"
for i in {1..2} #module
do 
  for j in {1..24} #interfaces
   do 
    if_name="GigabitEthernet$i/0/$j"
    if_desc=`/usr/lib/nagios/plugins/check_nwc_health --hostname "$host_addr" --mode interface-status --community mysnmp --name "$if_name" | cut -d' ' -f5 | tr -d ')'`
  
    if [ "$if_desc" == "is" ]; then
     continue
    fi
  
    if_setting='
vars.interfaces["'"$if_name"'"] = {
  description = "'"$if_desc"'"
}'
    echo "$if_setting"
   done
done

#####
#Port Channels
#####

for i in {1..10} #Port Channel Numbers
 do 
 if_name="Port-Channel$i"
 if_desc=`/usr/lib/nagios/plugins/check_nwc_health --hostname "$host_addr" --mode interface-status --community mysnmp --name "$if_name" | cut -d' ' -f5 | tr -d ')'`
  
 if [ "$if_desc" == "" ]; then
  continue
 fi
  
 if_setting='
vars.interfaces["'"$if_name"'"] = {
  description = "'"$if_desc"'"
}'
 echo "$if_setting"
done

No comments:

Post a Comment