2 Configuration - moudsen/mailGraph GitHub Wiki
Zabbix API bearer token
Apache
- Please make sure the following is configured in your Apache configuration (by default included in php.conf or similar in case of FPM):
- SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
 
NGINX
- Please make aure the following is configured in you NGÏNX configuration:
- proxy_set_header Authorization $http_authorization;
- proxy_pass_header Authorization;
 
Zabbix API token issue demonstration
- When this setting is missing in Apache or NGINX, the zabbix_api_tokenmethod will fail as the bearer token is not passed into Zabbix:- 2025-03-10 01:47:42 : > Adding API bearer token
- 2025-03-10 01:47:42 : > Cleared AUTH information
- 2025-03-10 01:47:42 : > Received 101 bytes
- 2025-03-10 01:47:42 : > Event data
- {
- "jsonrpc": 2,
- "error": {
- "code": -32602,
- "message": "Invalid params.",
- "data": "Not authorized."
- },
- "id": 2
- }
 
Detailed information on this behaviour available at https://support.zabbix.com/si/jira.issueviews:issue-html/ZBX-22952/ZBX-22952.html
MailGraph
- Goto your /config directory you've created in the Installation step.
- Two ways to configure the config.json file:
- with config.php or
- with your favorite text editor (note that you must have knowledge of JSON format to use this option! You can validate your code by executing the LIST command with config.php as per below)
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1# Using config.php
| Command | Description |
| :--- | :--- |
| php config.php config.json list| List the configured options | |php config.php config.json replace 'key_name' 'new_value'| Change any option (note the usage of the single quotes!) | |php config.php add 'key_name' 'new_value'| Add options with (note the usage of the single quotes!) |
 
Please note that for using the API token method (available in Zabbix 7.0 onwards) to login to Zabbix you need to add the "zabbix_api_token" element to config.json. After defining a token, the "zabbix_api_user" and "zabbix_api_pwd" are not used/ignored. For mailGraph to pick up the actual grahps from Zabbix, the "zabbix_user" and "zabbix_user_pwd" are still required as this section in the Zabbix library does not support the use of an API token (yet?).
Configurable options in config.json (v2.21)
| Options | Description | 
|---|---|
| script_baseurl | Should point to the URL of your directory where MailGraph is installed (ie. "https://mydomain.com/"). Note the ending '/'! | 
| zabbix_userandzabbix_user_pwd | Required for fetching the Zabbix graphs. Must be a Zabbix SuperAdmin user/password you need to have/create to login to Zabbix. | 
| zabbix_api_userandzabbix_api_pwd | Required to login into Zabbix API to grab the actual information of an event and related records. Must also be a Zabbix SuperAdmin user/password. When ommitted zabbix_user and zabbix_user_pwd will be used. | 
| zabbix_api_token | Zabbix 7 and onwards now support API bearer token login. If configured, zabbix_api_userandzabbix_api_pwdare ignored. | 
| mail_from | Must be a valid e-mail address which represents the 'from' address in the mails that are sent (ie. "[email protected]") that is acceptable by your mail server. Note: replaced by smtp_from_addressbut remains in place for backward compatibility. Ifsmtp_from_addressis definedmail_fromwill be ignored. | 
| period | Must be a valid Zabbix period (like "1d", "1w" or "48h") that will be applied to the graph. Default is "48h" when not specified. | 
| period_header | Is the header displayed above the graph. For example "Last 48 hours". Defaults to 'period' when not specified. | 
| graph_match | Is the matching method while searching for graphs ('Exact','Other'). | 
| item_value_truncate | Enables or disables ITEM value truncing (set to zero to disable). Refer to Tags for configuration for specific Triggers only. | 
| smtp_serverandsmtp_port | To define the SMTP server and port to be used. | 
| smtp_security | To define the SMTP transport methode ('none','starttls','smtps'; defaults to 'none'). | 
| smtp_strict | Is TLS certificate checking strict? ('yes','no'; defaults to 'yes'). | 
| smtp_usernameandsmtp_password | To define the username and password used for accessing the SMTP server. | 
| smtp_from_address | To define the sender e-mail address from mailGraph. If not set the default user e-mail address as configured for the mailer system will be used. If not set mail_fromwill be used (this allows for backward compatibility when usingmail_fromwith mailGraph<v2.14. | 
| smtp_from_name | To define the sender identification name. If not set the default "mailGraph" will be used. | 
| smtp_reply_address | To define the e-mail address to send responses to when replying to a mailGraph message. Does not generate a reply-to if not set. | 
| smtp_reply_name | To define a name with the reply-to address. Default to "mailGraph feedback" if not defined. | 
| retention_logsandretention_images | To define the number of days before old LOG and IMAGES files are removed (details in A- Cleaning up LOG and IMAGES directory) | 
Note that config.json can also hold entries starting with "cli_". Such entries are used in case of 8- Troubleshooting.
Load the Media Type "MailGraph" into Zabbix
- Login to your Zabbix instance
- Goto "Administration" => "Media types"
- Import the "mailGraph.xml" file
- Edit the new media type
- Configure some of the parameters associated
| Parameter | Description | 
|---|---|
| baseURL | Must contain your Zabbix URL (ie. "https://mydomain.com/zabbix/"). Note the ending '/'! | 
| graphWidthandGraphHeight | To size the graph to your convenience (defaults to 450,120). | 
| showLegend | You can switch the graph legend on or off (1=on, 0=off). | 
| subject | You can change the subject of the e-mail that is sent (note that the markup can be a combination of Zabbix MACRO and/or TWIG notation!). | 
| URL | Is the url to the mailGraph script (ie. "https://mydomain.com/mailGraph.php"). | 
| HTTPProxy | Proxy URL (i.e. 10.20.30.40:8080) that will be used by MailGraph to reach Zabbix. | 
| period | Define the period of a Graph (Zabbix time notation, i.e. "4h" for 4 hours). | 
| period_header | Define the header that will be displayed above the Graph (i.e. "4 hours"). | 
| periods | Define multiple periods (max 4) for embedding multiple periods of the same graph in the message (i.e. "10m,4h,1d,7d"). | 
| periods_header | Headers associated to these periods (i.e. "Last 10 minutes,Last 4 hours,Last day,Last 7 days"). | 
| debug | To attach debug logging to the mail message (0=off,1=on). | 
Save your configuration with "Update".
Some of the defined default parameters (like {EVENT.ID}) are important to MailGraph functioning correctly. Please do not touch or change these parameters!
Zabbix Actions configuration
At this point the Media type is ready for configuration under "actions" as per the regular way of Zabbix alert processing. Please refer to the manual how to configure.