Mailcow Monitoring Check
A Python-based monitoring check command for Mailcow, designed to work with monitoring systems like Icinga2 and Nagios. This script allows you to monitor various aspects of your Mailcow server including mail queues, container status, disk usage, mailbox quotas, and more.
Features
- Supports multiple monitoring modes:
- mailqueue – check mail queue length
- quarantine – monitor quarantine status
- containerstatus – check Docker container health
- diskstatus – monitor disk usage
- version – verify Mailcow version
- mailboxquota – check mailbox quota usage
- domainstatus – check domain availability
- spamscore – monitor spam detection
- compliance – check compliance settings
- Custom warning and critical thresholds
- Performance data output compatible with Nagios/Icinga
- Verbose output for detailed inspection
- HTTPS certificate verification toggle
Requirements
- Python 3.x
- requests Python library
Install the required Python library:
pip install requests
Installation
-
Clone or download the script to your monitoring server.
git clone https://github.com/k3nd0x/check_mailcow.git
-
Ensure the script has execution permissions:
chmod +x mailcow_check.py
- Test it manually to verify connectivity:
python mailcow_check.py -H --api-token -p -m version
Usage
python mailcow_check.py -H --api-token -p -m [options]
API Options
Option | Description |
---|---|
-H , --host |
Mailcow API hostname or IP address |
--api-token |
Mailcow API token |
-p , --port |
Mailcow API port |
-k , --insecure |
Disable HTTPS certificate verification |
Check Options
Option | Description |
---|---|
-m , --mode |
Monitoring check mode (required). Options: mailqueue , quarantine , containerstatus , diskstatus , version , mailboxquota , domainstatus , spamscore , compliance |
-v , --verbose |
Enable verbose output (-v, -vv, -vvv) |
-w , --warning |
Warning threshold value |
-c , --critical |
Critical threshold value |
-d , --domain |
Domain name (required for mailboxquota , domainstatus , spamscore checks) |
Examples
Check mail queue:
./mailcow_check.py -H mail.example.com --api-token ABC123 -p 8080 -m mailqueue -w 50 -c 100
Check disk usage:
./mailcow_check.py -H mail.example.com --api-token ABC123 -p 8080 -m diskstatus -w 80 -c 90
Check mailbox quotas for a domain:
./mailcow_check.py -H mail.example.com --api-token ABC123 -p 8080 -m mailboxquota -d example.com -w 80 -c 90
Check Mailcow version:
./mailcow_check.py -H mail.example.com --api-token ABC123 -p 8080 -m version
Exit Codes
Compatible with Nagios/Icinga: | Exit Code | State |
---|---|---|
0 | OK | |
1 | WARNING | |
2 | CRITICAL | |
3 | UNKNOWN |
Notes
-
Use the --insecure flag if using a self-signed certificate.
-
Thresholds (-w and -c) are numeric values used for warnings and critical states depending on the check mode.
-
Verbose output (-v) will display additional details.