Skip to content

Commit

Permalink
Allow dovecot_stats_ cope with Dovecot 2.3
Browse files Browse the repository at this point in the history
Dovecot has a new "stats" command, and the version that this plugin
works with is now called as "doveadm oldstats", so try to adapt the
command based on the dovecot version.

Fixes #1327
  • Loading branch information
darac authored and kenyon committed Jan 14, 2023
1 parent 5d028e8 commit caf2f06
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions plugins/dovecot/dovecot_stats_
Expand Up @@ -36,8 +36,24 @@ if [[ "$1" == "autoconf" ]]; then
exit 0
fi

# Dovecot 2.3 changes the stas format, but we can still access the older version with "doveadm oldstats".
dovecot_version=$(/usr/sbin/dovecot --version | awk '{print $1}')

verlte() {
[ "$1" = "$2" ] && return 1 || [ "$2" = "`echo -e "$1\n$2" | sort -V | head -n1`" ]
}

verlt() {
[ "$1" = "$2" ] && return 1 || verlte $2 $1
}

# The stats command is "stats" unless the version is NOT less than 2.3, in which case it's "oldstats".
stats_command="stats"
verlt $dovecot_version 2.3 || stats_command="oldstats"


if [[ "$1" == "suggest" ]]; then
doveadm stats dump domain|awk 'NR!=1 {print $1}'
doveadm $stats_command dump domain|awk 'NR!=1 {print $1}'
exit 0
fi

Expand Down Expand Up @@ -112,7 +128,7 @@ fi

# Fetch data
# Gawk script cadged from http://awk.info/?JanisP
doveadm stats dump domain domain=$domain | gawk -F\\t -v cols="user_cpu sys_cpu min_faults maj_faults vol_cs invol_cs read_count write_count num_logins num_cmds mail_lookup_path mail_lookup_attr mail_read_count mail_cache_hits " -v domain=${domain//\./_} '
doveadm $stats_command dump domain domain=$domain | gawk -F\\t -v cols="user_cpu sys_cpu min_faults maj_faults vol_cs invol_cs read_count write_count num_logins num_cmds mail_lookup_path mail_lookup_attr mail_read_count mail_cache_hits " -v domain=${domain//\./_} '
BEGIN {
n=split(cols,col," ")
for (i=1; i<=n; i++) s[col[i]]=i
Expand Down

0 comments on commit caf2f06

Please sign in to comment.