Skip to content

Commit

Permalink
cmd/scollector: vendor StackExchange/mof changes to support NULL stri…
Browse files Browse the repository at this point in the history
…ngs. Use __no_name__ if c_dsc_status collector has any NULL ConfigurationName values
  • Loading branch information
gbrayut committed Mar 1, 2017
1 parent 087417c commit ea52fac
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 9 deletions.
27 changes: 20 additions & 7 deletions cmd/scollector/collectors/dsc_windows.go
Expand Up @@ -10,6 +10,7 @@ import (

"bosun.org/metadata"
"bosun.org/opentsdb"
"bosun.org/slog"
"bosun.org/util"
"github.com/StackExchange/mof"
)
Expand All @@ -23,6 +24,9 @@ const (
dscLCM = "dsc.lcm."
dscMof = "dsc.mof."
dscStatus = "dsc.status."

//dscDefaultConfigurationName is used when the ConfigurationName value in the struct is NULL (non-pull based configuration usually)
dscDefaultConfigurationName = "__no_name__"
)

var (
Expand Down Expand Up @@ -83,17 +87,17 @@ func c_dsc_status() (opentsdb.MultiDataPoint, error) {
if err.Error() == "exit status 2147749889" {
return md, nil
} else {
return nil, err
return nil, slog.Wrap(err)
}
}
dscstatusbuffer := new(bytes.Buffer)
_, err = dscstatusbuffer.ReadFrom(dscstatusmof)
if err != nil {
return nil, err
return nil, slog.Wrap(err)
}
err = mof.Unmarshal(dscstatusbuffer.Bytes(), &dst)
if err != nil {
return nil, err
return nil, slog.Wrap(err)
}
if dst.ReturnValue != 0 {
return nil, fmt.Errorf("GetConfigurationStatus ReturnValue %v", dst.ReturnValue)
Expand All @@ -112,16 +116,18 @@ func c_dsc_status() (opentsdb.MultiDataPoint, error) {
Add(&md, dscStatus+"run_type", dscTypeToStatusCode(v.Type), nil, metadata.Gauge, metadata.Count, descWinDSCType)
configurations := make(map[string]dscResourceCount)
for _, r := range v.ResourcesInDesiredState {
c := configurations[r.ConfigurationName]
name := dscGetConfigurationName(r.ConfigurationName)
c := configurations[name]
c.Success++
c.Duration += r.DurationInSeconds
configurations[r.ConfigurationName] = c
configurations[name] = c
}
for _, r := range v.ResourcesNotInDesiredState {
c := configurations[r.ConfigurationName]
name := dscGetConfigurationName(r.ConfigurationName)
c := configurations[name]
c.Failed++
c.Duration += r.DurationInSeconds
configurations[r.ConfigurationName] = c
configurations[name] = c
}
for key, value := range configurations {
Add(&md, dscStatus+"resources", value.Success, opentsdb.TagSet{"state": "Success", "configuration": key}, metadata.Gauge, metadata.Count, descWinDSCResourceState)
Expand Down Expand Up @@ -247,3 +253,10 @@ func dscStartDateToAge(startdate string) float64 {
}
return time.Now().UTC().Sub(t).Seconds()
}

func dscGetConfigurationName(Name string) string {
if Name != "" {
return Name
}
return dscDefaultConfigurationName
}
14 changes: 14 additions & 0 deletions vendor/github.com/StackExchange/mof/node.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions vendor/github.com/StackExchange/mof/parse.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions vendor/vendor.json
Expand Up @@ -41,8 +41,8 @@
},
{
"path": "github.com/StackExchange/mof",
"revision": "2bb66392c0273ed914c2b83442e8a61effa42678",
"revisionTime": "2015-06-18T18:52:08-04:00"
"revision": "cfc83d4047d1c05c81d9c54ac1eaedb076582114",
"revisionTime": "2017-02-27T16:04:56-07:00"
},
{
"path": "github.com/StackExchange/wmi",
Expand Down

0 comments on commit ea52fac

Please sign in to comment.