...

Source file src/github.com/Azure/azure-sdk-for-go/services/monitor/mgmt/2020-10-01/insights/models.go

Documentation: github.com/Azure/azure-sdk-for-go/services/monitor/mgmt/2020-10-01/insights

     1  package insights
     2  
     3  // Copyright (c) Microsoft Corporation. All rights reserved.
     4  // Licensed under the MIT License. See License.txt in the project root for license information.
     5  //
     6  // Code generated by Microsoft (R) AutoRest Code Generator.
     7  // Changes may cause incorrect behavior and will be lost if the code is regenerated.
     8  
     9  import (
    10  	"context"
    11  	"encoding/json"
    12  	"github.com/Azure/go-autorest/autorest"
    13  	"github.com/Azure/go-autorest/autorest/to"
    14  	"github.com/Azure/go-autorest/tracing"
    15  	"net/http"
    16  )
    17  
    18  // The package's fully qualified name.
    19  const fqdn = "github.com/Azure/azure-sdk-for-go/services/monitor/mgmt/2020-10-01/insights"
    20  
    21  // ActionGroup a pointer to an Azure Action Group.
    22  type ActionGroup struct {
    23  	// ActionGroupID - The resource ID of the Action Group. This cannot be null or empty.
    24  	ActionGroupID *string `json:"actionGroupId,omitempty"`
    25  	// WebhookProperties - the dictionary of custom properties to include with the post operation. These data are appended to the webhook payload.
    26  	WebhookProperties map[string]*string `json:"webhookProperties"`
    27  }
    28  
    29  // MarshalJSON is the custom marshaler for ActionGroup.
    30  func (ag ActionGroup) MarshalJSON() ([]byte, error) {
    31  	objectMap := make(map[string]interface{})
    32  	if ag.ActionGroupID != nil {
    33  		objectMap["actionGroupId"] = ag.ActionGroupID
    34  	}
    35  	if ag.WebhookProperties != nil {
    36  		objectMap["webhookProperties"] = ag.WebhookProperties
    37  	}
    38  	return json.Marshal(objectMap)
    39  }
    40  
    41  // ActionList a list of Activity Log Alert rule actions.
    42  type ActionList struct {
    43  	// ActionGroups - The list of the Action Groups.
    44  	ActionGroups *[]ActionGroup `json:"actionGroups,omitempty"`
    45  }
    46  
    47  // ActivityLogAlertResource an Activity Log Alert rule resource.
    48  type ActivityLogAlertResource struct {
    49  	autorest.Response `json:"-"`
    50  	// AlertRuleProperties - The Activity Log Alert rule properties of the resource.
    51  	*AlertRuleProperties `json:"properties,omitempty"`
    52  	// ID - READ-ONLY; The resource Id.
    53  	ID *string `json:"id,omitempty"`
    54  	// Name - READ-ONLY; The name of the resource.
    55  	Name *string `json:"name,omitempty"`
    56  	// Type - READ-ONLY; The type of the resource.
    57  	Type *string `json:"type,omitempty"`
    58  	// Location - The location of the resource. Since Azure Activity Log Alerts is a global service, the location of the rules should always be 'global'.
    59  	Location *string `json:"location,omitempty"`
    60  	// Tags - The tags of the resource.
    61  	Tags map[string]*string `json:"tags"`
    62  }
    63  
    64  // MarshalJSON is the custom marshaler for ActivityLogAlertResource.
    65  func (alar ActivityLogAlertResource) MarshalJSON() ([]byte, error) {
    66  	objectMap := make(map[string]interface{})
    67  	if alar.AlertRuleProperties != nil {
    68  		objectMap["properties"] = alar.AlertRuleProperties
    69  	}
    70  	if alar.Location != nil {
    71  		objectMap["location"] = alar.Location
    72  	}
    73  	if alar.Tags != nil {
    74  		objectMap["tags"] = alar.Tags
    75  	}
    76  	return json.Marshal(objectMap)
    77  }
    78  
    79  // UnmarshalJSON is the custom unmarshaler for ActivityLogAlertResource struct.
    80  func (alar *ActivityLogAlertResource) UnmarshalJSON(body []byte) error {
    81  	var m map[string]*json.RawMessage
    82  	err := json.Unmarshal(body, &m)
    83  	if err != nil {
    84  		return err
    85  	}
    86  	for k, v := range m {
    87  		switch k {
    88  		case "properties":
    89  			if v != nil {
    90  				var alertRuleProperties AlertRuleProperties
    91  				err = json.Unmarshal(*v, &alertRuleProperties)
    92  				if err != nil {
    93  					return err
    94  				}
    95  				alar.AlertRuleProperties = &alertRuleProperties
    96  			}
    97  		case "id":
    98  			if v != nil {
    99  				var ID string
   100  				err = json.Unmarshal(*v, &ID)
   101  				if err != nil {
   102  					return err
   103  				}
   104  				alar.ID = &ID
   105  			}
   106  		case "name":
   107  			if v != nil {
   108  				var name string
   109  				err = json.Unmarshal(*v, &name)
   110  				if err != nil {
   111  					return err
   112  				}
   113  				alar.Name = &name
   114  			}
   115  		case "type":
   116  			if v != nil {
   117  				var typeVar string
   118  				err = json.Unmarshal(*v, &typeVar)
   119  				if err != nil {
   120  					return err
   121  				}
   122  				alar.Type = &typeVar
   123  			}
   124  		case "location":
   125  			if v != nil {
   126  				var location string
   127  				err = json.Unmarshal(*v, &location)
   128  				if err != nil {
   129  					return err
   130  				}
   131  				alar.Location = &location
   132  			}
   133  		case "tags":
   134  			if v != nil {
   135  				var tags map[string]*string
   136  				err = json.Unmarshal(*v, &tags)
   137  				if err != nil {
   138  					return err
   139  				}
   140  				alar.Tags = tags
   141  			}
   142  		}
   143  	}
   144  
   145  	return nil
   146  }
   147  
   148  // AlertRuleAllOfCondition an Activity Log Alert rule condition that is met when all its member conditions
   149  // are met.
   150  type AlertRuleAllOfCondition struct {
   151  	// AllOf - The list of Activity Log Alert rule conditions.
   152  	AllOf *[]AlertRuleAnyOfOrLeafCondition `json:"allOf,omitempty"`
   153  }
   154  
   155  // AlertRuleAnyOfOrLeafCondition an Activity Log Alert rule condition that is met when all its member
   156  // conditions are met.
   157  // Each condition can be of one of the following types:
   158  // __Important__: Each type has its unique subset of properties. Properties from different types CANNOT
   159  // exist in one condition.
   160  // * __Leaf Condition -__ must contain 'field' and either 'equals' or 'containsAny'.
   161  // _Please note, 'anyOf' should __not__ be set in a Leaf Condition._
   162  // * __AnyOf Condition -__ must contain __only__ 'anyOf' (which is an array of Leaf Conditions).
   163  // _Please note, 'field', 'equals' and 'containsAny' should __not__ be set in an AnyOf Condition._
   164  type AlertRuleAnyOfOrLeafCondition struct {
   165  	// AnyOf - An Activity Log Alert rule condition that is met when at least one of its member leaf conditions are met.
   166  	AnyOf *[]AlertRuleLeafCondition `json:"anyOf,omitempty"`
   167  	// Field - The name of the Activity Log event's field that this condition will examine.
   168  	// The possible values for this field are (case-insensitive): 'resourceId', 'category', 'caller', 'level', 'operationName', 'resourceGroup', 'resourceProvider', 'status', 'subStatus', 'resourceType', or anything beginning with 'properties'.
   169  	Field *string `json:"field,omitempty"`
   170  	// Equals - The value of the event's field will be compared to this value (case-insensitive) to determine if the condition is met.
   171  	Equals *string `json:"equals,omitempty"`
   172  	// ContainsAny - The value of the event's field will be compared to the values in this array (case-insensitive) to determine if the condition is met.
   173  	ContainsAny *[]string `json:"containsAny,omitempty"`
   174  }
   175  
   176  // AlertRuleLeafCondition an Activity Log Alert rule condition that is met by comparing the field and value
   177  // of an Activity Log event.
   178  // This condition must contain 'field' and either 'equals' or 'containsAny'.
   179  type AlertRuleLeafCondition struct {
   180  	// Field - The name of the Activity Log event's field that this condition will examine.
   181  	// The possible values for this field are (case-insensitive): 'resourceId', 'category', 'caller', 'level', 'operationName', 'resourceGroup', 'resourceProvider', 'status', 'subStatus', 'resourceType', or anything beginning with 'properties'.
   182  	Field *string `json:"field,omitempty"`
   183  	// Equals - The value of the event's field will be compared to this value (case-insensitive) to determine if the condition is met.
   184  	Equals *string `json:"equals,omitempty"`
   185  	// ContainsAny - The value of the event's field will be compared to the values in this array (case-insensitive) to determine if the condition is met.
   186  	ContainsAny *[]string `json:"containsAny,omitempty"`
   187  }
   188  
   189  // AlertRuleList a list of Activity Log Alert rules.
   190  type AlertRuleList struct {
   191  	autorest.Response `json:"-"`
   192  	// Value - The list of Activity Log Alert rules.
   193  	Value *[]ActivityLogAlertResource `json:"value,omitempty"`
   194  	// NextLink - Provides the link to retrieve the next set of elements.
   195  	NextLink *string `json:"nextLink,omitempty"`
   196  }
   197  
   198  // AlertRuleListIterator provides access to a complete listing of ActivityLogAlertResource values.
   199  type AlertRuleListIterator struct {
   200  	i    int
   201  	page AlertRuleListPage
   202  }
   203  
   204  // NextWithContext advances to the next value.  If there was an error making
   205  // the request the iterator does not advance and the error is returned.
   206  func (iter *AlertRuleListIterator) NextWithContext(ctx context.Context) (err error) {
   207  	if tracing.IsEnabled() {
   208  		ctx = tracing.StartSpan(ctx, fqdn+"/AlertRuleListIterator.NextWithContext")
   209  		defer func() {
   210  			sc := -1
   211  			if iter.Response().Response.Response != nil {
   212  				sc = iter.Response().Response.Response.StatusCode
   213  			}
   214  			tracing.EndSpan(ctx, sc, err)
   215  		}()
   216  	}
   217  	iter.i++
   218  	if iter.i < len(iter.page.Values()) {
   219  		return nil
   220  	}
   221  	err = iter.page.NextWithContext(ctx)
   222  	if err != nil {
   223  		iter.i--
   224  		return err
   225  	}
   226  	iter.i = 0
   227  	return nil
   228  }
   229  
   230  // Next advances to the next value.  If there was an error making
   231  // the request the iterator does not advance and the error is returned.
   232  // Deprecated: Use NextWithContext() instead.
   233  func (iter *AlertRuleListIterator) Next() error {
   234  	return iter.NextWithContext(context.Background())
   235  }
   236  
   237  // NotDone returns true if the enumeration should be started or is not yet complete.
   238  func (iter AlertRuleListIterator) NotDone() bool {
   239  	return iter.page.NotDone() && iter.i < len(iter.page.Values())
   240  }
   241  
   242  // Response returns the raw server response from the last page request.
   243  func (iter AlertRuleListIterator) Response() AlertRuleList {
   244  	return iter.page.Response()
   245  }
   246  
   247  // Value returns the current value or a zero-initialized value if the
   248  // iterator has advanced beyond the end of the collection.
   249  func (iter AlertRuleListIterator) Value() ActivityLogAlertResource {
   250  	if !iter.page.NotDone() {
   251  		return ActivityLogAlertResource{}
   252  	}
   253  	return iter.page.Values()[iter.i]
   254  }
   255  
   256  // Creates a new instance of the AlertRuleListIterator type.
   257  func NewAlertRuleListIterator(page AlertRuleListPage) AlertRuleListIterator {
   258  	return AlertRuleListIterator{page: page}
   259  }
   260  
   261  // IsEmpty returns true if the ListResult contains no values.
   262  func (arl AlertRuleList) IsEmpty() bool {
   263  	return arl.Value == nil || len(*arl.Value) == 0
   264  }
   265  
   266  // hasNextLink returns true if the NextLink is not empty.
   267  func (arl AlertRuleList) hasNextLink() bool {
   268  	return arl.NextLink != nil && len(*arl.NextLink) != 0
   269  }
   270  
   271  // alertRuleListPreparer prepares a request to retrieve the next set of results.
   272  // It returns nil if no more results exist.
   273  func (arl AlertRuleList) alertRuleListPreparer(ctx context.Context) (*http.Request, error) {
   274  	if !arl.hasNextLink() {
   275  		return nil, nil
   276  	}
   277  	return autorest.Prepare((&http.Request{}).WithContext(ctx),
   278  		autorest.AsJSON(),
   279  		autorest.AsGet(),
   280  		autorest.WithBaseURL(to.String(arl.NextLink)))
   281  }
   282  
   283  // AlertRuleListPage contains a page of ActivityLogAlertResource values.
   284  type AlertRuleListPage struct {
   285  	fn  func(context.Context, AlertRuleList) (AlertRuleList, error)
   286  	arl AlertRuleList
   287  }
   288  
   289  // NextWithContext advances to the next page of values.  If there was an error making
   290  // the request the page does not advance and the error is returned.
   291  func (page *AlertRuleListPage) NextWithContext(ctx context.Context) (err error) {
   292  	if tracing.IsEnabled() {
   293  		ctx = tracing.StartSpan(ctx, fqdn+"/AlertRuleListPage.NextWithContext")
   294  		defer func() {
   295  			sc := -1
   296  			if page.Response().Response.Response != nil {
   297  				sc = page.Response().Response.Response.StatusCode
   298  			}
   299  			tracing.EndSpan(ctx, sc, err)
   300  		}()
   301  	}
   302  	for {
   303  		next, err := page.fn(ctx, page.arl)
   304  		if err != nil {
   305  			return err
   306  		}
   307  		page.arl = next
   308  		if !next.hasNextLink() || !next.IsEmpty() {
   309  			break
   310  		}
   311  	}
   312  	return nil
   313  }
   314  
   315  // Next advances to the next page of values.  If there was an error making
   316  // the request the page does not advance and the error is returned.
   317  // Deprecated: Use NextWithContext() instead.
   318  func (page *AlertRuleListPage) Next() error {
   319  	return page.NextWithContext(context.Background())
   320  }
   321  
   322  // NotDone returns true if the page enumeration should be started or is not yet complete.
   323  func (page AlertRuleListPage) NotDone() bool {
   324  	return !page.arl.IsEmpty()
   325  }
   326  
   327  // Response returns the raw server response from the last page request.
   328  func (page AlertRuleListPage) Response() AlertRuleList {
   329  	return page.arl
   330  }
   331  
   332  // Values returns the slice of values for the current page or nil if there are no values.
   333  func (page AlertRuleListPage) Values() []ActivityLogAlertResource {
   334  	if page.arl.IsEmpty() {
   335  		return nil
   336  	}
   337  	return *page.arl.Value
   338  }
   339  
   340  // Creates a new instance of the AlertRuleListPage type.
   341  func NewAlertRuleListPage(cur AlertRuleList, getNextPage func(context.Context, AlertRuleList) (AlertRuleList, error)) AlertRuleListPage {
   342  	return AlertRuleListPage{
   343  		fn:  getNextPage,
   344  		arl: cur,
   345  	}
   346  }
   347  
   348  // AlertRulePatchObject an Activity Log Alert rule object for the body of patch operations.
   349  type AlertRulePatchObject struct {
   350  	// Tags - The resource tags
   351  	Tags map[string]*string `json:"tags"`
   352  	// AlertRulePatchProperties - The activity log alert settings for an update operation.
   353  	*AlertRulePatchProperties `json:"properties,omitempty"`
   354  }
   355  
   356  // MarshalJSON is the custom marshaler for AlertRulePatchObject.
   357  func (arpo AlertRulePatchObject) MarshalJSON() ([]byte, error) {
   358  	objectMap := make(map[string]interface{})
   359  	if arpo.Tags != nil {
   360  		objectMap["tags"] = arpo.Tags
   361  	}
   362  	if arpo.AlertRulePatchProperties != nil {
   363  		objectMap["properties"] = arpo.AlertRulePatchProperties
   364  	}
   365  	return json.Marshal(objectMap)
   366  }
   367  
   368  // UnmarshalJSON is the custom unmarshaler for AlertRulePatchObject struct.
   369  func (arpo *AlertRulePatchObject) UnmarshalJSON(body []byte) error {
   370  	var m map[string]*json.RawMessage
   371  	err := json.Unmarshal(body, &m)
   372  	if err != nil {
   373  		return err
   374  	}
   375  	for k, v := range m {
   376  		switch k {
   377  		case "tags":
   378  			if v != nil {
   379  				var tags map[string]*string
   380  				err = json.Unmarshal(*v, &tags)
   381  				if err != nil {
   382  					return err
   383  				}
   384  				arpo.Tags = tags
   385  			}
   386  		case "properties":
   387  			if v != nil {
   388  				var alertRulePatchProperties AlertRulePatchProperties
   389  				err = json.Unmarshal(*v, &alertRulePatchProperties)
   390  				if err != nil {
   391  					return err
   392  				}
   393  				arpo.AlertRulePatchProperties = &alertRulePatchProperties
   394  			}
   395  		}
   396  	}
   397  
   398  	return nil
   399  }
   400  
   401  // AlertRulePatchProperties an Activity Log Alert rule properties for patch operations.
   402  type AlertRulePatchProperties struct {
   403  	// Enabled - Indicates whether this Activity Log Alert rule is enabled. If an Activity Log Alert rule is not enabled, then none of its actions will be activated.
   404  	Enabled *bool `json:"enabled,omitempty"`
   405  }
   406  
   407  // AlertRuleProperties an Azure Activity Log Alert rule.
   408  type AlertRuleProperties struct {
   409  	// Scopes - A list of resource IDs that will be used as prefixes. The alert will only apply to Activity Log events with resource IDs that fall under one of these prefixes. This list must include at least one item.
   410  	Scopes *[]string `json:"scopes,omitempty"`
   411  	// Condition - The condition that will cause this alert to activate.
   412  	Condition *AlertRuleAllOfCondition `json:"condition,omitempty"`
   413  	// Actions - The actions that will activate when the condition is met.
   414  	Actions *ActionList `json:"actions,omitempty"`
   415  	// Enabled - Indicates whether this Activity Log Alert rule is enabled. If an Activity Log Alert rule is not enabled, then none of its actions will be activated.
   416  	Enabled *bool `json:"enabled,omitempty"`
   417  	// Description - A description of this Activity Log Alert rule.
   418  	Description *string `json:"description,omitempty"`
   419  }
   420  
   421  // AzureResource an Azure resource object.
   422  type AzureResource struct {
   423  	// ID - READ-ONLY; The resource Id.
   424  	ID *string `json:"id,omitempty"`
   425  	// Name - READ-ONLY; The name of the resource.
   426  	Name *string `json:"name,omitempty"`
   427  	// Type - READ-ONLY; The type of the resource.
   428  	Type *string `json:"type,omitempty"`
   429  	// Location - The location of the resource. Since Azure Activity Log Alerts is a global service, the location of the rules should always be 'global'.
   430  	Location *string `json:"location,omitempty"`
   431  	// Tags - The tags of the resource.
   432  	Tags map[string]*string `json:"tags"`
   433  }
   434  
   435  // MarshalJSON is the custom marshaler for AzureResource.
   436  func (ar AzureResource) MarshalJSON() ([]byte, error) {
   437  	objectMap := make(map[string]interface{})
   438  	if ar.Location != nil {
   439  		objectMap["location"] = ar.Location
   440  	}
   441  	if ar.Tags != nil {
   442  		objectMap["tags"] = ar.Tags
   443  	}
   444  	return json.Marshal(objectMap)
   445  }
   446  
   447  // ErrorResponse the error response.
   448  type ErrorResponse struct {
   449  	// Code - READ-ONLY; The error code.
   450  	Code *string `json:"code,omitempty"`
   451  	// Message - READ-ONLY; The error message indicating why the operation failed.
   452  	Message *string `json:"message,omitempty"`
   453  }
   454  
   455  // MarshalJSON is the custom marshaler for ErrorResponse.
   456  func (er ErrorResponse) MarshalJSON() ([]byte, error) {
   457  	objectMap := make(map[string]interface{})
   458  	return json.Marshal(objectMap)
   459  }
   460  

View as plain text