Skip to content

Commit c31ab43

Browse files
author
Linus Wallgren
committed
Add override for mac-file
That override is the environment variable MAC_FILE
1 parent 914df2f commit c31ab43

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

pkg/mac/mac.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,19 @@ type macTransformer struct {
1717

1818
func NewFileTransformer() proxy.Transformer {
1919
return &macTransformer{
20-
ipmac: readIPMacMap(),
20+
ipmac: readIPMacMap(getFilePath()),
2121
}
2222
}
2323

24+
func getFilePath() string {
25+
path, exists := os.LookupEnv("MAC_FILE")
26+
if exists {
27+
return path
28+
}
29+
30+
return "/var/lib/promscan/all"
31+
}
32+
2433
func (trans *macTransformer) Transform(line string) string {
2534
mac := getMac(trans.ipmac, line)
2635

@@ -41,9 +50,9 @@ func getMac(ipmac map[string]string, line string) string {
4150
return "UNKNOWN"
4251
}
4352

44-
func readIPMacMap() map[string]string {
53+
func readIPMacMap(filePath string) map[string]string {
4554
ipmac := make(map[string]string)
46-
file, err := os.Open("./all") // TODO
55+
file, err := os.Open(filePath)
4756
if err != nil {
4857
log.Fatal(err)
4958
}

0 commit comments

Comments
 (0)