-
Notifications
You must be signed in to change notification settings - Fork 245
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 #178 from Tinyblargon/CLI-Overhaul
Cli overhaul: MetricServer
- Loading branch information
Showing
10 changed files
with
830 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package get | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var get_metricserverCmd = &cobra.Command{ | ||
Use: "metricserver METRICSID", | ||
Short: "Gets the configuration of the specified MetricServer", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return GetConfig(args, "MetricServer") | ||
}, | ||
} | ||
|
||
func init() { | ||
getCmd.AddCommand(get_metricserverCmd) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package set | ||
|
||
import ( | ||
"github.com/Telmate/proxmox-api-go/cli" | ||
"github.com/Telmate/proxmox-api-go/proxmox" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var set_metricserverCmd = &cobra.Command{ | ||
Use: "metricserver METRICSID", | ||
Short: "Sets the current state of a MetricServer", | ||
Long: `Sets the current state of a MetricServer. | ||
Depending on the current state of the MetricServer, the MetricServer will be created or updated. | ||
The config can be set with the --file flag or piped from stdin. | ||
For config examples see "example metricserver"`, | ||
RunE: func(cmd *cobra.Command, args []string) (err error) { | ||
id := cli.ValidateIDset(args, 0,"MetricServerID") | ||
config, err := proxmox.NewConfigMetricsFromJson(cli.NewConfig()) | ||
if err != nil { | ||
return | ||
} | ||
c := cli.NewClient() | ||
err = config.SetMetrics(id, c) | ||
if err != nil { | ||
return | ||
} | ||
cli.PrintItemSet(setCmd.OutOrStdout() ,id ,"MericServer") | ||
return | ||
}, | ||
} | ||
|
||
func init() { | ||
setCmd.AddCommand(set_metricserverCmd) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,167 @@ | ||
package cli_metricservers_test | ||
|
||
import ( | ||
"testing" | ||
_ "github.com/Telmate/proxmox-api-go/cli/command/commands" | ||
cliTest "github.com/Telmate/proxmox-api-go/test/cli" | ||
) | ||
|
||
func Test_MetricServer_Errors_Type(t *testing.T) { | ||
Test := cliTest.Test{ | ||
InputJson: ` | ||
{ | ||
"type": "this gives an error" | ||
}`, | ||
ReqErr: true, | ||
ErrContains: "(type)", | ||
Args: []string{"-i","set","metricserver","test-metricserver00"}, | ||
} | ||
Test.StandardTest(t) | ||
} | ||
|
||
func Test_MetricServer_Errors_Server(t *testing.T) { | ||
Test := cliTest.Test{ | ||
InputJson: ` | ||
{ | ||
"type": "influxdb", | ||
"server": "" | ||
}`, | ||
ReqErr: true, | ||
ErrContains: "(server)", | ||
Args: []string{"-i","set","metricserver","test-metricserver00"}, | ||
} | ||
Test.StandardTest(t) | ||
} | ||
|
||
func Test_MetricServer_Errors_Port_Lower(t *testing.T) { | ||
Test := cliTest.Test{ | ||
InputJson: ` | ||
{ | ||
"type": "influxdb", | ||
"server": "192.168.67.3", | ||
"port": 0 | ||
}`, | ||
ReqErr: true, | ||
ErrContains: "(port)", | ||
Args: []string{"-i","set","metricserver","test-metricserver00"}, | ||
} | ||
Test.StandardTest(t) | ||
} | ||
|
||
func Test_MetricServer_Errors_Port_Upper(t *testing.T) { | ||
Test := cliTest.Test{ | ||
InputJson: ` | ||
{ | ||
"type": "influxdb", | ||
"server": "192.168.67.3", | ||
"port": 65537 | ||
}`, | ||
ReqErr: true, | ||
ErrContains: "(port)", | ||
Args: []string{"-i","set","metricserver","test-metricserver00"}, | ||
} | ||
Test.StandardTest(t) | ||
} | ||
|
||
func Test_MetricServer_Errors_MTU_Lower(t *testing.T) { | ||
Test := cliTest.Test{ | ||
InputJson: ` | ||
{ | ||
"type": "influxdb", | ||
"server": "192.168.67.3", | ||
"port": 65536, | ||
"mtu": 511 | ||
}`, | ||
ReqErr: true, | ||
ErrContains: "(mtu)", | ||
Args: []string{"-i","set","metricserver","test-metricserver00"}, | ||
} | ||
Test.StandardTest(t) | ||
} | ||
|
||
func Test_MetricServer_Errors_MTU_Upper(t *testing.T) { | ||
Test := cliTest.Test{ | ||
InputJson: ` | ||
{ | ||
"type": "influxdb", | ||
"server": "192.168.67.3", | ||
"port": 1, | ||
"mtu": 65537 | ||
}`, | ||
ReqErr: true, | ||
ErrContains: "(mtu)", | ||
Args: []string{"-i","set","metricserver","test-metricserver00"}, | ||
} | ||
Test.StandardTest(t) | ||
} | ||
|
||
func Test_MetricServer_Errors_Timeout(t *testing.T) { | ||
Test := cliTest.Test{ | ||
InputJson: ` | ||
{ | ||
"type": "influxdb", | ||
"server": "192.168.67.3", | ||
"port": 1, | ||
"mtu": 512, | ||
"timeout": -1 | ||
}`, | ||
ReqErr: true, | ||
ErrContains: "(timeout)", | ||
Args: []string{"-i","set","metricserver","test-metricserver00"}, | ||
} | ||
Test.StandardTest(t) | ||
} | ||
|
||
// Graphite | ||
func Test_MetricServer_Errors_Graphite_Protocol(t *testing.T) { | ||
Test := cliTest.Test{ | ||
InputJson: ` | ||
{ | ||
"type": "graphite", | ||
"server": "192.168.67.3", | ||
"graphite": { | ||
"protocol": "notvalid" | ||
} | ||
}`, | ||
ReqErr: true, | ||
ErrContains: "(graphite:{ protocol })", | ||
Args: []string{"-i","set","metricserver","test-metricserver00"}, | ||
} | ||
Test.StandardTest(t) | ||
} | ||
|
||
// InfluxDB | ||
func Test_MetricServer_Errors_InfluxDB_Protocol(t *testing.T) { | ||
Test := cliTest.Test{ | ||
InputJson: ` | ||
{ | ||
"type": "influxdb", | ||
"server": "192.168.67.3", | ||
"influxdb": { | ||
"protocol": "notvalid" | ||
} | ||
}`, | ||
ReqErr: true, | ||
ErrContains: "(influxdb:{ protocol })", | ||
Args: []string{"-i","set","metricserver","test-metricserver00"}, | ||
} | ||
Test.StandardTest(t) | ||
} | ||
|
||
func Test_MetricServer_Errors_InfluxDB_MaxBodySize(t *testing.T) { | ||
Test := cliTest.Test{ | ||
InputJson: ` | ||
{ | ||
"type": "influxdb", | ||
"server": "192.168.67.3", | ||
"port": 8089, | ||
"influxdb": { | ||
"max-body-size": 0 | ||
} | ||
}`, | ||
ReqErr: true, | ||
ErrContains: "(influxdb:{ max-body-size })", | ||
Args: []string{"-i","set","metricserver","test-metricserver00"}, | ||
} | ||
Test.StandardTest(t) | ||
} |
Oops, something went wrong.