Return a file where to store the data. We split the key by ":", using the first prefix as directory, if present. This is useful for integrations, which use the check_id formed with $check_name:$hash
(key string)
| 21 | // first prefix as directory, if present. This is useful for integrations, which |
| 22 | // use the check_id formed with $check_name:$hash |
| 23 | func getFileForKey(key string) (string, error) { |
| 24 | parent := config.Datadog.GetString("run_path") |
| 25 | paths := strings.SplitN(key, ":", 2) |
| 26 | cleanedPath := invalidChars.ReplaceAllString(paths[0], "") |
| 27 | if len(paths) == 1 { |
| 28 | // If there is no colon, just return the key |
| 29 | return filepath.Join(parent, cleanedPath), nil |
| 30 | } |
| 31 | // Otherwise, create the directory with a prefix |
| 32 | err := os.MkdirAll(filepath.Join(parent, cleanedPath), 0700) |
| 33 | if err != nil { |
| 34 | return "", err |
| 35 | } |
| 36 | cleanedFile := invalidChars.ReplaceAllString(paths[1], "") |
| 37 | return filepath.Join(parent, cleanedPath, cleanedFile), nil |
| 38 | } |
| 39 | |
| 40 | // Write stores data on disk in the run directory. |
| 41 | func Write(key, value string) error { |