|
60 | 60 | $debug = false; |
61 | 61 | $force = false; |
62 | 62 | $start = microtime(true); |
63 | | -$test_id = 0; |
64 | 63 | $test_cond = ''; |
65 | 64 | $poller_id = $config['poller_id']; |
66 | 65 | $poller_int = read_config_option('poller_interval'); |
|
75 | 74 | } |
76 | 75 |
|
77 | 76 | 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; |
87 | 77 | case '-f': |
88 | 78 | case '--force': |
89 | 79 | $force = true; |
|
162 | 152 | } |
163 | 153 | } |
164 | 154 |
|
| 155 | +$max_processes = read_config_option('servcheck_processes'); |
| 156 | + |
| 157 | +if (empty($max_processes)) { |
| 158 | + $max_processes = 8; |
| 159 | +} |
| 160 | + |
165 | 161 | $params = []; |
166 | 162 | $params[] = $poller_id; |
167 | | -$sql_where = ' AND poller_id = ?'; |
| 163 | +$sql_where = 'poller_id = ? '; |
168 | 164 |
|
169 | | -if ($test_id > 0) { |
170 | | - $sql_where = ' AND id = ?'; |
171 | | - $params[] = $test_id; |
| 165 | +if (!$force) { |
| 166 | + $sql_where .= 'AND enabled = "on" '; |
172 | 167 | } |
173 | 168 |
|
174 | | -$tests = db_fetch_assoc_prepared("SELECT * |
| 169 | +$tests = db_fetch_cell_prepared("SELECT COUNT(id) |
175 | 170 | FROM plugin_servcheck_test |
176 | | - WHERE enabled = 'on' |
| 171 | + WHERE |
177 | 172 | $sql_where", |
178 | 173 | $params); |
179 | 174 |
|
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); |
181 | 180 |
|
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'); |
184 | 185 | } |
185 | 186 |
|
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); |
204 | 188 |
|
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); |
212 | 195 |
|
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' : ''); |
215 | 198 |
|
216 | | - break; |
217 | | - } else { |
218 | | - usleep(2000); |
219 | | - } |
220 | | - |
221 | | - $loop_count++; |
| 199 | + exec_background($command, $args); |
222 | 200 | } |
223 | 201 | } |
224 | 202 | } else { |
|
248 | 226 | $stat_search_ok = 0; |
249 | 227 | $stat_search_ko = 0; |
250 | 228 |
|
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 | + |
252 | 236 | foreach ($tests as $test) { |
253 | 237 | $test_last = db_fetch_row_prepared('SELECT result, result_search |
254 | 238 | FROM plugin_servcheck_log |
@@ -362,7 +346,6 @@ function display_help() { |
362 | 346 |
|
363 | 347 | print PHP_EOL . 'usage: poller_servcheck.php [--debug] [--force]' . PHP_EOL . PHP_EOL; |
364 | 348 | 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; |
367 | 350 | print '--debug - Display verbose output during execution' . PHP_EOL . PHP_EOL; |
368 | 351 | } |
0 commit comments