From 90b2bdc983dd8d62ac5aed77ad7c984759bbe4cd Mon Sep 17 00:00:00 2001 From: Lisa Marie Maginnis Date: Wed, 28 May 2014 14:55:22 -0400 Subject: [PATCH] Added -D, fixed bugs --- nagios-website-add.sh | 80 +++++++++++++++++++++++-------------------- 1 file changed, 42 insertions(+), 38 deletions(-) diff --git a/nagios-website-add.sh b/nagios-website-add.sh index 6797e5b..9acfffb 100755 --- a/nagios-website-add.sh +++ b/nagios-website-add.sh @@ -1,8 +1,11 @@ #!/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 @@ -37,7 +40,7 @@ function write-config-header() { } function write-config-footer() { - echo "# END ${params[1]}" + echo "# END ${params[2]}" } function write-config-body() { @@ -49,23 +52,12 @@ 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 @@ -83,6 +75,9 @@ while getopts "Ww:h:sc:" opt; do cnames=${OPTARG} cname=1 ;; + D) + delete=1 + ;; *) help exit 1 @@ -108,32 +103,41 @@ if [ $cname -eq 1 ]; then 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 -- 2.25.1