in dev/import-beats/streams.go [49:115]
func createLogStreams(modulePath, moduleTitle, dataStreamName string) ([]packages.Stream, agentContent, error) {
manifestPath := filepath.Join(modulePath, dataStreamName, "manifest.yml")
manifestFile, err := ioutil.ReadFile(manifestPath)
if err != nil {
return nil, agentContent{}, errors.Wrapf(err, "reading manifest file failed (path: %s)", manifestPath)
}
vars, err := createLogStreamVariables(manifestFile)
if err != nil {
return nil, agentContent{}, errors.Wrapf(err, "creating log stream variables failed (path: %s)", manifestPath)
}
configFilePaths, err := filepath.Glob(filepath.Join(modulePath, dataStreamName, "config", "*.*"))
if err != nil {
return nil, agentContent{}, errors.Wrapf(err, "locating config files failed (modulePath: %s, dataStreamName: %s)", modulePath, dataStreamName)
}
if len(configFilePaths) == 0 {
return nil, agentContent{}, fmt.Errorf("expected at least one config file (modulePath: %s, dataStreamName: %s)", modulePath, dataStreamName)
}
var streams []packages.Stream
var agent agentContent
for _, configFilePath := range configFilePaths {
fileName := extractInputConfigFilename(configFilePath)
fileContent, err := ioutil.ReadFile(configFilePath)
if err != nil {
return nil, agentContent{}, errors.Wrapf(err, "reading file from config directory failed (filePath: %s)", configFilePath)
}
if strings.HasSuffix(configFilePath, ".js") {
agent.streams = append(agent.streams, streamContent{
targetFileName: fileName,
body: fileContent,
})
continue
}
root, err := parseStreamConfig(fileContent)
if err != nil {
return nil, agentContent{}, errors.Wrapf(err, "parsing stream config failed")
}
for _, inputType := range root.inputTypes() {
aType := inputType
if inputType == "log" {
aType = "logfile"
}
targetFileName := inputType + ".yml.hbs"
inputConfig := root.configForInput(inputType)
agent.streams = append(agent.streams, streamContent{
targetFileName: targetFileName,
body: inputConfig,
})
streams = append(streams, packages.Stream{
Input: aType,
Title: fmt.Sprintf("%s %s logs (%s)", moduleTitle, dataStreamName, inputType),
Description: fmt.Sprintf("Collect %s %s logs using %s input", moduleTitle, dataStreamName, inputType),
TemplatePath: targetFileName,
Vars: root.filterVarsForInput(inputType, vars),
})
}
}
return streams, agent, nil
}