Instantly share code, notes, and snippets.

Embed
What would you like to do?
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