Skip to content

Instantly share code, notes, and snippets.

@filipepgoes filipepgoes/nrpe-config.sh
Last active Feb 23, 2018

Embed
What would you like to do?
#!/bin/sh
set -u
usage()
{
echo "usage: <command> options: [-t] -i <ip interno da máquina monitoradora> -e <ip externo da máquina monitorada>"
}
while getopts ti:e: OPCAO; do
case "${OPCAO}" in
t) modo_teste=1 ;;
i) ipintradora="${OPTARG}" ;;
e) ipextradora="${OPTARG}" ;;
esac
done
if [ -z ${modo_teste+x} ]; then
echo "Production mode."
confxinetd="/etc/xinetd.conf"
confhosts="/etc/hosts.allow"
confnrpe="/usr/local/nagios/etc/nrpe.cfg"
else
echo "Test mode."
mkdir -p testresults
touch "testresults/xinetd.conf"
echo -e "#\tonly_from\t=" >> testresults/xinetd.conf
touch "testresults/hosts.allow"
touch "testresults/nrpe.cfg"
echo "command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1" >> testresults/nrpe.cfg
echo "allowed_hosts=127.0.0.1" >> testresults/nrpe.cfg
confxinetd="testresults/xinetd.conf"
confhosts="testresults/hosts.allow"
confnrpe="testresults/nrpe.cfg"
fi
echo "Using $confxinetd, $confhosts and $confnrpe."
if [ -z ${ipintradora+x} ]; then
echo "ERROR: internal IP of the monitoring machine not supplied. Aborting."
exit 1
fi
if [ -z ${ipextradora+x} ]; then
echo "ERROR: exernal IP of the monitoring machine not supplied. Aborting."
exit 1
fi
sed -i -e "s/^#\tonly_from\t=$/\tonly_from = 127.0.0.1 $ipintradora $ipextradora/" $confxinetd
grep -q "^ALL: $ipintradora : allow" $confhosts || echo "ALL: $ipintradora : allow" >> $confhosts
grep -q "^ALL: $ipextradora : allow" $confhosts || echo "ALL: $ipextradora : allow" >> $confhosts
sed -i -e 's/check_disk -w 20% -c 10% -p \/dev\/hda1/check_disk -w 20% -c 10% -p \/dev\/sda1/' $confnrpe
sed -i -e "s/^allowed_hosts=127.0.0.1$/allowed_hosts=127.0.0.1, $ipintradora, $ipextradora/" $confnrpe
systemctl restart nrpe
echo "Done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.