diff --git a/cmd/climc/main.go b/cmd/climc/main.go index 89226423b8..c5adb213c1 100644 --- a/cmd/climc/main.go +++ b/cmd/climc/main.go @@ -34,6 +34,7 @@ import ( _ "yunion.io/x/onecloud/cmd/climc/shell/monitor" _ "yunion.io/x/onecloud/cmd/climc/shell/notifyv2" _ "yunion.io/x/onecloud/cmd/climc/shell/servicetree" + _ "yunion.io/x/onecloud/cmd/climc/shell/suggestion" _ "yunion.io/x/onecloud/cmd/climc/shell/yunionconf" ) diff --git a/cmd/climc/shell/monitor/suggestsysalert.go b/cmd/climc/shell/monitor/suggestsysalert.go deleted file mode 100644 index eee8b00cd0..0000000000 --- a/cmd/climc/shell/monitor/suggestsysalert.go +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright 2019 Yunion -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package monitor - -import ( - "yunion.io/x/jsonutils" - - "yunion.io/x/onecloud/pkg/mcclient" - "yunion.io/x/onecloud/pkg/mcclient/modules/monitor" - options "yunion.io/x/onecloud/pkg/mcclient/options/monitor" -) - -func init() { - aN := cmdN("suggestsysalert") - R(&options.SuggestSysAlertListOptions{}, aN("list"), "List all suggestsysrules", - func(s *mcclient.ClientSession, args *options.SuggestSysAlertListOptions) error { - params, err := args.Params() - if err != nil { - return err - } - if len(args.Type) > 0 { - params.Add(jsonutils.NewString(args.Type), "type") - } - ret, err := monitor.SuggestSysAlertManager.List(s, params) - if err != nil { - return err - } - printList(ret, monitor.SuggestSysAlertManager.GetColumns(s)) - return nil - }) - - R(&options.SSuggestAlertShowOptions{}, aN("show"), "Show details of a alert rule", - func(s *mcclient.ClientSession, args *options.SSuggestAlertShowOptions) error { - ret, err := monitor.SuggestSysAlertManager.Get(s, args.ID, nil) - if err != nil { - return err - } - printObject(ret) - return nil - }) - - R(&options.SuggestAlertIgnoreOptions{}, aN("ignore"), "Ignore alert result", - func(s *mcclient.ClientSession, args *options.SuggestAlertIgnoreOptions) error { - params, err := args.Params() - if err != nil { - return err - } - ret, err := monitor.SuggestSysAlertManager.PerformAction(s, args.ID, "ignore", params) - if err != nil { - return err - } - printObject(ret) - return nil - }) -} diff --git a/cmd/climc/shell/suggestion/analysispredict.go b/cmd/climc/shell/suggestion/analysispredict.go new file mode 100644 index 0000000000..622cc6321c --- /dev/null +++ b/cmd/climc/shell/suggestion/analysispredict.go @@ -0,0 +1,12 @@ +package suggestion + +import ( + "yunion.io/x/onecloud/cmd/climc/shell" + "yunion.io/x/onecloud/pkg/mcclient/modules" + options "yunion.io/x/onecloud/pkg/mcclient/options/suggestion" +) + +func init() { + cmd := shell.NewResourceCmd(modules.AnalysisPredictManager) + cmd.Get("", new(options.AnalysisPredictConfigOptions)) +} diff --git a/cmd/climc/shell/suggestion/suggestsysalert.go b/cmd/climc/shell/suggestion/suggestsysalert.go new file mode 100644 index 0000000000..17c0f9f38f --- /dev/null +++ b/cmd/climc/shell/suggestion/suggestsysalert.go @@ -0,0 +1,28 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package suggestion + +import ( + "yunion.io/x/onecloud/cmd/climc/shell" + "yunion.io/x/onecloud/pkg/mcclient/modules/monitor" + options "yunion.io/x/onecloud/pkg/mcclient/options/monitor" +) + +func init() { + cmd := shell.NewResourceCmd(monitor.SuggestSysAlertManager) + cmd.List(new(options.SuggestSysAlertListOptions)) + cmd.Show(new(options.SSuggestAlertShowOptions)) + cmd.Perform("ignore", new(options.SuggestAlertIgnoreOptions)) +} diff --git a/cmd/climc/shell/monitor/suggestsysrule.go b/cmd/climc/shell/suggestion/suggestsysrule.go similarity index 98% rename from cmd/climc/shell/monitor/suggestsysrule.go rename to cmd/climc/shell/suggestion/suggestsysrule.go index 45b6c380dd..be786f4162 100644 --- a/cmd/climc/shell/monitor/suggestsysrule.go +++ b/cmd/climc/shell/suggestion/suggestsysrule.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package monitor +package suggestion import ( "yunion.io/x/onecloud/cmd/climc/shell" diff --git a/pkg/mcclient/modules/mod_analysis_predict.go b/pkg/mcclient/modules/mod_analysis_predict.go new file mode 100644 index 0000000000..a4c1d392dc --- /dev/null +++ b/pkg/mcclient/modules/mod_analysis_predict.go @@ -0,0 +1,23 @@ +package modules + +import "yunion.io/x/onecloud/pkg/mcclient/modulebase" + +var ( + AnalysisPredictManager *SAnalysisPredict +) + +func init() { + AnalysisPredictManager = NewAnalysisPredict() + Register(AnalysisPredictManager) +} + +type SAnalysisPredict struct { + *modulebase.ResourceManager +} + +func NewAnalysisPredict() *SAnalysisPredict { + man := NewSuggestionManager("analysispredict", "analysispredicts", []string{}, []string{}) + return &SAnalysisPredict{ + ResourceManager: &man, + } +} diff --git a/pkg/mcclient/options/monitor/suggestsysalert.go b/pkg/mcclient/options/monitor/suggestsysalert.go index 96d3df9e22..9eeb7a8cbf 100644 --- a/pkg/mcclient/options/monitor/suggestsysalert.go +++ b/pkg/mcclient/options/monitor/suggestsysalert.go @@ -25,10 +25,22 @@ type SuggestSysAlertListOptions struct { Type string `help:"Type of suggest rule" choices:"EIP_UNUSED|"` } +func (o *SuggestSysAlertListOptions) Params() (jsonutils.JSONObject, error) { + return options.ListStructToParams(o) +} + type SSuggestAlertShowOptions struct { ID string `help:"ID or name of the alert" json:"-"` } +func (o *SSuggestAlertShowOptions) Params() (jsonutils.JSONObject, error) { + return options.StructToParams(o) +} + +func (o *SSuggestAlertShowOptions) GetId() string { + return o.ID +} + type SuggestAlertIgnoreOptions struct { ID string `help:"ID or name of the alert" json:"-"` Scope string `help:"Resource scope" choices:"system|domain|project" default:"project"` @@ -36,6 +48,10 @@ type SuggestAlertIgnoreOptions struct { Project string `help:"'Owner project ID or Name" json:"project"` } -func (opt *SuggestAlertIgnoreOptions) Params() (*jsonutils.JSONDict, error) { +func (opt *SuggestAlertIgnoreOptions) Params() (jsonutils.JSONObject, error) { return options.StructToParams(opt) } + +func (o *SuggestAlertIgnoreOptions) GetId() string { + return o.ID +} diff --git a/pkg/mcclient/options/suggestion/analysispredict.go b/pkg/mcclient/options/suggestion/analysispredict.go new file mode 100644 index 0000000000..d082e47509 --- /dev/null +++ b/pkg/mcclient/options/suggestion/analysispredict.go @@ -0,0 +1,24 @@ +package suggestion + +import ( + "yunion.io/x/jsonutils" + + "yunion.io/x/onecloud/pkg/mcclient/options" +) + +type AnalysisPredictConfigOptions struct { + ID string `help:"ID or name of the alert" json:"-"` + options.BaseListOptions + QueryType string `help:"query_type of the analysis" choices:"expense_trend" json:"query_type"` + StartDate string `help:"start_date of the analysis" json:"start_date"` + EndDate string `help:"end_date of the analysis" json:"end_date"` + DataType string `help:"data_type of the analysis" choices:"day|month" json:"data_type"` +} + +func (o *AnalysisPredictConfigOptions) Params() (jsonutils.JSONObject, error) { + return options.ListStructToParams(o) +} + +func (o *AnalysisPredictConfigOptions) GetId() string { + return o.ID +} diff --git a/pkg/mcclient/options/suggestion/doc.go b/pkg/mcclient/options/suggestion/doc.go new file mode 100644 index 0000000000..7c2c559ef1 --- /dev/null +++ b/pkg/mcclient/options/suggestion/doc.go @@ -0,0 +1 @@ +package suggestion // import "yunion.io/x/onecloud/pkg/mcclient/options/suggestion"