Skip to content

Instantly share code, notes, and snippets.

@filipepgoes
Last active February 23, 2018 17:08
Show Gist options
  • Save filipepgoes/1b57c93cc0c3d334150e9ab4e9b96130 to your computer and use it in GitHub Desktop.
Save filipepgoes/1b57c93cc0c3d334150e9ab4e9b96130 to your computer and use it in GitHub Desktop.
#!/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