@@ -116,7 +116,10 @@ func (c Configuration) logger() (logger zerolog.Logger) {
116
116
return logger
117
117
}
118
118
119
- func (c Configuration ) consumers (db * pkg.AgentDB ) (consumers pkg.BaseConsumers ) {
119
+ /*
120
+ Initialises all the consumers along with pre-populating genericDiffPaths used by watcher
121
+ */
122
+ func (c Configuration ) consumers (db * pkg.AgentDB , genericDiffPaths * []string ) (consumers pkg.BaseConsumers ) {
120
123
fs := afero .NewOsFs ()
121
124
var existingConsumersFiles = make (map [string ]bool )
122
125
@@ -160,6 +163,8 @@ func (c Configuration) consumers(db *pkg.AgentDB) (consumers pkg.BaseConsumers)
160
163
}
161
164
consumers = append (consumers , & pkg.BaseConsumer {AgentDB : db , ParserLoader : state })
162
165
existingConsumersFiles [genericDiffFile .File ] = true
166
+ //this variable is used by watcher to get the complete list of paths to monitor, instead of the list from the config
167
+ * genericDiffPaths = append (* genericDiffPaths , genericDiffFile .File )
163
168
}
164
169
}
165
170
}
@@ -203,11 +208,28 @@ func (c Configuration) isFileToBeExcluded(file string, existingConsumersFiles ma
203
208
return isFileExcluded || existingConsumersFiles [file ]
204
209
}
205
210
211
+ // Gets the full list of paths to monitor
212
+ func (c Configuration ) getCompleteListOfPaths (pathList []string ) []string {
213
+ logger := c .logger ()
214
+ var completePathList []string
215
+ for _ , path := range pathList {
216
+ completePath , err := filepath .Glob (path )
217
+ if err != nil {
218
+ logger .Error ().Err (err ).Msgf ("Error getting complete list of paths to register: %v" , err )
219
+ continue
220
+ }
221
+ completePathList = append (completePathList , completePath ... )
222
+ }
223
+ return completePathList
224
+ }
225
+
206
226
// Gets list of files to be monitored from all files/dirs listed in the config
207
227
func (c Configuration ) getListOfFiles (fs afero.Fs , pathList []string ) []FileInfo {
208
228
logger := c .logger ()
209
229
var filesToMonitor []FileInfo
210
- for _ , fullPath := range pathList {
230
+ completeListOfPaths := c .getCompleteListOfPaths (pathList )
231
+
232
+ for _ , fullPath := range completeListOfPaths {
211
233
fullPath := fullPath
212
234
pkgFile := pkg .NewFile (func (file * pkg.File ) {
213
235
file .Fs , file .Path , file .Logger = fs , fullPath , logger
@@ -353,6 +375,7 @@ func (c Configuration) metrics() (*pkg.Metrics, error) {
353
375
354
376
func (c Configuration ) watcher () (* pkg.Watcher , error ) {
355
377
logger := c .logger ()
378
+ var genericDiffPaths []string
356
379
logger .Debug ().Str ("db" , c .Database ).Msg ("opening bolt database" )
357
380
db , err := bolt .Open (c .Database , 0600 , nil )
358
381
if err != nil {
@@ -365,15 +388,15 @@ func (c Configuration) watcher() (*pkg.Watcher, error) {
365
388
}
366
389
367
390
database := & pkg.AgentDB {Logger : logger , DB : db }
368
- consumers := c .consumers (database )
391
+ consumers := c .consumers (database , & genericDiffPaths )
369
392
370
393
for _ , consumer := range consumers {
371
394
if err := consumer .Init (); err != nil {
372
395
logger .Fatal ().Err (err ).Msg ("failed to init consumer" )
373
396
}
374
397
}
375
398
return pkg .NewWatcher (func (w * pkg.Watcher ) {
376
- w .Logger , w .Consumers , w .FIM , w .Database , w .Key , w .Excludes , w .GenericDiff = logger , consumers .Consumers (), fim , database , c .key , c .Consumers .Excludes , c . Consumers . GenericDiff
399
+ w .Logger , w .Consumers , w .FIM , w .Database , w .Key , w .Excludes , w .GenericDiff = logger , consumers .Consumers (), fim , database , c .key , c .Consumers .Excludes , genericDiffPaths
377
400
}), nil
378
401
}
379
402
0 commit comments