Corrected a issue that came from code cleanup earlier wherein missing performance counters caused it to return early from the loop, instead of ignoring missing in default configuration mode.

This commit is contained in:
Rune Darrud 2016-01-31 14:21:24 +01:00
parent 042cf517b2
commit a0776d4f28
2 changed files with 57 additions and 5 deletions

View File

@ -136,7 +136,7 @@ func (m *Win_PerfCounters) InvalidObject(exists uint32, query string, PerfObject
if PerfObject.FailOnMissing { if PerfObject.FailOnMissing {
err := errors.New("Performance object does not exist") err := errors.New("Performance object does not exist")
return err return err
} else if PerfObject.WarnOnMissing { } else {
fmt.Printf("Performance Object '%s' does not exist in query: %s\n", PerfObject.ObjectName, query) fmt.Printf("Performance Object '%s' does not exist in query: %s\n", PerfObject.ObjectName, query)
} }
} else if exists == 3221228473 { //win.PDH_CSTATUS_NO_COUNTER } else if exists == 3221228473 { //win.PDH_CSTATUS_NO_COUNTER
@ -144,14 +144,14 @@ func (m *Win_PerfCounters) InvalidObject(exists uint32, query string, PerfObject
if PerfObject.FailOnMissing { if PerfObject.FailOnMissing {
err := errors.New("Counter in Performance object does not exist") err := errors.New("Counter in Performance object does not exist")
return err return err
} else if PerfObject.WarnOnMissing { } else {
fmt.Printf("Counter '%s' does not exist in query: %s\n", counter, query) fmt.Printf("Counter '%s' does not exist in query: %s\n", counter, query)
} }
} else if exists == 2147485649 { //win.PDH_CSTATUS_NO_INSTANCE } else if exists == 2147485649 { //win.PDH_CSTATUS_NO_INSTANCE
if PerfObject.FailOnMissing { if PerfObject.FailOnMissing {
err := errors.New("Instance in Performance object does not exist") err := errors.New("Instance in Performance object does not exist")
return err return err
} else if PerfObject.WarnOnMissing { } else {
fmt.Printf("Instance '%s' does not exist in query: %s\n", instance, query) fmt.Printf("Instance '%s' does not exist in query: %s\n", instance, query)
} }
@ -199,12 +199,14 @@ func (m *Win_PerfCounters) ParseConfig(metrics *itemList) error {
m.AddItem(metrics, query, objectname, counter, instance, m.AddItem(metrics, query, objectname, counter, instance,
PerfObject.Measurement, PerfObject.IncludeTotal) PerfObject.Measurement, PerfObject.IncludeTotal)
} else { } else {
if PerfObject.FailOnMissing || PerfObject.WarnOnMissing {
err := m.InvalidObject(exists, query, PerfObject, instance, counter) err := m.InvalidObject(exists, query, PerfObject, instance, counter)
return err return err
} }
} }
} }
} }
}
return nil return nil
} else { } else {

View File

@ -273,6 +273,56 @@ func TestWinPerfcountersConfigGet6(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
} }
func TestWinPerfcountersConfigGet7(t *testing.T) {
metrics := itemList{}
var instances = make([]string, 1)
var counters = make([]string, 3)
var perfobjects = make([]perfobject, 1)
objectname := "Processor Information"
instances[0] = "_Total"
counters[0] = "% Processor Time"
counters[1] = "% Processor TimeERROR"
counters[2] = "% Idle Time"
var measurement string = "test"
var warnonmissing bool = false
var failonmissing bool = false
var includetotal bool = false
PerfObject := perfobject{
ObjectName: objectname,
Instances: instances,
Counters: counters,
Measurement: measurement,
WarnOnMissing: warnonmissing,
FailOnMissing: failonmissing,
IncludeTotal: includetotal,
}
perfobjects[0] = PerfObject
m := Win_PerfCounters{PrintValid: false, TestName: "ConfigGet7", Object: perfobjects}
err := m.ParseConfig(&metrics)
require.NoError(t, err)
if len(metrics.items) == 2 {
require.NoError(t, nil)
} else if len(metrics.items) < 2 {
var errorstring1 string = "Too few results returned from the query: " +
string(len(metrics.items))
err2 := errors.New(errorstring1)
require.NoError(t, err2)
} else if len(metrics.items) > 2 {
var errorstring1 string = "Too many results returned from the query: " +
string(len(metrics.items))
err2 := errors.New(errorstring1)
require.NoError(t, err2)
}
}
func TestWinPerfcountersConfigError1(t *testing.T) { func TestWinPerfcountersConfigError1(t *testing.T) {
metrics := itemList{} metrics := itemList{}