How To Deploy NRPE Rapidly Throughout A Network

How To Deploy NRPE Rapidly Throughout A Network

Nagios Remote Plugin Executor is a very popular tool used together with Nagios to monitor datacenters. It can be time consuming and painful to deploy nrpe throughout a datacenter. This post describes how create a deployment script that can be executed remotely against batches of hosts.

Script First

#!/bin/bash

sudo -i

NRPE_ALLOWED_HOSTS="127.0.0.1, 10.10.2.20"

function install_epel-release()
{
  wget "http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm" -O "/tmp/epel-release-5-4.noarch.rpm"
  rpm -Uvh "/tmp/epel-release-5-4.noarch.rpm"
}

function install_components()
{
  yum -y install nrpe nagios-plugins-{disk,load,users,procs}
}

function configure_nrpe()
{
  sed -i "{
    s/allowed_hosts=127.0.0.1.*/allowed_hosts=$NRPE_ALLOWED_HOSTS/

    /^command\[check_hda1\]/a \\
command[check_osvg-rootlv]=/usr/lib64/nagios/plugins/check_disk -w 20% -c 10% -p /dev/mapper/osvg-rootlv \\
command[check_osvg-homelv]=/usr/lib64/nagios/plugins/check_disk -w 20% -c 10% -p /dev/mapper/osvg-homelv \\
command[check_osvg-usrlv]=/usr/lib64/nagios/plugins/check_disk -w 20% -c 10% -p /dev/mapper/osvg-usrlv \\
command[check_osvg-usrlocallv]=/usr/lib64/nagios/plugins/check_disk -w 20% -c 10% -p /dev/mapper/osvg-usrlocallv \\
command[check_osvg-varlv]=/usr/lib64/nagios/plugins/check_disk -w 20% -c 10% -p /dev/mapper/osvg-varlv \\
command[check_osvg-yumlv]=/usr/lib64/nagios/plugins/check_disk -w 20% -c 10% -p /dev/mapper/osvg-yumlv \\
command[check_datavg-LOGlv]=/usr/lib64/nagios/plugins/check_disk -w 20% -c 10% -p /dev/mapper/datavg-LOGlv \\
command[check_datavg-locallv]=/usr/lib64/nagios/plugins/check_disk -w 20% -c 10% -p /dev/mapper/datavg-locallv
    /^command\[check_hda1\]/d

  }" /etc/nagios/nrpe.cfg
}

function start_nrpe()
{
  /etc/init.d/nrpe restart
}

function verify_nrpe_running()
{
  printf "NRPE running with PID: %d\n" `pidof nrpe`
  netstat -aonp | grep 5666
}

install_epel-release
install_components
configure_nrpe
start_nrpe
verify_nrpe_running