forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prospector_stdin.go
50 lines (39 loc) · 1.06 KB
/
prospector_stdin.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package prospector
import (
"fmt"
"github.com/elastic/beats/filebeat/harvester"
"github.com/elastic/beats/filebeat/input/file"
"github.com/elastic/beats/libbeat/logp"
)
type ProspectorStdin struct {
harvester *harvester.Harvester
started bool
}
// NewProspectorStdin creates a new stdin prospector
// This prospector contains one harvester which is reading from stdin
func NewProspectorStdin(p *Prospector) (*ProspectorStdin, error) {
prospectorer := &ProspectorStdin{
started: false,
}
var err error
prospectorer.harvester, err = p.createHarvester(file.State{Source: "-"})
if err != nil {
return nil, fmt.Errorf("Error initializing stdin harvester: %v", err)
}
return prospectorer, nil
}
func (p *ProspectorStdin) LoadStates(states []file.State) error {
return nil
}
func (p *ProspectorStdin) Run() {
// Make sure stdin harvester is only started once
if !p.started {
reader, err := p.harvester.Setup()
if err != nil {
logp.Err("Error starting stdin harvester: %s", err)
return
}
go p.harvester.Harvest(reader)
p.started = true
}
}