Beispiel #1
0
func New() (*OSInstallAgent, error) {
	// get config
	var conf, err = iniconf.NewContent([]byte(confContent)).Load()
	if err != nil {
		return nil, err
	}
	var log = logger.NewLogrusLogger(conf)
	var agent = &OSInstallAgent{
		Config: conf,
		Logger: log,
	}

	var data []byte
	// get sn
	if data, err = execScript(GetSNScript); err != nil {
		log.Error(err)
		return nil, err
	}
	agent.Sn = string(data)
	agent.Sn = strings.Trim(agent.Sn, "\n")

	// get mac addr
	if data, err = execScript(GetMacScript); err != nil {
		log.Error(err)
		return nil, err
	}
	agent.MacAddr = string(data)
	agent.MacAddr = strings.Trim(agent.MacAddr, "\n")

	var serverAddr = ""
	// get server addr
	if serverAddr, err = getCmdlineArgs(RegexpServerAddr); err != nil {
		log.Error(err)
		return nil, err
	}
	agent.ServerAddr = serverAddr
	// agent.ServerAddr = "http://10.0.0.135:8083"
	agent.ServerAddr = strings.Trim(agent.ServerAddr, "\n")

	// loop interval
	var interval string
	if interval, err = getCmdlineArgs(RegexpLoopInterval); err != nil {
		log.Error(err)
		agent.LoopInterval = defaultLoopInterval
	} else {
		agent.LoopInterval = parseInterval(interval)
	}

	// get Vendor
	if data, err = execScript(GetVendorScript); err != nil {
		log.Error(err)
		return nil, err
	}
	agent.Vendor = string(data)
	agent.Vendor = strings.Trim(agent.Vendor, "\n")

	// get Model number
	if data, err = execScript(GetModelNumScript); err != nil {
		log.Error(err)
		return nil, err
	}
	var productModel = strings.SplitN(string(data), " ", 2)
	agent.Product = productModel[0]
	if len(productModel) > 1 {
		agent.ModelName = productModel[1]
	} else {
		agent.ModelName = ""
	}
	agent.Product = strings.Trim(agent.Product, "\n")
	agent.ModelName = strings.Trim(agent.ModelName, "\n")

	return agent, nil
}
Beispiel #2
0
// New create agent
func New() (*OSInstallAgent, error) {
	// get config
	var conf, err = iniconf.NewContent([]byte(confContent)).Load()
	if err != nil {
		return nil, err
	}
	var log = logger.NewBeeLogger(conf)
	var agent = &OSInstallAgent{
		Config: conf,
		Logger: log,
	}

	// var data []byte
	// // get sn
	// agent.Logger.Debug("START to get SN")
	// if data, err = execScript(GetSNScript); err != nil {
	// 	agent.Logger.Error(data)
	// 	agent.Logger.Error(err)
	// 	return nil, fmt.Errorf("get SN error: \n#%s\n%v\n%s", GetSNScript, err, string(data))
	// }
	// agent.Sn = string(data)
	// agent.Sn = strings.Trim(agent.Sn, "\n")
	// agent.Logger.Debugf("SN: %s", agent.Sn)

	// get mac addr by sysinfo.sh
	// get mac addr
	// agent.Logger.Debug("START to get mac addr")
	// if data, err = execScript(GetMacScript); err != nil {
	// 	agent.Logger.Error(data)
	// 	log.Error(err)
	// 	return nil, fmt.Errorf("get mac addr error: \n#%s\n%v\n%s", GetMacScript, err, string(data))
	// }
	// agent.MacAddr = string(data)
	// agent.MacAddr = strings.Trim(agent.MacAddr, "\n")
	// agent.Logger.Debugf("Mac ADDR: %s", agent.MacAddr)

	var serverAddr = ""
	// get server addr
	agent.Logger.Debug("START to get SERVER_ADDR")
	if serverAddr, err = getCmdlineArgs(RegexpServerAddr); err != nil {
		return nil, err
	}
	agent.ServerAddr = serverAddr
	// agent.ServerAddr = "http://10.0.0.135:8083"
	agent.ServerAddr = strings.Trim(agent.ServerAddr, "\n")
	agent.Logger.Debugf("SERVER_ADDR: %s", agent.ServerAddr)

	// loop interval
	var interval string
	agent.Logger.Debug("START to get LOOP_INTERVAL")
	if interval, err = getCmdlineArgs(RegexpLoopInterval); err != nil {
		agent.Logger.Debug(err)
		agent.LoopInterval = defaultLoopInterval
	} else {
		agent.LoopInterval = parseInterval(interval)
	}
	agent.Logger.Debugf("LOOP_INTERVAL: %s", agent.LoopInterval)

	var developMode = ""
	agent.Logger.Debug("START to get DEVELOPER")
	if developMode, err = getCmdlineArgs(RegexpDeveloper); err != nil {
		agent.Logger.Debug(err)
		agent.DevelopeMode = ""
	}
	agent.DevelopeMode = developMode
	agent.DevelopeMode = strings.Trim(agent.DevelopeMode, "\n")
	agent.Logger.Debugf("DEVELOPER: %s", agent.DevelopeMode)

	return agent, nil
}