75 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			Bash
		
	
	
	
	
	
			
		
		
	
	
			75 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			Bash
		
	
	
	
	
	
| #!/usr/bin/env bash
 | |
| #
 | |
| # check if there is some mails in the deferred queue of postfix
 | |
| # + danger color if >= 100 messages
 | |
| # + warning color if >= 1 messages
 | |
| #
 | |
| # requirements: sudo apt install postfix
 | |
| 
 | |
| # GENERAL ###########################################################
 | |
| 
 | |
| # locale env
 | |
| unset LC_ALL
 | |
| export LC_MESSAGES=C
 | |
| 
 | |
| # check if module was disabled
 | |
| module_disable=${module_postqueue_disable:=0}
 | |
| if (($module_disable == 1)); then
 | |
|     exit 1
 | |
| fi
 | |
| 
 | |
| # colors
 | |
| c_txt=${c_txt:="39"}
 | |
| c_txt_emphase=${c_txt_emphase:="35"}
 | |
| c_txt_deco=${c_txt_deco:="97"}
 | |
| c_txt_invert=${c_txt_invert:="30"}
 | |
| c_bg=${c_bg_sec:="47"}
 | |
| c_danger=${c_danger:="31"}
 | |
| c_warning=${c_warning:="33"}
 | |
| c_success=${c_success:="32"}
 | |
| c_title=${c_title:="${c_bg};1;${c_txt_invert}m"}
 | |
| 
 | |
| # PREPARATIONS ######################################################
 | |
| 
 | |
| # print loading message
 | |
| echo -e "\nWaiting for Postqueue checks\e[5m...\e[0m"
 | |
| 
 | |
| # check if postfix is available, with qshape
 | |
| if ! command -v qshape 1>/dev/null; then
 | |
|     # output module header
 | |
|     echo -e "\e[1A\e[${c_title} Postfix deferred queue status  \e[0m\n"
 | |
|     echo -e "  no Postfix server available"
 | |
|     exit 1
 | |
| fi
 | |
| 
 | |
| # parse deferred messages qty with qshape
 | |
| deferredcmd=$(timeout 5 qshape -b 6 deferred 2>/dev/null)
 | |
| 
 | |
| # OUTPUT ############################################################
 | |
| 
 | |
| # if qshape timeout 5sec
 | |
| if [[ "$deferredcmd" == "" ]]; then
 | |
|     # output module header
 | |
|     echo -e "\e[1A\e[${c_title} Postfix deferred  \e[0m\n"
 | |
|     echo -e "  \e[1;${c_warning}mqshape needs more than 5 sec to parse the deferred Mails list,\n  you should investigate!\e[0m"
 | |
|     exit 1
 | |
| fi
 | |
| 
 | |
| # if total deferred is 0
 | |
| deferredtotal=$(echo -e "$deferredcmd" | grep TOTAL | awk '{print $2}')
 | |
| if [[ "$deferredtotal" == "0" ]]; then
 | |
|     # output module header
 | |
|     echo -e "\e[1A\e[${c_title} Postfix deferred queue status  \e[0m\n"
 | |
|     echo -e "  There is \e[1;${c_success}m${deferredtotal}\e[0m deferred Mails."
 | |
|     exit 1
 | |
| fi
 | |
| 
 | |
| # else print qshape output
 | |
| # output module header
 | |
| echo -e "\e[1A\e[${c_title} Postfix deferred queue status  \e[0m\n"
 | |
| if [[ "$deferredtotal" -gt 100 ]]; then
 | |
|     echo -e "  There is \e[1;${c_danger}m${deferredtotal}\e[0m deferred Mails in queue."
 | |
| else
 | |
|     echo -e "  There is \e[1;${c_warning}m${deferredtotal}\e[0m deferred Mails in queue."
 | |
| fi
 |