github.com/influxdata/influxdb/v2@v2.7.6/telegraf/plugins/inputs/file.go (about) 1 package inputs 2 3 import ( 4 "errors" 5 "fmt" 6 "strconv" 7 "strings" 8 ) 9 10 // File is based on telegraf input File plugin. 11 type File struct { 12 baseInput 13 Files []string `json:"files"` 14 } 15 16 // PluginName is based on telegraf plugin name. 17 func (f *File) PluginName() string { 18 return "file" 19 } 20 21 // UnmarshalTOML decodes the parsed data to the object 22 func (f *File) UnmarshalTOML(data interface{}) error { 23 dataOK, ok := data.(map[string]interface{}) 24 if !ok { 25 return errors.New("bad files for file input plugin") 26 } 27 files, ok := dataOK["files"].([]interface{}) 28 if !ok { 29 return errors.New("not an array for file input plugin") 30 } 31 for _, fl := range files { 32 f.Files = append(f.Files, fl.(string)) 33 } 34 return nil 35 } 36 37 // TOML encodes to toml string 38 func (f *File) TOML() string { 39 s := make([]string, len(f.Files)) 40 for k, v := range f.Files { 41 s[k] = strconv.Quote(v) 42 } 43 return fmt.Sprintf(`[[inputs.%s]] 44 ## Files to parse each interval. Accept standard unix glob matching rules, 45 ## as well as ** to match recursive files and directories. 46 files = [%s] 47 48 ## Name a tag containing the name of the file the data was parsed from. Leave empty 49 ## to disable. 50 # file_tag = "" 51 52 ## Character encoding to use when interpreting the file contents. Invalid 53 ## characters are replaced using the unicode replacement character. When set 54 ## to the empty string the data is not decoded to text. 55 ## ex: character_encoding = "utf-8" 56 ## character_encoding = "utf-16le" 57 ## character_encoding = "utf-16be" 58 ## character_encoding = "" 59 # character_encoding = "" 60 61 ## The dataformat to be read from files 62 ## Each data format has its own unique set of configuration options, read 63 ## more about them here: 64 ## https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_INPUT.md 65 data_format = "influx" 66 `, f.PluginName(), strings.Join(s, ", ")) 67 }