@cryptotaxi247 / netdata-1 / commits / c24d9caea

go.d add support for symlinked vnode config files (#18445)

Ilya Mashchenko committed Aug 30, 2024 at 12:28 UTC c24d9caeac5a1c5dc7ec39fc1fc03f6dca7617d4
1 file changed +29 -1
src/go/plugin/go.d/agent/vnodes/vnodes.go
+29 -1
@@ -61,11 +61,39 @@ func (vn *Vnodes) readConfDir() {
61 return nil
62 }
63
64 - if !d.Type().IsRegular() || !isConfigFile(path) {
64 + if d.Type()&os.ModeSymlink != 0 {
65 + dst, err := os.Readlink(path)
66 + if err != nil {
67 + vn.Warningf("failed to resolve symlink '%s': %v", path, err)
68 + return nil
69 + }
70 +
71 + if !filepath.IsAbs(dst) {
72 + dst = filepath.Join(filepath.Dir(path), filepath.Clean(dst))
73 + }
74 +
75 + fi, err := os.Stat(dst)
76 + if err != nil {
77 + vn.Warningf("failed to stat resolved path '%s': %v", dst, err)
78 + return nil
79 + }
80 + if !fi.Mode().IsRegular() {
81 + vn.Debugf("'%s' is not a regular file, skipping it", dst)
82 + return nil
83 + }
84 + path = dst
85 + } else if !d.Type().IsRegular() {
86 + vn.Debugf("'%s' is not a regular file, skipping it", path)
87 + return nil
88 + }
89 +
90 + if !isConfigFile(path) {
91 + vn.Debugf("'%s' is not a config file (wrong extension), skipping it", path)
92 return nil
93 }
94
95 var cfg []VirtualNode
96 +
97 if err := loadConfigFile(&cfg, path); err != nil {
98 vn.Warning(err)
99 return nil