@@ -25,12 +25,13 @@ import (
2525 "fmt"
2626 "gopkg.in/yaml.v2"
2727 "io/ioutil"
28+ "strconv"
2829)
2930
3031type ConfigYGlobal struct {
31- UseObjectStatus bool `yaml:"useObjectStatus" default:true`
32- UseResetQStats bool `yaml:"useResetQStats" default:false`
33- UsePublications bool `yaml:"usePublications" default:true`
32+ UseObjectStatus string `yaml:"useObjectStatus" default:" true" `
33+ UseResetQStats string `yaml:"useResetQStats" default:" false" `
34+ UsePublications string `yaml:"usePublications" default:" true" `
3435 LogLevel string `yaml:"logLevel"`
3536 MetaPrefix string
3637 PollInterval string `yaml:"pollInterval"`
@@ -41,7 +42,7 @@ type ConfigYGlobal struct {
4142type ConfigYConnection struct {
4243 QueueManager string `yaml:"queueManager"`
4344 User string
44- Client bool `yaml:"clientConnection"`
45+ Client string `yaml:"clientConnection" default:"false "`
4546 Password string
4647 ReplyQueue string `yaml:"replyQueue"`
4748 CcdtUrl string `yaml:"ccdtUrl"`
@@ -54,26 +55,40 @@ type ConfigYObjects struct {
5455 Channels []string
5556 Topics []string
5657 Subscriptions []string
57- ShowInactiveChannels bool `yaml:"showInactiveChannels"`
58+ ShowInactiveChannels string `yaml:"showInactiveChannels" default:"false "`
5859}
5960
6061func ReadConfigFile (f string , cmy interface {}) error {
6162
6263 data , e2 := ioutil .ReadFile (f )
6364 if e2 == nil {
6465 e2 = yaml .Unmarshal (data , cmy )
66+ fmt .Printf ("CMY: %+v\n " , cmy )
6567 }
6668
6769 return e2
6870}
6971
72+ // The Go YAML parsing is not what you might expect for booleans - you are
73+ // apparently unable to set a default of "true" for missing fields. So we read ut
74+ // as a string and parse that. The caller also sends in the default value if the string
75+ // cannot be decoded.
76+ func asBool (s string , def bool ) bool {
77+ b , err := strconv .ParseBool (s )
78+ if err == nil {
79+ return b
80+ } else {
81+ return def
82+ }
83+ }
84+
7085// This handles the configuration parameters that are common to all the collectors. The individual
7186// collectors call similar code for their own specific attributes
7287func CopyYamlConfig (cm * Config , cyg ConfigYGlobal , cyc ConfigYConnection , cyo ConfigYObjects ) {
73- cm .CC .UseStatus = CopyParmIfNotSetBool ("global" , "useObjectStatus" , cyg .UseObjectStatus )
74- cm .CC .UseResetQStats = CopyParmIfNotSetBool ("global" , "useResetQStats" , cyg .UseResetQStats )
75- cm .CC .UsePublications = CopyParmIfNotSetBool ("global" , "usePublications" , cyg .UsePublications )
76- cm .CC .ShowInactiveChannels = CopyParmIfNotSetBool ("objects" , "showInactiveChannels" , cyo .ShowInactiveChannels )
88+ cm .CC .UseStatus = CopyParmIfNotSetBool ("global" , "useObjectStatus" , asBool ( cyg .UseObjectStatus , true ) )
89+ cm .CC .UseResetQStats = CopyParmIfNotSetBool ("global" , "useResetQStats" , asBool ( cyg .UseResetQStats , false ) )
90+ cm .CC .UsePublications = CopyParmIfNotSetBool ("global" , "usePublications" , asBool ( cyg .UsePublications , true ) )
91+ cm .CC .ShowInactiveChannels = CopyParmIfNotSetBool ("objects" , "showInactiveChannels" , asBool ( cyo .ShowInactiveChannels , false ) )
7792
7893 cm .LogLevel = CopyParmIfNotSetStr ("global" , "logLevel" , cyg .LogLevel )
7994 cm .MetaPrefix = CopyParmIfNotSetStr ("global" , "metaprefix" , cyg .MetaPrefix )
@@ -86,7 +101,7 @@ func CopyYamlConfig(cm *Config, cyg ConfigYGlobal, cyc ConfigYConnection, cyo Co
86101 cm .CC .CcdtUrl = CopyParmIfNotSetStr ("connection" , "ccdtUrl" , cyc .CcdtUrl )
87102 cm .CC .ConnName = CopyParmIfNotSetStr ("connection" , "connName" , cyc .ConnName )
88103 cm .CC .Channel = CopyParmIfNotSetStr ("connection" , "channel" , cyc .Channel )
89- cm .CC .ClientMode = CopyParmIfNotSetBool ("connection" , "clientConnection" , cyc .Client )
104+ cm .CC .ClientMode = CopyParmIfNotSetBool ("connection" , "clientConnection" , asBool ( cyc .Client , false ) )
90105 cm .CC .UserId = CopyParmIfNotSetStr ("connection" , "user" , cyc .User )
91106 cm .CC .Password = CopyParmIfNotSetStr ("connection" , "password" , cyc .Password )
92107 cm .ReplyQ = CopyParmIfNotSetStr ("connection" , "replyQueue" , cyc .ReplyQueue )
0 commit comments