Skip to content

Instantly share code, notes, and snippets.

@luiselizondo
Created May 18, 2012 08:35
Show Gist options
  • Save luiselizondo/2724006 to your computer and use it in GitHub Desktop.
Save luiselizondo/2724006 to your computer and use it in GitHub Desktop.
Configure Nagios Client
#!/bin/bash
function ask {
echo -n "Allowed IP to access NRPE: "
# read -e ALLOWEDIP
}
function system_primary_ip {
# returns the primary IP assigned to eth0
echo $(ifconfig eth0 | awk -F: '/inet addr:/ {print $2}' | awk '{ print $1 }')
}
function installer {
sudo apt-get -y install nagios-nrpe-server
}
function perms {
sudo chown -R nagios:nagios /etc/nagios
sudo rm -R /etc/nagios/nrpe.cfg
sudo rm -R /etc/nagios/nrpe_local.cfg
}
# Add the configuration to the nrpe.cfg file
function configure {
sudo cat <<EOD > /etc/nagios/nrpe.cfg
#############################################################################
# Sample NRPE Config File
# Originally Written by: Ethan Galstad (nagios@nagios.org)
# Edited by Luis Elizondo
#
# NOTES:
# All the documentation of this file can be found with the NRPE file
# In Ubuntu this is located at /etc/nagios
#############################################################################
log_facility=daemon
pid_file=/var/run/nagios/nrpe.pid
server_port=5666
#server_address=127.0.0.1
nrpe_user=nagios
nrpe_group=nagios
allowed_hosts=173.255.196.113
# *** ENABLING THIS OPTION IS A SECURITY RISK! ***
# Values: 0=do not allow arguments, 1=allow command arguments
dont_blame_nrpe=0
# *** THIS EXAMPLE MAY POSE A POTENTIAL SECURITY RISK, SO USE WITH CAUTION! ***
# command_prefix=/usr/bin/sudo
# Values: 0=debugging off, 1=debugging on
debug=1
command_timeout=60
connection_timeout=300
#allow_weak_random_seed=1
#include=/etc/nagios/nrpe_local.cfg
include_dir=/etc/nagios/nrpe.d/
## Commands to Use with NRPE
# The following examples use hardcoded command arguments...
command[check_users]=/usr/lib/nagios/plugins/check_users -w 1 -c 2
command[check_load]=/usr/lib/nagios/plugins/check_load -w 15,10,5 -c 30,25,20
command[check_hda1]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/hda1
command[check_zombie_procs]=/usr/lib/nagios/plugins/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/lib/nagios/plugins/check_procs -w 150 -c 200
command[check_all_disks]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -e
command[check_apt]=/usr/lib/nagios/plugins/check_apt
command[check_procs_http]=/usr/lib/nagios/plugins/check_procs -w10 -c20 -s httpd
EOD
}
function restart {
sudo /etc/init.d/nagios-nrpe-server restart
}
function finish {
echo "Ready, add the $(system_primary_ip) to your host"
}
#ask
system_primary_ip
installer
perms
configure
restart
finish
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment