1.Настройка скрипта для анализа Exim-логов на Zabbix-агенте
1 |
# nano /etc/zabbix/scripts/exim4.sh |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
#!/bin/bash # Egor Minko. Synchron LLC. May.2012 zexim4ver="ver 2.1" rval=0 # MULTIPLE PARSERS PROTECTION LOCK=/tmp/zexim4.pid while [ -e "$LOCK" ]; do PID="`cat $LOCK`" while [ "`ps h -p $PID -o pid,comm|wc -l`" -gt 0 ] do sleep 0.$[ ( $RANDOM % 10 ) + 1 ]s done done echo $$ > $LOCK trap "rm -f $LOCK; exit" INT TERM EXIT # USAGE function usage() { echo "zexim version: $zexim4ver" echo "usage:" echo " $0 deliver -- Delivered Messages" echo " $0 arrive -- Submited Pakets" echo " $0 error -- Errors Total for Messages" echo " $0 defer -- Error status: Defered Messages" echo " $0 unroute -- Error status: Unroutable address" echo " $0 local -- Local/Virtual delivery of Messages" echo " $0 complete -- Finished Packets" echo " $0 reject -- Rejects Total for Packets" echo " $0 badrelay -- Reject status: Relay not permited" echo " $0 Pqueue -- Queue size in Packets" echo " $0 Mqueue -- Queue size in Messages" echo " $0 frozen -- Frozen Packets" echo "" echo " Packet = letter with many recipients" echo " Message = A single message for one recipient" echo "" } # GLOBAL INSTRUCTIONS CACHETTL="58" # sec main_log=/var/log/exim_mainlog tmp_log=/tmp/exim_log_pars.txt stats=/tmp/stats.txt exim=`which exim` function create_data() { # CREATING STATS FILE if [ ! -e "$stats" ] ; then touch $stats ; fi # CREATING TMP FILE # additional 'sub' in 'awk' used for cutting special chars that breaks next 'sed' parsing. For now: []() position=`tail -1 $stats |awk '{print $1" "$2" "$3}'` position_log=`tail -1 $main_log | awk '{sub(/\]/,""); sub(/\[/,""); sub(/\)/,""); sub(/\(/,""); print $1" "$2" "$3}'` # BUILDING REPORT ONLY IF THERE IS DIFFERENCE BETWEEN LAST LINE IN LOG if [ "$position" == "$position_log" ] then vars="0 0 0 0 0 0 0 0 0" else if ! grep -qc "" $stats || ! awk '{sub(/\]/,""); sub(/\[/,""); sub(/\)/,""); sub(/\(/,""); print}' $main_log|grep -qc "$position" then awk '{sub(/\]/,""); sub(/\[/,""); sub(/\)/,""); sub(/\(/,""); print}' $main_log $main_log > $tmp_log else awk '{sub(/\]/,""); sub(/\[/,""); sub(/\)/,""); sub(/\(/,""); print}' $main_log |sed 1,/"$position"/d | sed /"$position"/d > $tmp_log fi vars="`awk '\ BEGIN {deliver=0; arrive=0; error=0; local=0; complete=0; reject=0; badrelay=0; defer=0; unroute=0}\ /[-=]>/ { deliver++ }\ /<=/ {arrive++}\ / \*\* / {error++}\ /[=][=]/ {defer++}\ /al_delivery/ {local++}\ /Completed/ {complete++}\ /rejected/ {reject++}\ /relay not permitted/ {badrelay++}\ /Unrouteable address/ {unroute++}\ END {print deliver" "arrive" "error" "defer" "local" "complete" "reject" "badrelay" "unroute}' $tmp_log`" fi queue_size="`$exim -bpc`" recipients="`exipick -bpu |awk '$2==""{print $1}'|grep -vE "^$"|wc -l`" frozen="`exiqgrep -zi|wc -l`" echo $position_log $vars $queue_size $recipients $frozen >> $stats } function zabbix_answer() { case $CASE_VALUE in 'deliver') tail -n1 "$stats"|awk '{print $4}' rval=$?;; 'arrive') tail -n1 "$stats"|awk '{print $5}' rval=$?;; 'error') tail -n1 "$stats"|awk '{print $6}' rval=$?;; 'defer') tail -n1 "$stats"|awk '{print $7}' rval=$?;; 'local') tail -n1 "$stats"|awk '{print $8}' rval=$?;; 'complete') tail -n1 "$stats"|awk '{print $9}' rval=$?;; 'reject') tail -n1 "$stats"|awk '{print $10}' rval=$?;; 'badrelay') tail -n1 "$stats"|awk '{print $11}' rval=$?;; 'unroute') tail -n1 "$stats"|awk '{print $12}' rval=$?;; 'Pqueue') tail -n1 "$stats"|awk '{print $13}' rval=$?;; 'Mqueue') tail -n1 "$stats"|awk '{print $14}' rval=$?;; 'frozen') tail -n1 "$stats"|awk '{print $15}' rval=$?;; 'version') echo "$zexim4ver" rm $LOCK trap - INT TERM EXIT exit $rval;; *) usage rm $LOCK trap - INT TERM EXIT exit $rval;; esac } if [ -s "$stats" ]; then TIMECACHE=`stat -c"%Z" "$stats"` else TIMECACHE=0 fi TIMENOW=`date '+%s'` if [[ $# == 1 ]];then CASE_VALUE=$1 if [ "$(($TIMENOW - $TIMECACHE))" -gt "$CACHETTL" ]; then create_data fi zabbix_answer if [ "$rval" -ne 0 ]; then echo "ZBX_NOTSUPPORTED" fi rm $LOCK trap - INT TERM EXIT exit $rval else usage rm $LOCK trap - INT TERM EXIT exit 0 fi |
1 |
# chmod +x /etc/zabbix/scripts/exim4.sh |
В скрипте указываем корректный путь к Exim-лог файлу в переменной main_log По умолчанию стоит
1 |
main_log=/var/log/exim_mainlog |
Если утилита exipick не установлена в системе (например, на Cpanel-установках), то скачиваем ее с официального сайта и сохраняем под именем /usr/sbin/exipick
1 |
# wget -O /usr/sbin/exipick http://jetmore.org/john/code/exipick |
1 |
# chmod +x /usr/sbin/exipick |
Проверяем работу утилиты exipick
1 |
# exipick -bpu |
2.Настройка […]