Skip to content
This repository was archived by the owner on May 15, 2025. It is now read-only.

Commit a75c4ff

Browse files
authored
Add monitors get command (#354)
## Why? See galasa-dev/projectmanagement#2067 ## Changes - Added `galasactl monitors get` command to get monitors from a Galasa service with an optional `--name` flag to get a specific monitor by its name
1 parent afe09c1 commit a75c4ff

19 files changed

+1554
-1
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,27 @@ The run "C1234" can be cancelled using the following command:
457457
galasactl runs cancel --name C1234
458458
```
459459

460+
## monitors get
461+
462+
This command can be used to get the details of monitors, like resource cleanup monitors, that are available in the Galasa service.
463+
464+
By default, the output of `monitors get` will be in a "summary" format. To change the output format, you can supply the `--format` flag followed by the format that you wish the output to be displayed in. For a list of supported formats, view the command's help information by running `galasactl monitors get --help`.
465+
466+
### Examples
467+
468+
To get a list of all monitors that are currently available in the Galasa service, run the following command:
469+
470+
```
471+
galasactl monitors get
472+
```
473+
474+
If you would like to get a specific monitor, you can supply the name of the monitor with the `--name` flag. For example, the following command can be used to get a monitor named "myCustomMonitor":
475+
476+
```
477+
galasactl monitors get --name myCustomMonitor
478+
```
479+
480+
For a complete list of supported parameters see [here](./docs/generated/galasactl_monitors_get.md).
460481

461482
## properties get
462483
This command retrieves details of properties in a namespace.

docs/generated/errors-list.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,14 @@ The `galasactl` tool can generate the following errors:
214214
- GAL1215E: An attempt to update a user '{}' failed. Unexpected http status code {} received from the server. Error details from the server are not in a valid json format. Cause: '{}'
215215
- GAL1216E: An attempt to update a user '{}' failed. Unexpected http status code {} received from the server. Error details from the server are: '{}'
216216
- GAL1217E: An attempt to update a user '{}' failed. Unexpected http status code {} received from the server. Error details from the server are not in the json format.
217-
- GAL1225E: Failed to open file '{}' cause: {}. Check that this file exists, and that you have read permissions.
217+
- GAL1218E: Failed to get monitors. Sending the get request to the Galasa service failed. Cause is {}
218+
- GAL1219E: Failed to get monitors. Unexpected http status code {} received from the server.
219+
- GAL1220E: Failed to get monitors. Unexpected http status code {} received from the server. Error details from the server could not be read. Cause: {}
220+
- GAL1221E: Failed to get monitors. Unexpected http status code {} received from the server. Error details from the server are not in a valid json format. Cause: '{}'
221+
- GAL1222E: Failed to get monitors. Unexpected http status code {} received from the server. Error details from the server are: '{}'
222+
- GAL1223E: Failed to get monitors. Unexpected http status code {} received from the server. Error details from the server are not in the json format.
223+
- GAL1224E: Galasa Monitor named {} is not known on the Galasa service.
224+
- 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).
218225
- GAL1226E: Internal failure. Contents of gzip could be read, but not decoded. New gzip reader failed: file: {} error: {}
219226
- GAL1227E: Internal failure. Contents of gzip could not be decoded. {} error: {}
220227
- GAL1228E: Internal failure. Contents of gzip could not be encoded and compressed. {} error: {}

docs/generated/galasactl.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ A tool for controlling Galasa resources using the command-line.
1818

1919
* [galasactl auth](galasactl_auth.md) - Manages authentication with a Galasa ecosystem
2020
* [galasactl local](galasactl_local.md) - Manipulate local system
21+
* [galasactl monitors](galasactl_monitors.md) - Manage monitors in the Galasa service
2122
* [galasactl project](galasactl_project.md) - Manipulate local project source code
2223
* [galasactl properties](galasactl_properties.md) - Manages properties in an ecosystem
2324
* [galasactl resources](galasactl_resources.md) - Manages resources in an ecosystem
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
## galasactl monitors
2+
3+
Manage monitors in the Galasa service
4+
5+
### Synopsis
6+
7+
The parent command for operations to manipulate monitors in the Galasa service
8+
9+
### Options
10+
11+
```
12+
-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
13+
-h, --help Displays the options for the 'monitors' command.
14+
--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)
15+
--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)
16+
```
17+
18+
### Options inherited from parent commands
19+
20+
```
21+
--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.
22+
-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.
23+
```
24+
25+
### SEE ALSO
26+
27+
* [galasactl](galasactl.md) - CLI for Galasa
28+
* [galasactl monitors get](galasactl_monitors_get.md) - Get monitors from the Galasa service
29+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
## galasactl monitors get
2+
3+
Get monitors from the Galasa service
4+
5+
### Synopsis
6+
7+
Get a list of monitors or a specific monitor from the Galasa service
8+
9+
```
10+
galasactl monitors get [flags]
11+
```
12+
13+
### Options
14+
15+
```
16+
--format string the output format of the returned monitors. Supported formats are: 'summary', 'yaml'. (default "summary")
17+
-h, --help Displays the options for the 'monitors get' command.
18+
--name string An optional flag that identifies the monitor to be retrieved by name.
19+
```
20+
21+
### Options inherited from parent commands
22+
23+
```
24+
-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
25+
--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.
26+
-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.
27+
--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)
28+
--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)
29+
```
30+
31+
### SEE ALSO
32+
33+
* [galasactl monitors](galasactl_monitors.md) - Manage monitors in the Galasa service
34+

pkg/cmd/commandCollection.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ const (
3939
COMMAND_NAME_PROJECT_CREATE = "project create"
4040
COMMAND_NAME_LOCAL = "local"
4141
COMMAND_NAME_LOCAL_INIT = "local init"
42+
COMMAND_NAME_MONITORS = "monitors"
43+
COMMAND_NAME_MONITORS_GET = "monitors get"
4244
COMMAND_NAME_PROPERTIES = "properties"
4345
COMMAND_NAME_PROPERTIES_GET = "properties get"
4446
COMMAND_NAME_PROPERTIES_SET = "properties set"
@@ -137,6 +139,10 @@ func (commands *commandCollectionImpl) init(factory spi.Factory) error {
137139
err = commands.addLocalCommands(factory, rootCommand)
138140
}
139141

142+
if err == nil {
143+
err = commands.addMonitorsCommands(factory, rootCommand, commsFlagSet)
144+
}
145+
140146
if err == nil {
141147
err = commands.addProjectCommands(factory, rootCommand)
142148
}
@@ -430,6 +436,26 @@ func (commands *commandCollectionImpl) addSecretsCommands(factory spi.Factory, r
430436
return err
431437
}
432438

439+
func (commands *commandCollectionImpl) addMonitorsCommands(factory spi.Factory, rootCommand spi.GalasaCommand, commsFlagSet GalasaFlagSet) error {
440+
441+
var err error
442+
var monitorsCommand spi.GalasaCommand
443+
var monitorsGetCommand spi.GalasaCommand
444+
445+
monitorsCommand, err = NewMonitorsCmd(rootCommand, commsFlagSet)
446+
447+
if err == nil {
448+
monitorsGetCommand, err = NewMonitorsGetCommand(factory, monitorsCommand, commsFlagSet)
449+
}
450+
451+
if err == nil {
452+
commands.commandMap[monitorsCommand.Name()] = monitorsCommand
453+
commands.commandMap[monitorsGetCommand.Name()] = monitorsGetCommand
454+
}
455+
456+
return err
457+
}
458+
433459
func (commands *commandCollectionImpl) addUsersCommands(factory spi.Factory, rootCommand spi.GalasaCommand, commsFlagSet GalasaFlagSet) error {
434460

435461
var err error

pkg/cmd/monitors.go

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* Copyright contributors to the Galasa project
3+
*
4+
* SPDX-License-Identifier: EPL-2.0
5+
*/
6+
package cmd
7+
8+
import (
9+
"github.com/galasa-dev/cli/pkg/spi"
10+
"github.com/spf13/cobra"
11+
)
12+
13+
type MonitorsCmdValues struct {
14+
name string
15+
}
16+
17+
type MonitorsCommand struct {
18+
cobraCommand *cobra.Command
19+
values *MonitorsCmdValues
20+
}
21+
22+
// ------------------------------------------------------------------------------------------------
23+
// Constructors
24+
// ------------------------------------------------------------------------------------------------
25+
26+
func NewMonitorsCmd(rootCommand spi.GalasaCommand, commsFlagSet GalasaFlagSet) (spi.GalasaCommand, error) {
27+
cmd := new(MonitorsCommand)
28+
err := cmd.init(rootCommand, commsFlagSet)
29+
return cmd, err
30+
}
31+
32+
// ------------------------------------------------------------------------------------------------
33+
// Public functions
34+
// ------------------------------------------------------------------------------------------------
35+
36+
func (cmd *MonitorsCommand) Name() string {
37+
return COMMAND_NAME_MONITORS
38+
}
39+
40+
func (cmd *MonitorsCommand) CobraCommand() *cobra.Command {
41+
return cmd.cobraCommand
42+
}
43+
44+
func (cmd *MonitorsCommand) Values() interface{} {
45+
return cmd.values
46+
}
47+
48+
// ------------------------------------------------------------------------------------------------
49+
// Private functions
50+
// ------------------------------------------------------------------------------------------------
51+
52+
func (cmd *MonitorsCommand) init(rootCommand spi.GalasaCommand, commsFlagSet GalasaFlagSet) error {
53+
54+
var err error
55+
56+
cmd.values = &MonitorsCmdValues{}
57+
cmd.cobraCommand, err = cmd.createCobraCommand(rootCommand, commsFlagSet)
58+
59+
return err
60+
}
61+
62+
func (cmd *MonitorsCommand) createCobraCommand(rootCommand spi.GalasaCommand, commsFlagSet GalasaFlagSet) (*cobra.Command, error) {
63+
64+
var err error
65+
66+
monitorsCobraCmd := &cobra.Command{
67+
Use: "monitors",
68+
Short: "Manage monitors in the Galasa service",
69+
Long: "The parent command for operations to manipulate monitors in the Galasa service",
70+
}
71+
72+
monitorsCobraCmd.PersistentFlags().AddFlagSet(commsFlagSet.Flags())
73+
rootCommand.CobraCommand().AddCommand(monitorsCobraCmd)
74+
75+
return monitorsCobraCmd, err
76+
}
77+
78+
func addMonitorNameFlag(cmd *cobra.Command, isMandatory bool, monitorsCmdValues *MonitorsCmdValues) {
79+
80+
flagName := "name"
81+
var description string
82+
if isMandatory {
83+
description = "A mandatory flag that identifies the monitor to be manipulated by name."
84+
} else {
85+
description = "An optional flag that identifies the monitor to be retrieved by name."
86+
}
87+
88+
cmd.Flags().StringVar(&monitorsCmdValues.name, flagName, "", description)
89+
90+
if isMandatory {
91+
cmd.MarkFlagRequired(flagName)
92+
}
93+
}

0 commit comments

Comments
 (0)