#!/usr/bin/env bash
+# Modes (0 = off/false, 1 = true/on)
ssl=0
www=0
cname=0
+delete=0
+
config_dir=/etc/nagios3/conf.d
config_file_web=$config_dir/web_services.cfg
}
function write-config-footer() {
- echo "# END ${params[1]}"
+ echo "# END ${params[2]}"
}
function write-config-body() {
echo "}"
}
-#define service {
-# use http-vhost2
-# description www.defectivebydesign.org
-# host_name www0.defectivebydesign.org
-# check_command check_http_vhost2!www0.defectivebydesign.org!www.defectivebydesign.org
-#}
-
-# Service: SSL CERT
-#define service{
-# use http-vhost
-# host_name www0.defectivebydesign.org
-# description www.defectivebydesign.org SSL cert
-# check_command check_ssl_cert!www.defectivebydesign.org
-#}
+function delete-monitors() {
+ sed '/^# AUTOGENERATED CONFIG FOR HOST: '$host'$/,/^# END '$host'$/d' -i $config_file_web
+}
# Process our args
-while getopts "Ww:h:sc:" opt; do
+while getopts "DWw:h:sc:" opt; do
case "${opt}" in
s)
ssl=1
cnames=${OPTARG}
cname=1
;;
+ D)
+ delete=1
+ ;;
*)
help
exit 1
fi
cnames=$(echo $cnames | sed 's/,/ /g')
fi
-
-# Basic HTTP check, include basic header
+# Set our generic configs (these are overwritten as we go)
set-http-params $website $host
-write-config-header >> $config_file_web
-write-config-body >> $config_file_web
-# www CNAME, special request :D
-if [ $www -eq 1 ]; then
- set-https-params www.$website $host
+# Delete records on request
+if [ $delete -eq 1 ]; then
+ delete-monitors
+else
+ # Double check that a duplicate monitor does not exist (does nothing if it doesnt exist)
+ delete-monitors
+
+ # Basic HTTP check, include basic header
+ write-config-header >> $config_file_web
write-config-body >> $config_file_web
-fi
-# Additional CNAMEs if requested
-if [ $cname -eq 1 ]; then
- for name in $cnames; do
- set-http-params $name.$website $host
+ # www CNAME, special request :D
+ if [ $www -eq 1 ]; then
+ set-https-params www.$website $host
write-config-body >> $config_file_web
- done
-fi
-
-# SSL cert check, if requeted
-if [ $ssl -eq 1 ]; then
- set-https-params $website $host
- write-config-body >> $config_file_web
-fi
+ fi
-# Write out our footer
-write-config-footer >> $config_file_web
\ No newline at end of file
+ # Additional CNAMEs if requested
+ if [ $cname -eq 1 ]; then
+ for name in $cnames; do
+ set-http-params $name.$website $host
+ write-config-body >> $config_file_web
+ done
+ fi
+
+ # SSL cert check, if requeted
+ if [ $ssl -eq 1 ]; then
+ set-https-params $website $host
+ write-config-body >> $config_file_web
+ fi
+
+ # Write out our footer
+ write-config-footer >> $config_file_web
+fi
\ No newline at end of file