Replace parts by new common function

This commit is contained in:
nemo 2019-06-01 11:36:01 +02:00
parent bc8d4ecfe2
commit 7443c41234
2 changed files with 47 additions and 31 deletions

View file

@ -1,35 +1,45 @@
print_config_title 'CHECK POSTFIX BASIC CONFIG' print_config_title 'CHECK POSTFIX BASIC CONFIG'
# This script just check the parameter inet_protocols # Check /etc/postfix/main.cf config file mail_owner/inet_protocols parameters
echo -e "Check ${BLUE}Postfix${NC} config file /etc/postfix/main.cf (parameter inet_protocols)"
# Check if inet_protocols exist but different than expected (success if return code = 1) # mail_owner
grep "^[[:space:]]*inet_protocols" /etc/postfix/main.cf \ check_value_in_conf_file "SNMP" "/etc/postfix/main.cf" "mail_owner" "postfix"
| grep -q -v -e "^[[:space:]]*inet_protocols[[:space:]]*=[[:space:]]*all[[:space:]]*$"
# Return Code case ${?} in
RC=$? 0) # OK, nothing to do
;;
1) # Error (wrong number of param or other)
POSTFIX_CONFIG_CHECK_FAILED=${POSTFIX_CONFIG_CHECK_FAILED}" Error during mail_owner check with function check_value_in_conf_file, maybe incorrect number of parameter;"
;;
2) # Unexpected value is set
POSTFIX_CONFIG_CHECK_FAILED=${POSTFIX_CONFIG_CHECK_FAILED}" mail_owner are not well configured or has other value, set 'mail_owner = postfix';"
;;
3) # All expected values are NOT configured
POSTFIX_CONFIG_CHECK_FAILED=${POSTFIX_CONFIG_CHECK_FAILED}" mail_owner are not well configured, set 'mail_owner = postfix';"
;;
*) # Unknown return code...
POSTFIX_CONFIG_CHECK_FAILED=${POSTFIX_CONFIG_CHECK_FAILED}" Error, unknown return code when calling check_value_in_conf_file to check mail_owner;"
;;
esac
# inet_protocols has other value than expected
if [ $RC -eq 0 ]
then
POSTFIX_CONFIG_CHECK_FAILED="${POSTFIX_CONFIG_CHECK_FAILED} Postfix inet_protocols is not configured as expected, expected : 'inet_protocols = all'"
echo -e "${RED}Postfix inet_protocols is NOT CONFIGURED as EXPECTED : check KO${NC}\n"
# inet_protocols hasn't unexpected value
else
# Check if ALL protocols (IPv4 and IPv6) are configured (success if return code = 0)
grep -q "^[[:space:]]*inet_protocols[[:space:]]*=[[:space:]]*all[[:space:]]*$" /etc/postfix/main.cf
# Return Code # inet_protocols
RC=$? check_value_in_conf_file "SNMP" "/etc/postfix/main.cf" "inet_protocols" "all"
case ${?} in
0) # OK, nothing to do
;;
1) # Error (wrong number of param or other)
POSTFIX_CONFIG_CHECK_FAILED=${POSTFIX_CONFIG_CHECK_FAILED}" Error during inet_protocols check with function check_value_in_conf_file, maybe incorrect number of parameter;"
;;
2) # Unexpected value is set
POSTFIX_CONFIG_CHECK_FAILED=${POSTFIX_CONFIG_CHECK_FAILED}" inet_protocols are not well configured or has other value, set 'inet_protocols = all';"
;;
3) # All expected values are NOT configured
POSTFIX_CONFIG_CHECK_FAILED=${POSTFIX_CONFIG_CHECK_FAILED}" inet_protocols are not well configured, set 'inet_protocols = all';"
;;
*) # Unknown return code...
POSTFIX_CONFIG_CHECK_FAILED=${POSTFIX_CONFIG_CHECK_FAILED}" Error, unknown return code when calling check_value_in_conf_file to check inet_protocols;"
;;
esac
# All protocols not configured
if [ $RC -ne 0 ]
then
POSTFIX_CONFIG_CHECK_FAILED="${POSTFIX_CONFIG_CHECK_FAILED} Postfix inet_protocols is not configured as expected, expected : 'inet_protocols = all'"
echo -e "${RED}Postfix inet_protocols is NOT CONFIGURED as EXPECTED : check KO${NC}\n"
# All protocols configured
else
echo -e "${GREEN}POSTFIX inet_protocols is CONFIGURED as expected : check OK${NC}\n"
fi
fi

View file

@ -1,8 +1,9 @@
print_config_title 'CHECK SNMP BASIC CONFIG' print_config_title 'CHECK SNMP BASIC CONFIG'
# This does NOT check if SNMP 'monitoring server' has configured this machine # This does NOT check if SNMP 'monitoring server' has configured this machine
# Check /etc/snmp/snmpd.conf config file agentAddress, rocommunity and trapsink/trap2sink parameters # Check /etc/snmp/snmpd.conf config file agentAddress, rocommunity and trapsink/trap2sink/informsink/sysLocation/sysContact parameters
#agentAddress
check_value_in_conf_file "SNMP" "/etc/snmp/snmpd.conf" "agentAddress" "udp:127.0.0.1:161 udp:${IPV4_ADMIN_LAN_IP}:161 udp6:\[::1\]:161 udp6:\[${IPV6_ADMIN_LAN_IP}\]:161" check_value_in_conf_file "SNMP" "/etc/snmp/snmpd.conf" "agentAddress" "udp:127.0.0.1:161 udp:${IPV4_ADMIN_LAN_IP}:161 udp6:\[::1\]:161 udp6:\[${IPV6_ADMIN_LAN_IP}\]:161"
case ${?} in case ${?} in
@ -23,6 +24,7 @@ case ${?} in
esac esac
#rocommunity
# No IPv6 here.... # No IPv6 here....
check_value_in_conf_file "SNMP" "/etc/snmp/snmpd.conf" "rocommunity" "public[[:space:]]*127.0.0.1 public[[:space:]]*${IPV4_ADMIN_NETWORK}0/24" check_value_in_conf_file "SNMP" "/etc/snmp/snmpd.conf" "rocommunity" "public[[:space:]]*127.0.0.1 public[[:space:]]*${IPV4_ADMIN_NETWORK}0/24"
@ -44,6 +46,7 @@ case ${?} in
esac esac
# trap2sink
check_value_in_conf_file "SNMP" "/etc/snmp/snmpd.conf" "trap2sink" "${NAME_MASTER_MONITORING}[[:space:]]*public" check_value_in_conf_file "SNMP" "/etc/snmp/snmpd.conf" "trap2sink" "${NAME_MASTER_MONITORING}[[:space:]]*public"
case ${?} in case ${?} in
@ -64,6 +67,7 @@ case ${?} in
esac esac
# informsink
check_value_in_conf_file "SNMP" "/etc/snmp/snmpd.conf" "informsink" "${NAME_MASTER_MONITORING}[[:space:]]*public" check_value_in_conf_file "SNMP" "/etc/snmp/snmpd.conf" "informsink" "${NAME_MASTER_MONITORING}[[:space:]]*public"
case ${?} in case ${?} in
@ -84,6 +88,7 @@ case ${?} in
esac esac
# sysLocation
check_value_in_conf_file "SNMP" "/etc/snmp/snmpd.conf" "sysLocation" "${DC_for_function_check_value_in_conf_file}" check_value_in_conf_file "SNMP" "/etc/snmp/snmpd.conf" "sysLocation" "${DC_for_function_check_value_in_conf_file}"
case ${?} in case ${?} in
@ -104,6 +109,7 @@ case ${?} in
esac esac
# sysContact
check_value_in_conf_file "SNMP" "/etc/snmp/snmpd.conf" "sysContact" "${ENTITY_for_function_check_value_in_conf_file}[[:space:]]*<${MAIL_ALIAS_ROOT}>" check_value_in_conf_file "SNMP" "/etc/snmp/snmpd.conf" "sysContact" "${ENTITY_for_function_check_value_in_conf_file}[[:space:]]*<${MAIL_ALIAS_ROOT}>"
case ${?} in case ${?} in