func()

in pkg/custompluginmonitor/types/config.go [126:162]


func (cpc CustomPluginConfig) Validate() error {
	if cpc.Plugin != customPluginName {
		return fmt.Errorf("NPD does not support %q plugin for now. Only support \"custom\"", cpc.Plugin)
	}

	for _, rule := range cpc.Rules {
		if rule.Timeout != nil && *rule.Timeout > *cpc.PluginGlobalConfig.Timeout {
			return fmt.Errorf("plugin timeout is greater than global timeout. "+
				"Rule: %+v. Global timeout: %v", rule, cpc.PluginGlobalConfig.Timeout)
		}
	}

	for _, rule := range cpc.Rules {
		if _, err := os.Stat(rule.Path); os.IsNotExist(err) {
			return fmt.Errorf("rule path %q does not exist. Rule: %+v", rule.Path, rule)
		}
	}

	for _, rule := range cpc.Rules {
		if rule.Type != types.Perm {
			continue
		}
		conditionType := rule.Condition
		defaultConditionExists := false
		for _, cond := range cpc.DefaultConditions {
			if conditionType == cond.Type {
				defaultConditionExists = true
				break
			}
		}
		if !defaultConditionExists {
			return fmt.Errorf("Permanent problem %s does not have preset default condition.", conditionType)
		}
	}

	return nil
}