Skip to content

Instantly share code, notes, and snippets.

@tjstein
Created May 9, 2011 22:02
Show Gist options
  • Save tjstein/963520 to your computer and use it in GitHub Desktop.
Save tjstein/963520 to your computer and use it in GitHub Desktop.
#!/bin/bash
##
## are you root?
##
if [ "$(whoami)" != "root" ]; then
echo "You need to be root to run this!"
exit 2
fi
##
## configure nagios host
##
echo "Enter the hostname you want to monitor:"
read mthost
export mthost
echo "Enter the IP address of this host:"
read mtip
export mtip
echo "Enter the service ID number of this host:"
read mtservice
export mtservice
##
## setup nagios host
##
touch /usr/local/nagios/etc/api/$mtservice.cfg
cat <<EOF > /usr/local/nagios/etc/api/$mtservice.cfg
define host{
use linux-server
host_name $mthost
address $mtip
alias $mthost
}
define service{
use local-service
host_name $mthost
service_description Memory
check_command check_mt_memory!$mtservice
}
define service{
use local-service
host_name $mthost
service_description CPU
check_command check_mt_cpu!$mtservice
}
define service{
use local-service
host_name $mthost
service_description Disk
check_command check_mt_disk!$mtservice
}
define service{
use local-service
host_name $mthost
service_description Load
check_command check_mt_load!$mtservice
}
define service{
use local-service
host_name $mthost
service_description State
check_command check_mt_state!$mtservice
}
EOF
##
## reload nagios configuration
##
/etc/init.d/nagios reload
##
## exit message
##
echo ""
echo "Thank you! $mthost is now monitored by Nagios."
echo ""
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment