Skip to content

Commit dc75cc3

Browse files
TheWitnessCopilot
andauthored
Fixing SQL issues when there are no service checks to perform (Cacti#72)
* Small issue with no tests * Syntax error in SQL * Update poller_servcheck.php Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 69c3f60 commit dc75cc3

1 file changed

Lines changed: 21 additions & 19 deletions

File tree

poller_servcheck.php

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@
164164

165165
$params = [];
166166
$params[] = $poller_id;
167-
$sql_where = 'AND poller_id = ?';
167+
$sql_where = ' AND poller_id = ?';
168168

169169
if ($test_id > 0) {
170170
$sql_where = ' AND id = ?';
@@ -173,8 +173,8 @@
173173

174174
$tests = db_fetch_assoc_prepared("SELECT *
175175
FROM plugin_servcheck_test
176-
WHERE enabled = 'on',
177-
$sql_where",
176+
WHERE enabled = 'on'
177+
$sql_where",
178178
$params);
179179

180180
$max_processes = read_config_option('servcheck_processes');
@@ -248,23 +248,25 @@
248248
$stat_search_ok = 0;
249249
$stat_search_ko = 0;
250250

251-
foreach ($tests as $test) {
252-
$test_last = db_fetch_row_prepared('SELECT result, result_search
253-
FROM plugin_servcheck_log
254-
WHERE test_id = ?
255-
ORDER BY id DESC LIMIT 1',
256-
[$test['id']]);
257-
258-
if (isset($test_last['result']) && ($test_last['result'] == 'ok' || $test_last['result'] == 'not yet')) {
259-
$stat_ok++;
260-
} else {
261-
$stat_ko++;
262-
}
251+
if (cacti_sizeof($tests)) {
252+
foreach ($tests as $test) {
253+
$test_last = db_fetch_row_prepared('SELECT result, result_search
254+
FROM plugin_servcheck_log
255+
WHERE test_id = ?
256+
ORDER BY id DESC LIMIT 1',
257+
[$test['id']]);
258+
259+
if (isset($test_last['result']) && ($test_last['result'] == 'ok' || $test_last['result'] == 'not yet')) {
260+
$stat_ok++;
261+
} else {
262+
$stat_ko++;
263+
}
263264

264-
if (isset($test_last['result_search']) && ($test_last['result_search'] == 'ok' || $test_last['result_search'] == 'not yet ' || $test_last['result_search'] == 'not tested')) {
265-
$stat_search_ok++;
266-
} else {
267-
$stat_search_ko++;
265+
if (isset($test_last['result_search']) && ($test_last['result_search'] == 'ok' || $test_last['result_search'] == 'not yet' || $test_last['result_search'] == 'not tested')) {
266+
$stat_search_ok++;
267+
} else {
268+
$stat_search_ko++;
269+
}
268270
}
269271
}
270272

0 commit comments

Comments
 (0)