()
| 81 | } |
| 82 | |
| 83 | func (s *Sensor) run() error { |
| 84 | log.Info("sensor: waiting for commands...") |
| 85 | |
| 86 | for { |
| 87 | mon, err := s.runWithoutMonitor() |
| 88 | if err != nil { |
| 89 | s.exe.HookMonitorFailed() |
| 90 | s.exe.PubEvent(event.StartMonitorFailed, |
| 91 | &event.StartMonitorFailedData{ |
| 92 | Component: event.ComMonitorRunner, //TODO: need to get to the real component |
| 93 | State: s.exe.State(), |
| 94 | Errors: []string{err.Error()}, |
| 95 | }) |
| 96 | |
| 97 | return fmt.Errorf("run sensor without monitor failed: %w", err) |
| 98 | } |
| 99 | |
| 100 | if mon == nil { |
| 101 | return nil |
| 102 | } |
| 103 | |
| 104 | s.exe.PubEvent(event.StartMonitorDone) |
| 105 | |
| 106 | if err := s.runWithMonitor(mon); err != nil { |
| 107 | return fmt.Errorf("run sensor with monitor failed: %w", err) |
| 108 | } |
| 109 | |
| 110 | s.exe.HookMonitorPostShutdown() |
| 111 | s.exe.PubEvent(event.StopMonitorDone) |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | func (s *Sensor) runWithoutMonitor() (monitor.CompositeMonitor, error) { |
| 116 | ticker := time.NewTicker(5 * time.Second) |
no test coverage detected