Skip to content
This repository was archived by the owner on May 15, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,26 @@ The run "C1234" can be cancelled using the following command:
galasactl runs cancel --name C1234
```

## monitors set

This command can be used to update a monitor in the Galasa service. The name of the monitor to be enabled must be provided using the `--name` flag.

### Examples

To enable a monitor named "myCustomMonitor":

```
galasactl monitors set --name myCustomMonitor --is-enabled true
```

To disable a monitor named "myCustomMonitor":

```
galasactl monitors set --name myCustomMonitor --is-enabled false
```

For a complete list of supported parameters see [here](./docs/generated/galasactl_monitors_set.md).

## monitors get

This command can be used to get the details of monitors, like resource cleanup monitors, that are available in the Galasa service.
Expand Down
12 changes: 7 additions & 5 deletions docs/generated/errors-list.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,13 @@ The `galasactl` tool can generate the following errors:
- GAL1223E: Failed to get monitors. Unexpected http status code {} received from the server. Error details from the server are not in the json format.
- GAL1224E: Galasa Monitor named {} is not known on the Galasa service.
- GAL1225E: Invalid monitor name provided. The name provided with the --name flag cannot be empty and must only contain characters in the following ranges: 'a'-'z', 'A'-'Z', '0'-'9', '-' (dash), '_' (underscore).
- GAL1226E: Internal failure. Contents of gzip could be read, but not decoded. New gzip reader failed: file: {} error: {}
- GAL1227E: Internal failure. Contents of gzip could not be decoded. {} error: {}
- GAL1228E: Internal failure. Contents of gzip could not be encoded and compressed. {} error: {}
- GAL1229E: Internal failure. Contents of gzip could not be flushed while encoding and compressing. {} error: {}
- GAL1230E: Internal failure. Gzip file could not be closed while encoding and compressing. {} error: {}
- GAL1226E: Invalid '--is-enabled' value provided. Supported values are 'true' and 'false'. Check your command parameters and try again.
- GAL1227E: Failed to update a monitor named '{}'. Sending the put request to the Galasa service failed. Cause is {}
- GAL1228E: Failed to update a monitor named '{}'. Unexpected http status code {} received from the server.
- GAL1229E: Failed to update a monitor named '{}'. Unexpected http status code {} received from the server. Error details from the server could not be read. Cause: {}
- GAL1230E: Failed to update a monitor named '{}'. Unexpected http status code {} received from the server. Error details from the server are not in a valid json format. Cause: '{}'
- GAL1231E: Failed to update a monitor named '{}'. Unexpected http status code {} received from the server. Error details from the server are: '{}'
- GAL1232E: Failed to update a monitor named '{}'. Unexpected http status code {} received from the server. Error details from the server are not in the json format.
- GAL2000W: Warning: Maven configuration file settings.xml should contain a reference to a Galasa repository so that the galasa OBR can be resolved. The official release repository is '{}', and 'pre-release' repository is '{}'
- GAL2501I: Downloaded {} artifacts to folder '{}'

Expand Down
1 change: 1 addition & 0 deletions docs/generated/galasactl_monitors.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ The parent command for operations to manipulate monitors in the Galasa service

* [galasactl](galasactl.md) - CLI for Galasa
* [galasactl monitors get](galasactl_monitors_get.md) - Get monitors from the Galasa service
* [galasactl monitors set](galasactl_monitors_set.md) - Update a monitor in the Galasa service

33 changes: 33 additions & 0 deletions docs/generated/galasactl_monitors_disable.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
## galasactl monitors disable

Disable a monitor in the Galasa service

### Synopsis

Disables a monitor with the given name in the Galasa service

```
galasactl monitors disable [flags]
```

### Options

```
-h, --help Displays the options for the 'monitors disable' command.
--name string A mandatory flag that identifies the monitor to be manipulated by name.
```

### Options inherited from parent commands

```
-b, --bootstrap string Bootstrap URL. Should start with 'http://' or 'file://'. If it starts with neither, it is assumed to be a fully-qualified path. If missing, it defaults to use the 'bootstrap.properties' file in your GALASA_HOME. Example: http://example.com/bootstrap, file:///user/myuserid/.galasa/bootstrap.properties , file://C:/Users/myuserid/.galasa/bootstrap.properties
--galasahome string Path to a folder where Galasa will read and write files and configuration settings. The default is '${HOME}/.galasa'. This overrides the GALASA_HOME environment variable which may be set instead.
-l, --log string File to which log information will be sent. Any folder referred to must exist. An existing file will be overwritten. Specify "-" to log to stderr. Defaults to not logging.
--rate-limit-retries int The maximum number of retries that should be made when requests to the Galasa Service fail due to rate limits being exceeded. Must be a whole number. Defaults to 3 retries (default 3)
--rate-limit-retry-backoff-secs float The amount of time in seconds to wait before retrying a command if it failed due to rate limits being exceeded. Defaults to 1 second. (default 1)
```

### SEE ALSO

* [galasactl monitors](galasactl_monitors.md) - Manage monitors in the Galasa service

33 changes: 33 additions & 0 deletions docs/generated/galasactl_monitors_enable.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
## galasactl monitors enable

Enable a monitor in the Galasa service

### Synopsis

Enables a monitor with the given name in the Galasa service

```
galasactl monitors enable [flags]
```

### Options

```
-h, --help Displays the options for the 'monitors enable' command.
--name string A mandatory flag that identifies the monitor to be manipulated by name.
```

### Options inherited from parent commands

```
-b, --bootstrap string Bootstrap URL. Should start with 'http://' or 'file://'. If it starts with neither, it is assumed to be a fully-qualified path. If missing, it defaults to use the 'bootstrap.properties' file in your GALASA_HOME. Example: http://example.com/bootstrap, file:///user/myuserid/.galasa/bootstrap.properties , file://C:/Users/myuserid/.galasa/bootstrap.properties
--galasahome string Path to a folder where Galasa will read and write files and configuration settings. The default is '${HOME}/.galasa'. This overrides the GALASA_HOME environment variable which may be set instead.
-l, --log string File to which log information will be sent. Any folder referred to must exist. An existing file will be overwritten. Specify "-" to log to stderr. Defaults to not logging.
--rate-limit-retries int The maximum number of retries that should be made when requests to the Galasa Service fail due to rate limits being exceeded. Must be a whole number. Defaults to 3 retries (default 3)
--rate-limit-retry-backoff-secs float The amount of time in seconds to wait before retrying a command if it failed due to rate limits being exceeded. Defaults to 1 second. (default 1)
```

### SEE ALSO

* [galasactl monitors](galasactl_monitors.md) - Manage monitors in the Galasa service

34 changes: 34 additions & 0 deletions docs/generated/galasactl_monitors_set.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
## galasactl monitors set

Update a monitor in the Galasa service

### Synopsis

Updates a monitor with the given name in the Galasa service

```
galasactl monitors set [flags]
```

### Options

```
-h, --help Displays the options for the 'monitors set' command.
--is-enabled string A boolean flag that determines whether the given monitor should be enabled or disabled. Supported values are 'true' and 'false'.
--name string A mandatory flag that identifies the monitor to be manipulated by name.
```

### Options inherited from parent commands

```
-b, --bootstrap string Bootstrap URL. Should start with 'http://' or 'file://'. If it starts with neither, it is assumed to be a fully-qualified path. If missing, it defaults to use the 'bootstrap.properties' file in your GALASA_HOME. Example: http://example.com/bootstrap, file:///user/myuserid/.galasa/bootstrap.properties , file://C:/Users/myuserid/.galasa/bootstrap.properties
--galasahome string Path to a folder where Galasa will read and write files and configuration settings. The default is '${HOME}/.galasa'. This overrides the GALASA_HOME environment variable which may be set instead.
-l, --log string File to which log information will be sent. Any folder referred to must exist. An existing file will be overwritten. Specify "-" to log to stderr. Defaults to not logging.
--rate-limit-retries int The maximum number of retries that should be made when requests to the Galasa Service fail due to rate limits being exceeded. Must be a whole number. Defaults to 3 retries (default 3)
--rate-limit-retry-backoff-secs float The amount of time in seconds to wait before retrying a command if it failed due to rate limits being exceeded. Defaults to 1 second. (default 1)
```

### SEE ALSO

* [galasactl monitors](galasactl_monitors.md) - Manage monitors in the Galasa service

4 changes: 4 additions & 0 deletions pkg/cmd/commandCollection.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const (
COMMAND_NAME_LOCAL_INIT = "local init"
COMMAND_NAME_MONITORS = "monitors"
COMMAND_NAME_MONITORS_GET = "monitors get"
COMMAND_NAME_MONITORS_SET = "monitors set"
COMMAND_NAME_PROPERTIES = "properties"
COMMAND_NAME_PROPERTIES_GET = "properties get"
COMMAND_NAME_PROPERTIES_SET = "properties set"
Expand Down Expand Up @@ -441,16 +442,19 @@ func (commands *commandCollectionImpl) addMonitorsCommands(factory spi.Factory,
var err error
var monitorsCommand spi.GalasaCommand
var monitorsGetCommand spi.GalasaCommand
var monitorsSetCommand spi.GalasaCommand

monitorsCommand, err = NewMonitorsCmd(rootCommand, commsFlagSet)

if err == nil {
monitorsGetCommand, err = NewMonitorsGetCommand(factory, monitorsCommand, commsFlagSet)
monitorsSetCommand, err = NewMonitorsSetCommand(factory, monitorsCommand, commsFlagSet)
}

if err == nil {
commands.commandMap[monitorsCommand.Name()] = monitorsCommand
commands.commandMap[monitorsGetCommand.Name()] = monitorsGetCommand
commands.commandMap[monitorsSetCommand.Name()] = monitorsSetCommand
}

return err
Expand Down
152 changes: 152 additions & 0 deletions pkg/cmd/monitorsSet.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
/*
* Copyright contributors to the Galasa project
*
* SPDX-License-Identifier: EPL-2.0
*/
package cmd

import (
"log"

"github.com/galasa-dev/cli/pkg/api"
"github.com/galasa-dev/cli/pkg/galasaapi"
"github.com/galasa-dev/cli/pkg/monitors"
"github.com/galasa-dev/cli/pkg/spi"
"github.com/galasa-dev/cli/pkg/utils"
"github.com/spf13/cobra"
)

type MonitorsSetCmdValues struct {
isEnabledStr string
}

type MonitorsSetCommand struct {
values *MonitorsSetCmdValues
cobraCommand *cobra.Command
}

// ------------------------------------------------------------------------------------------------
// Constructors methods
// ------------------------------------------------------------------------------------------------
func NewMonitorsSetCommand(
factory spi.Factory,
monitorsSetCommand spi.GalasaCommand,
commsFlagSet GalasaFlagSet,
) (spi.GalasaCommand, error) {

cmd := new(MonitorsSetCommand)

err := cmd.init(factory, monitorsSetCommand, commsFlagSet)
return cmd, err
}

// ------------------------------------------------------------------------------------------------
// Public methods
// ------------------------------------------------------------------------------------------------
func (cmd *MonitorsSetCommand) Name() string {
return COMMAND_NAME_MONITORS_SET
}

func (cmd *MonitorsSetCommand) CobraCommand() *cobra.Command {
return cmd.cobraCommand
}

func (cmd *MonitorsSetCommand) Values() interface{} {
return cmd.values
}

// ------------------------------------------------------------------------------------------------
// Private methods
// ------------------------------------------------------------------------------------------------
func (cmd *MonitorsSetCommand) init(factory spi.Factory, monitorsCommand spi.GalasaCommand, commsFlagSet GalasaFlagSet) error {
var err error

cmd.values = &MonitorsSetCmdValues{}
cmd.cobraCommand, err = cmd.createCobraCmd(factory, monitorsCommand, commsFlagSet.Values().(*CommsFlagSetValues))

return err
}

func (cmd *MonitorsSetCommand) createCobraCmd(
factory spi.Factory,
monitorsCommand spi.GalasaCommand,
commsFlagSetValues *CommsFlagSetValues,
) (*cobra.Command, error) {

var err error

monitorsCommandValues := monitorsCommand.Values().(*MonitorsCmdValues)
monitorsSetCobraCmd := &cobra.Command{
Use: "set",
Short: "Update a monitor in the Galasa service",
Long: "Updates a monitor with the given name in the Galasa service",
Aliases: []string{COMMAND_NAME_MONITORS_SET},
RunE: func(cobraCommand *cobra.Command, args []string) error {
return cmd.executeMonitorsSet(factory, monitorsCommand.Values().(*MonitorsCmdValues), commsFlagSetValues)
},
}

addMonitorNameFlag(monitorsSetCobraCmd, true, monitorsCommandValues)
isEnabledFlag := "is-enabled"

monitorsSetCobraCmd.Flags().StringVar(&cmd.values.isEnabledStr, isEnabledFlag, "", "A boolean flag that determines whether the given monitor should be enabled or disabled. Supported values are 'true' and 'false'.")

monitorsSetCobraCmd.MarkFlagsOneRequired(
isEnabledFlag,
)

monitorsCommand.CobraCommand().AddCommand(monitorsSetCobraCmd)

return monitorsSetCobraCmd, err
}

func (cmd *MonitorsSetCommand) executeMonitorsSet(
factory spi.Factory,
monitorsCmdValues *MonitorsCmdValues,
commsFlagSetValues *CommsFlagSetValues,
) error {

var err error
// Operations on the file system will all be relative to the current folder.
fileSystem := factory.GetFileSystem()

err = utils.CaptureLog(fileSystem, commsFlagSetValues.logFileName)
if err == nil {
commsFlagSetValues.isCapturingLogs = true

log.Println("Galasa CLI - Update monitors in the Galasa service")

env := factory.GetEnvironment()

var galasaHome spi.GalasaHome
galasaHome, err = utils.NewGalasaHome(fileSystem, env, commsFlagSetValues.CmdParamGalasaHomePath)
if err == nil {

var commsClient api.APICommsClient
commsClient, err = api.NewAPICommsClient(
commsFlagSetValues.bootstrap,
commsFlagSetValues.maxRetries,
commsFlagSetValues.retryBackoffSeconds,
factory,
galasaHome,
)

if err == nil {

byteReader := factory.GetByteReader()

setMonitorsFunc := func(apiClient *galasaapi.APIClient) error {
return monitors.SetMonitor(
monitorsCmdValues.name,
cmd.values.isEnabledStr,
apiClient,
byteReader,
)
}
err = commsClient.RunAuthenticatedCommandWithRateLimitRetries(setMonitorsFunc)
}
}
}

return err
}
Loading