WriteProtoAgentEvent writes v1.AgentEvent into the output writer.
(r *observerpb.GetAgentEventsResponse)
| 599 | |
| 600 | // WriteProtoAgentEvent writes v1.AgentEvent into the output writer. |
| 601 | func (p *Printer) WriteProtoAgentEvent(r *observerpb.GetAgentEventsResponse) error { |
| 602 | e := r.GetAgentEvent() |
| 603 | if e == nil { |
| 604 | return errors.New("not an agent event") |
| 605 | } |
| 606 | |
| 607 | switch p.opts.output { |
| 608 | case JSONLegacyOutput: |
| 609 | return p.jsonEncoder.Encode(e) |
| 610 | case JSONPBOutput: |
| 611 | return p.jsonEncoder.Encode(r) |
| 612 | case DictOutput: |
| 613 | w := p.createStdoutWriter() |
| 614 | |
| 615 | if p.line != 0 { |
| 616 | w.print(dictSeparator) |
| 617 | } |
| 618 | |
| 619 | w.print(" TIMESTAMP: ", fmtTimestamp(p.opts.timeFormat, r.GetTime()), newline) |
| 620 | if p.opts.nodeName { |
| 621 | w.print(" NODE: ", r.GetNodeName(), newline) |
| 622 | } |
| 623 | w.print( |
| 624 | " TYPE: ", e.GetType(), newline, |
| 625 | " DETAILS: ", getAgentEventDetails(e, p.opts.timeFormat), newline, |
| 626 | ) |
| 627 | if w.err != nil { |
| 628 | return fmt.Errorf("failed to write out agent event: %w", w.err) |
| 629 | } |
| 630 | case TabOutput: |
| 631 | w := p.createTabWriter() |
| 632 | if p.line == 0 { |
| 633 | w.print("TIMESTAMP", tab) |
| 634 | if p.opts.nodeName { |
| 635 | w.print("NODE", tab) |
| 636 | } |
| 637 | w.print( |
| 638 | "TYPE", tab, |
| 639 | "DETAILS", newline, |
| 640 | ) |
| 641 | } |
| 642 | w.print(fmtTimestamp(p.opts.timeFormat, r.GetTime()), tab) |
| 643 | if p.opts.nodeName { |
| 644 | w.print(r.GetNodeName(), tab) |
| 645 | } |
| 646 | w.print( |
| 647 | e.GetType(), tab, |
| 648 | getAgentEventDetails(e, p.opts.timeFormat), newline, |
| 649 | ) |
| 650 | if w.err != nil { |
| 651 | return fmt.Errorf("failed to write out agent event: %w", w.err) |
| 652 | } |
| 653 | case CompactOutput: |
| 654 | w := p.createStdoutWriter() |
| 655 | var node string |
| 656 | |
| 657 | if p.opts.nodeName { |
| 658 | node = fmt.Sprintf(" [%s]", r.GetNodeName()) |
no test coverage detected