Skip to content

Instantly share code, notes, and snippets.

@mikejsutherland
Last active October 9, 2017 02:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikejsutherland/41cccb888a7936c7c0fed95ae7fbfb20 to your computer and use it in GitHub Desktop.
Save mikejsutherland/41cccb888a7936c7c0fed95ae7fbfb20 to your computer and use it in GitHub Desktop.
Nagios NRPE installation script for FreeNAS
#!/bin/sh
#
# Nagios NRPE installation script for FreeNAS
# See: https://haphazard.io/blog/install-nagios-nrpe-on-freenas/#install
#
# Copyright 2017 Michael Sutherland
# mike@haphazard.io
#
# Check if nrpe service is already installed/running
if [ -e /etc/rc.d/nrpe ]; then
NRPE=$(service nrpe status);
if [ $? == 0 ]; then
echo $NRPE;
echo "Stop the service and rerun install.sh"
fi
fi
# Create the nagios group
if ! grep -q ^nagios /etc/group; then
pw add group nagios
else
grep ^nagios /etc/group
fi
# Create the nagios user
if ! grep -q ^nagios /etc/passwd; then
pw add user nagios -g nagios -s /usr/bin/false
else
grep ^nagios /etc/passwd
fi
# Install the nrpe services definition
if ! grep -q "5666/tcp" /etc/services; then
echo >> /etc/services
echo '# Nagios services' >> /etc/services
echo 'nrpe 5666/tcp' >> /etc/services
else
grep nrpe /etc/services
fi
# Install the nrpe service rc.conf entry
if ! grep -q nrpe_enable /etc/rc.conf; then
echo >> /etc/rc.conf
echo nrpe_enable="YES" >> /etc/rc.conf
else
grep nrpe /etc/rc.conf
fi
# Create nagios directory
test -d /usr/local/nagios/ || mkdir -p /usr/local/nagios/
# Backup and install the nrpe.cfg
test -e /usr/local/nagios/etc/nrpe.cfg && mv /usr/local/nagios/etc/nrpe.cfg /usr/local/nagios/etc/nrpe.cfg.bak && echo "nrpe.cfg renamed to nrpe.cfg.bak"
# Copy nagios files
cp -R usr/local/nagios/* /usr/local/nagios/
cp etc/rc.d/nrpe /etc/rc.d/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment