Answer the question
In order to leave comments, you need to log in
How to set up postfix monitoring on zabbix?
Salute to all.
There was a task to monitor operability of a mail rayleigh.
On this issue, I came across this article.
https://serveradmin.ru/monitoring-postfix-v-zabbix/
There is a script
if echo "${TEMP_DATA}" | grep -iq "Mail queue is empty"; then
elif echo "${TEMP_DATA}" | grep -iPq "in\s+\d+\s+request"; then
echo "${TEMP_DATA}" | sed -e 's/.*in\s\+\([0-9]\+\)\s\+request.*/\1/gI' 2> /dev/null | head-n1
if [ -s "${CACHE_FILE}" ]; then
CACHE_TIME=`stat -c"%Y" "${CACHE_FILE}"`
DELTA_TIME=$((${NOW_TIME} - ${CACHE_TIME}))
if [ ${DELTA_TIME} -lt ${EXEC_TIMEOUT} ]; then
sleep $((${EXEC_TIMEOUT} - ${DELTA_TIME}))
elif [ ${DELTA_TIME} -gt ${CACHE_TTL} ]; then
echo "" >> "${CACHE_FILE}" # !!!
DATE_TO=`date +%d\ %H:%M:%S`
DATE_FROM=`date -d @${CACHE_TIME} +%d\ %H:%M:%S`
DATA_CACHE=`sudo cat ${MAILLOG} | sed -e 's/^\([a-zA-Z]\{3\}\s\)\s\([0-9]\s\)/\10\2/g' | awk '$2" "$3>=from && $2" "$3<=to' from="${DATE_FROM}" to="${DATE_TO}" | ${PFLOGSUMM} -h 0 -u 0 --bounce_detail=0 --deferral_detail=0 --reject_detail=0 --smtpd_warning_detail=0 --no_no_msg_size 2>&1`
echo "${DATA_CACHE}" > ${CACHE_FILE} # !!!
chmod 640 ${CACHE_FILE}
fi
awk "BEGIN{IGNORECASE=1} /${METRIC}/ {print \$1}" ${CACHE_FILE} | awk '{print $1}' | awk '/k|m/{p = /k/?1:2}{printf "%d\n", int($1) * 1024 ^ p}' | head-n1
Answer the question
In order to leave comments, you need to log in
if evaluates to 0 (true) and not zero (false), so the bottom line is that if
if echo "${TEMP_DATA}" | grep -iq "Mail queue is empty" ; then
returns 0 (that is, grep found the phrase "Mail queue is empty" at least once), then the condition is met.
Otherwise, it tries another condition:
elif echo "${TEMP_DATA}" | grep -iPq "in\s+\d+\s+request"; then
In this condition, we are looking for the phrase "in numbers request", if we find it, we execute it.
echo "${TEMP_DATA}" | sed -e 's/.*in\s\+\([0-9]\+\)\s\+request.*/\1/gI' 2> /dev/null | head -n1
Thus, three conditions
If the queue is empty - print 0, if not empty - print the number of request-s, otherwise we print an error.
Then the question is how does zabbix process it - it just takes these numbers and builds a graph, and reacts to an error, or something else.
In general, it is better, of course, to learn the basics of bash and regular expressions. Such scripts are hints for those who are already writing. They are not end-user solutions that you can just take and put on your server without understanding what they do. That is, there is always a risk that they do not do everything you want.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question