diff --git a/profiles/preview/preview/alertsmanagement/mgmt/alertsmanagement/models.go b/profiles/preview/preview/alertsmanagement/mgmt/alertsmanagement/models.go index ac0313d8bbbd..e2b1c943c285 100644 --- a/profiles/preview/preview/alertsmanagement/mgmt/alertsmanagement/models.go +++ b/profiles/preview/preview/alertsmanagement/mgmt/alertsmanagement/models.go @@ -26,7 +26,8 @@ import ( ) const ( - DefaultBaseURI = original.DefaultBaseURI + DefaultBaseURI = original.DefaultBaseURI + DefaultIdentifier = original.DefaultIdentifier ) type ActionRuleStatus = original.ActionRuleStatus @@ -78,6 +79,13 @@ const ( AlertsSummaryGroupByFieldsSignalType AlertsSummaryGroupByFields = original.AlertsSummaryGroupByFieldsSignalType ) +type MetadataIdentifier = original.MetadataIdentifier + +const ( + MetadataIdentifierAlertsMetaDataProperties MetadataIdentifier = original.MetadataIdentifierAlertsMetaDataProperties + MetadataIdentifierMonitorServiceList MetadataIdentifier = original.MetadataIdentifierMonitorServiceList +) + type MonitorCondition = original.MonitorCondition const ( @@ -209,11 +217,14 @@ type AlertsClient = original.AlertsClient type AlertsList = original.AlertsList type AlertsListIterator = original.AlertsListIterator type AlertsListPage = original.AlertsListPage +type AlertsMetaData = original.AlertsMetaData +type AlertsMetaDataProperties = original.AlertsMetaDataProperties type AlertsSummary = original.AlertsSummary type AlertsSummaryGroup = original.AlertsSummaryGroup type AlertsSummaryGroupItem = original.AlertsSummaryGroupItem type BaseClient = original.BaseClient type BasicActionRuleProperties = original.BasicActionRuleProperties +type BasicAlertsMetaDataProperties = original.BasicAlertsMetaDataProperties type Bool = original.Bool type Condition = original.Condition type Conditions = original.Conditions @@ -222,6 +233,8 @@ type ErrorResponse = original.ErrorResponse type ErrorResponseBody = original.ErrorResponseBody type Essentials = original.Essentials type ManagedResource = original.ManagedResource +type MonitorServiceDetails = original.MonitorServiceDetails +type MonitorServiceList = original.MonitorServiceList type Operation = original.Operation type OperationDisplay = original.OperationDisplay type OperationsClient = original.OperationsClient @@ -315,6 +328,9 @@ func PossibleAlertsSortByFieldsValues() []AlertsSortByFields { func PossibleAlertsSummaryGroupByFieldsValues() []AlertsSummaryGroupByFields { return original.PossibleAlertsSummaryGroupByFieldsValues() } +func PossibleMetadataIdentifierValues() []MetadataIdentifier { + return original.PossibleMetadataIdentifierValues() +} func PossibleMonitorConditionValues() []MonitorCondition { return original.PossibleMonitorConditionValues() } diff --git a/services/preview/alertsmanagement/mgmt/2019-05-05/alertsmanagement/alerts.go b/services/preview/alertsmanagement/mgmt/2019-05-05/alertsmanagement/alerts.go index cdc469399c25..b61dfab4b030 100644 --- a/services/preview/alertsmanagement/mgmt/2019-05-05/alertsmanagement/alerts.go +++ b/services/preview/alertsmanagement/mgmt/2019-05-05/alertsmanagement/alerts.go @@ -580,3 +580,72 @@ func (client AlertsClient) GetSummaryResponder(resp *http.Response) (result Aler result.Response = autorest.Response{Response: resp} return } + +// MetaData list alerts meta data information based on value of identifier parameter. +func (client AlertsClient) MetaData(ctx context.Context) (result AlertsMetaData, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/AlertsClient.MetaData") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.MetaDataPreparer(ctx) + if err != nil { + err = autorest.NewErrorWithError(err, "alertsmanagement.AlertsClient", "MetaData", nil, "Failure preparing request") + return + } + + resp, err := client.MetaDataSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "alertsmanagement.AlertsClient", "MetaData", resp, "Failure sending request") + return + } + + result, err = client.MetaDataResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "alertsmanagement.AlertsClient", "MetaData", resp, "Failure responding to request") + } + + return +} + +// MetaDataPreparer prepares the MetaData request. +func (client AlertsClient) MetaDataPreparer(ctx context.Context) (*http.Request, error) { + const APIVersion = "2019-05-05-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + "identifier": autorest.Encode("query", "MonitorServiceList"), + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPath("/providers/Microsoft.AlertsManagement/alertsMetaData"), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// MetaDataSender sends the MetaData request. The method will close the +// http.Response Body if it receives an error. +func (client AlertsClient) MetaDataSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// MetaDataResponder handles the response to the MetaData request. The method always +// closes the http.Response Body. +func (client AlertsClient) MetaDataResponder(resp *http.Response) (result AlertsMetaData, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/services/preview/alertsmanagement/mgmt/2019-05-05/alertsmanagement/alertsmanagementapi/interfaces.go b/services/preview/alertsmanagement/mgmt/2019-05-05/alertsmanagement/alertsmanagementapi/interfaces.go index faaf5395b80f..d2d90ae31f3c 100644 --- a/services/preview/alertsmanagement/mgmt/2019-05-05/alertsmanagement/alertsmanagementapi/interfaces.go +++ b/services/preview/alertsmanagement/mgmt/2019-05-05/alertsmanagement/alertsmanagementapi/interfaces.go @@ -36,6 +36,7 @@ type AlertsClientAPI interface { GetByID(ctx context.Context, alertID string) (result alertsmanagement.Alert, err error) GetHistory(ctx context.Context, alertID string) (result alertsmanagement.AlertModification, err error) GetSummary(ctx context.Context, groupby alertsmanagement.AlertsSummaryGroupByFields, includeSmartGroupsCount *bool, targetResource string, targetResourceType string, targetResourceGroup string, monitorService alertsmanagement.MonitorService, monitorCondition alertsmanagement.MonitorCondition, severity alertsmanagement.Severity, alertState alertsmanagement.AlertState, alertRule string, timeRange alertsmanagement.TimeRange, customTimeRange string) (result alertsmanagement.AlertsSummary, err error) + MetaData(ctx context.Context) (result alertsmanagement.AlertsMetaData, err error) } var _ AlertsClientAPI = (*alertsmanagement.AlertsClient)(nil) diff --git a/services/preview/alertsmanagement/mgmt/2019-05-05/alertsmanagement/client.go b/services/preview/alertsmanagement/mgmt/2019-05-05/alertsmanagement/client.go index 497ccddd5807..c8a30b18418b 100644 --- a/services/preview/alertsmanagement/mgmt/2019-05-05/alertsmanagement/client.go +++ b/services/preview/alertsmanagement/mgmt/2019-05-05/alertsmanagement/client.go @@ -27,6 +27,8 @@ import ( const ( // DefaultBaseURI is the default URI used for the service Alertsmanagement DefaultBaseURI = "https://management.azure.com" + // DefaultIdentifier is the default value for identifier + DefaultIdentifier = "MonitorServiceList" ) // BaseClient is the base client for Alertsmanagement. @@ -34,6 +36,7 @@ type BaseClient struct { autorest.Client BaseURI string SubscriptionID string + Identifier string } // New creates an instance of the BaseClient client. @@ -47,5 +50,6 @@ func NewWithBaseURI(baseURI string, subscriptionID string) BaseClient { Client: autorest.NewClientWithUserAgent(UserAgent()), BaseURI: baseURI, SubscriptionID: subscriptionID, + Identifier: DefaultIdentifier, } } diff --git a/services/preview/alertsmanagement/mgmt/2019-05-05/alertsmanagement/models.go b/services/preview/alertsmanagement/mgmt/2019-05-05/alertsmanagement/models.go index 9bfe3b9e0f7c..cb42cbdb47fa 100644 --- a/services/preview/alertsmanagement/mgmt/2019-05-05/alertsmanagement/models.go +++ b/services/preview/alertsmanagement/mgmt/2019-05-05/alertsmanagement/models.go @@ -133,6 +133,21 @@ func PossibleAlertStateValues() []AlertState { return []AlertState{AlertStateAcknowledged, AlertStateClosed, AlertStateNew} } +// MetadataIdentifier enumerates the values for metadata identifier. +type MetadataIdentifier string + +const ( + // MetadataIdentifierAlertsMetaDataProperties ... + MetadataIdentifierAlertsMetaDataProperties MetadataIdentifier = "alertsMetaDataProperties" + // MetadataIdentifierMonitorServiceList ... + MetadataIdentifierMonitorServiceList MetadataIdentifier = "MonitorServiceList" +) + +// PossibleMetadataIdentifierValues returns an array of possible values for the MetadataIdentifier const type. +func PossibleMetadataIdentifierValues() []MetadataIdentifier { + return []MetadataIdentifier{MetadataIdentifierAlertsMetaDataProperties, MetadataIdentifierMonitorServiceList} +} + // MonitorCondition enumerates the values for monitor condition. type MonitorCondition string @@ -1018,6 +1033,109 @@ func NewAlertsListPage(getNextPage func(context.Context, AlertsList) (AlertsList return AlertsListPage{fn: getNextPage} } +// AlertsMetaData alert meta data information. +type AlertsMetaData struct { + autorest.Response `json:"-"` + Properties BasicAlertsMetaDataProperties `json:"properties,omitempty"` +} + +// UnmarshalJSON is the custom unmarshaler for AlertsMetaData struct. +func (amd *AlertsMetaData) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + for k, v := range m { + switch k { + case "properties": + if v != nil { + properties, err := unmarshalBasicAlertsMetaDataProperties(*v) + if err != nil { + return err + } + amd.Properties = properties + } + } + } + + return nil +} + +// BasicAlertsMetaDataProperties alert meta data property bag +type BasicAlertsMetaDataProperties interface { + AsMonitorServiceList() (*MonitorServiceList, bool) + AsAlertsMetaDataProperties() (*AlertsMetaDataProperties, bool) +} + +// AlertsMetaDataProperties alert meta data property bag +type AlertsMetaDataProperties struct { + // MetadataIdentifier - Possible values include: 'MetadataIdentifierAlertsMetaDataProperties', 'MetadataIdentifierMonitorServiceList' + MetadataIdentifier MetadataIdentifier `json:"metadataIdentifier,omitempty"` +} + +func unmarshalBasicAlertsMetaDataProperties(body []byte) (BasicAlertsMetaDataProperties, error) { + var m map[string]interface{} + err := json.Unmarshal(body, &m) + if err != nil { + return nil, err + } + + switch m["metadataIdentifier"] { + case string(MetadataIdentifierMonitorServiceList): + var msl MonitorServiceList + err := json.Unmarshal(body, &msl) + return msl, err + default: + var amdp AlertsMetaDataProperties + err := json.Unmarshal(body, &amdp) + return amdp, err + } +} +func unmarshalBasicAlertsMetaDataPropertiesArray(body []byte) ([]BasicAlertsMetaDataProperties, error) { + var rawMessages []*json.RawMessage + err := json.Unmarshal(body, &rawMessages) + if err != nil { + return nil, err + } + + amdpArray := make([]BasicAlertsMetaDataProperties, len(rawMessages)) + + for index, rawMessage := range rawMessages { + amdp, err := unmarshalBasicAlertsMetaDataProperties(*rawMessage) + if err != nil { + return nil, err + } + amdpArray[index] = amdp + } + return amdpArray, nil +} + +// MarshalJSON is the custom marshaler for AlertsMetaDataProperties. +func (amdp AlertsMetaDataProperties) MarshalJSON() ([]byte, error) { + amdp.MetadataIdentifier = MetadataIdentifierAlertsMetaDataProperties + objectMap := make(map[string]interface{}) + if amdp.MetadataIdentifier != "" { + objectMap["metadataIdentifier"] = amdp.MetadataIdentifier + } + return json.Marshal(objectMap) +} + +// AsMonitorServiceList is the BasicAlertsMetaDataProperties implementation for AlertsMetaDataProperties. +func (amdp AlertsMetaDataProperties) AsMonitorServiceList() (*MonitorServiceList, bool) { + return nil, false +} + +// AsAlertsMetaDataProperties is the BasicAlertsMetaDataProperties implementation for AlertsMetaDataProperties. +func (amdp AlertsMetaDataProperties) AsAlertsMetaDataProperties() (*AlertsMetaDataProperties, bool) { + return &amdp, true +} + +// AsBasicAlertsMetaDataProperties is the BasicAlertsMetaDataProperties implementation for AlertsMetaDataProperties. +func (amdp AlertsMetaDataProperties) AsBasicAlertsMetaDataProperties() (BasicAlertsMetaDataProperties, bool) { + return &amdp, true +} + // AlertsSummary summary of alerts based on the input filters and 'groupby' parameters. type AlertsSummary struct { autorest.Response `json:"-"` @@ -1237,6 +1355,50 @@ func (mr ManagedResource) MarshalJSON() ([]byte, error) { return json.Marshal(objectMap) } +// MonitorServiceDetails details of a monitor service +type MonitorServiceDetails struct { + // Name - Monitor service name + Name *string `json:"name,omitempty"` + // DisplayName - Monitor service display name + DisplayName *string `json:"displayName,omitempty"` +} + +// MonitorServiceList monitor service details +type MonitorServiceList struct { + // Data - Array of operations + Data *[]MonitorServiceDetails `json:"data,omitempty"` + // MetadataIdentifier - Possible values include: 'MetadataIdentifierAlertsMetaDataProperties', 'MetadataIdentifierMonitorServiceList' + MetadataIdentifier MetadataIdentifier `json:"metadataIdentifier,omitempty"` +} + +// MarshalJSON is the custom marshaler for MonitorServiceList. +func (msl MonitorServiceList) MarshalJSON() ([]byte, error) { + msl.MetadataIdentifier = MetadataIdentifierMonitorServiceList + objectMap := make(map[string]interface{}) + if msl.Data != nil { + objectMap["data"] = msl.Data + } + if msl.MetadataIdentifier != "" { + objectMap["metadataIdentifier"] = msl.MetadataIdentifier + } + return json.Marshal(objectMap) +} + +// AsMonitorServiceList is the BasicAlertsMetaDataProperties implementation for MonitorServiceList. +func (msl MonitorServiceList) AsMonitorServiceList() (*MonitorServiceList, bool) { + return &msl, true +} + +// AsAlertsMetaDataProperties is the BasicAlertsMetaDataProperties implementation for MonitorServiceList. +func (msl MonitorServiceList) AsAlertsMetaDataProperties() (*AlertsMetaDataProperties, bool) { + return nil, false +} + +// AsBasicAlertsMetaDataProperties is the BasicAlertsMetaDataProperties implementation for MonitorServiceList. +func (msl MonitorServiceList) AsBasicAlertsMetaDataProperties() (BasicAlertsMetaDataProperties, bool) { + return &msl, true +} + // Operation operation provided by provider type Operation struct { // Name - Name of the operation