Run a task with a file descriptor corresponding to its log file
(self, task)
| 320 | log("Exit code %d" % result) |
| 321 | |
| 322 | def run(self, task): |
| 323 | """Run a task with a file descriptor corresponding to its log file""" |
| 324 | command_to_print = getattr(task, "command_to_print", task.command) |
| 325 | if task.will_run(): |
| 326 | log("%s (%s) - " % (task.description, command_to_print), end="") |
| 327 | if task.privileged and os.getuid() != 0: |
| 328 | log("skipped (needs root privs)") |
| 329 | return |
| 330 | |
| 331 | if hasattr(task, "log_file"): |
| 332 | filename = task.log_file |
| 333 | else: |
| 334 | filename = self.default_name |
| 335 | |
| 336 | fp = self.get_file(filename) |
| 337 | if not task.no_header: |
| 338 | self.header(fp, task.description, command_to_print) |
| 339 | |
| 340 | for i in range(task.num_samples): |
| 341 | if i > 0: |
| 342 | log( |
| 343 | "Taking sample %d after %f seconds - " % (i + 1, task.interval), |
| 344 | end="", |
| 345 | ) |
| 346 | time.sleep(task.interval) |
| 347 | result = task.execute(fp) |
| 348 | self.log_result(result) |
| 349 | fp.flush() |
| 350 | |
| 351 | elif self.verbosity >= 2: |
| 352 | log( |
| 353 | 'Skipping "%s" (%s): not for platform %s' |
| 354 | % (task.description, command_to_print, sys.platform) |
| 355 | ) |
| 356 | |
| 357 | def redact_and_zip(self, filename: str, log_type: str, salt: str, node: str): |
| 358 | """ |