Use netsender.IsConfigured() rather than maintaining a global.

This commit is contained in:
Alan Noble 2018-05-07 09:26:22 +09:30
parent b2269ef8d8
commit de633f1061
1 changed files with 8 additions and 19 deletions

View File

@ -92,11 +92,10 @@ const (
// Globals
var (
configReceived bool = true
varSum int = 0
vars = make(map[string]string)
revidInst revid.Revid
config revid.Config
varSum int = 0
vars = make(map[string]string)
revidInst revid.Revid
config revid.Config
)
func main() {
@ -278,32 +277,22 @@ func netsenderInit() {
config.Logger = netsender.GetLogger()
netsender.Init(false)
netsender.ExternalReader = revidReportActions
//try get initial config
if err := netsender.GetConfig(); err != nil {
//default to a config?????
config.Logger.Log("Error", err.Error())
} else {
configReceived = true
}
}
//periodicNetsenderReport is called by the main function every monPeriod seconds. It makes sure a config has been recieved, and then
//reports back CPU stats and updates vars
func periodicNetsenderReport() {
if !configReceived {
if !netsender.IsConfigured() {
if err := netsender.GetConfig(); err != nil {
config.Logger.Log("Error", err.Error())
} else {
configReceived = true
}
}
inputs := netsender.SplitCSV(netsender.GetConfigParam("inputs"))
if _, reconfig, err := netsender.Send(netsender.RequestPoll, inputs); err == nil && reconfig {
if err = netsender.GetConfig(); err != nil {
config.Logger.Log("Error", err.Error())
}
if err = netsender.GetConfig(); err != nil {
config.Logger.Log("Error", err.Error())
}
}
if cloudVarSum := netsender.GetVarSum(); cloudVarSum != varSum {