diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4e97819..01e685b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -20,6 +20,7 @@
* feature#341: Add info about disabled notify admin
* feature#350: Add poller host errors (Cacti 1.3+)
* Add CI workflow and Custom Agents
+* issue: Fix servcheck plugin panel
--- 4.0.4 ---
diff --git a/panellib/misc.php b/panellib/misc.php
index 2e337af..18c5d5b 100644
--- a/panellib/misc.php
+++ b/panellib/misc.php
@@ -488,18 +488,27 @@ function servcheck($panel, $user_id) {
$all = db_fetch_cell('SELECT COUNT(*) FROM plugin_servcheck_test');
$disa = db_fetch_cell("SELECT COUNT(*) FROM plugin_servcheck_test WHERE enabled != 'on'");
+ // servcheck < 0.3 uses another name
$dncolumn = db_fetch_cell("SELECT COLUMN_NAME FROM information_schema.columns
WHERE TABLE_NAME = 'plugin_servcheck_test' AND COLUMN_NAME = 'display_name'");
- // servcheck < 0.3 uses another name
if (!$dncolumn) {
$dncolumn = 'name';
}
- $tests = db_fetch_assoc('SELECT ' . $dncolumn . ' as name, type, id, lastcheck FROM plugin_servcheck_test');
+
+ // servcheck < 0.4 uses another name
+ $lchcolumn = db_fetch_cell("SELECT COLUMN_NAME FROM information_schema.columns
+ WHERE TABLE_NAME = 'plugin_servcheck_test' AND COLUMN_NAME = 'last_check'");
+
+ if (!$lchcolumn) {
+ $lchcolumn = 'lastcheck';
+ }
+
+ $tests = db_fetch_assoc('SELECT ' . $dncolumn . ' as name, type, id, ' . $lchcolumn . ' FROM plugin_servcheck_test');
foreach ($tests as $test) {
$state = db_fetch_cell_prepared('SELECT result FROM plugin_servcheck_log
- WHERE test_id = ? ORDER BY lastcheck DESC LIMIT 1',
+ WHERE test_id = ? ORDER BY id DESC LIMIT 1',
[$test['id']]);
if ($state == 'ok') {
@@ -516,11 +525,12 @@ function servcheck($panel, $user_id) {
$panel['data'] .= __('Number of checks (all/disabled): ', 'intropage') . $all . ' / ' . $disa . '
';
$panel['data'] .= __('Status (ok/error): ', 'intropage') . $ok . ' / ' . $ko . '
';
- $logs = db_fetch_assoc('SELECT psl.lastcheck as `lastcheck`, result, error, ' . $dncolumn . ' as name, type,
- UNIX_TIMESTAMP(psl.lastcheck) AS secs
+ $logs = db_fetch_assoc('SELECT psl.' . $lchcolumn . ' as `lastcheck`, result, error, ' . $dncolumn . ' as name, type,
+ UNIX_TIMESTAMP(psl.' . $lchcolumn . ') AS secs
FROM plugin_servcheck_log AS psl
LEFT JOIN plugin_servcheck_test AS pst
- ON psl.test_id = pst.id
+ ON psl.test_id = pst.id
+ ORDER BY psl.id DESC
LIMIT ' . ($lines - 4));
if (cacti_sizeof($logs) > 0) {
@@ -588,20 +598,28 @@ function servcheck_detail() {
'detail' => '',
];
+ // servcheck < 0.3 uses another name
$dncolumn = db_fetch_cell("SELECT COLUMN_NAME FROM information_schema.columns
WHERE TABLE_NAME = 'plugin_servcheck_test' AND COLUMN_NAME = 'display_name'");
- // servcheck < 0.3 uses another name
if (!$dncolumn) {
$dncolumn = 'name';
}
- $logs = db_fetch_assoc('SELECT psl.lastcheck as `lastcheck`, result, error, ' . $dncolumn . ', type,
- UNIX_TIMESTAMP(psl.lastcheck) AS secs
+ // servcheck < 0.4 uses another name
+ $lchcolumn = db_fetch_cell("SELECT COLUMN_NAME FROM information_schema.columns
+ WHERE TABLE_NAME = 'plugin_servcheck_test' AND COLUMN_NAME = 'last_check'");
+
+ if (!$lchcolumn) {
+ $lchcolumn = 'lastcheck';
+ }
+
+ $logs = db_fetch_assoc('SELECT psl.' . $lchcolumn . ' as `lastcheck`, result, result_search, error, ' . $dncolumn . ', type,
+ UNIX_TIMESTAMP(psl.' . $lchcolumn . ') AS secs
FROM plugin_servcheck_log AS psl
LEFT JOIN plugin_servcheck_test AS pst
ON psl.test_id = pst.id
- ORDER BY psl.lastcheck DESC
+ ORDER BY psl.' . $lchcolumn . ' DESC
LIMIT 40');
$panel['detail'] = '
| ' . __('Test', 'intropage') . ' | ' . '' . __('Type', 'intropage') . ' | ' . '' . __('Result', 'intropage') . ' | ' . + '' . __('Search result', 'intropage') . ' | ' . '' . __('Error', 'intropage') . ' | ' . '' . __('Failed') . ' | '; } - $panel['detail'] .= '' . $log['result'] . ' | '; + $panel['detail'] .= '' . $log['result_search'] . ' | '; $panel['detail'] .= '' . $log['error'] . ' | '; if ($color == 'red') {
|---|