github.1485827954.workers.dev/wtfutil/wtf@v0.43.0/modules/newrelic/client/alert_conditions.go (about)

     1  package newrelic
     2  
     3  // AlertCondition describes what triggers an alert for a specific policy.
     4  type AlertCondition struct {
     5  	Enabled     bool                 `json:"enabled,omitempty"`
     6  	Entities    []string             `json:"entities,omitempty"`
     7  	ID          int                  `json:"id,omitempty"`
     8  	Metric      string               `json:"metric,omitempty"`
     9  	Name        string               `json:"name,omitempty"`
    10  	RunbookURL  string               `json:"runbook_url,omitempty"`
    11  	Terms       []AlertConditionTerm `json:"terms,omitempty"`
    12  	Type        string               `json:"type,omitempty"`
    13  	UserDefined AlertUserDefined     `json:"user_defined,omitempty"`
    14  }
    15  
    16  // AlertConditionTerm defines thresholds that trigger an AlertCondition.
    17  type AlertConditionTerm struct {
    18  	Duration     string `json:"duration,omitempty"`
    19  	Operator     string `json:"operator,omitempty"`
    20  	Priority     string `json:"priority,omitempty"`
    21  	Threshold    string `json:"threshold,omitempty"`
    22  	TimeFunction string `json:"time_function,omitempty"`
    23  }
    24  
    25  // AlertUserDefined describes user-defined behavior for an AlertCondition.
    26  type AlertUserDefined struct {
    27  	Metric        string `json:"metric,omitempty"`
    28  	ValueFunction string `json:"value_function,omitempty"`
    29  }
    30  
    31  // AlertConditionOptions define filters for GetAlertConditions.
    32  type AlertConditionOptions struct {
    33  	policyID int
    34  	Page     int
    35  }
    36  
    37  func (o *AlertConditionOptions) String() string {
    38  	if o == nil {
    39  		return ""
    40  	}
    41  	return encodeGetParams(map[string]interface{}{
    42  		"policy_id": o.policyID,
    43  		"page":      o.Page,
    44  	})
    45  }
    46  
    47  // GetAlertConditions will return any AlertCondition defined for a given
    48  // policy, optionally filtered by AlertConditionOptions.
    49  func (c *Client) GetAlertConditions(policy int, options *AlertConditionOptions) ([]AlertCondition, error) {
    50  	resp := &struct {
    51  		Conditions []AlertCondition `json:"conditions,omitempty"`
    52  	}{}
    53  	options.policyID = policy
    54  	err := c.doGet("alerts_conditions.json", options, resp)
    55  	if err != nil {
    56  		return nil, err
    57  	}
    58  	return resp.Conditions, nil
    59  }