(ctx context.Context, outFile string, fast bool)
| 513 | } |
| 514 | |
| 515 | func (cli *cliSupport) dump(ctx context.Context, outFile string, fast bool) error { |
| 516 | var skipCAPI, skipLAPI, skipAgent bool |
| 517 | |
| 518 | collector := &StringHook{ |
| 519 | LogLevels: log.AllLevels, |
| 520 | } |
| 521 | log.AddHook(collector) |
| 522 | |
| 523 | cfg := cli.cfg() |
| 524 | |
| 525 | if outFile == "" { |
| 526 | outFile = filepath.Join(os.TempDir(), "crowdsec-support.zip") |
| 527 | } |
| 528 | |
| 529 | w := bytes.NewBuffer(nil) |
| 530 | zipWriter := zip.NewWriter(w) |
| 531 | |
| 532 | db, err := require.DBClient(ctx, cfg.DbConfig) |
| 533 | if err != nil { |
| 534 | log.Warn(err) |
| 535 | } |
| 536 | |
| 537 | if err = cfg.LoadAPIServer(true, false); err != nil { |
| 538 | log.Warnf("could not load LAPI, skipping CAPI check") |
| 539 | |
| 540 | skipCAPI = true |
| 541 | } |
| 542 | |
| 543 | if err = cfg.LoadCrowdsec(); err != nil { |
| 544 | log.Warnf("could not load agent config, skipping crowdsec config check") |
| 545 | |
| 546 | skipAgent = true |
| 547 | } |
| 548 | |
| 549 | hub, err := require.Hub(cfg, nil) |
| 550 | if err != nil { |
| 551 | log.Warn("Could not init hub, running on LAPI? Hub related information will not be collected") |
| 552 | // XXX: lapi status check requires scenarios, will return an error |
| 553 | } |
| 554 | |
| 555 | if cfg.API.Client == nil || cfg.API.Client.Credentials == nil { |
| 556 | log.Warn("no agent credentials found, skipping LAPI connectivity check") |
| 557 | |
| 558 | skipLAPI = true |
| 559 | } |
| 560 | |
| 561 | if cfg.API.Server == nil || cfg.API.Server.OnlineClient == nil || cfg.API.Server.OnlineClient.Credentials == nil { |
| 562 | log.Warn("no CAPI credentials found, skipping CAPI connectivity check") |
| 563 | |
| 564 | skipCAPI = true |
| 565 | } |
| 566 | |
| 567 | if err = cli.dumpMetrics(ctx, db, zipWriter); err != nil { |
| 568 | log.Warn(err) |
| 569 | } |
| 570 | |
| 571 | if err = cli.dumpSystemInfo(zipWriter); err != nil { |
| 572 | log.Warnf("could not collect system information: %s", err) |
no test coverage detected