From c429b254fc59b9e7312bac51719b46b50ef90ceb Mon Sep 17 00:00:00 2001 From: Lisa Marie Maginnis Date: Wed, 28 May 2014 16:59:18 -0400 Subject: [PATCH] Fixed logic issues around multiple host/vhost pairs --- nagios-website-add.sh | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/nagios-website-add.sh b/nagios-website-add.sh index 749a651..2eecaaa 100755 --- a/nagios-website-add.sh +++ b/nagios-website-add.sh @@ -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 -- 2.25.1