From b30161b80c7585fcdff87e4e236d883d64dbdf39 Mon Sep 17 00:00:00 2001 From: Neil Lathwood Date: Wed, 8 Mar 2017 04:14:51 +0000 Subject: [PATCH] fix: Correct the use of GetContacts() #5012 (#6059) * fix: Correct the use of GetContacts() #5012 * small update * array set * Properly check the results --- alerts.php | 7 ++++++- html/includes/output/query.inc.php | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/alerts.php b/alerts.php index 112a9ec1a0..b59ad5fcc6 100755 --- a/alerts.php +++ b/alerts.php @@ -111,7 +111,12 @@ function IssueAlert($alert) } if ($config['alert']['fixed-contacts'] == false) { - $alert['details']['contacts'] = GetContacts($alert['details']['rule']); + if (empty($alert['query'])) { + $alert['query'] = GenSQL($alert['rule']); + } + $sql = $alert['query']; + $qry = dbFetchRows($sql, array($alert['device_id'])); + $alert['details']['contacts'] = GetContacts($qry); } $obj = DescribeAlert($alert); diff --git a/html/includes/output/query.inc.php b/html/includes/output/query.inc.php index 377cc90de3..08f0530389 100644 --- a/html/includes/output/query.inc.php +++ b/html/includes/output/query.inc.php @@ -38,6 +38,7 @@ switch ($type) { $device = device_by_id_cache($device_id); $rules = GetRules($device_id); $output = ''; + $results = array(); foreach ($rules as $rule) { if (empty($rule['query'])) { $rule['query'] = GenSQL($rule['rule']); @@ -45,6 +46,7 @@ switch ($type) { $sql = $rule['query']; $qry = dbFetchRow($sql, array($device_id)); if (is_array($qry)) { + $results[] = $qry; $response = 'matches'; } else { $response = 'no match'; @@ -55,7 +57,7 @@ switch ($type) { $output .= 'Rule match: ' . $response . PHP_EOL . PHP_EOL; } if ($config['alert']['transports']['mail'] === true) { - $contacts = GetContacts($rules); + $contacts = GetContacts($results); if (count($contacts) > 0) { $output .= 'Found ' . count($contacts) . ' contacts to send alerts to.' . PHP_EOL; }