Skip to content

Commit

Permalink
Merge pull request #418 from mackerelio/host-memo
Browse files Browse the repository at this point in the history
added memo on host
  • Loading branch information
yseto authored Nov 29, 2021
2 parents 110bc59 + 0738282 commit 7c4070d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
13 changes: 11 additions & 2 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ var commandStatus = cli.Command{
var commandUpdate = cli.Command{
Name: "update",
Usage: "Update the host",
ArgsUsage: "[--name | -n <name>] [--displayName <displayName>] [--status | -st <status>] [--roleFullname | -R <service:role>] [--overwriteRoles | -o] [<hostIds...>]",
ArgsUsage: "[--name | -n <name>] [--displayName <displayName>] [--status | -st <status>] [--roleFullname | -R <service:role>] [--overwriteRoles | -o] [--memo <memo>] [<hostIds...>]",
Description: `
Update the host identified with <hostId>.
Requests "PUT /api/v0/hosts/<hostId>". See https://mackerel.io/api-docs/entry/hosts#update-information .
Expand All @@ -77,6 +77,7 @@ var commandUpdate = cli.Command{
Usage: "Update rolefullname.",
},
cli.BoolFlag{Name: "overwriteRoles, o", Usage: "Overwrite roles instead of adding specified roles."},
cli.StringFlag{Name: "memo", Value: "", Usage: "memo for the Host"},
},
}

Expand Down Expand Up @@ -172,6 +173,7 @@ func doUpdate(c *cli.Context) error {
optStatus := c.String("status")
optRoleFullnames := c.StringSlice("roleFullname")
overwriteRoles := c.Bool("overwriteRoles")
optMemo := c.String("memo")

if len(argHostIDs) < 1 {
argHostIDs = make([]string, 1)
Expand All @@ -182,7 +184,7 @@ func doUpdate(c *cli.Context) error {

needUpdateHostStatus := optStatus != ""
needUpdateRolesInHostUpdate := !overwriteRoles && len(optRoleFullnames) > 0
needUpdateHost := (optName != "" || optDisplayName != "" || overwriteRoles || needUpdateRolesInHostUpdate)
needUpdateHost := (optName != "" || optDisplayName != "" || overwriteRoles || optMemo != "" || needUpdateRolesInHostUpdate)

if !needUpdateHostStatus && !needUpdateHost {
logger.Log("update", "at least one argumet is required.")
Expand Down Expand Up @@ -217,11 +219,18 @@ func doUpdate(c *cli.Context) error {
} else {
displayname = optDisplayName
}
memo := ""
if optMemo == "" {
memo = host.Memo
} else {
memo = optMemo
}
param := &mackerel.UpdateHostParam{
Name: name,
DisplayName: displayname,
Meta: host.Meta,
Interfaces: host.Interfaces,
Memo: memo,
}
if needUpdateRolesInHostUpdate {
param.RoleFullnames = optRoleFullnames
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/jpillora/backoff v0.0.0-20180909062703-3050d21c67d7
github.com/mackerelio/checkers v0.0.0-20190411030116-60cbd7b55456
github.com/mackerelio/mackerel-agent v0.72.4
github.com/mackerelio/mackerel-client-go v0.19.0
github.com/mackerelio/mackerel-client-go v0.20.0
github.com/mholt/archiver v3.1.1+incompatible
github.com/motemen/go-colorine v0.0.0-20180816141035-45d19169413a
github.com/pkg/errors v0.9.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -516,8 +516,8 @@ github.com/mackerelio/golib v1.2.1/go.mod h1:b8ZaapsHGH1FlEJlCqfD98CqafLeyMevyAT
github.com/mackerelio/mackerel-agent v0.72.4 h1:Z54FBX9uejMG8UbtrpH0+yPKVUYV/7z/n+dbcNIvLmo=
github.com/mackerelio/mackerel-agent v0.72.4/go.mod h1:BXrYUAOOWEzNMLph0e8eZSx2mQT1jc1Nwt4Ng4VKxIg=
github.com/mackerelio/mackerel-client-go v0.17.0/go.mod h1:/GNOj+y1eFsd3CK8c6IQ/uS38/GT0+NWImk5YGJs5Lk=
github.com/mackerelio/mackerel-client-go v0.19.0 h1:DkYVD07fmklFTMKLaHcjtkU53Nt+nhvXNUSEeKfRSZs=
github.com/mackerelio/mackerel-client-go v0.19.0/go.mod h1:/GNOj+y1eFsd3CK8c6IQ/uS38/GT0+NWImk5YGJs5Lk=
github.com/mackerelio/mackerel-client-go v0.20.0 h1:qqzT/1qv1YFCJKS+WLxwPZ812RVWYwmSPmyDrUo9kqc=
github.com/mackerelio/mackerel-client-go v0.20.0/go.mod h1:/GNOj+y1eFsd3CK8c6IQ/uS38/GT0+NWImk5YGJs5Lk=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/magiconair/properties v1.8.5 h1:b6kJs+EmPFMYGkow9GiUyCyOvIwYetYJ3fSaWak/Gls=
github.com/magiconair/properties v1.8.5/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
Expand Down
2 changes: 2 additions & 0 deletions hosts/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,15 @@ type createHostParam struct {
roleFullnames []string
status string
customIdentifier string
memo string
}

func (ha *hostApp) createHost(param createHostParam) error {
hostID, err := ha.client.CreateHost(&mackerel.CreateHostParam{
Name: param.name,
RoleFullnames: param.roleFullnames,
CustomIdentifier: param.customIdentifier,
Memo: param.memo,
})
if err != nil {
ha.error(err)
Expand Down
6 changes: 4 additions & 2 deletions hosts/commandCreate.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import (
var CommandCreate = cli.Command{
Name: "create",
Usage: "Create a new host",
ArgsUsage: "[--status | -st <status>] [--roleFullname | -R <service:role>] [--customIdentifier <customIdentifier>] <hostName>",
ArgsUsage: "[--status | -st <status>] [--roleFullname | -R <service:role>] [--customIdentifier <customIdentifier>] [--memo <memo>] <hostName>",
Description: `
Create a new host with status, roleFullname and/or customIdentifier.
Create a new host with status, roleFullname, customIdentifier and/or memo.
Requests "POST /api/v0/hosts". See https://mackerel.io/api-docs/entry/hosts#create .
`,
Action: doCreate,
Expand All @@ -26,6 +26,7 @@ var CommandCreate = cli.Command{
Usage: "Multiple choices are allowed. ex. My-Service:proxy, My-Service:db-master",
},
cli.StringFlag{Name: "customIdentifier", Value: "", Usage: "CustomIdentifier for the Host"},
cli.StringFlag{Name: "memo", Value: "", Usage: "memo for the Host"},
},
}

Expand All @@ -49,5 +50,6 @@ func doCreate(c *cli.Context) error {
roleFullnames: c.StringSlice("roleFullname"),
status: c.String("status"),
customIdentifier: c.String("customIdentifier"),
memo: c.String("memo"),
})
}

0 comments on commit 7c4070d

Please sign in to comment.