diff --git a/defaults/main.yml b/defaults/main.yml index a858bd5..2742e6a 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -9,7 +9,7 @@ obs_agent_pg_enable: false obs_agent_apache_enable: false obs_agent_bind_stats: "/var/cache/bind/named.stats" obs_agent_bind_enable: false - +obs_agent_postfix_enable: false diff --git a/tasks/main.yml b/tasks/main.yml index fe5aada..b8f1b16 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -42,3 +42,6 @@ - include: tasks/bind.yml when: obs_agent_bind_enable == true + +- include: tasks/postfix.yml + when: obs_agent_postfix_enable == true diff --git a/tasks/postfix.yml b/tasks/postfix.yml new file mode 100644 index 0000000..098c3b5 --- /dev/null +++ b/tasks/postfix.yml @@ -0,0 +1,14 @@ +--- +# postfix mailgraph local agent +# TODO: consider modification of /usr/sbin/mailgraph from $rrdstep = 60 to my $rrdstep = 300; in this script, +# requires cleanup of old rrds and restart to mailgraph after +# http://docs.observium.org/apps/#postfix-mailgraph +- name: be sure rrdtool is installed + apt: pkg=rrdtool state=installed + tags: rrdtool + + when: ansible_distribution == "Debian" +- name: deploy mailgraph local agent + copy: src=templates/local-agents/postfix_mailgraph dest=/usr/lib/observium_agent/local/postfix_mailgraph owner=root group=root mode=0655 + + diff --git a/templates/local-agents/postfix_mailgraph b/templates/local-agents/postfix_mailgraph new file mode 100644 index 0000000..968f4e3 --- /dev/null +++ b/templates/local-agents/postfix_mailgraph @@ -0,0 +1,34 @@ +#!/bin/bash + +RRDPATH=/var/lib/mailgraph + +RRD_FIELDS="" +RRD_VALUES="" + +for FILENAME in mailgraph_greylist.rrd mailgraph.rrd mailgraph_virus.rrd +do + + if [ -f $RRDPATH/$FILENAME ]; + then + OUTPUT=$(rrdtool lastupdate $RRDPATH/$FILENAME 2>/dev/null) + if [ "$OUTPUT" != "" ]; + then + RRD_FIELDS+=$(echo "$OUTPUT"|head -n1) + RRD_VALUES+=$(echo "$OUTPUT"|tail -n1|cut -d: -f2) + fi + fi +done + +read -a FIELDS <<< "$RRD_FIELDS" +read -a VALUES <<< "$RRD_VALUES" + +if [ ${#FIELDS[@]} != 0 ]; +then + echo "<<>>" + + for i in `seq ${#FIELDS[@]}` + do + echo ${FIELDS[$i-1]}:${VALUES[$i-1]} + done +fi +