Skip to content

Commit

Permalink
Fix possible panic when file info cannot be gotten
Browse files Browse the repository at this point in the history
closes #2061
  • Loading branch information
sparrc committed Dec 13, 2016
1 parent 07684fb commit e7b1c51
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions plugins/inputs/filestat/filestat.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"crypto/md5"
"fmt"
"io"
"log"
"os"

"github.com/influxdata/telegraf"
Expand Down Expand Up @@ -78,8 +79,14 @@ func (f *FileStat) Gather(acc telegraf.Accumulator) error {
"file": fileName,
}
fields := map[string]interface{}{
"exists": int64(1),
"size_bytes": fileInfo.Size(),
"exists": int64(1),
}

if fileInfo == nil {
log.Printf("E! Unable to get info for file [%s], possible permissions issue",
fileName)
} else {
fields["size_bytes"] = fileInfo.Size()
}

if f.Md5 {
Expand Down

0 comments on commit e7b1c51

Please sign in to comment.