Skip to content

Commit

Permalink
Add a munin plugin to count the number of emails in folders
Browse files Browse the repository at this point in the history
Uses the doveadm command
  • Loading branch information
amedee committed Sep 16, 2024
1 parent 4ada7a5 commit 76d8fc5
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 7 deletions.
2 changes: 2 additions & 0 deletions roles/mailinabox/files/etc/munin/plugin-conf.d/mailbox_count
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[mailbox_count]
user root
Empty file modified roles/mailinabox/files/etc/munin/plugins/backup_size
100644 → 100755
Empty file.
57 changes: 57 additions & 0 deletions roles/mailinabox/files/etc/munin/plugins/mailbox_count
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/sh

output_config() {
cat <<'EOM'
inbox.label Inbox
archive.label Archive
drafts.label Drafts
sent.label Sent
spam.label Spam
trash.label Trash
graph_args --base 1000 --lower-limit 0
graph_scale no
graph_category email
graph_info Number of emails in each folder
graph_title Emails
graph_vlabel Emails
EOM
}

output_values() {
printf "inbox.value %d\n" "$(number_of_emails Inbox)"
printf "archive.value %d\n" "$(number_of_emails Archive)"
printf "drafts.value %d\n" "$(number_of_emails Drafts)"
printf "sent.value %d\n" "$(number_of_emails Sent)"
printf "spam.value %d\n" "$(number_of_emails Spam)"
printf "trash.value %d\n" "$(number_of_emails Trash)"
}

number_of_emails() {
/usr/bin/doveadm search -A mailbox "$1" | wc --lines
}

output_usage() {
printf >&2 "%s - munin plugin to graph number of emails\n" "${0##*/}"
printf >&2 "Usage: %s [config]\n" "${0##*/}"
}

case $# in
0)
output_values
;;
1)
case $1 in
config)
output_config
;;
*)
output_usage
exit 1
;;
esac
;;
*)
output_usage
exit 1
;;
esac
14 changes: 7 additions & 7 deletions roles/mailinabox/tasks/munin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@
path: /lib/systemd/system/munin-node.service
section: Service
option: ProtectHome
value: read-only
value: false
ignore_spaces: true
no_extra_spaces: true
owner: root
mode: u=rw,go=r
notify: Reload systemd

- name: Add duplicity plugin
- name: Add munin plugins
ansible.builtin.copy:
src: etc/munin/plugins/backup_size
dest: /etc/munin/plugins/backup_size
src: etc/munin/plugins/
dest: /etc/munin/plugins/
owner: root
mode: u=rwx,go=rx
notify: Restart munin-node

- name: Add duplicity plugin configuration
- name: Add munin plugin configurations
ansible.builtin.copy:
src: etc/munin/plugin-conf.d/backup_size
dest: /etc/munin/plugin-conf.d/backup_size
src: etc/munin/plugin-conf.d/
dest: /etc/munin/plugin-conf.d/
owner: root
mode: u=rw,go=r
notify: Restart munin-node
Expand Down

0 comments on commit 76d8fc5

Please sign in to comment.