func convertAction(global *inspeqtor.ConfigFile, check inspeqtor.Eventable, action ast.Action) (inspeqtor.Action, error) {
	switch action.Name() {
	case "alert":
		owner := ""

		own, ok := action.(Owned)
		if ok {
			owner = own.Owner()
		}
		if owner == "" {
			owner = check.Parameter("owner")
		}

		route := global.AlertRoutes[owner]
		if owner == "" && route == nil {
			return nil, fmt.Errorf("Please configure a \"send alerts\" statement in inspeqtor.conf.")
		}
		if route == nil {
			return nil, fmt.Errorf("No such alert route: %s", owner)
		}
		return inspeqtor.Actions["alert"](check, route)
	case "reload":
		return inspeqtor.Actions["reload"](check, nil)
	case "restart":
		return inspeqtor.Actions["restart"](check, nil)
	default:
		return nil, fmt.Errorf("Unknown action: %s", action.Name())
	}
}
Esempio n. 2
0
func convertAction(global *ConfigFile, check Eventable, action ast.Action) (Action, error) {
	switch action.Name() {
	case "alert":
		route := global.AlertRoutes[""]
		if route == nil {
			return nil, fmt.Errorf("Please configure a \"send alerts\" statement in inspeqtor.conf.")
		}
		return Actions["alert"](check, route)
	case "reload":
		return Actions["reload"](check, nil)
	case "restart":
		return Actions["restart"](check, nil)
	default:
		return nil, fmt.Errorf("Unknown action: %s", action.Name())
	}
}