Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## ChangeLog

--- develop ---
* issue: Log each template import error using its own message (#757)
* bug: Element-qualify the `.thold-pill` CSS so it outranks the single-class theme rules (e.g. `.deviceUpFull` `width:14%`) that were clipping the pill to a fixed width; status pills now size to their label on the Device Status page and everywhere else
* feature: Clicking an already-selected status pill now clears that filter (resets to All) instead of re-applying it, on the Thresholds, Device Status and Threshold Log sub-tabs
* bug: Pass a boolean (not the integer `1`) to `api_plugin_register_hook()`'s `$enable` argument so the hook registration stays type-correct under Cacti 1.3's strict `bool $enable` type-hint (the int only coerces while this file lacks `declare(strict_types=1)`)
Expand Down
35 changes: 35 additions & 0 deletions tests/Unit/TemplateImportErrorLoggingTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004-2026 The Cacti Group |
| |
| This program is free software; you can redistribute it and/or |
| modify it under the terms of the GNU General Public License |
| as published by the Free Software Foundation; either version 2 |
| of the License, or (at your option) any later version. |
+-------------------------------------------------------------------------+
| Cacti: The Complete RRDtool-based Graphing Solution |
+-------------------------------------------------------------------------+
| http://www.cacti.net/ |
+-------------------------------------------------------------------------+
*/

/** Regression for template error logs reusing a previous success message. */
final class TemplateImportErrorLoggingTest extends TestCase {
public function testEachImportErrorUsesItsOwnMessage(): void {
$source = file_get_contents(dirname(__DIR__, 2) . '/thold_templates.php');
preg_match('/foreach \(\$return_data\[\'errors\'\] as \$error\) \{(.*?)\n\t\t\}/s', $source, $loop);
$this->assertNotEmpty($loop);
$return_data = ['errors' => ['missing field', 'invalid template']];
$message = 'previous success';
$debug_data = [];
// Run the production loop body using the existing logging recorder.
foreach ($return_data['errors'] as $error) {
eval($loop[1]);
}
$this->assertSame([
'NOTE: Template Import Error!. Message: missing field',
'NOTE: Template Import Error!. Message: invalid template',
], CactiStubs::$log);
}
}
2 changes: 1 addition & 1 deletion thold_templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -2718,7 +2718,7 @@ function template_import() {
if (isset($return_data['errors'])) {
foreach ($return_data['errors'] as $error) {
$debug_data[] = '<span class="deviceDown">' . __('ERROR:', 'thold') . '</span> ' . $error;
cacti_log('NOTE: Template Import Error!. Message: ' . $message, false, 'THOLD');
cacti_log('NOTE: Template Import Error!. Message: ' . $error, false, 'THOLD');
}
}

Expand Down
Loading