Skip to content

Commit

Permalink
Change key name from nickname to displayName
Browse files Browse the repository at this point in the history
  • Loading branch information
Sixeight committed May 11, 2015
1 parent 83b7d3b commit fa4f639
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
16 changes: 8 additions & 8 deletions command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,20 @@ func saveHostID(root string, id string) error {
}

// buildHostSpec build data structure for Host specs
func buildHostSpec(name string, meta map[string]interface{}, interfaces []map[string]interface{}, roleFullnames []string, checks []string, nickname string) map[string]interface{} {
func buildHostSpec(name string, meta map[string]interface{}, interfaces []map[string]interface{}, roleFullnames []string, checks []string, displayName string) map[string]interface{} {
return map[string]interface{}{
"name": name,
"meta": meta,
"interfaces": interfaces,
"roleFullnames": roleFullnames,
"checks": checks,
"nickname": nickname,
"displayName": displayName,
}
}

// prepareHost collects specs of the host and sends them to Mackerel server.
// A unique host-id is returned by the server if one is not specified.
func prepareHost(root string, api *mackerel.API, roleFullnames []string, checks []string, nickname string) (*mackerel.Host, error) {
func prepareHost(root string, api *mackerel.API, roleFullnames []string, checks []string, displayName string) (*mackerel.Host, error) {
// XXX this configuration should be moved to under spec/linux
os.Setenv("PATH", "/sbin:/usr/sbin:/bin:/usr/bin:"+os.Getenv("PATH"))
os.Setenv("LANG", "C") // prevent changing outputs of some command, e.g. ifconfig.
Expand All @@ -82,7 +82,7 @@ func prepareHost(root string, api *mackerel.API, roleFullnames []string, checks
var result *mackerel.Host
if hostID, err := loadHostID(root); err != nil { // create
logger.Debugf("Registering new host on mackerel...")
createdHostID, err := api.CreateHost(hostname, meta, interfaces, roleFullnames, nickname)
createdHostID, err := api.CreateHost(hostname, meta, interfaces, roleFullnames, displayName)
if err != nil {
return nil, fmt.Errorf("Failed to register this host: %s", err.Error())
}
Expand All @@ -96,7 +96,7 @@ func prepareHost(root string, api *mackerel.API, roleFullnames []string, checks
if err != nil {
return nil, fmt.Errorf("Failed to find this host on mackerel (You may want to delete file \"%s\" to register this host to an another organization): %s", idFilePath(root), err.Error())
}
err := api.UpdateHost(hostID, buildHostSpec(hostname, meta, interfaces, roleFullnames, checks, nickname))
err := api.UpdateHost(hostID, buildHostSpec(hostname, meta, interfaces, roleFullnames, checks, displayName))
if err != nil {
return nil, fmt.Errorf("Failed to update this host: %s", err.Error())
}
Expand Down Expand Up @@ -456,7 +456,7 @@ func UpdateHostSpecs(conf *config.Config, api *mackerel.API, host *mackerel.Host
return
}

err = api.UpdateHost(host.ID, buildHostSpec(hostname, meta, interfaces, conf.Roles, conf.CheckNames(), conf.Nickname))
err = api.UpdateHost(host.ID, buildHostSpec(hostname, meta, interfaces, conf.Roles, conf.CheckNames(), conf.DisplayName))
if err != nil {
logger.Errorf("Error while updating host specs: %s", err)
} else {
Expand All @@ -472,7 +472,7 @@ func Prepare(conf *config.Config) (*mackerel.API, *mackerel.Host, error) {
return nil, nil, fmt.Errorf("Failed to prepare an api: %s", err.Error())
}

host, err := prepareHost(conf.Root, api, conf.Roles, conf.CheckNames(), conf.Nickname)
host, err := prepareHost(conf.Root, api, conf.Roles, conf.CheckNames(), conf.DisplayName)
if err != nil {
return nil, nil, fmt.Errorf("Failed to prepare host: %s", err.Error())
}
Expand All @@ -492,7 +492,7 @@ func RunOnce(conf *config.Config) {
logger.Infof("Collecting metrics may take one minutes.")
metrics := ag.CollectMetrics(time.Now())
payload := map[string]interface{}{
"host": buildHostSpec(hostname, meta, interfaces, conf.Roles, conf.CheckNames(), conf.Nickname),
"host": buildHostSpec(hostname, meta, interfaces, conf.Roles, conf.CheckNames(), conf.DisplayName),
"metrics": metrics,
}
json, err := json.Marshal(payload)
Expand Down
18 changes: 9 additions & 9 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ func getApibase() string {

// Config represents mackerel-agent's configuration file.
type Config struct {
Apibase string
Apikey string
Root string
Pidfile string
Conffile string
Roles []string
Verbose bool
Connection ConnectionConfig
Nickname string
Apibase string
Apikey string
Root string
Pidfile string
Conffile string
Roles []string
Verbose bool
Connection ConnectionConfig
DisplayName string

// Corresponds to the set of [plugin.<kind>.<name>] sections
// the key of the map is <kind>, which should be one of "metrics" or "checks".
Expand Down
4 changes: 2 additions & 2 deletions mackerel/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,15 @@ func (api *API) FindHost(id string) (*Host, error) {
}

// CreateHost XXX
func (api *API) CreateHost(name string, meta map[string]interface{}, interfaces []map[string]interface{}, roleFullnames []string, nickname string) (string, error) {
func (api *API) CreateHost(name string, meta map[string]interface{}, interfaces []map[string]interface{}, roleFullnames []string, displayName string) (string, error) {
requestJSON, err := json.Marshal(map[string]interface{}{
"name": name,
"type": "unknown",
"status": "working",
"meta": meta,
"interfaces": interfaces,
"roleFullnames": roleFullnames,
"nickname": nickname,
"displayName": displayName,
})
if err != nil {
return "", err
Expand Down

0 comments on commit fa4f639

Please sign in to comment.