rafael747 / zabbix-postfix Goto Github PK
View Code? Open in Web Editor NEWPostfix template for Zabbix
Postfix template for Zabbix
Hello,
Thanks for your plugin, work nice after a modification for a rights problem with passive script with the file /tmp/zabbix-postfix-passive-statsfile.dat
on Ubuntu 22.04.
Same problem when I let the zabbix-server, or execute by zabbix_agentd -t postfix[deferred]
or directly with sudo /usr/local/sbin/zabbix_postfix_passive.sh deferred
.
I need to change the owner to root for working. And work like a charm. And something weird , when reapply owner and gorup to zabbix, it's continue to work... Until reboot and tmp files deleted of course.
In my case, no need to have zabbix as owner, it can be root like for /tmp/zabbix-postfix-passive-offset.dat
, as we execute the script as root with the sudoers. I don't know why needed theses lines and I comment them.
I don't send a pull request, because maybe it's needed for something for someone ? But on Debian based I think not.
if [ ! -w "${PFSTATSFILE}" ]; then
touch "${PFSTATSFILE}" && chown zabbix:zabbix "${PFSTATSFILE}" > /dev/null 2>&1
if [ ! $? -eq 0 ]; then
result_text="ERROR: wrong exit code returned while creating file ${PFSTATSFILE} and setting its owner to zaabbix:zabbix"
result_code="1"
write_result "${result_code}" "${result_text}"
fi
fi
Have a nice day
Hey Rafael,
Thanks for these postfix monitoring.
I've imported to my server and I've got the error from "Postfix queue" that there is a unsupported item key.
Also I have to change the line 1 for interpreter in this script to python3
https://github.com/rafael747/zabbix-postfix/blob/master/pygtail.py#L1 to work with my environment.
All other things in this script works well.
Do you know why I got the "unsupported item key"?
Hello,
your template looks interesting.
Here is one typo (at least on ubuntu 18.04 and Debian 9 as well) on installation script (install_postfix_template_zabbix.sh) on line 38 must be :
cd /etc/zabbix/zabbix_agentd.d/
not: cd /etc/zabbix/zabbix_agentd.conf.d/
However, I installed it via your script and imported template, but from all existing items, only one that returns data is Postfix queue - the key: pf.mailq
I'm using zabbix-proxy and for any other requests I got answer - not existing key:
$ zabbix_get -s postfix_hostname -p 10050 -k pf.delivered
ZBX_NOTSUPPORTED: Unsupported item key.
Same response or any keys: pf.deferred, pf.discarded, pf.rejected and so on.
Only one that responds with number of mails in the queue is: pf.mailq
(ok, probably the most important one :-)
I have zabbix-server version 4.4.7, zabbix_proxy (Zabbix) 4.4.7
Postfix version: 3.3.0
Python 2.7.17 (however also 3.6.9)
I can't find anything related in zabbix logs (agent or proxy).
All the best,
Franko
"Held Messages" are not displayed correclty:
Console Output from your script (check the failures in the end of the line)
DATA="$(${LOGTAIL} -o ${FPOS} ${MAILLOG} | ${PFLOGSUMM} -h 0 -u 0 --bounce_detail=0 --deferral_detail=0 --reject_detail=0 --no_no_msg_size --smtpd_warning_detail=0)"
echo -e $DATA
Grand Totals ------------ messages 0 received 0 delivered 0 forwarded 0 deferred 0 bounced 0 rejected (0%) 0 reject warnings 0 held 0 discarded (0%) 0 bytes received 0 bytes delivered 0 senders 0 sending hosts/domains 0 recipients 0 recipient hosts/domains Per-Hour Traffic Summary ------------------------ time received delivered deferred bounced rejected -------------------------------------------------------------------- 0000-0100 0 0 0 0 0 0100-0200 0 0 0 0 0 0200-0300 0 0 0 0 0 0300-0400 0 0 0 0 0 0400-0500 0 0 0 0 0 0500-0600 0 0 0 0 0 0600-0700 0 0 0 0 0 0700-0800 0 0 0 0 0 0800-0900 0 0 0 0 0 0900-1000 0 0 0 0 0 1000-1100 0 0 0 0 0 1100-1200 0 0 0 0 0 1200-1300 0 0 0 0 0 1300-1400 0 0 0 0 0 1400-1500 0 0 0 0 0 1500-1600 0 0 0 0 0 1600-1700 0 0 0 0 0 1700-1800 0 0 0 0 0 1800-1900 0 0 0 0 0 1900-2000 0 0 0 0 0 2000-2100 0 0 0 0 0 2100-2200 0 0 0 0 0 2200-2300 0 0 0 0 0 2300-2400 0 0 0 0 0 smtp delivery failures: none Fatal Errors: none Panics: none Master daemon messages: none
Output from other check command
root@server:~# mailq -hq
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
791XX12XXX 5037 Thu Jun 30 08:49:45 [email protected]
(connect to maksed.foo.bar[xxx.xxx.xxx.xxx]:25: Connection timed out)
[email protected]
-- 4 Kbytes in 1 Request.
In case anyone wanna do this on centos 6 (probably also 7)
Edit the zabbix_postfix.sh file:
#!/bin/bash
# DEPS: /usr/sbin/pflogsumm
# DEPS: pygtail.py
# DEPS: bc
MAILLOG=/var/log/maillog
FPOS=/tmp/zabbix-postfix-offset.dat
PFLOGSUMM=/usr/sbin/pflogsumm
LOGTAIL=/usr/local/sbin/pygtail.py
ZABBIX_CONF=/etc/zabbix/zabbix_agentd.conf
function zsend {
/usr/bin/zabbix_sender -c $ZABBIX_CONF -k $1 -o $2
}
DATA="$(${LOGTAIL} -o ${FPOS} ${MAILLOG} | ${PFLOGSUMM} -h 0 -u 0 --no_bounce_detail --no_deferral_detail --no_reject_detail --no_no_msg_size --no_smtpd_warnings)"
zsend pf.received $(echo -e "${DATA}" | grep -m 1 received | cut -f1 -d"r")
zsend pf.delivered $(echo -e "${DATA}" | grep -m 1 delivered | cut -f1 -d"d")
zsend pf.forwarded $(echo -e "${DATA}" | grep -m 1 forwarded | cut -f1 -d"f")
zsend pf.deferred $(echo -e "${DATA}" | grep -m 1 deferred | cut -f1 -d"d")
zsend pf.bounced $(echo -e "${DATA}" | grep -m 1 bounced | cut -f1 -d"b")
zsend pf.rejected $(echo -e "${DATA}" | grep -m 1 rejected | cut -f1 -d"r")
zsend pf.rejectwarnings $(echo -e "${DATA}" | grep -m 1 "reject warnings" | cut -f1 -d"r")
zsend pf.held $(echo -e "${DATA}" | grep -m 1 held | cut -f1 -d"h")
zsend pf.discarded $(echo -e "${DATA}" | grep -m 1 discarded | cut -f1 -d"d")
zsend pf.bytesreceived $(echo -e "${DATA}" | grep -m 1 "bytes received" | cut -f1 -d"b"|sed -e 's/k/\*1024/g' -e 's/m/\*1048576/g' -e 's/g/\*1073741824/g' |bc)
zsend pf.bytesdelivered $(echo -e "${DATA}" | grep -m 1 "bytes delivered" | cut -f1 -d"b"|sed -e 's/k/\*1024/g' -e 's/m/\*1048576/g' -e 's/g/\*1073741824/g' |bc)
Run these commands instead (replace the zabbix version with the one your using):
yum install postfix-perl-scripts bc
cp zabbix_postfix.sh /usr/local/sbin/
cp pygtail.py /usr/local/sbin/
chmod +x /usr/local/sbin/pygtail.py
chmod +x /usr/local/sbin/zabbix_postfix.sh
cp zabbix_postfix /etc/sudoers.d/
chmod 440 /etc/sudoers.d/zabbix_postfix
yum install https://repo.zabbix.com/zabbix/4.2/rhel/6/x86_64/zabbix-release-4.2-1.el6.noarch.rpm
yum install zabbix-agent zabbix-sender
cp zabbix_postfix.conf /etc/zabbix/zabbix_agentd.d/
service zabbix-agent restart
At first I thought the reason the cron entry wasn't working was because I had put it in the zabbix user's crontab instead of root. But even after switching that, it didn't work. Eventually I figured out that it was because it was looking for /etc/zabbix/zabbix_agentd.conf instead of /etc/zabbix/zabbix_agent2.conf.
Hi
I've after quite a bit of wrestling managed to get this working on an Alma 8 (essentially Red Hat/Centos 8) system. I suspect the problems I encountered would be more or less identical on RHEL 9/Alma 9/Rocky 9/Centos Stream. I'm feeding back some info in the event it's helpful for either making some tweaks to the script, or for anybody else reading who may have encountering these issues:
grep zabbix_agent /var/log/audit/audit.log | audit2allow -M zabbix_agent
grep execute_no_trans /var/log/audit/audit.log | audit2allow -M execute_no_trans
grep unix_dgram_socket /var/log/audit/audit.log | audit2allow -M zabbix-postfix-unix_dgram_socket
grep showq /var/log/audit/audit.log | audit2allow -M zabbix-postfix-showq
It was basically a case of repeat tailing the audit log for zabbix/postfix related "denied" entries, then pushing them through Audit2allow and activating the resultant policy files. Which isn't ideal in the grand scheme of things, but I think the only other option I'm aware of would be fore them to be more precisely specified/written into an installer or install script.
UserParameter=pf.mailq,/usr/bin/mailq | grep -v "Mail queue is empty" | grep -c '^[0-9A-Z]'
This also meant that sudo file/entry in /etc/sudoers.d
for the zabbix user was no longer needed.
AllowKey=system.run["/usr/bin/mailq | grep -v 'Mail queue is empty' | grep -c '^[0-9A-Z]'"]
/bin/python3
to allow the cron job to pull data through and transmit it.I hope this is helpful either the the maintainer or to other users, if I can supply any further info please let me know.
Hi Rafael, your template for Postfix, works with passive agent? Thanks.
Add crontab entry
*/5 * * * * /usr/local/sbin/zabbix_postfix.sh 1>/dev/null 2>/dev/null'
correct
*/5 * * * * /usr/local/sbin/zabbix_postfix.sh 1>/dev/null 2>/dev/null
I don't have problem fo install install_postfix_template_zabbix.sh io ok for ubuntu 23.04 LTS
What do you think about to create / discover a tigger for item "held messages"? So when more then 1 messages are held for more then 10 Minutes, there comes up a alert?
I opted to set up the new Zabbix alpha version from scratch.
This template will not import into 7.0.0alpha1. "Unexpected Server Error" is shown. There is nothing useful in the apache logs. I am importing the standard template, not the passive template.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.