#!/bin/bash

if [ -z $2 ]; then
	echo "
do this:
	export \$WHAT=machine0,machine1,machine2
	nagios.entry.maker.sh \"\$WHAT\" [redhat|solaris|cisco|nt] \"[atm|bgp-chi|bgp-ny|cpu|errors|dns|ftp|http|ios|opt|ping|ram|rvd|rvrd|rvrd-mdapi|serial|savvis|smtp|ttchron|ttm|uptime|users|yipes]\"\|mysql.nagios.sh

such as:
	nagios.entry.maker.sh \"\$WHAT\" solaris \"opt users dns ftp ping http\"|mysql.nagios.sh"
	exit 1
fi

list=`echo "$1"|awk -F,		'{ ORS=" "
					for (i = 1; i < NF+1; i++)
						print $i
				}'`
SERVICES="$3"

for machine in $list; do
	echo "DELETE FROM hostextinfo WHERE host_name = \"$machine\";"
	echo "DELETE FROM serviceextinfo WHERE host_name = \"$machine\";"

	case $2 in
		cisco)
			echo "INSERT INTO hostextinfo VALUES ('$machine','','cisco.png','cisco.jpeg','cisco.gd2','',0,0,0.0000,0.0000,0.0000,0,0);"
			;;
		nt)
			echo "INSERT INTO hostextinfo VALUES ('$machine','','win40.png','win40.jpg','win40.gd2','',0,0,0.0000,0.0000,0.0000,0,0);"
			echo "INSERT INTO serviceextinfo VALUES ('$machine','Drive Space','','drive.png','Drive Space');"
			echo "INSERT INTO serviceextinfo VALUES ('$machine','Drive Space E','','drive.png','Drive Space');"
			;;
		redhat)
			echo "INSERT INTO hostextinfo VALUES ('$machine','','redhat.png','redhat.jpg','redhat.gd2','',0,0,0.0000,0.0000,0.0000,0,0);"
			;;
		solaris)
			echo "INSERT INTO hostextinfo VALUES ('$machine','','solaris.png','solaris.jpeg','solaris.gd2','',0,0,0.0000,0.0000,0.0000,0,0);"
			;;
		*)
			echo -e "\n\n\tALERT!  UNKNOWN HOST TYPE PASSED!  FIX THIS BEFORE USING THIS OUTPUT!\n"
			;;
	esac
	
	for service in $SERVICES; do
		case $service in
			a-ping)
				echo "INSERT INTO serviceextinfo VALUES ('$machine','Ping','/nagios/cgi-bin/apan.cgi?host=$machine&service=Ping','pong.png','Ping');"
				;;
			atm)
				echo "INSERT INTO serviceextinfo VALUES ('$machine','ATM Interface Status','','atm.png','Asynchronous Transfer Module Interface Status');"
				;;
			bgp-chi)
				echo "INSERT INTO serviceextinfo VALUES ('$machine','BGP Peer Status ATT','','bgp.png','Border Gateway Protocol Peer Status');"
				echo "INSERT INTO serviceextinfo VALUES ('$machine','BGP Peer Status CC Chi','','bgp.png','Border Gateway Protocol Peer Status');"
				echo "INSERT INTO serviceextinfo VALUES ('$machine','BGP Peer Status Yipes','','bgp.png','Border Gateway Protocol Peer Status');"
				echo "INSERT INTO serviceextinfo VALUES ('$machine','BGP Peer Status Yipes-Backup','','bgp.png','Border Gateway Protocol Peer Status');"
				;;
			bgp-ny)
				echo "INSERT INTO serviceextinfo VALUES ('$machine','BGP Peer Status CC NY','','bgp.png','Border Gateway Protocol Peer Status');"
				echo "INSERT INTO serviceextinfo VALUES ('$machine','BGP Peer Status Focal','','bgp.png','Border Gateway Protocol Peer Status');"
				;;
			errors)
				echo "INSERT INTO serviceextinfo VALUES ('$machine','Input Errors','','error.png','Input Errors');"
				;;
			dns)
				echo "INSERT INTO serviceextinfo VALUES ('$machine','DNS Server','','bind.png','Domain Name Server');"
				;;
			ftp)
				echo "INSERT INTO serviceextinfo VALUES ('$machine','FTP','','ftp.png','File Transfer Protocol');"
				;;
			http)
				echo "INSERT INTO serviceextinfo VALUES ('$machine','HTTP','','http.png','Web Server');"
				;;
			ios)
				echo "INSERT INTO serviceextinfo VALUES ('$machine','Cisco IOS Version','','ios.png','Cisco Internetworking Operating System Version');"
				;;
			load)
				echo "INSERT INTO serviceextinfo VALUES ('$machine','CPU Load','','load.png','CPU Utilization');"
				;;
			opt)
				echo "INSERT INTO serviceextinfo VALUES ('$machine','/opt','','drive.png','Free Space in /opt file system');"
				;;
			ping)
				echo "INSERT INTO serviceextinfo VALUES ('$machine','Ping','','pong.png','Ping');"
				;;
			ram)
				echo "INSERT INTO serviceextinfo VALUES ('$machine','Memory Usage','','ram.png','Memory Utilization');"
				;;
			rvd)
				echo "INSERT INTO serviceextinfo VALUES ('$machine','RVD Process','','tibco.png','Rendezvous Remote Daemon');"
				;;
			rvrd)
				echo "INSERT INTO serviceextinfo VALUES ('$machine','RVRD Process','','tibco.png','Rendezvous Remote Daemon');"
				;;
			rvrd-mdapi)
				echo "INSERT INTO serviceextinfo VALUES ('$machine','RVRD MDAPI','','tibco.png','Rendezvous Remote Daemon - Market Data Application Programming Interface');"
				;;
			serial)
				echo "INSERT INTO serviceextinfo VALUES ('$machine','Serial Interface Status','','rj45.png','Serial Interface Status');"
				;;
			savvis)
				echo "INSERT INTO serviceextinfo VALUES ('$machine','Savvis Status','','savvis.png','Savvis Circuit Status');"
				;;
			smtp)
				echo "INSERT INTO serviceextinfo VALUES ('$machine','SMTP','','smtp.png','Simple Mail Transfer Protocol');"
				;;
			ttchron)
				echo "INSERT INTO serviceextinfo VALUES ('$machine','TTChron','','chron.png','TT Chron Service');"
				;;
			ttm)
				echo "INSERT INTO serviceextinfo VALUES ('$machine','TTM','','ttm.png','TT Messaging Service Daemon');"
				;;
			uptime)
				echo "INSERT INTO serviceextinfo VALUES ('$machine','Uptime','','uptime.png','System Uptime');"
				;;
			users)
				echo "INSERT INTO serviceextinfo VALUES ('$machine','Current Users','','users.png','Current Users');"
				;;
			yipes)
				echo "INSERT INTO serviceextinfo VALUES ('$machine','Yipes Internet Status','','yipes.png','Yipes! That\'s Fast!');"
				;;
			*)
				echo "ALERT!  UNKNOWN SERVICE LISTED!  FIX THIS!"
				;;
		esac
	done
done
exit $?
