Update cscli doc for docusaurus (#924)

This commit is contained in:
blotus 2021-08-31 15:03:47 +02:00 committed by GitHub
parent b40fd36607
commit e54b5beb8d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 291 additions and 201 deletions

View file

@ -251,6 +251,7 @@ cscli alerts list --ip 1.2.3.4
cscli alerts list --range 1.2.3.0/24 cscli alerts list --range 1.2.3.0/24
cscli alerts list -s crowdsecurity/ssh-bf cscli alerts list -s crowdsecurity/ssh-bf
cscli alerts list --type ban`, cscli alerts list --type ban`,
DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
var err error var err error
@ -353,7 +354,8 @@ cscli alerts list --type ban`,
Example: `cscli alerts delete --ip 1.2.3.4 Example: `cscli alerts delete --ip 1.2.3.4
cscli alerts delete --range 1.2.3.0/24 cscli alerts delete --range 1.2.3.0/24
cscli alerts delete -s crowdsecurity/ssh-bf"`, cscli alerts delete -s crowdsecurity/ssh-bf"`,
Args: cobra.ExactArgs(0), DisableAutoGenTag: true,
Args: cobra.ExactArgs(0),
PreRun: func(cmd *cobra.Command, args []string) { PreRun: func(cmd *cobra.Command, args []string) {
if AlertDeleteAll { if AlertDeleteAll {
return return
@ -421,9 +423,10 @@ cscli alerts delete -s crowdsecurity/ssh-bf"`,
var details bool var details bool
var cmdAlertsInspect = &cobra.Command{ var cmdAlertsInspect = &cobra.Command{
Use: "inspect <alert_id>", Use: `inspect "alert_id"`,
Short: `Show info about an alert`, Short: `Show info about an alert`,
Example: `cscli alerts inspect 123`, Example: `cscli alerts inspect 123`,
DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 { if len(args) == 0 {
_ = cmd.Help() _ = cmd.Help()

View file

@ -26,7 +26,8 @@ func NewBouncersCmd() *cobra.Command {
Long: `To list/add/delete bouncers. Long: `To list/add/delete bouncers.
Note: This command requires database direct access, so is intended to be run on Local API/master. Note: This command requires database direct access, so is intended to be run on Local API/master.
`, `,
Args: cobra.MinimumNArgs(1), Args: cobra.MinimumNArgs(1),
DisableAutoGenTag: true,
PersistentPreRun: func(cmd *cobra.Command, args []string) { PersistentPreRun: func(cmd *cobra.Command, args []string) {
var err error var err error
if err := csConfig.LoadAPIServer(); err != nil || csConfig.DisableAPI { if err := csConfig.LoadAPIServer(); err != nil || csConfig.DisableAPI {
@ -43,11 +44,12 @@ Note: This command requires database direct access, so is intended to be run on
} }
var cmdBouncersList = &cobra.Command{ var cmdBouncersList = &cobra.Command{
Use: "list", Use: "list",
Short: "List bouncers", Short: "List bouncers",
Long: `List bouncers`, Long: `List bouncers`,
Example: `cscli bouncers list`, Example: `cscli bouncers list`,
Args: cobra.ExactArgs(0), Args: cobra.ExactArgs(0),
DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, arg []string) { Run: func(cmd *cobra.Command, arg []string) {
blockers, err := dbClient.ListBouncers() blockers, err := dbClient.ListBouncers()
if err != nil { if err != nil {
@ -99,7 +101,8 @@ Note: This command requires database direct access, so is intended to be run on
Long: `add bouncer`, Long: `add bouncer`,
Example: `cscli bouncers add MyBouncerName Example: `cscli bouncers add MyBouncerName
cscli bouncers add MyBouncerName -l 24`, cscli bouncers add MyBouncerName -l 24`,
Args: cobra.ExactArgs(1), Args: cobra.ExactArgs(1),
DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, arg []string) { Run: func(cmd *cobra.Command, arg []string) {
keyName := arg[0] keyName := arg[0]
if keyName == "" { if keyName == "" {
@ -136,9 +139,10 @@ cscli bouncers add MyBouncerName -l 24`,
cmdBouncers.AddCommand(cmdBouncersAdd) cmdBouncers.AddCommand(cmdBouncersAdd)
var cmdBouncersDelete = &cobra.Command{ var cmdBouncersDelete = &cobra.Command{
Use: "delete MyBouncerName", Use: "delete MyBouncerName",
Short: "delete bouncer", Short: "delete bouncer",
Args: cobra.ExactArgs(1), Args: cobra.ExactArgs(1),
DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, arg []string) { Run: func(cmd *cobra.Command, arg []string) {
keyName := arg[0] keyName := arg[0]
if keyName == "" { if keyName == "" {

View file

@ -24,9 +24,10 @@ var CAPIBaseURL string = "https://api.crowdsec.net/"
func NewCapiCmd() *cobra.Command { func NewCapiCmd() *cobra.Command {
var cmdCapi = &cobra.Command{ var cmdCapi = &cobra.Command{
Use: "capi [action]", Use: "capi [action]",
Short: "Manage interaction with Central API (CAPI)", Short: "Manage interaction with Central API (CAPI)",
Args: cobra.MinimumNArgs(1), Args: cobra.MinimumNArgs(1),
DisableAutoGenTag: true,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error { PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if err := csConfig.LoadAPIServer(); err != nil || csConfig.DisableAPI { if err := csConfig.LoadAPIServer(); err != nil || csConfig.DisableAPI {
log.Fatal("Local API is disabled, please run this command on the local API machine") log.Fatal("Local API is disabled, please run this command on the local API machine")
@ -40,9 +41,10 @@ func NewCapiCmd() *cobra.Command {
} }
var cmdCapiRegister = &cobra.Command{ var cmdCapiRegister = &cobra.Command{
Use: "register", Use: "register",
Short: "Register to Central API (CAPI)", Short: "Register to Central API (CAPI)",
Args: cobra.MinimumNArgs(0), Args: cobra.MinimumNArgs(0),
DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
var err error var err error
@ -103,9 +105,10 @@ func NewCapiCmd() *cobra.Command {
cmdCapi.AddCommand(cmdCapiRegister) cmdCapi.AddCommand(cmdCapiRegister)
var cmdCapiStatus = &cobra.Command{ var cmdCapiStatus = &cobra.Command{
Use: "status", Use: "status",
Short: "Check status with the Central API (CAPI)", Short: "Check status with the Central API (CAPI)",
Args: cobra.MinimumNArgs(0), Args: cobra.MinimumNArgs(0),
DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
var err error var err error
if csConfig.API.Server == nil { if csConfig.API.Server == nil {

View file

@ -16,7 +16,8 @@ func NewCollectionsCmd() *cobra.Command {
Short: "Manage collections from hub", Short: "Manage collections from hub",
Long: `Install/Remove/Upgrade/Inspect collections from the CrowdSec Hub.`, Long: `Install/Remove/Upgrade/Inspect collections from the CrowdSec Hub.`,
/*TBD fix help*/ /*TBD fix help*/
Args: cobra.MinimumNArgs(1), Args: cobra.MinimumNArgs(1),
DisableAutoGenTag: true,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error { PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if err := csConfig.LoadHub(); err != nil { if err := csConfig.LoadHub(); err != nil {
log.Fatalf(err.Error()) log.Fatalf(err.Error())
@ -45,11 +46,12 @@ func NewCollectionsCmd() *cobra.Command {
} }
var cmdCollectionsInstall = &cobra.Command{ var cmdCollectionsInstall = &cobra.Command{
Use: "install collection", Use: "install collection",
Short: "Install given collection(s)", Short: "Install given collection(s)",
Long: `Fetch and install given collection(s) from hub`, Long: `Fetch and install given collection(s) from hub`,
Example: `cscli collections install crowdsec/xxx crowdsec/xyz`, Example: `cscli collections install crowdsec/xxx crowdsec/xyz`,
Args: cobra.MinimumNArgs(1), Args: cobra.MinimumNArgs(1),
DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
for _, name := range args { for _, name := range args {
InstallItem(name, cwhub.COLLECTIONS, forceAction) InstallItem(name, cwhub.COLLECTIONS, forceAction)
@ -61,11 +63,12 @@ func NewCollectionsCmd() *cobra.Command {
cmdCollections.AddCommand(cmdCollectionsInstall) cmdCollections.AddCommand(cmdCollectionsInstall)
var cmdCollectionsRemove = &cobra.Command{ var cmdCollectionsRemove = &cobra.Command{
Use: "remove collection", Use: "remove collection",
Short: "Remove given collection(s)", Short: "Remove given collection(s)",
Long: `Remove given collection(s) from hub`, Long: `Remove given collection(s) from hub`,
Example: `cscli collections remove crowdsec/xxx crowdsec/xyz`, Example: `cscli collections remove crowdsec/xxx crowdsec/xyz`,
Args: cobra.MinimumNArgs(1), Args: cobra.MinimumNArgs(1),
DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
if all { if all {
RemoveMany(cwhub.COLLECTIONS, "") RemoveMany(cwhub.COLLECTIONS, "")
@ -90,10 +93,11 @@ func NewCollectionsCmd() *cobra.Command {
cmdCollections.AddCommand(cmdCollectionsRemove) cmdCollections.AddCommand(cmdCollectionsRemove)
var cmdCollectionsUpgrade = &cobra.Command{ var cmdCollectionsUpgrade = &cobra.Command{
Use: "upgrade collection", Use: "upgrade collection",
Short: "Upgrade given collection(s)", Short: "Upgrade given collection(s)",
Long: `Fetch and upgrade given collection(s) from hub`, Long: `Fetch and upgrade given collection(s) from hub`,
Example: `cscli collections upgrade crowdsec/xxx crowdsec/xyz`, Example: `cscli collections upgrade crowdsec/xxx crowdsec/xyz`,
DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
if all { if all {
UpgradeConfig(cwhub.COLLECTIONS, "", forceAction) UpgradeConfig(cwhub.COLLECTIONS, "", forceAction)
@ -112,11 +116,12 @@ func NewCollectionsCmd() *cobra.Command {
cmdCollections.AddCommand(cmdCollectionsUpgrade) cmdCollections.AddCommand(cmdCollectionsUpgrade)
var cmdCollectionsInspect = &cobra.Command{ var cmdCollectionsInspect = &cobra.Command{
Use: "inspect collection", Use: "inspect collection",
Short: "Inspect given collection", Short: "Inspect given collection",
Long: `Inspect given collection`, Long: `Inspect given collection`,
Example: `cscli collections inspect crowdsec/xxx crowdsec/xyz`, Example: `cscli collections inspect crowdsec/xxx crowdsec/xyz`,
Args: cobra.MinimumNArgs(1), Args: cobra.MinimumNArgs(1),
DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
for _, name := range args { for _, name := range args {
InspectItem(name, cwhub.COLLECTIONS) InspectItem(name, cwhub.COLLECTIONS)
@ -127,11 +132,12 @@ func NewCollectionsCmd() *cobra.Command {
cmdCollections.AddCommand(cmdCollectionsInspect) cmdCollections.AddCommand(cmdCollectionsInspect)
var cmdCollectionsList = &cobra.Command{ var cmdCollectionsList = &cobra.Command{
Use: "list collection [-a]", Use: "list collection [-a]",
Short: "List all collections or given one", Short: "List all collections or given one",
Long: `List all collections or given one`, Long: `List all collections or given one`,
Example: `cscli collections list`, Example: `cscli collections list`,
Args: cobra.ExactArgs(0), Args: cobra.ExactArgs(0),
DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
ListItem(cwhub.COLLECTIONS, args) ListItem(cwhub.COLLECTIONS, args)
}, },

View file

@ -14,7 +14,7 @@ func NewCompletionCmd() *cobra.Command {
Long: `To load completions: Long: `To load completions:
### Bash: ### Bash:
` + "```shell" + `
$ source <(cscli completion bash) $ source <(cscli completion bash)
# To load completions for each session, execute once: # To load completions for each session, execute once:
@ -35,9 +35,10 @@ func NewCompletionCmd() *cobra.Command {
* Install bash-completion package * Install bash-completion package
$ source /etc/profile $ source /etc/profile
$ source <(cscli completion bash) $ source <(cscli completion bash)
` + "```" + `
### Zsh: ### Zsh:
` + "```shell" + `
# If shell completion is not already enabled in your environment, # If shell completion is not already enabled in your environment,
# you will need to enable it. You can execute the following once: # you will need to enable it. You can execute the following once:
@ -48,8 +49,9 @@ func NewCompletionCmd() *cobra.Command {
$ cscli completion zsh > "${fpath[1]}/_cscli" $ cscli completion zsh > "${fpath[1]}/_cscli"
# You will need to start a new shell for this setup to take effect. # You will need to start a new shell for this setup to take effect.
`, ` + "```",
DisableFlagsInUseLine: true, DisableFlagsInUseLine: true,
DisableAutoGenTag: true,
ValidArgs: []string{"bash", "zsh"}, ValidArgs: []string{"bash", "zsh"},
Args: cobra.ExactValidArgs(1), Args: cobra.ExactValidArgs(1),
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {

View file

@ -274,15 +274,17 @@ func restoreConfigFromDirectory(dirPath string) error {
func NewConfigCmd() *cobra.Command { func NewConfigCmd() *cobra.Command {
var cmdConfig = &cobra.Command{ var cmdConfig = &cobra.Command{
Use: "config [command]", Use: "config [command]",
Short: "Allows to view current config", Short: "Allows to view current config",
Args: cobra.ExactArgs(0), Args: cobra.ExactArgs(0),
DisableAutoGenTag: true,
} }
var cmdConfigShow = &cobra.Command{ var cmdConfigShow = &cobra.Command{
Use: "show", Use: "show",
Short: "Displays current config", Short: "Displays current config",
Long: `Displays the current cli configuration.`, Long: `Displays the current cli configuration.`,
Args: cobra.ExactArgs(0), Args: cobra.ExactArgs(0),
DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
switch csConfig.Cscli.Output { switch csConfig.Cscli.Output {
case "human": case "human":
@ -375,7 +377,7 @@ func NewConfigCmd() *cobra.Command {
cmdConfig.AddCommand(cmdConfigShow) cmdConfig.AddCommand(cmdConfigShow)
var cmdConfigBackup = &cobra.Command{ var cmdConfigBackup = &cobra.Command{
Use: "backup <directory>", Use: `backup "directory"`,
Short: "Backup current config", Short: "Backup current config",
Long: `Backup the current crowdsec configuration including : Long: `Backup the current crowdsec configuration including :
@ -385,8 +387,9 @@ func NewConfigCmd() *cobra.Command {
- List of scenarios, parsers, postoverflows and collections that are up-to-date - List of scenarios, parsers, postoverflows and collections that are up-to-date
- Tainted/local/out-of-date scenarios, parsers, postoverflows and collections - Tainted/local/out-of-date scenarios, parsers, postoverflows and collections
- Backup of API credentials (local API and online API)`, - Backup of API credentials (local API and online API)`,
Example: `cscli config backup ./my-backup`, Example: `cscli config backup ./my-backup`,
Args: cobra.ExactArgs(1), Args: cobra.ExactArgs(1),
DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
var err error var err error
if err := csConfig.LoadHub(); err != nil { if err := csConfig.LoadHub(); err != nil {
@ -404,9 +407,9 @@ func NewConfigCmd() *cobra.Command {
cmdConfig.AddCommand(cmdConfigBackup) cmdConfig.AddCommand(cmdConfigBackup)
var cmdConfigRestore = &cobra.Command{ var cmdConfigRestore = &cobra.Command{
Use: "restore <directory>", Use: `restore "directory"`,
Short: "Restore config in backup <directory>", Short: `Restore config in backup "directory"`,
Long: `Restore the crowdsec configuration from specified backup <directory> including: Long: `Restore the crowdsec configuration from specified backup "directory" including:
- Main config (config.yaml) - Main config (config.yaml)
- Simulation config (simulation.yaml) - Simulation config (simulation.yaml)
@ -414,7 +417,8 @@ func NewConfigCmd() *cobra.Command {
- List of scenarios, parsers, postoverflows and collections that are up-to-date - List of scenarios, parsers, postoverflows and collections that are up-to-date
- Tainted/local/out-of-date scenarios, parsers, postoverflows and collections - Tainted/local/out-of-date scenarios, parsers, postoverflows and collections
- Backup of API credentials (local API and online API)`, - Backup of API credentials (local API and online API)`,
Args: cobra.ExactArgs(1), Args: cobra.ExactArgs(1),
DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
var err error var err error
if err := csConfig.LoadHub(); err != nil { if err := csConfig.LoadHub(); err != nil {

View file

@ -38,8 +38,9 @@ Enroll this instance to https://app.crowdsec.net
You can get your enrollment key by creating an account on https://app.crowdsec.net. You can get your enrollment key by creating an account on https://app.crowdsec.net.
After running this command your will need to validate the enrollment in the webapp.`, After running this command your will need to validate the enrollment in the webapp.`,
Example: "cscli console enroll YOUR-ENROLL-KEY", Example: "cscli console enroll YOUR-ENROLL-KEY",
Args: cobra.ExactArgs(1), Args: cobra.ExactArgs(1),
DisableAutoGenTag: true,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error { PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if err := csConfig.LoadAPIServer(); err != nil || csConfig.DisableAPI { if err := csConfig.LoadAPIServer(); err != nil || csConfig.DisableAPI {
log.Fatal("Local API is disabled, please run this command on the local API machine") log.Fatal("Local API is disabled, please run this command on the local API machine")

View file

@ -45,7 +45,8 @@ func NewDashboardCmd() *cobra.Command {
Long: `Install/Start/Stop/Remove a metabase container exposing dashboard and metrics. Long: `Install/Start/Stop/Remove a metabase container exposing dashboard and metrics.
Note: This command requires database direct access, so is intended to be run on Local API/master. Note: This command requires database direct access, so is intended to be run on Local API/master.
`, `,
Args: cobra.ExactArgs(1), Args: cobra.ExactArgs(1),
DisableAutoGenTag: true,
Example: ` Example: `
cscli dashboard setup cscli dashboard setup
cscli dashboard start cscli dashboard start
@ -87,10 +88,11 @@ cscli dashboard remove
var force bool var force bool
var cmdDashSetup = &cobra.Command{ var cmdDashSetup = &cobra.Command{
Use: "setup", Use: "setup",
Short: "Setup a metabase container.", Short: "Setup a metabase container.",
Long: `Perform a metabase docker setup, download standard dashboards, create a fresh user and start the container`, Long: `Perform a metabase docker setup, download standard dashboards, create a fresh user and start the container`,
Args: cobra.ExactArgs(0), Args: cobra.ExactArgs(0),
DisableAutoGenTag: true,
Example: ` Example: `
cscli dashboard setup cscli dashboard setup
cscli dashboard setup --listen 0.0.0.0 cscli dashboard setup --listen 0.0.0.0
@ -176,10 +178,11 @@ cscli dashboard setup -l 0.0.0.0 -p 443 --password <password>
cmdDashboard.AddCommand(cmdDashSetup) cmdDashboard.AddCommand(cmdDashSetup)
var cmdDashStart = &cobra.Command{ var cmdDashStart = &cobra.Command{
Use: "start", Use: "start",
Short: "Start the metabase container.", Short: "Start the metabase container.",
Long: `Stats the metabase container using docker.`, Long: `Stats the metabase container using docker.`,
Args: cobra.ExactArgs(0), Args: cobra.ExactArgs(0),
DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
mb, err := metabase.NewMetabase(metabaseConfigPath, metabaseContainerID) mb, err := metabase.NewMetabase(metabaseConfigPath, metabaseContainerID)
if err != nil { if err != nil {
@ -195,10 +198,11 @@ cscli dashboard setup -l 0.0.0.0 -p 443 --password <password>
cmdDashboard.AddCommand(cmdDashStart) cmdDashboard.AddCommand(cmdDashStart)
var cmdDashStop = &cobra.Command{ var cmdDashStop = &cobra.Command{
Use: "stop", Use: "stop",
Short: "Stops the metabase container.", Short: "Stops the metabase container.",
Long: `Stops the metabase container using docker.`, Long: `Stops the metabase container using docker.`,
Args: cobra.ExactArgs(0), Args: cobra.ExactArgs(0),
DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
if err := metabase.StopContainer(metabaseContainerID); err != nil { if err := metabase.StopContainer(metabaseContainerID); err != nil {
log.Fatalf("unable to stop container '%s': %s", metabaseContainerID, err) log.Fatalf("unable to stop container '%s': %s", metabaseContainerID, err)
@ -208,10 +212,11 @@ cscli dashboard setup -l 0.0.0.0 -p 443 --password <password>
cmdDashboard.AddCommand(cmdDashStop) cmdDashboard.AddCommand(cmdDashStop)
var cmdDashRemove = &cobra.Command{ var cmdDashRemove = &cobra.Command{
Use: "remove", Use: "remove",
Short: "removes the metabase container.", Short: "removes the metabase container.",
Long: `removes the metabase container using docker.`, Long: `removes the metabase container using docker.`,
Args: cobra.ExactArgs(0), Args: cobra.ExactArgs(0),
DisableAutoGenTag: true,
Example: ` Example: `
cscli dashboard remove cscli dashboard remove
cscli dashboard remove --force cscli dashboard remove --force

View file

@ -103,7 +103,8 @@ func NewDecisionsCmd() *cobra.Command {
Long: `Add/List/Delete decisions from LAPI`, Long: `Add/List/Delete decisions from LAPI`,
Example: `cscli decisions [action] [filter]`, Example: `cscli decisions [action] [filter]`,
/*TBD example*/ /*TBD example*/
Args: cobra.MinimumNArgs(1), Args: cobra.MinimumNArgs(1),
DisableAutoGenTag: true,
PersistentPreRun: func(cmd *cobra.Command, args []string) { PersistentPreRun: func(cmd *cobra.Command, args []string) {
if err := csConfig.LoadAPIClient(); err != nil { if err := csConfig.LoadAPIClient(); err != nil {
log.Fatalf(err.Error()) log.Fatalf(err.Error())
@ -153,7 +154,8 @@ cscli decisions list -r 1.2.3.0/24
cscli decisions list -s crowdsecurity/ssh-bf cscli decisions list -s crowdsecurity/ssh-bf
cscli decisions list -t ban cscli decisions list -t ban
`, `,
Args: cobra.ExactArgs(0), Args: cobra.ExactArgs(0),
DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
var err error var err error
/*take care of shorthand options*/ /*take care of shorthand options*/
@ -262,7 +264,8 @@ cscli decisions add --ip 1.2.3.4 --duration 24h --type captcha
cscli decisions add --scope username --value foobar cscli decisions add --scope username --value foobar
`, `,
/*TBD : fix long and example*/ /*TBD : fix long and example*/
Args: cobra.ExactArgs(0), Args: cobra.ExactArgs(0),
DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
var err error var err error
var ip, ipRange string var ip, ipRange string
@ -361,8 +364,9 @@ cscli decisions add --scope username --value foobar
var delDecisionId string var delDecisionId string
var delDecisionAll bool var delDecisionAll bool
var cmdDecisionsDelete = &cobra.Command{ var cmdDecisionsDelete = &cobra.Command{
Use: "delete [options]", Use: "delete [options]",
Short: "Delete decisions", Short: "Delete decisions",
DisableAutoGenTag: true,
Example: `cscli decisions delete -r 1.2.3.0/24 Example: `cscli decisions delete -r 1.2.3.0/24
cscli decisions delete -i 1.2.3.4 cscli decisions delete -i 1.2.3.4
cscli decisions delete -s crowdsecurity/ssh-bf cscli decisions delete -s crowdsecurity/ssh-bf

View file

@ -24,7 +24,8 @@ Hub is manage by cscli, to get latest hub files from [Crowdsec Hub](https://hub.
cscli hub list # List all installed configurations cscli hub list # List all installed configurations
cscli hub update # Download list of available configurations from the hub cscli hub update # Download list of available configurations from the hub
`, `,
Args: cobra.ExactArgs(0), Args: cobra.ExactArgs(0),
DisableAutoGenTag: true,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error { PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if csConfig.Cscli == nil { if csConfig.Cscli == nil {
return fmt.Errorf("you must configure cli before interacting with hub") return fmt.Errorf("you must configure cli before interacting with hub")
@ -36,9 +37,10 @@ cscli hub update # Download list of available configurations from the hub
cmdHub.PersistentFlags().StringVarP(&cwhub.HubBranch, "branch", "b", "", "Use given branch from hub") cmdHub.PersistentFlags().StringVarP(&cwhub.HubBranch, "branch", "b", "", "Use given branch from hub")
var cmdHubList = &cobra.Command{ var cmdHubList = &cobra.Command{
Use: "list [-a]", Use: "list [-a]",
Short: "List installed configs", Short: "List installed configs",
Args: cobra.ExactArgs(0), Args: cobra.ExactArgs(0),
DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
if err := csConfig.LoadHub(); err != nil { if err := csConfig.LoadHub(); err != nil {
@ -73,7 +75,8 @@ cscli hub update # Download list of available configurations from the hub
Long: ` Long: `
Fetches the [.index.json](https://github.com/crowdsecurity/hub/blob/master/.index.json) file from hub, containing the list of available configs. Fetches the [.index.json](https://github.com/crowdsecurity/hub/blob/master/.index.json) file from hub, containing the list of available configs.
`, `,
Args: cobra.ExactArgs(0), Args: cobra.ExactArgs(0),
DisableAutoGenTag: true,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error { PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if csConfig.Cscli == nil { if csConfig.Cscli == nil {
return fmt.Errorf("you must configure cli before interacting with hub") return fmt.Errorf("you must configure cli before interacting with hub")
@ -106,7 +109,8 @@ Fetches the [.index.json](https://github.com/crowdsecurity/hub/blob/master/.inde
Long: ` Long: `
Upgrade all configs installed from Crowdsec Hub. Run 'sudo cscli hub update' if you want the latest versions available. Upgrade all configs installed from Crowdsec Hub. Run 'sudo cscli hub update' if you want the latest versions available.
`, `,
Args: cobra.ExactArgs(0), Args: cobra.ExactArgs(0),
DisableAutoGenTag: true,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error { PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if csConfig.Cscli == nil { if csConfig.Cscli == nil {
return fmt.Errorf("you must configure cli before interacting with hub") return fmt.Errorf("you must configure cli before interacting with hub")

View file

@ -24,9 +24,10 @@ var lapiUser string
func NewLapiCmd() *cobra.Command { func NewLapiCmd() *cobra.Command {
var cmdLapi = &cobra.Command{ var cmdLapi = &cobra.Command{
Use: "lapi [action]", Use: "lapi [action]",
Short: "Manage interaction with Local API (LAPI)", Short: "Manage interaction with Local API (LAPI)",
Args: cobra.MinimumNArgs(1), Args: cobra.MinimumNArgs(1),
DisableAutoGenTag: true,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error { PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if err := csConfig.LoadAPIClient(); err != nil { if err := csConfig.LoadAPIClient(); err != nil {
return fmt.Errorf("loading api client: %s", err.Error()) return fmt.Errorf("loading api client: %s", err.Error())
@ -46,7 +47,8 @@ func NewLapiCmd() *cobra.Command {
Short: "Register a machine to Local API (LAPI)", Short: "Register a machine to Local API (LAPI)",
Long: `Register you machine to the Local API (LAPI). Long: `Register you machine to the Local API (LAPI).
Keep in mind the machine needs to be validated by an administrator on LAPI side to be effective.`, Keep in mind the machine needs to be validated by an administrator on LAPI side to be effective.`,
Args: cobra.MinimumNArgs(0), Args: cobra.MinimumNArgs(0),
DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
var err error var err error
if lapiUser == "" { if lapiUser == "" {
@ -124,9 +126,10 @@ Keep in mind the machine needs to be validated by an administrator on LAPI side
cmdLapi.AddCommand(cmdLapiRegister) cmdLapi.AddCommand(cmdLapiRegister)
var cmdLapiStatus = &cobra.Command{ var cmdLapiStatus = &cobra.Command{
Use: "status", Use: "status",
Short: "Check authentication to Local API (LAPI)", Short: "Check authentication to Local API (LAPI)",
Args: cobra.MinimumNArgs(0), Args: cobra.MinimumNArgs(0),
DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
var err error var err error

View file

@ -84,7 +84,8 @@ func NewMachinesCmd() *cobra.Command {
Long: `To list/add/delete/validate machines. Long: `To list/add/delete/validate machines.
Note: This command requires database direct access, so is intended to be run on the local API machine. Note: This command requires database direct access, so is intended to be run on the local API machine.
`, `,
Example: `cscli machines [action]`, Example: `cscli machines [action]`,
DisableAutoGenTag: true,
PersistentPreRun: func(cmd *cobra.Command, args []string) { PersistentPreRun: func(cmd *cobra.Command, args []string) {
if err := csConfig.LoadAPIServer(); err != nil || csConfig.DisableAPI { if err := csConfig.LoadAPIServer(); err != nil || csConfig.DisableAPI {
log.Fatal("Local API is disabled, please run this command on the local API machine") log.Fatal("Local API is disabled, please run this command on the local API machine")
@ -97,11 +98,12 @@ Note: This command requires database direct access, so is intended to be run on
} }
var cmdMachinesList = &cobra.Command{ var cmdMachinesList = &cobra.Command{
Use: "list", Use: "list",
Short: "List machines", Short: "List machines",
Long: `List `, Long: `List `,
Example: `cscli machines list`, Example: `cscli machines list`,
Args: cobra.MaximumNArgs(1), Args: cobra.MaximumNArgs(1),
DisableAutoGenTag: true,
PreRun: func(cmd *cobra.Command, args []string) { PreRun: func(cmd *cobra.Command, args []string) {
var err error var err error
dbClient, err = database.NewClient(csConfig.DbConfig) dbClient, err = database.NewClient(csConfig.DbConfig)
@ -156,9 +158,10 @@ Note: This command requires database direct access, so is intended to be run on
cmdMachines.AddCommand(cmdMachinesList) cmdMachines.AddCommand(cmdMachinesList)
var cmdMachinesAdd = &cobra.Command{ var cmdMachinesAdd = &cobra.Command{
Use: "add", Use: "add",
Short: "add machine to the database.", Short: "add machine to the database.",
Long: `Register a new machine in the database. cscli should be on the same machine as LAPI.`, DisableAutoGenTag: true,
Long: `Register a new machine in the database. cscli should be on the same machine as LAPI.`,
Example: ` Example: `
cscli machines add --auto cscli machines add --auto
cscli machines add MyTestMachine --auto cscli machines add MyTestMachine --auto
@ -260,10 +263,11 @@ cscli machines add MyTestMachine --password MyPassword
cmdMachines.AddCommand(cmdMachinesAdd) cmdMachines.AddCommand(cmdMachinesAdd)
var cmdMachinesDelete = &cobra.Command{ var cmdMachinesDelete = &cobra.Command{
Use: "delete --machine MyTestMachine", Use: "delete --machine MyTestMachine",
Short: "delete machines", Short: "delete machines",
Example: `cscli machines delete <machine_name>`, Example: `cscli machines delete "machine_name"`,
Args: cobra.ExactArgs(1), Args: cobra.ExactArgs(1),
DisableAutoGenTag: true,
PreRun: func(cmd *cobra.Command, args []string) { PreRun: func(cmd *cobra.Command, args []string) {
var err error var err error
dbClient, err = database.NewClient(csConfig.DbConfig) dbClient, err = database.NewClient(csConfig.DbConfig)
@ -285,11 +289,12 @@ cscli machines add MyTestMachine --password MyPassword
cmdMachines.AddCommand(cmdMachinesDelete) cmdMachines.AddCommand(cmdMachinesDelete)
var cmdMachinesValidate = &cobra.Command{ var cmdMachinesValidate = &cobra.Command{
Use: "validate", Use: "validate",
Short: "validate a machine to access the local API", Short: "validate a machine to access the local API",
Long: `validate a machine to access the local API.`, Long: `validate a machine to access the local API.`,
Example: `cscli machines validate <machine_name>`, Example: `cscli machines validate "machine_name"`,
Args: cobra.ExactArgs(1), Args: cobra.ExactArgs(1),
DisableAutoGenTag: true,
PreRun: func(cmd *cobra.Command, args []string) { PreRun: func(cmd *cobra.Command, args []string) {
var err error var err error
dbClient, err = database.NewClient(csConfig.DbConfig) dbClient, err = database.NewClient(csConfig.DbConfig)

View file

@ -1,6 +1,11 @@
package main package main
import ( import (
"fmt"
"path"
"path/filepath"
"strings"
"github.com/crowdsecurity/crowdsec/pkg/csconfig" "github.com/crowdsecurity/crowdsec/pkg/csconfig"
"github.com/crowdsecurity/crowdsec/pkg/cwhub" "github.com/crowdsecurity/crowdsec/pkg/cwhub"
"github.com/crowdsecurity/crowdsec/pkg/cwversion" "github.com/crowdsecurity/crowdsec/pkg/cwversion"
@ -83,6 +88,22 @@ var validArgs = []string{
"config", "completion", "version", "console", "config", "completion", "version", "console",
} }
func prepender(filename string) string {
const header = `---
id: %s
title: %s
---
`
name := filepath.Base(filename)
base := strings.TrimSuffix(name, path.Ext(name))
return fmt.Sprintf(header, base, strings.Replace(base, "_", " ", -1))
}
func linkHandler(name string) string {
base := strings.TrimSuffix(name, path.Ext(name))
return fmt.Sprintf("/docs/cscli/%s", base)
}
func main() { func main() {
var rootCmd = &cobra.Command{ var rootCmd = &cobra.Command{
@ -94,12 +115,13 @@ It is meant to allow you to manage bans, parsers/scenarios/etc, api and generall
/*TBD examples*/ /*TBD examples*/
} }
var cmdDocGen = &cobra.Command{ var cmdDocGen = &cobra.Command{
Use: "doc", Use: "doc",
Short: "Generate the documentation in `./doc/`. Directory must exist.", Short: "Generate the documentation in `./doc/`. Directory must exist.",
Args: cobra.ExactArgs(0), Args: cobra.ExactArgs(0),
Hidden: true, Hidden: true,
DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
if err := doc.GenMarkdownTree(rootCmd, "./doc/"); err != nil { if err := doc.GenMarkdownTreeCustom(rootCmd, "./doc/", prepender, linkHandler); err != nil {
log.Fatalf("Failed to generate cobra doc: %s", err.Error()) log.Fatalf("Failed to generate cobra doc: %s", err.Error())
} }
}, },
@ -107,9 +129,10 @@ It is meant to allow you to manage bans, parsers/scenarios/etc, api and generall
rootCmd.AddCommand(cmdDocGen) rootCmd.AddCommand(cmdDocGen)
/*usage*/ /*usage*/
var cmdVersion = &cobra.Command{ var cmdVersion = &cobra.Command{
Use: "version", Use: "version",
Short: "Display version and exit.", Short: "Display version and exit.",
Args: cobra.ExactArgs(0), Args: cobra.ExactArgs(0),
DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
cwversion.Show() cwversion.Show()
}, },

View file

@ -377,10 +377,11 @@ func ShowPrometheus(url string) {
func NewMetricsCmd() *cobra.Command { func NewMetricsCmd() *cobra.Command {
/* ---- UPDATE COMMAND */ /* ---- UPDATE COMMAND */
var cmdMetrics = &cobra.Command{ var cmdMetrics = &cobra.Command{
Use: "metrics", Use: "metrics",
Short: "Display crowdsec prometheus metrics.", Short: "Display crowdsec prometheus metrics.",
Long: `Fetch metrics from the prometheus server and display them in a human-friendly way`, Long: `Fetch metrics from the prometheus server and display them in a human-friendly way`,
Args: cobra.ExactArgs(0), Args: cobra.ExactArgs(0),
DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
if err := csConfig.LoadPrometheus(); err != nil { if err := csConfig.LoadPrometheus(); err != nil {
log.Fatalf(err.Error()) log.Fatalf(err.Error())

View file

@ -20,7 +20,8 @@ cscli parsers upgrade crowdsecurity/sshd-logs
cscli parsers list cscli parsers list
cscli parsers remove crowdsecurity/sshd-logs cscli parsers remove crowdsecurity/sshd-logs
`, `,
Args: cobra.MinimumNArgs(1), Args: cobra.MinimumNArgs(1),
DisableAutoGenTag: true,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error { PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if err := csConfig.LoadHub(); err != nil { if err := csConfig.LoadHub(); err != nil {
log.Fatalf(err.Error()) log.Fatalf(err.Error())
@ -48,11 +49,12 @@ cscli parsers remove crowdsecurity/sshd-logs
} }
var cmdParsersInstall = &cobra.Command{ var cmdParsersInstall = &cobra.Command{
Use: "install [config]", Use: "install [config]",
Short: "Install given parser(s)", Short: "Install given parser(s)",
Long: `Fetch and install given parser(s) from hub`, Long: `Fetch and install given parser(s) from hub`,
Example: `cscli parsers install crowdsec/xxx crowdsec/xyz`, Example: `cscli parsers install crowdsec/xxx crowdsec/xyz`,
Args: cobra.MinimumNArgs(1), Args: cobra.MinimumNArgs(1),
DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
for _, name := range args { for _, name := range args {
InstallItem(name, cwhub.PARSERS, forceAction) InstallItem(name, cwhub.PARSERS, forceAction)
@ -64,11 +66,12 @@ cscli parsers remove crowdsecurity/sshd-logs
cmdParsers.AddCommand(cmdParsersInstall) cmdParsers.AddCommand(cmdParsersInstall)
var cmdParsersRemove = &cobra.Command{ var cmdParsersRemove = &cobra.Command{
Use: "remove [config]", Use: "remove [config]",
Short: "Remove given parser(s)", Short: "Remove given parser(s)",
Long: `Remove given parse(s) from hub`, Long: `Remove given parse(s) from hub`,
Example: `cscli parsers remove crowdsec/xxx crowdsec/xyz`, Example: `cscli parsers remove crowdsec/xxx crowdsec/xyz`,
Args: cobra.MinimumNArgs(1), Args: cobra.MinimumNArgs(1),
DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
if all { if all {
RemoveMany(cwhub.PARSERS, "") RemoveMany(cwhub.PARSERS, "")
@ -85,10 +88,11 @@ cscli parsers remove crowdsecurity/sshd-logs
cmdParsers.AddCommand(cmdParsersRemove) cmdParsers.AddCommand(cmdParsersRemove)
var cmdParsersUpgrade = &cobra.Command{ var cmdParsersUpgrade = &cobra.Command{
Use: "upgrade [config]", Use: "upgrade [config]",
Short: "Upgrade given parser(s)", Short: "Upgrade given parser(s)",
Long: `Fetch and upgrade given parser(s) from hub`, Long: `Fetch and upgrade given parser(s) from hub`,
Example: `cscli parsers upgrade crowdsec/xxx crowdsec/xyz`, Example: `cscli parsers upgrade crowdsec/xxx crowdsec/xyz`,
DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
if all { if all {
UpgradeConfig(cwhub.PARSERS, "", forceAction) UpgradeConfig(cwhub.PARSERS, "", forceAction)
@ -107,11 +111,12 @@ cscli parsers remove crowdsecurity/sshd-logs
cmdParsers.AddCommand(cmdParsersUpgrade) cmdParsers.AddCommand(cmdParsersUpgrade)
var cmdParsersInspect = &cobra.Command{ var cmdParsersInspect = &cobra.Command{
Use: "inspect [name]", Use: "inspect [name]",
Short: "Inspect given parser", Short: "Inspect given parser",
Long: `Inspect given parser`, Long: `Inspect given parser`,
Example: `cscli parsers inspect crowdsec/xxx`, Example: `cscli parsers inspect crowdsec/xxx`,
Args: cobra.MinimumNArgs(1), DisableAutoGenTag: true,
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
InspectItem(args[0], cwhub.PARSERS) InspectItem(args[0], cwhub.PARSERS)
}, },
@ -125,6 +130,7 @@ cscli parsers remove crowdsecurity/sshd-logs
Long: `List all parsers or given one`, Long: `List all parsers or given one`,
Example: `cscli parsers list Example: `cscli parsers list
cscli parser list crowdsecurity/xxx`, cscli parser list crowdsecurity/xxx`,
DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
ListItem(cwhub.PARSERS, args) ListItem(cwhub.PARSERS, args)
}, },

View file

@ -19,7 +19,8 @@ func NewPostOverflowsCmd() *cobra.Command {
cscli postoverflows upgrade crowdsecurity/cdn-whitelist cscli postoverflows upgrade crowdsecurity/cdn-whitelist
cscli postoverflows list cscli postoverflows list
cscli postoverflows remove crowdsecurity/cdn-whitelist`, cscli postoverflows remove crowdsecurity/cdn-whitelist`,
Args: cobra.MinimumNArgs(1), Args: cobra.MinimumNArgs(1),
DisableAutoGenTag: true,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error { PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if err := csConfig.LoadHub(); err != nil { if err := csConfig.LoadHub(); err != nil {
log.Fatalf(err.Error()) log.Fatalf(err.Error())
@ -47,11 +48,12 @@ func NewPostOverflowsCmd() *cobra.Command {
} }
var cmdPostOverflowsInstall = &cobra.Command{ var cmdPostOverflowsInstall = &cobra.Command{
Use: "install [config]", Use: "install [config]",
Short: "Install given postoverflow(s)", Short: "Install given postoverflow(s)",
Long: `Fetch and install given postoverflow(s) from hub`, Long: `Fetch and install given postoverflow(s) from hub`,
Example: `cscli postoverflows install crowdsec/xxx crowdsec/xyz`, Example: `cscli postoverflows install crowdsec/xxx crowdsec/xyz`,
Args: cobra.MinimumNArgs(1), Args: cobra.MinimumNArgs(1),
DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
for _, name := range args { for _, name := range args {
InstallItem(name, cwhub.PARSERS_OVFLW, forceAction) InstallItem(name, cwhub.PARSERS_OVFLW, forceAction)
@ -63,11 +65,12 @@ func NewPostOverflowsCmd() *cobra.Command {
cmdPostOverflows.AddCommand(cmdPostOverflowsInstall) cmdPostOverflows.AddCommand(cmdPostOverflowsInstall)
var cmdPostOverflowsRemove = &cobra.Command{ var cmdPostOverflowsRemove = &cobra.Command{
Use: "remove [config]", Use: "remove [config]",
Short: "Remove given postoverflow(s)", Short: "Remove given postoverflow(s)",
Long: `remove given postoverflow(s)`, Long: `remove given postoverflow(s)`,
Example: `cscli postoverflows remove crowdsec/xxx crowdsec/xyz`, Example: `cscli postoverflows remove crowdsec/xxx crowdsec/xyz`,
Args: cobra.MinimumNArgs(1), DisableAutoGenTag: true,
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
if all { if all {
RemoveMany(cwhub.PARSERS_OVFLW, "") RemoveMany(cwhub.PARSERS_OVFLW, "")
@ -84,10 +87,11 @@ func NewPostOverflowsCmd() *cobra.Command {
cmdPostOverflows.AddCommand(cmdPostOverflowsRemove) cmdPostOverflows.AddCommand(cmdPostOverflowsRemove)
var cmdPostOverflowsUpgrade = &cobra.Command{ var cmdPostOverflowsUpgrade = &cobra.Command{
Use: "upgrade [config]", Use: "upgrade [config]",
Short: "Upgrade given postoverflow(s)", Short: "Upgrade given postoverflow(s)",
Long: `Fetch and Upgrade given postoverflow(s) from hub`, Long: `Fetch and Upgrade given postoverflow(s) from hub`,
Example: `cscli postoverflows upgrade crowdsec/xxx crowdsec/xyz`, Example: `cscli postoverflows upgrade crowdsec/xxx crowdsec/xyz`,
DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
if all { if all {
UpgradeConfig(cwhub.PARSERS_OVFLW, "", forceAction) UpgradeConfig(cwhub.PARSERS_OVFLW, "", forceAction)
@ -106,11 +110,12 @@ func NewPostOverflowsCmd() *cobra.Command {
cmdPostOverflows.AddCommand(cmdPostOverflowsUpgrade) cmdPostOverflows.AddCommand(cmdPostOverflowsUpgrade)
var cmdPostOverflowsInspect = &cobra.Command{ var cmdPostOverflowsInspect = &cobra.Command{
Use: "inspect [config]", Use: "inspect [config]",
Short: "Inspect given postoverflow", Short: "Inspect given postoverflow",
Long: `Inspect given postoverflow`, Long: `Inspect given postoverflow`,
Example: `cscli postoverflows inspect crowdsec/xxx crowdsec/xyz`, Example: `cscli postoverflows inspect crowdsec/xxx crowdsec/xyz`,
Args: cobra.MinimumNArgs(1), DisableAutoGenTag: true,
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
InspectItem(args[0], cwhub.PARSERS_OVFLW) InspectItem(args[0], cwhub.PARSERS_OVFLW)
}, },
@ -123,6 +128,7 @@ func NewPostOverflowsCmd() *cobra.Command {
Long: `List all postoverflows or given one`, Long: `List all postoverflows or given one`,
Example: `cscli postoverflows list Example: `cscli postoverflows list
cscli postoverflows list crowdsecurity/xxx`, cscli postoverflows list crowdsecurity/xxx`,
DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
ListItem(cwhub.PARSERS_OVFLW, args) ListItem(cwhub.PARSERS_OVFLW, args)
}, },

View file

@ -20,7 +20,8 @@ cscli scenarios inspect crowdsecurity/ssh-bf
cscli scenarios upgrade crowdsecurity/ssh-bf cscli scenarios upgrade crowdsecurity/ssh-bf
cscli scenarios remove crowdsecurity/ssh-bf cscli scenarios remove crowdsecurity/ssh-bf
`, `,
Args: cobra.MinimumNArgs(1), Args: cobra.MinimumNArgs(1),
DisableAutoGenTag: true,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error { PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if err := csConfig.LoadHub(); err != nil { if err := csConfig.LoadHub(); err != nil {
log.Fatalf(err.Error()) log.Fatalf(err.Error())
@ -48,11 +49,12 @@ cscli scenarios remove crowdsecurity/ssh-bf
} }
var cmdScenariosInstall = &cobra.Command{ var cmdScenariosInstall = &cobra.Command{
Use: "install [config]", Use: "install [config]",
Short: "Install given scenario(s)", Short: "Install given scenario(s)",
Long: `Fetch and install given scenario(s) from hub`, Long: `Fetch and install given scenario(s) from hub`,
Example: `cscli scenarios install crowdsec/xxx crowdsec/xyz`, Example: `cscli scenarios install crowdsec/xxx crowdsec/xyz`,
Args: cobra.MinimumNArgs(1), Args: cobra.MinimumNArgs(1),
DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
for _, name := range args { for _, name := range args {
InstallItem(name, cwhub.SCENARIOS, forceAction) InstallItem(name, cwhub.SCENARIOS, forceAction)
@ -64,11 +66,12 @@ cscli scenarios remove crowdsecurity/ssh-bf
cmdScenarios.AddCommand(cmdScenariosInstall) cmdScenarios.AddCommand(cmdScenariosInstall)
var cmdScenariosRemove = &cobra.Command{ var cmdScenariosRemove = &cobra.Command{
Use: "remove [config]", Use: "remove [config]",
Short: "Remove given scenario(s)", Short: "Remove given scenario(s)",
Long: `remove given scenario(s)`, Long: `remove given scenario(s)`,
Example: `cscli scenarios remove crowdsec/xxx crowdsec/xyz`, Example: `cscli scenarios remove crowdsec/xxx crowdsec/xyz`,
Args: cobra.MinimumNArgs(1), Args: cobra.MinimumNArgs(1),
DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
if all { if all {
RemoveMany(cwhub.SCENARIOS, "") RemoveMany(cwhub.SCENARIOS, "")
@ -85,10 +88,11 @@ cscli scenarios remove crowdsecurity/ssh-bf
cmdScenarios.AddCommand(cmdScenariosRemove) cmdScenarios.AddCommand(cmdScenariosRemove)
var cmdScenariosUpgrade = &cobra.Command{ var cmdScenariosUpgrade = &cobra.Command{
Use: "upgrade [config]", Use: "upgrade [config]",
Short: "Upgrade given scenario(s)", Short: "Upgrade given scenario(s)",
Long: `Fetch and Upgrade given scenario(s) from hub`, Long: `Fetch and Upgrade given scenario(s) from hub`,
Example: `cscli scenarios upgrade crowdsec/xxx crowdsec/xyz`, Example: `cscli scenarios upgrade crowdsec/xxx crowdsec/xyz`,
DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
if all { if all {
UpgradeConfig(cwhub.SCENARIOS, "", forceAction) UpgradeConfig(cwhub.SCENARIOS, "", forceAction)
@ -107,11 +111,12 @@ cscli scenarios remove crowdsecurity/ssh-bf
cmdScenarios.AddCommand(cmdScenariosUpgrade) cmdScenarios.AddCommand(cmdScenariosUpgrade)
var cmdScenariosInspect = &cobra.Command{ var cmdScenariosInspect = &cobra.Command{
Use: "inspect [config]", Use: "inspect [config]",
Short: "Inspect given scenario", Short: "Inspect given scenario",
Long: `Inspect given scenario`, Long: `Inspect given scenario`,
Example: `cscli scenarios inspect crowdsec/xxx`, Example: `cscli scenarios inspect crowdsec/xxx`,
Args: cobra.MinimumNArgs(1), Args: cobra.MinimumNArgs(1),
DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
InspectItem(args[0], cwhub.SCENARIOS) InspectItem(args[0], cwhub.SCENARIOS)
}, },
@ -125,6 +130,7 @@ cscli scenarios remove crowdsecurity/ssh-bf
Long: `List all scenario(s) or given one`, Long: `List all scenario(s) or given one`,
Example: `cscli scenarios list Example: `cscli scenarios list
cscli scenarios list crowdsecurity/xxx`, cscli scenarios list crowdsecurity/xxx`,
DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
ListItem(cwhub.SCENARIOS, args) ListItem(cwhub.SCENARIOS, args)
}, },

View file

@ -104,6 +104,7 @@ func NewSimulationCmds() *cobra.Command {
Example: `cscli simulation status Example: `cscli simulation status
cscli simulation enable crowdsecurity/ssh-bf cscli simulation enable crowdsecurity/ssh-bf
cscli simulation disable crowdsecurity/ssh-bf`, cscli simulation disable crowdsecurity/ssh-bf`,
DisableAutoGenTag: true,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error { PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if err := csConfig.LoadSimulation(); err != nil { if err := csConfig.LoadSimulation(); err != nil {
log.Fatalf(err.Error()) log.Fatalf(err.Error())
@ -127,9 +128,10 @@ cscli simulation disable crowdsecurity/ssh-bf`,
var forceGlobalSimulation bool var forceGlobalSimulation bool
var cmdSimulationEnable = &cobra.Command{ var cmdSimulationEnable = &cobra.Command{
Use: "enable [scenario] [-global]", Use: "enable [scenario] [-global]",
Short: "Enable the simulation, globally or on specified scenarios", Short: "Enable the simulation, globally or on specified scenarios",
Example: `cscli simulation enable`, Example: `cscli simulation enable`,
DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
if err := csConfig.LoadHub(); err != nil { if err := csConfig.LoadHub(); err != nil {
log.Fatalf(err.Error()) log.Fatalf(err.Error())
@ -189,9 +191,10 @@ cscli simulation disable crowdsecurity/ssh-bf`,
cmdSimulation.AddCommand(cmdSimulationEnable) cmdSimulation.AddCommand(cmdSimulationEnable)
var cmdSimulationDisable = &cobra.Command{ var cmdSimulationDisable = &cobra.Command{
Use: "disable [scenario]", Use: "disable [scenario]",
Short: "Disable the simulation mode. Disable only specified scenarios", Short: "Disable the simulation mode. Disable only specified scenarios",
Example: `cscli simulation disable`, Example: `cscli simulation disable`,
DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
if len(args) > 0 { if len(args) > 0 {
for _, scenario := range args { for _, scenario := range args {
@ -232,9 +235,10 @@ cscli simulation disable crowdsecurity/ssh-bf`,
cmdSimulation.AddCommand(cmdSimulationDisable) cmdSimulation.AddCommand(cmdSimulationDisable)
var cmdSimulationStatus = &cobra.Command{ var cmdSimulationStatus = &cobra.Command{
Use: "status", Use: "status",
Short: "Show simulation mode status", Short: "Show simulation mode status",
Example: `cscli simulation status`, Example: `cscli simulation status`,
DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
if err := simulationStatus(); err != nil { if err := simulationStatus(); err != nil {
log.Fatalf(err.Error()) log.Fatalf(err.Error())