-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #561 from Scalingo/feature/552/add_log_drains_add_cmd
Log drains add command
- Loading branch information
Showing
8 changed files
with
136 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -219,6 +219,7 @@ var ( | |
migrationFollowCommand, | ||
|
||
// Log drains | ||
logDrainsAddCommand, | ||
logDrainsListCommand, | ||
|
||
gitSetup, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import ( | |
"github.com/Scalingo/cli/appdetect" | ||
"github.com/Scalingo/cli/cmd/autocomplete" | ||
"github.com/Scalingo/cli/log_drains" | ||
"github.com/Scalingo/go-scalingo" | ||
"github.com/urfave/cli" | ||
) | ||
|
||
|
@@ -15,7 +16,9 @@ var ( | |
Usage: "List the log drains of an application", | ||
Description: `List all the log drains of an application: | ||
$ scalingo --app my-app log-drains`, | ||
$ scalingo --app my-app log-drains | ||
# See also commands 'log-drains-add'`, | ||
|
||
Action: func(c *cli.Context) { | ||
currentApp := appdetect.CurrentApp(c) | ||
|
@@ -33,4 +36,48 @@ var ( | |
autocomplete.CmdFlagsAutoComplete(c, "log-drains") | ||
}, | ||
} | ||
|
||
logDrainsAddCommand = cli.Command{ | ||
Name: "log-drains-add", | ||
Category: "Log drains", | ||
Usage: "Add a log drain to an application", | ||
Flags: []cli.Flag{appFlag, | ||
cli.StringFlag{Name: "type", Usage: "Communication protocol", Required: true}, | ||
cli.StringFlag{Name: "url", Usage: "URL of self hosted ELK"}, | ||
cli.StringFlag{Name: "host", Usage: "Host of logs management service"}, | ||
cli.StringFlag{Name: "port", Usage: "Port of logs management service"}, | ||
cli.StringFlag{Name: "token", Usage: "Used by certain vendor for authentication"}, | ||
cli.StringFlag{Name: "drain-region", Usage: "Used by certain logs management service to identify the region of their servers"}, | ||
}, | ||
Description: `Add a log drain to an application: | ||
Examples: | ||
$ scalingo --app my-app log-drains-add --type datadog --token 123456789abcdef --drain-region eu-west-2 | ||
$ scalingo --app my-app log-drains-add --type ovh-graylog --token 123456789abcdef --host tag3.logs.ovh.com | ||
$ scalingo --app my-app log-drains-add --type logentries --token 123456789abcdef | ||
$ scalingo --app my-app log-drains-add --type papertrail --host logs2.papertrailapp.com --port 12345 | ||
$ scalingo --app my-app log-drains-add --type syslog --host custom.logstash.com --port 12345 | ||
$ scalingo --app my-app log-drains-add --type elk --url https://my-user:[email protected] | ||
# See also commands 'log-drains'`, | ||
|
||
Action: func(c *cli.Context) { | ||
currentApp := appdetect.CurrentApp(c) | ||
|
||
err := log_drains.Add(currentApp, scalingo.LogDrainAddParams{ | ||
Type: c.String("type"), | ||
URL: c.String("url"), | ||
Host: c.String("host"), | ||
Port: c.String("port"), | ||
Token: c.String("token"), | ||
DrainRegion: c.String("drain-region"), | ||
}) | ||
if err != nil { | ||
errorQuit(err) | ||
} | ||
}, | ||
BashComplete: func(c *cli.Context) { | ||
autocomplete.CmdFlagsAutoComplete(c, "log-drains") | ||
}, | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package log_drains | ||
|
||
import ( | ||
"github.com/Scalingo/cli/config" | ||
"github.com/Scalingo/cli/io" | ||
"github.com/Scalingo/go-scalingo" | ||
"gopkg.in/errgo.v1" | ||
) | ||
|
||
func Add(app string, params scalingo.LogDrainAddParams) error { | ||
c, err := config.ScalingoClient() | ||
if err != nil { | ||
return errgo.Notef(err, "fail to get Scalingo client to add a log drain") | ||
} | ||
|
||
d, err := c.LogDrainAdd(app, params) | ||
if err != nil { | ||
return errgo.Notef(err, "fail to add drain to the application") | ||
} | ||
|
||
io.Status("Log drain", d.Drain.URL, "has been added to the application", app) | ||
return nil | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.