Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check_mailq with mailscanner #754

Closed
darkfritz2 opened this issue Jan 28, 2024 · 29 comments
Closed

check_mailq with mailscanner #754

darkfritz2 opened this issue Jan 28, 2024 · 29 comments
Labels

Comments

@darkfritz2
Copy link

Hello,

I have a few cpanel servers that are running on configserver mailscanner.
If I specify in check_mailq the mailserver it mostly says that there is no email in queue even though I have over 100 mails in queue right now.
Can it be that mailscanner is not working with mailq plugin ? or is there a way to make both work ?

@chicks-net
Copy link

Mailscanner sets up multiple mail queues. Are you specifying the right mail queue name? You might need a few invocations of check_mailq to handle all of the queues.

@darkfritz2
Copy link
Author

darkfritz2 commented Jan 29, 2024

well if i let it to autodetect then i get on line 355 an error

/usr/lib64/nagios/plugins/check_mailq -w 50 -c 100
mailq: Mail queue is empty
Use of uninitialized value $lines[0] in pattern match (m//) at /usr/lib64/nagios/plugins/check_mailq line 355.
Use of uninitialized value $lines[0] in pattern match (m//) at /usr/lib64/nagios/plugins/check_mailq line 357.
Couldn't match /usr/bin/mailq output

if i specify the mailserver (exim, sendmail or whatever) then my mail queue is zero.

/usr/lib64/nagios/plugins/check_mailq -M sendmail -w 50 -c 100
OK: sendmail mailq is empty|unsent=0;50;100;0
/usr/lib64/nagios/plugins/check_mailq -M exim -w 50 -c 100
OK: exim mailq (0) is below threshold (50/100)|unsent=0;50;100;0

there were 3 mail server specified that also gave errors:

/usr/lib64/nagios/plugins/check_mailq -M qmail -w 50 -c 100
ERROR:  is not executable by (uid 0:gid(0 0 966))
/usr/lib64/nagios/plugins/check_mailq -M postfix -w 50 -c 100
Couldn't match /usr/bin/mailq output
/usr/lib64/nagios/plugins/check_mailq -M opensmtpd -w 50 -c 100
ERROR: $utils::PATH_TO_SMTPCTL is not defined

OS: Almalinux 8.9
cpanel with mailscanner.

@darkfritz2
Copy link
Author

upon further checking i found out that: Mailq can usually only be accessed by root or a TrustedUser. so i added visudo:
nrpe ALL=(ALL) NOPASSWD:/usr/sbin/exim -bpc
as i found in old tutorials (from 2015). i don't know if it's still viable or what i should do.

@darkfritz2
Copy link
Author

help ?

@chicks-net
Copy link

Looking at how this plugin works, it does not provide a way to specify multiple queues. So it is going to be hard to make it useful with a mailscanner install.

The default queue (iirc) for mailscanner is used for incoming mail on the server. Then mailscanner processes batches of that mail and puts it into another queue for delivery. It sounds like that queue is where your problems are. And since you would have to provide an option to the mailq command that this plugin does not currently support, you're stuck without tweaking the source code of the plugin.

@darkfritz2
Copy link
Author

i see. ok. thank you.
for exim: what would be the default way to make it work ? should it work out of the box or is it necessary to create a trusteduser ?

@chicks-net
Copy link

I haven't used exim, so I'm not sure if there's anything unique to that.

I don't see any way to get the plugin to work in your scenario without tweaking the code.

@darkfritz2
Copy link
Author

so mailscanner is using exim. but to get the mail queue they use this command:
exim -bpc -C /etc/exim_outgoing.conf
how to do i say to nagios_mailq this command so it can fetch me the information ?

@chicks-net
Copy link

There is an option in the source for adding arguments to the mailq command, but it seems to only work in sendmail and postfix. For exim, it looks like you would need to tweak the source somehow to support what you are looking for.

@sawolf sawolf added the Bug label Mar 21, 2024
@tsadpbb
Copy link
Contributor

tsadpbb commented Mar 29, 2024

I made a potential fix in this PR. Does this fix your issue?

@darkfritz2
Copy link
Author

darkfritz2 commented Mar 30, 2024

hello, i did what you suggested. how should the command look like ? because i tried this:

[root@andromeda ~]# /usr/lib64/nagios/plugins/check_mailq -M exim -w 200 -c 400
OK: exim mailq (0) is below threshold (200/400)|unsent=0;200;400;0

didnt work.
and this:

[root@andromeda ~]# /usr/lib64/nagios/plugins/check_mailq -M exim -bpc -C /etc/exim_outgoing.conf -w 200 -c 400
Unknown option: b
Unknown option: p
Value "-C" invalid for option c (number expected)
OK: exim mailq (0) is below threshold (200/400)|unsent=0;200;400;0

didn't work.

for comparison:

[root@andromeda ~]# exim -bpc -C /etc/exim_outgoing.conf
3006

this is what it should get me.

@tsadpbb
Copy link
Contributor

tsadpbb commented Apr 1, 2024

Try it without the -bpc option.

/usr/lib64/nagios/plugins/check_mailq -M exim -C /etc/exim_outgoing.conf -w 200 -c 400

@darkfritz2
Copy link
Author

[root@andromeda ~]# /usr/lib64/nagios/plugins/check_mailq -M exim -C /etc/exim_outgoing.conf -w 200 -c 400
Unknown option: C
OK: exim mailq (0) is below threshold (200/400)|unsent=0;200;400;0

@tsadpbb
Copy link
Contributor

tsadpbb commented Apr 1, 2024

I apologize, I messed up the command, it should be

/usr/lib64/nagios/plugins/check_mailq -M exim -d /etc/exim_outgoing.conf -w 200 -c 400

@darkfritz2
Copy link
Author

[root@andromeda ~]# /usr/lib64/nagios/plugins/check_mailq -M exim -d /etc/exim_outgoing.conf -w 200 -c 400
OK: exim mailq (0) is below threshold (200/400)|unsent=0;200;400;0

this should have shown:

[root@andromeda ~]# exim -bpc -C /etc/exim_outgoing.conf
1236

@tsadpbb
Copy link
Contributor

tsadpbb commented Apr 2, 2024

Oh I see what's going on here, exim changed the structure of the message ID's at some point. I added a fix for this. Can you try the PR now?

@darkfritz2
Copy link
Author

thank you for your help.
i change line 510 to if ( (/\s[\w\d]{6}-[\w\d]{6}-[\w\d]{2}\s/) || (/\s[\w\d]{6}-[\w\d]{11}-[\w\d]{4}\s/) ) { # message id 19aEEr-0007hx-Dy

still using these commands doesnt change anything:

[root@andromeda ~]# /usr/lib64/nagios/plugins/check_mailq -M exim -d /etc/exim_outgoing.conf -w 200 -c 400
OK: exim mailq (0) is below threshold (200/400)|unsent=0;200;400;0

@tsadpbb
Copy link
Contributor

tsadpbb commented Apr 4, 2024

What does the output of exim -bp look like?

Does it differ from exim -bp -C /etc/exim_outgoing.conf?

How about mailq and the output of mailq -C /etc/exim_outgoing.conf?

@darkfritz2
Copy link
Author

so : exim -bp
doesnt give anything.
exim -bp -C /etc/exim_outgoing.conf
gives me a long list of emails which are in queue (not the number in total)

[root@andromeda ~]# mailq -C /etc/exim_outgoing.conf
0 mails to deliver

@tsadpbb
Copy link
Contributor

tsadpbb commented Apr 4, 2024

That's strange that mailq outputs different information than exim -bp

https://www.exim.org/exim-html-current/doc/html/spec_html/ch-the_exim_command_line.html

The exim documentation says that mailq is essentially just exim -bp

If you do mailq --help does it refer you to the exim documentation?

What version of exim do you have? exim --version

When you say you updated the 510 line, did you also do the rest of the changes in the PR? I'm referring to the changes allowing the -d /etc/exim_outgoing.conf option.

@darkfritz2
Copy link
Author

[root@andromeda ~]# mailq --help
0 mails to deliver

[root@andromeda ~]# exim --version
Exim version 4.96.2 #2 built 27-Dec-2023 11:01:49
Copyright (c) University of Cambridge, 1995 - 2018
(c) The Exim Maintainers and contributors in ACKNOWLEDGMENTS file, 2007 - 2022
Berkeley DB: Berkeley DB 5.3.28: (September  9, 2013)
Support for: crypteq iconv() IPv6 PAM Perl OpenSSL TLS_resume Content_Scanning DANE DKIM DNSSEC Event I18N OCSP PIPECONNECT PRDR Queue_Ramp SPF SRS TCP_Fast_Open
Lookups (built-in): lsearch wildlsearch nwildlsearch iplsearch cdb dbm dbmjz dbmnz dnsdb dsearch passwd sqlite
Authenticators: cram_md5 dovecot plaintext spa
Routers: accept dnslookup ipliteral manualroute queryprogram redirect
Transports: appendfile/maildir autoreply lmtp pipe smtp
Malware: f-protd f-prot6d drweb fsecure sophie clamd avast sock cmdline
Configure owner: 0:0
Size of off_t: 8
2024-04-07 21:54:28 cwd=/root 2 args: exim --version
Configuration file is /etc/exim.conf

you mean if i added:

if (! open (MAILQ, "$sudo $utils::PATH_TO_MAILQ$mailq_args 2>&1 | " ) ) {
			print "ERROR: could not open $utils::PATH_TO_MAILQ$mailq_args\n";

and so on ?
yes.

here is my check_mailq file in txt
check_mailq.txt

@tsadpbb
Copy link
Contributor

tsadpbb commented Apr 9, 2024

What's your output of

rpm -qf `which mailq`

@darkfritz2
Copy link
Author

[root@artemis .cagefs]# rpm -qf `which mailq`
ssmtp-2.64-14.el7.x86_64

@tsadpbb
Copy link
Contributor

tsadpbb commented Apr 10, 2024

I see. The plugin is expecting that mailq is from exim with the exim formatting.

[user@localhost nagioscore]# rpm -qf `which mailq`
exim-4.97.1-1.el9.x86_64

Would you be able to try making it such that mailq is provided by exim instead of ssmtp and then try the plugin again?

@darkfritz2
Copy link
Author

i'm sorry but i don't know how to do that.

also i tested your command on different server (all of them are cpanel).

on cloudlinux 8:

[root@andromeda ~]# rpm -qf `which mailq`
esmtp-1.2-15.el8.x86_64

and on cloudlinux 7:

[root@artemis ~]# rpm -qf `which mailq`
ssmtp-2.64-14.el7.x86_64

@tsadpbb
Copy link
Contributor

tsadpbb commented Apr 10, 2024

If you try reinstalling exim with yum reinstall exim does that add exim to the results of rpm -qf `which mailq`?

@darkfritz2
Copy link
Author

i opened a ticket at cpanel. this is their official resposne:

Thank you for contacting cPanel Technical Support!

I see that you are a cPanel Partner. We appreciate your business and thank you for choosing cPanel!

At this time the cPanel team does not ship the mailq binary with exim:

[20:32:05 artemis root@95244923 ]cPs# rpm -ql cpanel-exim-4.96.2-2.cp108el7.x86_64 | grep mailq
[20:32:13 artemis root@95244923 ~]cPs#

It is provided by the ssmtp package as you mentioned.

[20:32:34 artemis root@95244923 ~]cPs# rpm -qf $(which mailq)
ssmtp-2.64-14.el7.x86_64

You would need to file a feature request for cPanel to also provide mailq. You can do this on our website here:

How to submit a feature request

You could attempt to create your own exim package to include mailq, details to do that in our documentation here:

https://docs.cpanel.net/knowledge-base/general-systems-administration/how-to-build-and-install-custom-rpms-on-red-hat-systems/

If you need anything else don't hesitate to contact us again.

@tsadpbb
Copy link
Contributor

tsadpbb commented Apr 10, 2024

Well I don't think I can help a whole lot in this situation anymore as I don't have access to anything cpanel related.

The plugin was designed to call the mailq command and parse it depending on whatever mail agent you specified because many different packages provide mailq. If you need to use exim, you need mailq to be equivalent to exim -bp or you need to configure nagios plugins to somehow call exim -bp when executing mailq

@tsadpbb
Copy link
Contributor

tsadpbb commented Apr 11, 2024

Kind of a hack, but can you try either configuring nagios plugins with,

./configure --with-mailq-command="$(which exim)"
make
make install

or modifying the $PATH_TO_MAILQ value to the output of which exim wherever utils.pm is

Then the command looks like

/usr/lib64/nagios/plugins/check_mailq -M exim -d "/etc/exim_outgoing.conf -bp" -w 200 -c 400

dylan-at-nagios added a commit that referenced this issue Apr 16, 2024
 Fix [#754]: Add config directory option for exim mailservers
@sawolf sawolf closed this as completed May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants