Skip to content

Commit

Permalink
Retry fetching the Devicelist once on error
Browse files Browse the repository at this point in the history
This is useful when FritzOS decides to log out all users from a specific
IP because of "abuse". Logging in again will be possible right away, so
there is no need to return an error in that case.
  • Loading branch information
jayme-github committed Feb 7, 2022
1 parent a22a92a commit 96dfc65
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,23 @@ func (fc *fritzCollector) Describe(ch chan<- *prometheus.Desc) {

func (fc *fritzCollector) Collect(ch chan<- prometheus.Metric) {
var err error
l, err := fritzClient.SafeList()
var l *fritz.Devicelist
retry := 1
for retry >= 0 {
l, err = fritzClient.SafeList()
if err == nil {
break
}
if retry > 0 {
log.Println("Failed to get devicelist, retrying:", err)
// Retry login once
loginErr := fritzClient.SafeLogin()
if loginErr != nil {
log.Println("Login on retry failed:", loginErr)
}
retry -= 1
}
}

if err != nil {
log.Println("Unable to collect data:", err)
Expand Down

0 comments on commit 96dfc65

Please sign in to comment.