From 0a210208e097ec9c2e8e103aa0561a14ba91c719 Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Mon, 27 Aug 2018 15:02:36 -0500 Subject: [PATCH] Fixed alert notes (#9093) Fix test-template.php to work like the actual alert code. DO NOT DELETE THIS TEXT #### Please note > Please read this information carefully. You can run `./scripts/pre-commit.php` to check your code before submitting. - [x] Have you followed our [code guidelines?](http://docs.librenms.org/Developing/Code-Guidelines/) #### Testers If you would like to test this pull request then please run: `./scripts/github-apply `, i.e `./scripts/github-apply 5926` --- includes/alerts.inc.php | 1 + scripts/test-template.php | 17 +++++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/includes/alerts.inc.php b/includes/alerts.inc.php index dfea835d27..de96bc8c19 100644 --- a/includes/alerts.inc.php +++ b/includes/alerts.inc.php @@ -688,6 +688,7 @@ function loadAlerts($where) } else { $alert['alert_id'] = $alert_status['id']; $alert['state'] = $alert_status['state']; + $alert['note'] = $alert_status['note']; $alert['details'] = json_decode(gzuncompress($alert['details']), true); $alerts[] = $alert; } diff --git a/scripts/test-template.php b/scripts/test-template.php index 0b9069f90f..6581a7bb3e 100755 --- a/scripts/test-template.php +++ b/scripts/test-template.php @@ -14,15 +14,20 @@ if (isset($options['t']) && isset($options['h']) && isset($options['r'])) { $template_id = $options['t']; $device_id = ctype_digit($options['h']) ? $options['h'] : getidbyname($options['h']); - $rule_id = $options['r']; + $rule_id = (int)$options['r']; + + $where = 'alerts.device_id=' . $device_id . ' && alerts.rule_id=' . $rule_id; if (isset($options['s'])) { - $alert = dbFetchRow('SELECT alert_log.id,alert_log.rule_id,alert_log.device_id,alert_log.state,alert_log.details,alert_log.time_logged,alert_rules.rule,alert_rules.severity,alert_rules.extra,alert_rules.name FROM alert_log,alert_rules WHERE alert_log.rule_id = alert_rules.id && alert_log.device_id = ? && alert_log.rule_id = ? && alert_rules.disabled = 0 && alert_log.state=? ORDER BY alert_log.id DESC LIMIT 1', array($device_id, $rule_id, intval($options['s']))); + $where .= ' alerts.state=' . (int)$options['s']; } - if (!isset($alert)) { - $alert = dbFetchRow('SELECT alert_log.id,alert_log.rule_id,alert_log.device_id,alert_log.state,alert_log.details,alert_log.time_logged,alert_rules.rule,alert_rules.severity,alert_rules.extra,alert_rules.name FROM alert_log,alert_rules WHERE alert_log.rule_id = alert_rules.id && alert_log.device_id = ? && alert_log.rule_id = ? && alert_rules.disabled = 0 ORDER BY alert_log.id DESC LIMIT 1', array($device_id, $rule_id)); + + $alerts = loadAlerts($where); + if (empty($alerts)) { + echo "No alert found, make sure to select an active alert.\n"; + exit(2); } - $alert['details'] = json_decode(gzuncompress($alert['details']), true); - $obj = DescribeAlert($alert); + + $obj = DescribeAlert($alerts[0]); if (isset($options['p'])) { $obj['transport'] = $options['p']; }