Fixed logic issues around multiple host/vhost pairs
authorLisa Marie Maginnis <lisam@fsf.org>
Wed, 28 May 2014 20:59:18 +0000 (16:59 -0400)
committerLisa Marie Maginnis <lisam@fsf.org>
Wed, 28 May 2014 20:59:18 +0000 (16:59 -0400)
nagios-website-add.sh

index 749a65137fd2c4ca1522eee40112d816810516fe..2eecaaa324bb30e272a12e01e458b494091a2ccb 100755 (executable)
@@ -7,6 +7,7 @@ cname=0
 delete=0
 awstats=0
 reload=0
+content=0
 
 config_dir=/etc/nagios3/conf.d
 config_file_web=$config_dir/web_services.cfg
@@ -15,13 +16,14 @@ init_script=/etc/init.d/nagios3
 export params=''
 
 function help() {
-    echo $0': [-s|-W|-A|-r] <[-D] -w website> [-h hostname] [-c cname1,cname2,etc...]'
+    echo $0': [-s|-W|-A|-r] <[-D] -w website> [-h hostname] [-c cname1,cname2,etc...] [-C /path!string]'
     echo -e "\t-s Add SSL monitoring"
     echo -e "\t-W Also add a monitor for the WWW record"
     echo -e "\t-D Delete the monitor(s) for the hostname/website provided"
     echo -e "\t-h Provide a hostname, useful for VHOSTs"
     echo -e "\t-c A comma seperated list of cnames to add monitors for"
     echo -e "\t-A Adds an AWSTATS monitor for this host"
+    echo -e "\t-C Adds a Content check for string matching"
     echo -e "\t-r Reloads nagios after config files are updated"
 }
 
@@ -42,6 +44,10 @@ function set-awstats-params() {
     set-params 'check-termite' "AWSTATS: $1" "termite.fsf.org" "check_termite!$1"
 }
 
+function set-content-params() {
+    set-params 'http-vhost' "URL Content: $1" $2 "check_http_string!$2!$3"
+}
+
 function write-config-header() {
     echo "# AUTOGENERATED CONFIG FOR HOST: $host:$website"
     echo "# User: $USER"
@@ -50,7 +56,6 @@ function write-config-header() {
 
 function write-config-footer() {
     echo "# END $host:$website"
-    echo
 }
 
 function write-config-body() {
@@ -68,7 +73,7 @@ function delete-monitors() {
 }
 
 # Process our args
-while getopts "rADWw:h:sc:" opt; do
+while getopts "rADWw:h:sc:C:" opt; do
     case "${opt}" in
        s)
            ssl=1
@@ -95,6 +100,9 @@ while getopts "rADWw:h:sc:" opt; do
        r)
            reload=1
            ;;
+       C)
+           content_data=${OPTARG}
+           content=1
        *)
            help
            exit 1
@@ -162,6 +170,11 @@ else
        write-config-body >> $config_file_web
     fi
 
+    if [ $content -eq 1 ]; then
+       set-content-params $website $host $content_data
+       write-config-body >> $config_file_web
+    fi
+
     # AWSTATS check, if requested
     if [ $awstats -eq 1 ]; then
        if [ $www -eq 1 ]; then