| 
 | 1 | +package monitor  | 
 | 2 | + | 
 | 3 | +import (  | 
 | 4 | +	"bytes"  | 
 | 5 | +	"encoding/json"  | 
 | 6 | +	"io"  | 
 | 7 | +)  | 
 | 8 | + | 
 | 9 | +// --- Constants --  | 
 | 10 | +const (  | 
 | 11 | +	// alert types enum  | 
 | 12 | +	AlertV2AlertType_AdvancedManual   = "ADVANCED_MANUAL"  | 
 | 13 | +	AlertV2AlertType_AnomalyDetection = "ANOMALY_DETECTION"  | 
 | 14 | +	AlertV2AlertType_Dowtime          = "DOWNTIME"  | 
 | 15 | +	AlertV2AlertType_Event            = "EVENT"  | 
 | 16 | +	AlertV2AlertType_GroupOutlier     = "GROUP_OUTLIER"  | 
 | 17 | +	AlertV2AlertType_Manual           = "MANUAL"  | 
 | 18 | +	AlertV2AlertType_Prometheus       = "PROMETHEUS"  | 
 | 19 | + | 
 | 20 | +	// severities enum  | 
 | 21 | +	AlertV2Severity_High   = "high"  | 
 | 22 | +	AlertV2Severity_Medium = "medium"  | 
 | 23 | +	AlertV2Severity_Low    = "low"  | 
 | 24 | +	AlertV2Severity_Info   = "info"  | 
 | 25 | + | 
 | 26 | +	// alert link type  | 
 | 27 | +	AlertLinkV2Type_Dashboard = "dashboard"  | 
 | 28 | +	AlertLinkV2Type_Runbook   = "runbook"  | 
 | 29 | + | 
 | 30 | +	// others  | 
 | 31 | +	AlertV2CaptureFilenameRegexp = `.*?\.scap`  | 
 | 32 | +)  | 
 | 33 | + | 
 | 34 | +// enums severity values  | 
 | 35 | +func AlertV2Severity_Values() []string {  | 
 | 36 | +	return []string{  | 
 | 37 | +		AlertV2Severity_High,  | 
 | 38 | +		AlertV2Severity_Medium,  | 
 | 39 | +		AlertV2Severity_Low,  | 
 | 40 | +		AlertV2Severity_Info,  | 
 | 41 | +	}  | 
 | 42 | +}  | 
 | 43 | + | 
 | 44 | +// AlertV2  | 
 | 45 | +type AlertV2Common struct {  | 
 | 46 | +	ID                            int                            `json:"id,omitempty"`  | 
 | 47 | +	Version                       int                            `json:"version,omitempty"`  | 
 | 48 | +	Name                          string                         `json:"name"`  | 
 | 49 | +	Description                   string                         `json:"description,omitempty"`  | 
 | 50 | +	DurationSec                   int                            `json:"durationSec"`  | 
 | 51 | +	Type                          string                         `json:"type"`  | 
 | 52 | +	Group                         string                         `json:"group,omitempty"`  | 
 | 53 | +	Severity                      string                         `json:"severity"`  | 
 | 54 | +	TeamID                        int                            `json:"teamId,omitempty"`  | 
 | 55 | +	Enabled                       bool                           `json:"enabled"`  | 
 | 56 | +	NotificationChannelConfigList *[]NotificationChannelConfigV2 `json:"notificationChannelConfigList,omitempty"`  | 
 | 57 | +	CustomNotificationTemplate    *CustomNotificationTemplateV2  `json:"customNotificationTemplate,omitempty"`  | 
 | 58 | +	CaptureConfig                 *CaptureConfigV2               `json:"captureConfig,omitempty"`  | 
 | 59 | +	Links                         *[]AlertLinkV2                 `json:"links,omitempty"`  | 
 | 60 | +}  | 
 | 61 | + | 
 | 62 | +type AlertV2ConfigPrometheus struct {  | 
 | 63 | +	Query string `json:"query"`  | 
 | 64 | +}  | 
 | 65 | + | 
 | 66 | +type AlertV2Prometheus struct {  | 
 | 67 | +	AlertV2Common  | 
 | 68 | +	Config *AlertV2ConfigPrometheus `json:"config"`  | 
 | 69 | +}  | 
 | 70 | + | 
 | 71 | +func (a *AlertV2Prometheus) ToJSON() io.Reader {  | 
 | 72 | +	data := struct {  | 
 | 73 | +		Alert AlertV2Prometheus `json:"alert"`  | 
 | 74 | +	}{Alert: *a}  | 
 | 75 | +	payload, _ := json.Marshal(data)  | 
 | 76 | +	return bytes.NewBuffer(payload)  | 
 | 77 | +}  | 
 | 78 | + | 
 | 79 | +func AlertV2PrometheusFromJSON(body []byte) AlertV2Prometheus {  | 
 | 80 | +	var result struct {  | 
 | 81 | +		Alert AlertV2Prometheus  | 
 | 82 | +	}  | 
 | 83 | +	_ = json.Unmarshal(body, &result)  | 
 | 84 | +	return result.Alert  | 
 | 85 | +}  | 
 | 86 | + | 
 | 87 | +// AlertScopeV2  | 
 | 88 | +type AlertScopeV2 struct {  | 
 | 89 | +	Expressions []ScopeExpressionV2 `json:"expressions"`  | 
 | 90 | +}  | 
 | 91 | + | 
 | 92 | +type AlertLabelDescriptorV2 struct {  | 
 | 93 | +	ID       string `json:"id"`  | 
 | 94 | +	PublicID string `json:"publicId"`  | 
 | 95 | +}  | 
 | 96 | + | 
 | 97 | +type NotificationGroupingConditionV2 struct {  | 
 | 98 | +	Type  string  `json:"type"`  | 
 | 99 | +	Value float64 `json:"value"`  | 
 | 100 | +}  | 
 | 101 | + | 
 | 102 | +type AlertMetricDescriptorV2 struct {  | 
 | 103 | +	ID                string        `json:"id"`  | 
 | 104 | +	PublicID          string        `json:"publicId"`  | 
 | 105 | +	MetricType        string        `json:"metricType"`  | 
 | 106 | +	Type              string        `json:"type"`  | 
 | 107 | +	Scale             float64       `json:"scale"`  | 
 | 108 | +	GroupAggregations []Aggregation `json:"groupAggregations"`  | 
 | 109 | +	TimeAggregations  []Aggregation `json:"timeAggregations"`  | 
 | 110 | +}  | 
 | 111 | + | 
 | 112 | +type Aggregation struct {  | 
 | 113 | +	ID               int         `json:"id"`  | 
 | 114 | +	Percentile       bool        `json:"percentile"`  | 
 | 115 | +	AggregationValue interface{} `json:"aggregationValue"`  | 
 | 116 | +}  | 
 | 117 | + | 
 | 118 | +type ScopeExpressionV2 struct {  | 
 | 119 | +	Operand    string                  `json:"operand"`  | 
 | 120 | +	Descriptor AlertLabelDescriptorV2  `json:"descriptor"`  | 
 | 121 | +	Operator   ScopeExpressionOperator `json:"operator"`  | 
 | 122 | +	Value      []string                `json:"value"`  | 
 | 123 | +}  | 
 | 124 | + | 
 | 125 | +type ScopeExpressionOperator struct {  | 
 | 126 | +}  | 
 | 127 | + | 
 | 128 | +type NotificationChannelConfigV2 struct {  | 
 | 129 | +	// Type can be one of EMAIL, SNS, SLACK, PAGER_DUTY, VICTOROPS, OPSGENIE, WEBHOOK, IBM_FUNCTION, MS_TEAMS, TEAM_EMAIL, IBM_EVENT_NOTIFICATIONS, PROMETHEUS_ALERT_MANAGER  | 
 | 130 | +	ChannelID int                           `json:"channelId,omitempty"`  | 
 | 131 | +	Type      string                        `json:"type,omitempty"`  | 
 | 132 | +	Name      string                        `json:"nam,omitempty"`  | 
 | 133 | +	Enabled   bool                          `json:"enabled,omitempty"`  | 
 | 134 | +	Options   *NotificationChannelOptionsV2 `json:"options,omitempty"`  | 
 | 135 | +}  | 
 | 136 | + | 
 | 137 | +type NotificationChannelOptionsV2 struct {  | 
 | 138 | +	// commons  | 
 | 139 | +	NotifyOnAcknowledge        bool                          `json:"notifyOnAcknowledge,omitempty"`  | 
 | 140 | +	NotifyOnResolve            bool                          `json:"notifyOnResolve,omitempty"`  | 
 | 141 | +	ReNotifyEverySec           int                           `json:"reNotifyEverySec,omitempty"`  | 
 | 142 | +	CustomNotificationTemplate *CustomNotificationTemplateV2 `json:"customNotificationTemplate,omitempty"`  | 
 | 143 | +	Thresholds                 []string                      `json:"thresholds,omitempty"`  | 
 | 144 | +}  | 
 | 145 | + | 
 | 146 | +type CustomNotificationTemplateV2 struct {  | 
 | 147 | +	Subject     string `json:"subject,omitempty"`  | 
 | 148 | +	PrependText string `json:"prependText,omitempty"`  | 
 | 149 | +	AppendText  string `json:"appendText,omitempty"`  | 
 | 150 | +}  | 
 | 151 | + | 
 | 152 | +type CaptureConfigV2 struct {  | 
 | 153 | +	DurationSec int    `json:"durationSec"`  | 
 | 154 | +	Storage     string `json:"storage"`  | 
 | 155 | +	Filter      string `json:"filter,omitempty"`  | 
 | 156 | +	FileName    string `json:"fileName"`  | 
 | 157 | +	Enabled     bool   `json:"enabled"`  | 
 | 158 | +}  | 
 | 159 | + | 
 | 160 | +// enums link types values  | 
 | 161 | +func AlertLinkV2Type_Values() []string {  | 
 | 162 | +	return []string{  | 
 | 163 | +		AlertLinkV2Type_Dashboard,  | 
 | 164 | +		AlertLinkV2Type_Runbook,  | 
 | 165 | +	}  | 
 | 166 | +}  | 
 | 167 | + | 
 | 168 | +type AlertLinkV2 struct {  | 
 | 169 | +	Name string `json:"name"`  | 
 | 170 | +	Type string `json:"type"`  | 
 | 171 | +	ID   string `json:"id"`  | 
 | 172 | +	Href string `json:"href"`  | 
 | 173 | +}  | 
0 commit comments