mirror of
https://github.com/moudsen/mailGraph
synced 2025-10-28 16:17:39 +01:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
01fafd98c5 | ||
|
|
fbcc359f05 | ||
|
|
12c9f1e331 | ||
|
|
2a599cb777 | ||
|
|
e40342cd94 |
@@ -48,6 +48,7 @@ Principal bug fixing on mailGraph v2.x (logic failure or similar) will continue
|
|||||||
I'm open to new feature requests - please raise an issue for this in this Github space.
|
I'm open to new feature requests - please raise an issue for this in this Github space.
|
||||||
|
|
||||||
[#50 - Docker support](https://github.com/moudsen/mailGraph/issues/50) - Docker support inserted shortly after testing; will be pushed into release 3 shortly.
|
[#50 - Docker support](https://github.com/moudsen/mailGraph/issues/50) - Docker support inserted shortly after testing; will be pushed into release 3 shortly.
|
||||||
|
_Please refer to the `docker` directory for the first release of the docker image on Docker Hub (hoppa66/zabbix-mailgraph)_
|
||||||
|
|
||||||
## Special thank you ##
|
## Special thank you ##
|
||||||
I would like to express my gratitude to the following people that have actively contributed to bring bugs and improvements to my attention:
|
I would like to express my gratitude to the following people that have actively contributed to bring bugs and improvements to my attention:
|
||||||
|
|||||||
1
docker/.env
Normal file
1
docker/.env
Normal file
@@ -0,0 +1 @@
|
|||||||
|
RESTART_POLICY=unless-stopped
|
||||||
88
docker/Dockerfile
Normal file
88
docker/Dockerfile
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
FROM ubuntu:latest
|
||||||
|
|
||||||
|
#########################################################################################################
|
||||||
|
#########################################################################################################
|
||||||
|
##
|
||||||
|
## ZABBIX-MAILGRAPH (Dockerfile)
|
||||||
|
## =============================
|
||||||
|
## Dockerfile to builld and configure the zabbix-mailgraph image.
|
||||||
|
##
|
||||||
|
## -----------------------------------------------------------------------------------------------------
|
||||||
|
## v0.9.1 2025/05/05 - Mark Oudsen - First public beta - Pending documentation
|
||||||
|
## v0.9.0 2025/05/05 - Mark Oudsen - Internal test release
|
||||||
|
## v0.1.0 2025/05/05 - Mark Oudsen - Initial build, based on idea from "dima-online
|
||||||
|
## "https://github.com/moudsen/mailGraph/issues/50
|
||||||
|
##
|
||||||
|
## -----------------------------------------------------------------------------------------------------
|
||||||
|
##
|
||||||
|
## (C) M.J.Oudsen, mark.oudsen@puzzl.nl
|
||||||
|
## MIT License
|
||||||
|
## Credits: "demi-online" (https://github.com/dima-online)
|
||||||
|
##
|
||||||
|
#########################################################################################################
|
||||||
|
#########################################################################################################
|
||||||
|
|
||||||
|
# Disable interactive functions
|
||||||
|
ENV DEBIAN_FRONTEND=noninteractive
|
||||||
|
|
||||||
|
# Install Apache, PHP and supplimentary programs
|
||||||
|
RUN apt-get update && \
|
||||||
|
apt-get install -y apache2 \
|
||||||
|
libapache2-mod-php \
|
||||||
|
php-curl \
|
||||||
|
php-zip \
|
||||||
|
curl \
|
||||||
|
git
|
||||||
|
|
||||||
|
# Clean out APT files
|
||||||
|
RUN rm -rf /var/lib/apt/lists/*
|
||||||
|
RUN apt-get clean -y
|
||||||
|
|
||||||
|
# Install Composer for PHP dependencies
|
||||||
|
RUN cd /tmp && curl -sS https://getcomposer.org/installer | php && mv composer.phar /usr/local/bin/composer
|
||||||
|
|
||||||
|
# Enable Apache modules
|
||||||
|
RUN a2enmod php8.3
|
||||||
|
RUN a2enmod rewrite
|
||||||
|
|
||||||
|
# Update the PHP.ini file, enable <? ?> tags and quieten logging.
|
||||||
|
RUN sed -i "s/short_open_tag = Off/short_open_tag = On/" /etc/php/8.3/apache2/php.ini
|
||||||
|
RUN sed -i "s/error_reporting = .*$/error_reporting = E_ERROR | E_WARNING | E_PARSE/" /etc/php/8.3/apache2/php.ini
|
||||||
|
|
||||||
|
# Manually set up the apache environment variables
|
||||||
|
ENV APACHE_RUN_USER=www-data
|
||||||
|
ENV APACHE_RUN_GROUP=www-data
|
||||||
|
ENV APACHE_LOG_DIR="/var/log/apache2"
|
||||||
|
ENV APACHE_LOCK_DIR="/var/lock/apache2"
|
||||||
|
ENV APACHE_PID_FILE="/var/run/apache2.pid"
|
||||||
|
|
||||||
|
# Copy the Github code into Apache site directory (run fetch_mailgraph.sh before building!)
|
||||||
|
ADD www /var/www/site/public
|
||||||
|
|
||||||
|
# Copy the cleanup script into local bin
|
||||||
|
ADD cleanup.sh /usr/local/bin/cleanup
|
||||||
|
RUN chmod +x /usr/local/bin/cleanup
|
||||||
|
|
||||||
|
# Fetch dependencies via Composer
|
||||||
|
RUN composer require phpmailer/phpmailer
|
||||||
|
RUN composer require twig/twig
|
||||||
|
|
||||||
|
# Move into the site directory
|
||||||
|
RUN mv /composer* /var/www/site/public/.
|
||||||
|
RUN mv /vendor /var/www/site/public/.
|
||||||
|
|
||||||
|
# Create some directories not existing yet
|
||||||
|
RUN mkdir /var/www/site/public/log
|
||||||
|
RUN mkdir /var/www/site/public/tmp
|
||||||
|
|
||||||
|
# Fix ownership
|
||||||
|
RUN chown www-data.www-data -R /var/www/site/public
|
||||||
|
|
||||||
|
# Update(/overwrite) the default apache site with the config we created
|
||||||
|
ADD apache-config.conf /etc/apache2/sites-enabled/000-default.conf
|
||||||
|
|
||||||
|
# Expose the HTTP port to external
|
||||||
|
EXPOSE 80
|
||||||
|
|
||||||
|
# By default, simply start apache
|
||||||
|
ENTRYPOINT ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]
|
||||||
44
docker/README.md
Normal file
44
docker/README.md
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
## Introduction ##
|
||||||
|
With the following instructions, mailGraph can be run in a Docker container.
|
||||||
|
Every new version of mailGraph will also be deployed to Docker Hub.
|
||||||
|
|
||||||
|
WORK-IN-PROGRESS
|
||||||
|
|
||||||
|
## Instructions - Plain vanilla deployment ##
|
||||||
|
- Create a directory structure on your system as follows:
|
||||||
|
```
|
||||||
|
mkdir /opt/Zabbix-Mailgraph
|
||||||
|
mkdir /opt/Zabbix-Mailgraph/config
|
||||||
|
mkdir /opt/Zabbix-Mailgraph/templates
|
||||||
|
```
|
||||||
|
- Create a new `config.json` in the above `config` directory and configure accordingly (refer to the wiki for more detailed instructions or use the `config.json.template` as a boilerplate).
|
||||||
|
- Copy the `plain.template` and `html.template` into the above `templates` directory.
|
||||||
|
- Deploy the mailGraph container, preferably using `docker-compose`:
|
||||||
|
-- Adopt and configure the `docker-compose.yml` file to your needs;
|
||||||
|
-- Configure `RESTART_POLICY=unless-stopped` in a file name `.env` (same directory as `docker-compose`).
|
||||||
|
- Start the container: `docker-compose -D up`.
|
||||||
|
- Follow best-practices on your applicable Linux version to ensure the container is started after a reboot.
|
||||||
|
|
||||||
|
When running:
|
||||||
|
- mailGraph is exposed on port `9080` (point the Zabbix webhook to this location).
|
||||||
|
- Apache logging is exposed on `/opt/Zabbix-Mailgraph/apache.log`.
|
||||||
|
|
||||||
|
## Testing and Debugging ##
|
||||||
|
- Display currently running containers `docker ps`.
|
||||||
|
- Execute `docker exec -it <container name> sh` for a shell into the container.
|
||||||
|
- Following the instructions in the Wiki on troubleshooting and debugging, i.e.:
|
||||||
|
-- `cd /var/www/site/public`
|
||||||
|
-- `php mailGraph.test test`
|
||||||
|
- When done testing, `exit` the container.
|
||||||
|
|
||||||
|
## Periodic cleanup of images and logs ##
|
||||||
|
The following command must be run on a regular basis to clean up images and logs (add to cron for example):
|
||||||
|
- `docker exec -it <container name> cleanup`
|
||||||
|
|
||||||
|
## Custom deployment ##
|
||||||
|
In case you like to adjust the container to your needs, you can adopt and modiyfy the provisioned scripts and files in this directory.
|
||||||
|
Please do not forget to modify the repository name in `build.sh` and `docker-compose.yml`.
|
||||||
|
|
||||||
|
## Special thank you ##
|
||||||
|
I would like to express my gratitude to the following people that have actively contributed to bring bugs and improvements to my attention with regards for mailGraph on Docker:
|
||||||
|
- [dima-online](https://github.com/dima-online)
|
||||||
18
docker/apache-config.conf
Normal file
18
docker/apache-config.conf
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
ServerName mailgraph.mydomain.com
|
||||||
|
|
||||||
|
<VirtualHost *:80>
|
||||||
|
ServerAdmin me@mydomain.com
|
||||||
|
|
||||||
|
DocumentRoot /var/www/site/public
|
||||||
|
|
||||||
|
<Directory /var/www/site/public>
|
||||||
|
Options Indexes FollowSymLinks MultiViews
|
||||||
|
AllowOverride All
|
||||||
|
Order deny,allow
|
||||||
|
Allow from all
|
||||||
|
</Directory>
|
||||||
|
|
||||||
|
ErrorLog ${APACHE_LOG_DIR}/error.log
|
||||||
|
CustomLog ${APACHE_LOG_DIR}/access.log combined
|
||||||
|
|
||||||
|
</VirtualHost>
|
||||||
2
docker/build.sh
Executable file
2
docker/build.sh
Executable file
@@ -0,0 +1,2 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
docker build -t hoppa66/zabbix-mailgraph .
|
||||||
3
docker/cleanup.sh
Normal file
3
docker/cleanup.sh
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
cd /var/www/site/public
|
||||||
|
php mailGraph.php cleanup
|
||||||
13
docker/docker-compose.yml
Normal file
13
docker/docker-compose.yml
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
version: '2.1'
|
||||||
|
|
||||||
|
services:
|
||||||
|
webhook:
|
||||||
|
image: hoppa66/zabbix-mailgraph:latest
|
||||||
|
restart: ${RESTART_POLICY}
|
||||||
|
hostname: mailgraph
|
||||||
|
ports:
|
||||||
|
- "9080:80"
|
||||||
|
volumes:
|
||||||
|
- /opt/Zabbix-mailGraph/apache.log:/var/log/apache2:rw
|
||||||
|
- /opt/Zabbix-mailGraph/config:/var/www/site/public/config:ro
|
||||||
|
- /opt/Zabbix-mailGraph/templates:/var/www/site/public/templates:ro
|
||||||
3
docker/fetch_mailgraph.sh
Executable file
3
docker/fetch_mailgraph.sh
Executable file
@@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
rm -rf www
|
||||||
|
git clone https://github.com/moudsen/mailGraph.git www
|
||||||
@@ -46,6 +46,7 @@
|
|||||||
// ------------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------------
|
||||||
// 2.20 Tested in Zabbix 7.0.7 LTS and Zabbix 7.2.2
|
// 2.20 Tested in Zabbix 7.0.7 LTS and Zabbix 7.2.2
|
||||||
// 2.21 2025/02/20 - Mark Oudsen - Added #57 enhancement for manipulation of data value truncing
|
// 2.21 2025/02/20 - Mark Oudsen - Added #57 enhancement for manipulation of data value truncing
|
||||||
|
// 2.22 2025/03/19 - Mark Oudsen - Fixed #60 incorrect JSON request (boolean as text instead of bool)
|
||||||
// ------------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// (C) M.J.Oudsen, mark.oudsen@puzzl.nl
|
// (C) M.J.Oudsen, mark.oudsen@puzzl.nl
|
||||||
@@ -110,7 +111,7 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// CONSTANTS
|
// CONSTANTS
|
||||||
$cVersion = 'v2.21';
|
$cVersion = 'v2.22';
|
||||||
$cCRLF = chr(10).chr(13);
|
$cCRLF = chr(10).chr(13);
|
||||||
$maskDateTime = 'Y-m-d H:i:s';
|
$maskDateTime = 'Y-m-d H:i:s';
|
||||||
$maxGraphs = 8;
|
$maxGraphs = 8;
|
||||||
@@ -418,52 +419,27 @@
|
|||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// Check the array for information we do not want to share in any logging
|
// Check the array if it contains information that should not be logged
|
||||||
|
|
||||||
function maskOutputFields($info)
|
function maskKey(&$theValue, $theKey)
|
||||||
{
|
{
|
||||||
foreach($info as $aKey=>$aValue)
|
switch($theKey)
|
||||||
{
|
{
|
||||||
switch($aKey)
|
case 'zabbix_user':
|
||||||
{
|
case 'zabbix_user_pwd':
|
||||||
case 'zabbix_user':
|
case 'zabbix_api_user':
|
||||||
case 'zabbix_user_pwd':
|
case 'zabbix_api_pwd':
|
||||||
case 'zabbix_api_user':
|
case 'zabbix_api_token':
|
||||||
case 'zabbix_api_pwd':
|
case 'username':
|
||||||
case 'zabbix_api_token':
|
case 'password':
|
||||||
$info[$aKey] = '<masked>';
|
$theValue = '<masked>';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return($info);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check the array if it contains information that should not be logged
|
|
||||||
|
|
||||||
function maskOutputContent($info)
|
function maskOutputContent($info)
|
||||||
{
|
{
|
||||||
global $config;
|
array_walk_recursive($info,'maskKey');
|
||||||
|
|
||||||
foreach($info as $infoKey=>$infoValue)
|
|
||||||
{
|
|
||||||
if (is_array($infoValue)) { $info[$infoKey] = maskOutputContent($infoValue); }
|
|
||||||
|
|
||||||
foreach($config as $aKey=>$aValue)
|
|
||||||
{
|
|
||||||
switch($aKey)
|
|
||||||
{
|
|
||||||
case 'zabbix_user':
|
|
||||||
case 'zabbix_user_pwd':
|
|
||||||
case 'zabbix_api_user':
|
|
||||||
case 'zabbix_api_pwd':
|
|
||||||
case 'zabbix_api_token':
|
|
||||||
if ($aValue==$infoValue) { $info[$infoKey] = '<masked>'; };
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return($info);
|
return($info);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -555,7 +531,7 @@
|
|||||||
$config = readConfig(getcwd().'/config/config.json');
|
$config = readConfig(getcwd().'/config/config.json');
|
||||||
|
|
||||||
_log('# Configuration taken from config.json'.$cCRLF.
|
_log('# Configuration taken from config.json'.$cCRLF.
|
||||||
json_encode(maskOutputFields($config),JSON_PRETTY_PRINT|JSON_NUMERIC_CHECK));
|
json_encode(maskOutputContent($config),JSON_PRETTY_PRINT|JSON_NUMERIC_CHECK));
|
||||||
|
|
||||||
// --- MAIL DATA ---
|
// --- MAIL DATA ---
|
||||||
|
|
||||||
@@ -871,7 +847,7 @@
|
|||||||
$request = array('jsonrpc'=>'2.0',
|
$request = array('jsonrpc'=>'2.0',
|
||||||
'method'=>'problem.get',
|
'method'=>'problem.get',
|
||||||
'params'=>array('output'=>'extend',
|
'params'=>array('output'=>'extend',
|
||||||
'recent'=>'true',
|
'recent'=>TRUE,
|
||||||
'limit'=>1),
|
'limit'=>1),
|
||||||
'auth'=>$token,
|
'auth'=>$token,
|
||||||
'id'=>nextRequestID());
|
'id'=>nextRequestID());
|
||||||
@@ -890,7 +866,7 @@
|
|||||||
$request = array('jsonrpc'=>'2.0',
|
$request = array('jsonrpc'=>'2.0',
|
||||||
'method'=>'problem.get',
|
'method'=>'problem.get',
|
||||||
'params'=>array('output'=>'extend',
|
'params'=>array('output'=>'extend',
|
||||||
'recent'=>'false',
|
'recent'=>FALSE,
|
||||||
'limit'=>1),
|
'limit'=>1),
|
||||||
'auth'=>$token,
|
'auth'=>$token,
|
||||||
'id'=>nextRequestID());
|
'id'=>nextRequestID());
|
||||||
|
|||||||
Reference in New Issue
Block a user