smtp server configuration via config.json - fixed config template bug (v1.12)

This commit is contained in:
Mark Oudsen 2021-03-01 18:13:32 +01:00
parent 7e1c5e5d98
commit 1fb10ed089
2 changed files with 20 additions and 7 deletions

View File

@ -6,11 +6,13 @@
"cli_eventValue": 0, "cli_eventValue": 0,
"cli_duration": 0, "cli_duration": 0,
"cli_recipient": "recipient@domain.com", "cli_recipient": "recipient@domain.com",
"cli_subject": "\"{{ HOST_NAME }}\": ({{ EVENT_SEVERITY }}) {{ EVENT_NAME }}" "cli_subject": "{{ HOST_NAME }}: ({{ EVENT_SEVERITY }}) {{ EVENT_NAME }}",
"cli_baseURL": "https:\/\/domain.com\/zabbix\/", "cli_baseURL": "https:\/\/domain.com\/zabbix\/",
"zabbix_user": "alogicalusername", "zabbix_user": "alogicalusername",
"zabbix_user_pwd": "astrongpassword", "zabbix_user_pwd": "astrongpassword",
"zabbix_api_user": "alogicalusername", "zabbix_api_user": "alogicalusername",
"zabbix_api_pwd": "astrongpassword", "zabbix_api_pwd": "astrongpassword",
"mail_from": "sender@domain.com" "mail_from": "sender@domain.com",
"smtp_server": "localhost",
"smtp_port": 25
} }

View File

@ -12,6 +12,7 @@
// 1.01 2021/02/27 - Mark Oudsen - Enhanced search for associated graphs to an item // bug fixes // 1.01 2021/02/27 - Mark Oudsen - Enhanced search for associated graphs to an item // bug fixes
// 1.10 2021/02/27 - Mark Oudsen - Moved all configuration outside code // 1.10 2021/02/27 - Mark Oudsen - Moved all configuration outside code
// 1.11 2021/02/28 - Mark Oudsen - Bugfixes // 1.11 2021/02/28 - Mark Oudsen - Bugfixes
// 1.12 2021/03/01 - Mark Oudsen - Bugfixes - Adding mail server configuration via config.json
// ------------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------------
// //
// (C) M.J.Oudsen, mark.oudsen@puzzl.nl // (C) M.J.Oudsen, mark.oudsen@puzzl.nl
@ -37,7 +38,7 @@
// CONSTANTS // CONSTANTS
$cVersion = 'v1.11'; $cVersion = 'v1.12';
$cCRLF = chr(10).chr(13); $cCRLF = chr(10).chr(13);
$maskDateTime = 'Y-m-d H:i:s'; $maskDateTime = 'Y-m-d H:i:s';
@ -297,6 +298,8 @@
// [CONFIGURE] Change only when you want to place your config file somewhere else ... // [CONFIGURE] Change only when you want to place your config file somewhere else ...
$config = readConfig(getcwd().'/config/config.json'); $config = readConfig(getcwd().'/config/config.json');
_log('# Configuration taken from config.json'.$cCRLF.json_encode($config,JSON_PRETTY_PRINT|JSON_NUMERIC_CHECK));
// Read POST data // Read POST data
$problemJSON = file_get_contents('php://input'); $problemJSON = file_get_contents('php://input');
$problemData = json_decode($problemJSON,TRUE); $problemData = json_decode($problemJSON,TRUE);
@ -323,6 +326,10 @@
} }
} }
_log('# Data passed from Zabbix'.$cCRLF.json_encode($problemData,JSON_PRETTY_PRINT|JSON_NUMERIC_CHECK));
# --- Process into p_ variables for usage across the script
if (!isset($problemData['itemId'])) { echo "Missing ITEM ID?\n"; die; } if (!isset($problemData['itemId'])) { echo "Missing ITEM ID?\n"; die; }
$p_itemId = intval($problemData['itemId']); $p_itemId = intval($problemData['itemId']);
@ -356,7 +363,11 @@
$p_showLegend = 0; $p_showLegend = 0;
if (isset($problemData['showLegend'])) { $p_showLegend = intval($problemData['showLegend']); } if (isset($problemData['showLegend'])) { $p_showLegend = intval($problemData['showLegend']); }
_log('# Data passed from Zabbix'.$cCRLF.json_encode($problemData,JSON_PRETTY_PRINT|JSON_NUMERIC_CHECK)); $p_smtp_server = 'localhost';
if (isset($config['smtp_server'])) { $p_smtp_server = $config['smtp_server']; }
$p_smtp_port = 25;
if (isset($config['smtp_port'])) { $p_smtp_port = $config['smtp_port']; }
// --- CONFIGURATION --- // --- CONFIGURATION ---
@ -676,7 +687,7 @@
_log('# Setting up mailer'); _log('# Setting up mailer');
$transport = (new Swift_SmtpTransport('mail.puzzl.nl', 25)); $transport = (new Swift_SmtpTransport($p_smtp_server, $p_smtp_port));
$mailer = new Swift_Mailer($transport); $mailer = new Swift_Mailer($transport);
$message = (new Swift_Message()); $message = (new Swift_Message());