func createExecutableCallback(filepath string, args bool, product string) func(event *mms.ProductEvent) error {
	_, err := exec.LookPath(filepath)

	if err != nil {
		log.Fatalf("command executable not found, %s", err)
	}

	return func(event *mms.ProductEvent) error {
		var productLocation string

		// Ignore events not matching product filter, if set.
		if product != "" && event.Product != product {
			return nil
		}

		if args {
			productLocation = event.ProductLocation
		} else {
			productLocation = ""
		}

		command := exec.Command(filepath, productLocation)
		command.Env = os.Environ()
		envVars, err := eventAsEnvVariables(event)
		if err != nil {
			return err
		}
		command.Env = append(command.Env, envVars...)

		var stdout bytes.Buffer
		var stderr bytes.Buffer
		command.Stdout = &stdout
		command.Stderr = &stderr

		err = command.Run()

		if err != nil {
			fmt.Println("Failed", err, stderr.String())
			return fmt.Errorf("failed to run executable, %s", err.Error())
		}

		fmt.Println(stdout.String())
		return nil
	}
}
// createExecutableCallback generate a callback that filter on product and call the command at filepath.
// The command gets the product-location as first argument and the complete serialized event as the env variable MMS_EVENT.
createExecutableCallback generate a callback that filter on product and call the command at filepath.
The command gets the product-location as first argument and the complete serialized event as the env variable MMS_EVENT.
// createExecutableCallback generate a callback that filter on product and call the command at filepath . // The command gets the product - location as first argument and the complete serialized event as the env variable MMS_EVENT .
func createExecutableCallback(filepath string, args bool, product string) func(event *mms.ProductEvent) error {
	_, err := exec.LookPath(filepath)
	if err != nil {
		log.Fatalf("command executable not found, %s", err)
	}
	return func(event *mms.ProductEvent) error {
		var productLocation string
		if product != "" && event.Product != product {
			return nil
		}
		if args {
			productLocation = event.ProductLocation
		} else {
			productLocation = ""
		}
		command := exec.Command(filepath, productLocation)
		command.Env = os.Environ()
		envVars, err := eventAsEnvVariables(event)
		if err != nil {
			return err
		}
		command.Env = append(command.Env, envVars...)
		var stdout bytes.Buffer
		var stderr bytes.Buffer
		command.Stdout = &stdout
		command.Stderr = &stderr
		err = command.Run()
		if err != nil {
			fmt.Println("Failed", err, stderr.String())
			return fmt.Errorf("failed to run executable, %s", err.Error())
		}
		fmt.Println(stdout.String())
		return nil
	}
}
func createExecutableCallback ( filepath string , args bool , product string ) func ( event * mms . ProductEvent ) error { _ , err := exec . LookPath ( filepath ) if err != nil { log . Fatalf ( " " , err ) } return func ( event * mms . ProductEvent ) error { var productLocation string if product != " " && event . Product != product { return nil } if args { productLocation = event . ProductLocation } else { productLocation = " " } command := exec . Command ( filepath , productLocation ) command . Env = os . Environ ( ) envVars , err := eventAsEnvVariables ( event ) if err != nil { return err } command . Env = append ( command . Env , envVars ... ) var stdout bytes . Buffer var stderr bytes . Buffer command . Stdout = & stdout command . Stderr = & stderr err = command . Run ( ) if err != nil { fmt . Println ( " " , err , stderr . String ( ) ) return fmt . Errorf ( " " , err . Error ( ) ) } fmt . Println ( stdout . String ( ) ) return nil } }
createExecutableCallback generate a callback that filter on product and call the command at filepath.
createExecutableCallback generate a callback that filter on product and call the command at filepath .
// Ignore events not matching product filter, if set.