6 config_dir
=/etc
/nagios
3/conf.d
7 config_file_web
=$config_dir/web_services.cfg
12 echo $0': [-s|-W|-D] <-w website> [-h hostname] [-c cname1,cname2,etc...]'
13 echo -e "\t-s Add SSL monitoring"
14 echo -e "\t-W Also add a monitor for the WWW record."
15 echo -e "\t-D Delete the monitor(s) for the hostname/website provided."
16 echo -e "\t-h Provide a hostname, useful for VHOSTs"
17 echo -e "\t-c A comma seperated list of cnames to add monitors for."
20 function set-params
() {
21 # Array is: use, description, host_name, check_command
22 params
=("$1" "$2" "$3" "$4")
25 function set-http-params
() {
26 set-params
'http-vhost2' "URL: $1" $2 "check_http_vhost2!$2!$1"
29 function set-https-params
() {
30 set-params
'http-vhost' "SSL Cert: $1" $2 "check_http_vhost2!$2!$1"
33 function write-config-header
() {
34 echo "# AUTOGENERATED CONFIG FOR ${params[1]}"
36 echo "# Date: `date '+%D %T'`"
39 function write-config-footer
() {
40 echo "# END ${params[1]}"
43 function write-config-body
() {
44 echo "define service {"
45 echo -e "\tuse\t\t\t${params[0]}"
46 echo -e "\tdescription\t\t${params[1]}"
47 echo -e "\thost_name\t\t${params[2]}"
48 echo -e "\tcheck_command\t\t${params[3]}"
54 # description www.defectivebydesign.org
55 # host_name www0.defectivebydesign.org
56 # check_command check_http_vhost2!www0.defectivebydesign.org!www.defectivebydesign.org
62 # host_name www0.defectivebydesign.org
63 # description www.defectivebydesign.org SSL cert
64 # check_command check_ssl_cert!www.defectivebydesign.org
68 while getopts "Ww:h:sc:" opt
; do
92 # Print help and quit if website is not provided
93 if [ -z ${website} ]; then
98 # Set host_name to website if not provided
99 if [ -z ${host} ]; then
103 # Prep CNAMEs (if provided) for a for loop by replacing the delimiter
104 if [ $cname -eq 1 ]; then
105 if [ -z ${cnames} ]; then
106 echo "Error: CNAMEs garbled."
109 cnames
=$
(echo $cnames |
sed 's/,/ /g')
113 # Basic HTTP check, include basic header
114 set-http-params
$website $host
118 # Additional CNAMEs if requested
119 if [ $cname -eq 1 ]; then
120 for name
in $cnames; do
121 set-http-params
$name.
$website $host
126 # SSL cert check, if requeted
127 if [ $ssl -eq 1 ]; then
128 set-https-params
$website $host
132 # Write out our footer