Debian Codegraph @

contrib/epel-patches/nagios.upgrade_to_v4.sh

raw
1 #!/bin/sh
2 # this script checks the nagios.cfg file and comments out several lines in accordance with the README.
3 # You will want to migrate to the Nagios v4 nagios.cfg file as soon as possible to take advantage of new features.
4
5
6 # this is the nagios.cfg file we will modify
7 nagios_cfg=/etc/nagios/nagios.cfg
8
9 tmp1=`mktemp /tmp/nagios.cfg.XXXXXXXX`
10 cat $nagios_cfg > $tmp1
11
12 # search for and replace the check_result_buffer_slots attribute into a temporary file
13 sed -i --regexp-extended -e "s/^(\s*check_result_buffer_slots\s*=\s*)/# Line Commented out for Nagios v4 Compatibility\n#\1/g" \
14 -e 's/^(\s*use_embedded_perl_implicitly\s*=\s*)/# Line Commented out for Nagios v4 Compatibility\n#\1/g' \
15 -e 's/^(\s*sleep_time\s*=\s*)/# Line Commented out for Nagios v4 Compatibility\n#\1/g' \
16 -e 's/^(\s*p1_file\s*=\s*)/# Line Commented out for Nagios v4 Compatibility\n#\1/g' \
17 -e 's/^(\s*external_command_buffer_slots\s*=\s*)/# Line Commented out for Nagios v4 Compatibility\n#\1/g' \
18 -e 's/^(\s*enable_embedded_perl\s*=\s*)/# Line Commented out for Nagios v4 Compatibility\n#\1/g' \
19 -e 's/^(\s*command_check_interval\s*=\s*)/# Line Commented out for Nagios v4 Compatibility\n#\1/g' \
20 -e 's|^(\s*#?query_socket\s*=\s*/var/log/nagios/rw/nagios.qh)|query_socket=/var/spool/nagios/cmd/nagios.qh|' $tmp1
21
22 # add query_socket if none exist
23 grep -q -F 'query_socket' $tmp1 || echo 'query_socket=/var/spool/nagios/cmd/nagios.qh' >> $tmp1
24
25 # check the diff
26 diff_output=`diff -u $nagios_cfg $tmp1`
27 diff_exit=$?
28
29 # Decide whether or not to replace the file
30 if [ "$diff_exit" = "0" ]; then
31 echo "No changes were made to the Nagios Config file: $nagios_cfg"
32 elif [ "$diff_exit" = "1" ]; then
33 echo "The following changes were made to the Nagios Config file: $nagios_cfg"
34 echo "previous config has been saved to $nagios_cfg.oldrpm"
35 echo "$diff_output"
36
37 # since changes were made, move the temp file into place
38 cp $nagios_cfg $nagios_cfg.oldrpm
39 cat $tmp1 > $nagios_cfg
40 else
41 echo "ERROR: Unexpected exit code from diff. No changes made to file: $nagios_cfg"
42 fi
43
44 rm -f $tmp1
45