Skip to content

Commit a0ffaa7

Browse files
committed
csfixer
1 parent 74eb747 commit a0ffaa7

11 files changed

Lines changed: 1099 additions & 368 deletions

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* feature: Add log retention
1111
* feature: Command run only for selected tests
1212
* feature: Add configurable test timeout
13+
* feature: Add Servcheck graph template
1314
* issue: Better themes support
1415

1516
--- 0.3 ---

includes/test_snmp.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function snmp_try($test) {
2929

3030
$version = 2;
3131
$port = 161;
32-
$timeout = ($test['duration_trigger'] > 0 ? ($test['duration_trigger'] + 2) : read_config_option('servcheck_test_max_duration'))*1000;
32+
$timeout = ($test['duration_trigger'] > 0 ? ($test['duration_trigger'] + 2) : read_config_option('servcheck_test_max_duration')) * 1000;
3333

3434
// default result
3535
$results['result'] = 'error';

includes/test_ssh.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ function ssh_try($test) {
6363

6464
$ssh->setTimeout($test['duration_trigger'] > 0 ? ($test['duration_trigger'] + 2) : read_config_option('servcheck_test_max_duration'));
6565

66-
6766
if ($test['cred_id'] > 0) {
6867
$cred = db_fetch_row_prepared('SELECT * FROM plugin_servcheck_credential WHERE id = ?',
6968
[$test['cred_id']]);

poller_servcheck.php

Lines changed: 38 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
$debug = false;
6161
$force = false;
6262
$start = microtime(true);
63-
$test_id = 0;
6463
$test_cond = '';
6564
$poller_id = $config['poller_id'];
6665
$poller_int = read_config_option('poller_interval');
@@ -75,15 +74,6 @@
7574
}
7675

7776
switch ($arg) {
78-
case '--id':
79-
if (is_numeric($value) && $value > 0) {
80-
$test_id = $value;
81-
} else {
82-
print "FATAL: Option 'id' is not numeric" . PHP_EOL;
83-
exit(1);
84-
}
85-
86-
break;
8777
case '-f':
8878
case '--force':
8979
$force = true;
@@ -162,63 +152,51 @@
162152
}
163153
}
164154

155+
$max_processes = read_config_option('servcheck_processes');
156+
157+
if (empty($max_processes)) {
158+
$max_processes = 8;
159+
}
160+
165161
$params = [];
166162
$params[] = $poller_id;
167-
$sql_where = ' AND poller_id = ?';
163+
$sql_where = 'poller_id = ? ';
168164

169-
if ($test_id > 0) {
170-
$sql_where = ' AND id = ?';
171-
$params[] = $test_id;
165+
if (!$force) {
166+
$sql_where .= 'AND enabled = "on" ';
172167
}
173168

174-
$tests = db_fetch_assoc_prepared("SELECT *
169+
$tests = db_fetch_cell_prepared("SELECT COUNT(id)
175170
FROM plugin_servcheck_test
176-
WHERE enabled = 'on'
171+
WHERE
177172
$sql_where",
178173
$params);
179174

180-
$max_processes = read_config_option('servcheck_processes');
175+
$timeout = db_fetch_cell_prepared("SELECT MAX(duration_trigger*attempt)
176+
FROM plugin_servcheck_test
177+
WHERE
178+
$sql_where",
179+
$params);
181180

182-
if (empty($max_processes)) {
183-
$max_processes = 8;
181+
if ($timeout > 0) {
182+
$timeout += 2;
183+
} else {
184+
read_config_option('servcheck_test_max_duration');
184185
}
185186

186-
if (cacti_sizeof($tests)) {
187-
$loop_count = 0;
188-
189-
foreach ($tests as $test) {
190-
while (true) {
191-
$running = db_fetch_cell_prepared('SELECT COUNT(id)
192-
FROM processes
193-
WHERE tasktype = ?
194-
AND taskname = ?',
195-
['servcheck', "child:$poller_id"]);
196-
197-
if ($loop_count % 40 == 0) {
198-
servcheck_debug("There are $running processes");
199-
}
200-
201-
if ($max_processes - $running > 0) {
202-
// The timeout is the number of attempts * the duration trigger or 5 seconds plus 5 seconds overhead
203-
$timeout = $test['attempt'] * ($test['duration_trigger'] == 0 ? 5 : $test['duration_trigger']) + 5;
187+
$use_processes = min($tests, $max_processes);
204188

205-
if (!register_process_start('servcheck', $taskname, $test['id'], $timeout)) {
206-
cacti_log(sprintf('WARNING: Not Running Service Check %s it is still running', $test['name']), false, 'SERVCHECK');
207-
} else {
208-
servcheck_debug('Launching Service Check ' . $test['name']);
209-
210-
$command = read_config_option('path_php_binary');
211-
$args = '-q "' . $config['base_path'] . '/plugins/servcheck/servcheck_process.php" --id=' . $test['id'] . ($debug ? ' --debug' : '');
189+
if ($tests > 0) {
190+
for ($f = 1; $f <= $use_processes; $f++) {
191+
if (!register_process_start('servcheck', $taskname, $f, $timeout)) {
192+
cacti_log(sprintf('WARNING: Not Running Service Check %s it is still running', $test['name']), false, 'SERVCHECK');
193+
} else {
194+
servcheck_debug('Launching Servceck process ' . $f);
212195

213-
exec_background($command, $args);
214-
}
196+
$command = read_config_option('path_php_binary');
197+
$args = '-q "' . $config['base_path'] . '/plugins/servcheck/servcheck_process.php" --process=' . $f . ($debug ? ' --debug' : '') . ($force ? ' --force' : '');
215198

216-
break;
217-
} else {
218-
usleep(2000);
219-
}
220-
221-
$loop_count++;
199+
exec_background($command, $args);
222200
}
223201
}
224202
} else {
@@ -248,7 +226,13 @@
248226
$stat_search_ok = 0;
249227
$stat_search_ko = 0;
250228

251-
if (cacti_sizeof($tests)) {
229+
if ($tests > 0) {
230+
$tests = db_fetch_assoc_prepared("SELECT *
231+
FROM plugin_servcheck_test
232+
WHERE
233+
$sql_where",
234+
$params);
235+
252236
foreach ($tests as $test) {
253237
$test_last = db_fetch_row_prepared('SELECT result, result_search
254238
FROM plugin_servcheck_log
@@ -362,7 +346,6 @@ function display_help() {
362346

363347
print PHP_EOL . 'usage: poller_servcheck.php [--debug] [--force]' . PHP_EOL . PHP_EOL;
364348
print 'This binary will exec all the Service check child processes.' . PHP_EOL . PHP_EOL;
365-
print '--id - Run for a specific test' . PHP_EOL . PHP_EOL;
366-
print '--force - Force all the service checks to run now' . PHP_EOL . PHP_EOL;
349+
print '--force - Force all the service checks to run now. Run even if the job is disabled or set to run less frequently than every poller cycle' . PHP_EOL . PHP_EOL;
367350
print '--debug - Display verbose output during execution' . PHP_EOL . PHP_EOL;
368351
}

0 commit comments

Comments
 (0)