First commit

This commit is contained in:
Jack-Benny Persson 2013-12-31 23:57:29 +01:00
commit fe3828cffd
8 changed files with 140 additions and 0 deletions

View File

0
dummy_checks/check_ftp Normal file
View File

0
dummy_checks/check_http Normal file
View File

0
dummy_checks/check_ssh Normal file
View File

92
nagios-bootstrap.sh Executable file
View File

@ -0,0 +1,92 @@
#!/bin/bash
# Binaries
Nmap="/usr/bin/nmap"
Sed="/bin/sed"
Awk="/usr/bin/awk"
Printf="/usr/bin/printf"
Ls="/bin/ls"
Grep="/bin/grep"
Cut="/usr/bin/cut"
# Variables
Version="0.1"
Plugindir="dummy_checks"
# Sanity check
for Bin in $Nmap $Sed $Awk $Printf; do
if [ ! -x $Bin ]; then
echo "Can't execute $Bin"
fi
done
print_usage()
{
$Printf "Usage: `basename $0` -H <host> -o <output> -h (help)\n"
}
print_help()
{
$Printf "-h This help screen\n"
$Printf "-H Host to scan and bootstrap for Nagios\n"
$Printf "-o Output file to save the configuration file in\n"
}
# Parse options and arguments
while getopts H:ho: Opts; do
case "$Opts" in
h) print_help
exit 1
;;
o) Outfile="$OPTARG"
exec 1> $Outfile
;;
H) Host="$OPTARG"
;;
*) print_usage
exit 1
;;
esac
done
### Main ###
# Scan the host and save all the output in a variable
Output=`$Nmap $Host`
IP=`echo "$Output" | $Sed -n '3p' | tr -d '()' | awk '{ print $6 }'`
Hostname=`echo "$Output" | $Sed -n '3p' | awk '{ print $5 }'`
Alias=`echo $Hostname | $Awk -F"." '{ printf $1 }'`
Services=`nmap labrat.nixnet.jke | sed -n '7,$p' | head -n -2 \
| awk '{ print $3 }'`
Index=0
for i in ${Services[@]}; do
TempServ=`$Ls ${Plugindir}/ | $Grep $i`
if [ $? -eq 0 ]; then
CheckCommand[$Index]=$TempServ
((Index++))
fi
done
$Printf "define host {\n"
$Printf "\thost_name\t${Hostname}\n"
$Printf "\talias\t\t${Alias}\n"
$Printf "\taddress\t\t${IP}\n"
$Printf "\tuse\t\tgeneric-host\n"
$Printf "\t}\n\n"
CheckIndex=0
for i in ${CheckCommand[@]}; do
Desc=`echo ${CheckCommand[$CheckIndex]} | $Cut -c7-50`
$Printf "define service {\n"
$Printf "\tuse\t\t\tgeneric-service\n"
$Printf "\thost_name\t\t${Hostname}\n"
$Printf "\tservice_description\t${Desc}\n"
$Printf "\tcheck_command\t\t${CheckCommand[$CheckIndex]}\n"
$Printf "}\n\n"
((CheckIndex++))
done
exit 0

15
sample.cfg Normal file
View File

@ -0,0 +1,15 @@
define host {
host_name labrat.example.com
alias labrat
address 192.168.0.27
use generic-host
}
define service {
use generic-service
host_name labrat.example.com
service_description HTTP
check_command check_http
}

12
sampleoutput.txt Normal file
View File

@ -0,0 +1,12 @@
Starting Nmap 6.00 ( http://nmap.org ) at 2013-12-31 19:47 CET
Nmap scan report for labrat.nixnet.jke (192.168.0.27)
Host is up (0.026s latency).
Not shown: 996 closed ports
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
111/tcp open rpcbind
514/tcp open shell
Nmap done: 1 IP address (1 host up) scanned in 1.76 seconds

21
testconf.cfg Normal file
View File

@ -0,0 +1,21 @@
define host {
host_name labrat.nixnet.jke
alias labrat
ddress 192.168.0.27
use generic-host
}
define service {
use generic-service
host_name labrat.nixnet.jke
service_description ssh
check_command check_ssh
}
define service {
use generic-service
host_name labrat.nixnet.jke
service_description http
check_command check_http
}