Skip to content

Commit

Permalink
Merge pull request #241 from szook/protect-against-empty-result-set
Browse files Browse the repository at this point in the history
protect against empty wmi query result sets
  • Loading branch information
carlpett authored Aug 8, 2018
2 parents 832771b + c156f2b commit fe7e5cb
Show file tree
Hide file tree
Showing 9 changed files with 994 additions and 944 deletions.
5 changes: 5 additions & 0 deletions collector/ad.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
package collector

import (
"errors"

"github.com/StackExchange/wmi"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/log"
Expand Down Expand Up @@ -616,6 +618,9 @@ func (c *ADCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, er
if err := wmi.Query(q, &dst); err != nil {
return nil, err
}
if len(dst) == 0 {
return nil, errors.New("WMI query returned empty result set")
}

ch <- prometheus.MustNewConstMetric(
c.AddressBookOperationsTotal,
Expand Down
5 changes: 5 additions & 0 deletions collector/cs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package collector

import (
"errors"

"github.com/StackExchange/wmi"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/log"
Expand Down Expand Up @@ -60,6 +62,9 @@ func (c *CSCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, er
if err := wmi.Query(q, &dst); err != nil {
return nil, err
}
if len(dst) == 0 {
return nil, errors.New("WMI query returned empty result set")
}

ch <- prometheus.MustNewConstMetric(
c.LogicalProcessors,
Expand Down
5 changes: 5 additions & 0 deletions collector/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package collector

import (
"errors"

"github.com/StackExchange/wmi"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/log"
Expand Down Expand Up @@ -237,6 +239,9 @@ func (c *DNSCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, e
if err := wmi.Query(q, &dst); err != nil {
return nil, err
}
if len(dst) == 0 {
return nil, errors.New("WMI query returned empty result set")
}

ch <- prometheus.MustNewConstMetric(
c.ZoneTransferRequestsReceived,
Expand Down
Loading

0 comments on commit fe7e5cb

Please sign in to comment.