Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions cmd/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,17 @@ func GenRecipeCmd() *cobra.Command {
"group:core": "true",
},
RunE: func(cmd *cobra.Command, args []string) error {
sinkList := strings.Split(sinks, ",")
procList := strings.Split(processors, ",")

var sinkList []string
var procList []string

if sinks != "" {
sinkList = strings.Split(sinks, ",")
}

if processors != "" {
procList = strings.Split(processors, ",")
}
return generator.Recipe(args[0], extractor, sinkList, procList)
},
}
Expand Down
42 changes: 28 additions & 14 deletions generator/recipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,39 @@ type Template struct {
}

// Recipe checks if the recipe is valid and returns a Template
func Recipe(name string, source string, sinks []string, processors []string) error {
func Recipe(name string, source string, sinks []string, processors []string) (err error) {
tem := Template{
Name: name,
Source: make(map[string]string),
Sinks: make(map[string]string),
Processors: make(map[string]string),
Name: name,
}

sinfo, _ := registry.Extractors.Info(source)
tem.Source[source] = indent.String(sinfo.SampleConfig, size)

for _, sink := range sinks {
info, _ := registry.Sinks.Info(sink)
tem.Sinks[sink] = indent.String(info.SampleConfig, size+3)
if source != "" {
tem.Source = make(map[string]string)
sinfo, err := registry.Extractors.Info(source)
if err != nil {
return err
}
tem.Source[source] = indent.String(sinfo.SampleConfig, size)
}
if len(sinks) > 0 {
tem.Sinks = make(map[string]string)
for _, sink := range sinks {
info, err := registry.Sinks.Info(sink)
if err != nil {
return err
}
tem.Sinks[sink] = indent.String(info.SampleConfig, size+3)
}
}

for _, procc := range processors {
info, _ := registry.Processors.Info(procc)
tem.Processors[procc] = indent.String(info.SampleConfig, size+3)
if len(processors) > 0 {
tem.Processors = make(map[string]string)
for _, procc := range processors {
info, err := registry.Processors.Info(procc)
if err != nil {
return err
}
tem.Processors[procc] = indent.String(info.SampleConfig, size+3)
}
}

tmpl, err := template.ParseFS(file, "*")
Expand Down
10 changes: 9 additions & 1 deletion generator/recipe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,21 @@ source:
type: {{$key}}
config: {{$value}}
{{- end }}
{{- if ne (len .Sinks) 0 }}
sinks:
{{- range $key, $value := .Sinks }}
- name: {{$key}}
{{- if $value}}
config: {{$value}}
{{- end }}
{{- end }}
{{- end }}
{{- if ne (len .Processors) 0 }}
processors:
{{- range $key, $value := .Processors }}
- name: {{$key}}
{{- if $value}}
config: {{$value}}
{{- end }}
{{- end }}
{{- end }}
{{- end }}