| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- // 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 (
- "time"
- "yunion.io/x/jsonutils"
- "yunion.io/x/pkg/errors"
- "yunion.io/x/onecloud/pkg/apis"
- "yunion.io/x/onecloud/pkg/apis/monitor"
- monitor2 "yunion.io/x/onecloud/pkg/mcclient/modules/monitor"
- "yunion.io/x/onecloud/pkg/mcclient/options"
- )
- type CommonAlertListOptions struct {
- options.BaseListOptions
- // 报警类型
- AlertType string `help:"common alert type" choices:"normal|system"`
- Level string `help:"common alert notify level" choices:"normal|important|fatal"`
- MonitorResourceId []string `help:"monitor resource id"`
- StartTime *time.Time `help:"start time, format: 2025-01-01 00:00:00" json:"start_time"`
- EndTime *time.Time `help:"end time, format: 2025-01-01 00:00:00" json:"end_time"`
- Top *int `help:"top" json:"top"`
- }
- func (o *CommonAlertListOptions) Params() (jsonutils.JSONObject, error) {
- return options.ListStructToParams(o)
- }
- type CommonAlertShowOptions struct {
- ID string `help:"ID of alart " json:"-"`
- }
- func (o *CommonAlertShowOptions) Params() (jsonutils.JSONObject, error) {
- return options.StructToParams(o)
- }
- func (o *CommonAlertShowOptions) GetId() string {
- return o.ID
- }
- type CommonAlertUpdateOptions struct {
- ID string `help:"ID of alart " json:"-"`
- Period string `help:"exec period of alert" json:"period"`
- Comparator string `help:"Alarm policy threshold comparison method" json:"comparator" `
- Threshold string `help:"Alarm policy threshold" json:"threshold"`
- Reason string `help:"Alarm policy reason" json:"reason"`
- // 为 true 时不发送恢复通知
- DisableNotifyRecovery *bool `help:"when true, do not send recovery notifications" json:"disable_notify_recovery"`
- }
- func (o *CommonAlertUpdateOptions) Params() (jsonutils.JSONObject, error) {
- return options.StructToParams(o)
- }
- func (o *CommonAlertUpdateOptions) GetId() string {
- return o.ID
- }
- type CommonAlertDeleteOptions struct {
- ID []string `help:"ID of alart"`
- Force bool `help:"force to delete alert"`
- }
- func (o *CommonAlertDeleteOptions) GetIds() []string {
- return o.ID
- }
- func (o *CommonAlertDeleteOptions) Params() (jsonutils.JSONObject, error) {
- return options.StructToParams(o)
- }
- type CommonAlertConditionOptions struct {
- AlertConditionOptions
- }
- func (o CommonAlertConditionOptions) Params(conf *monitor2.AlertConfig) (*monitor2.AlertCondition, error) {
- cond, err := o.AlertConditionOptions.Params(conf)
- if err != nil {
- return nil, errors.Wrap(err, "AlertConditionOptions.Params")
- }
- return cond, nil
- }
- type CommonAlertCreateOptions struct {
- apis.Meta
- monitor.CommonAlertCreateBaseInput
- CommonAlertConditionOptions
- AlertStatesOptions
- NAME string `help:"Name of the alert"`
- // 报警级别
- Level string `json:"level"`
- }
- func (o *CommonAlertCreateOptions) Params() (jsonutils.JSONObject, error) {
- input, err := monitor2.NewAlertConfig(o.NAME, o.Period, true)
- if err != nil {
- return nil, err
- }
- if _, err := o.CommonAlertConditionOptions.Params(input); err != nil {
- return nil, err
- }
- input.NoDataState(o.NoDataState)
- input.ExecutionErrorState(o.ExecutionErrorState)
- ret := input.ToCommonAlertCreateInput(&o.CommonAlertCreateBaseInput)
- return ret.JSON(ret), nil
- }
|