Make Python compatability a flag

This commit is contained in:
Ian Fijolek
2020-02-19 17:31:04 -08:00
parent 8f93997b80
commit a39c188a6c
5 changed files with 42 additions and 17 deletions
+8 -4
View File
@@ -51,16 +51,20 @@ func (alert *Alert) BuildTemplates() error {
if alert.commandTemplate == nil && alert.Command.Command != nil {
alert.commandTemplate = []*template.Template{}
for i, cmdPart := range alert.Command.Command {
cmdPart = legacy.Replace(cmdPart)
if PyCompat {
cmdPart = legacy.Replace(cmdPart)
}
alert.commandTemplate = append(alert.commandTemplate, template.Must(
template.New(alert.Name+string(i)).Parse(cmdPart),
))
}
} else if alert.commandShellTemplate == nil && alert.Command.ShellCommand != "" {
shellCmd := alert.Command.ShellCommand
if PyCompat {
shellCmd = legacy.Replace(shellCmd)
}
alert.commandShellTemplate = template.Must(
template.New(alert.Name).Parse(
legacy.Replace(alert.Command.ShellCommand),
),
template.New(alert.Name).Parse(shellCmd),
)
} else {
return fmt.Errorf("No template provided for alert %s", alert.Name)