Example #1
0
func NewInstaller(terminal *term.Terminal, basedir string, api *api.Api, instanceRepo *instance.Repo, agentConfig *agent.Config, flags Flags) *Installer {
	if agentConfig.ApiHostname == "" {
		agentConfig.ApiHostname = agent.DEFAULT_API_HOSTNAME
	}
	if agentConfig.PidFile == "" {
		agentConfig.PidFile = agent.DEFAULT_PIDFILE
	}
	hostname, _ := os.Hostname()
	defaultDSN := mysql.DSN{
		Username: flags.String["mysql-user"],
		Password: flags.String["mysql-pass"],
		Hostname: flags.String["mysql-host"],
		Port:     flags.String["mysql-port"],
		Socket:   flags.String["mysql-socket"],
	}
	installer := &Installer{
		term:         terminal,
		basedir:      basedir,
		api:          api,
		instanceRepo: instanceRepo,
		agentConfig:  agentConfig,
		flags:        flags,
		// --
		hostname:   hostname,
		defaultDSN: defaultDSN,
	}
	return installer
}
Example #2
0
func ParsePTAgentConf(content string, agent *agent.Config, dsn *mysql.DSN) (string, error) {
	libDir := ""
	if content == "" {
		return libDir, nil
	}

	libDirRe := regexp.MustCompile(`lib\s*=(\S+)`)
	m := libDirRe.FindStringSubmatch(content)
	if len(m) > 1 {
		libDir = m[1]
		fmt.Printf("pt-agent lib dir: %s\n", libDir)
	}

	apiKeyRe := regexp.MustCompile(`^\s*api-key\s*=(\S+)`)
	m = apiKeyRe.FindStringSubmatch(content)
	if len(m) > 1 {
		agent.ApiKey = m[1]
		fmt.Printf("pt-agent API key: %s\n", agent.ApiKey)
	}

	socketRe := regexp.MustCompile(`socket\s*=(\S+)`)
	m = socketRe.FindStringSubmatch(content)
	if len(m) > 1 {
		dsn.Socket = m[1]
		fmt.Printf("pt-agent socket: %s\n", dsn.Socket)
	}

	return libDir, nil
}
Example #3
0
func ParsePTAgentResource(content []byte, agent *agent.Config) error {
	if content != nil && len(content) == 0 {
		return nil
	}
	config := &PTAgentConfig{}
	if err := json.Unmarshal(content, config); err != nil {
		return err
	}
	agent.AgentUuid = config.Uuid
	fmt.Printf("pt-agent UUID: %s\n", agent.AgentUuid)
	return nil
}
Example #4
0
func NewInstaller(term *Terminal, basedir string, api pct.APIConnector, agentConfig *agent.Config, flags Flags) *Installer {
	if agentConfig.ApiHostname == "" {
		agentConfig.ApiHostname = agent.DEFAULT_API_HOSTNAME
	}
	hostname, _ := os.Hostname()
	installer := &Installer{
		term:        term,
		basedir:     basedir,
		api:         api,
		agentConfig: agentConfig,
		flags:       flags,
		// --
		hostname: hostname,
	}
	return installer
}