package config import ( "errors" "fmt" "os" "path" "wazuh-notify/log" "github.com/BurntSushi/toml" ) var File Config func Read() error { const SystemConfigPath = "/etc/wazuh-notify/wazuh-notify-config.toml" var LocalConfigPath string execPath, _ := os.Executable() LocalConfigPath = path.Join(path.Dir(execPath), "wazuh-notify-config.toml") var tomlFile []byte var err error tomlFile, err = os.ReadFile(SystemConfigPath) if err == nil { log.Log(fmt.Sprintf("TOML loaded from system path: %s", SystemConfigPath)) } if errors.Is(err, os.ErrNotExist) { log.Log("TOML not found in system path, attempting local fallback.") tomlFile, err = os.ReadFile(LocalConfigPath) if err == nil { log.Log(fmt.Sprintf("TOML loaded from local path: %s", LocalConfigPath)) } } if err != nil { log.Log(fmt.Sprintf("FATAL: TOML config failed to load from both paths. Last error: %v", err)) return err } err = toml.Unmarshal(tomlFile, &File) if err != nil { log.Log(err.Error()) return err } else { log.Log("yaml loaded") } return nil } // Config holds the entire configuration structure defined in the TOML file. type Config struct { General General `toml:"general"` PriorityMaps []PriorityMap `toml:"priority_map"` Discord Discord `toml:"discord"` Ntfy Ntfy `toml:"ntfy"` Slack Slack `toml:"slack"` } // General maps the values within the [general] TOML table. type General struct { Targets string `toml:"targets"` FullAlert string `toml:"full_alert"` ExcludedRules string `toml:"excluded_rules"` ExcludedAgents string `toml:"excluded_agents"` ExcludeDescriptions []string `toml:"exclude_descriptions"` Sender string `toml:"sender"` Click string `toml:"click"` } // PriorityMap maps the values within a single [[priority_map]] TOML table entry. type PriorityMap struct { ThreatMap []int `toml:"threat_map"` MentionThreshold int `toml:"mention_threshold"` NotifyThreshold int `toml:"notify_threshold"` Color int `toml:"color"` } type Discord struct { Webhook string `toml:"webhook"` } // Ntfy maps the values within the [ntfy] TOML table. type Ntfy struct { Webhook string `toml:"webhook"` } // Slack maps the values within the [slack] TOML table. type Slack struct { Webhook string `toml:"webhook"` }