diff --git a/alert_rules.go b/alert_rules.go index 5ac4e6a..d5b48f3 100644 --- a/alert_rules.go +++ b/alert_rules.go @@ -63,20 +63,6 @@ func (s *AlertRulesService) ReadCounterTotal(ctx context.Context) (*RuleCounterT return out, resp, nil } -// Export alert rules. -// -// Export the configuration of selected alert rules as a portable JSON array, compatible with `POST /monit/rule/import`. -// -// API: POST /monit/rule/export (monit-rule-read-export). -func (s *AlertRulesService) ReadExport(ctx context.Context, req *RuleIDsRequest) (*AlertRuleExportListResponse, *Response, error) { - out := new(AlertRuleExportListResponse) - resp, err := s.client.do(ctx, "/monit/rule/export", req, out) - if err != nil { - return nil, resp, err - } - return out, resp, nil -} - // Get alert rule detail (V2). // // Return the full V2 configuration of an alert rule by ID, including lifecycle v2 recovery and ending modes. @@ -151,20 +137,6 @@ func (s *AlertRulesService) WriteFieldsUpdate(ctx context.Context, req *RuleFiel return out, resp, nil } -// Import alert rules. -// -// Import one or more alert rules from a JSON array. Returns the result for each rule, indicating success or failure. -// -// API: POST /monit/rule/import (monit-rule-write-import). -func (s *AlertRulesService) WriteImport(ctx context.Context, req *RuleImportRequest) (*RuleImportResponse, *Response, error) { - out := new(RuleImportResponse) - resp, err := s.client.do(ctx, "/monit/rule/import", req, out) - if err != nil { - return nil, resp, err - } - return out, resp, nil -} - // Move alert rules to folder. // // Move one or more alert rules to a different folder. diff --git a/alert_rules_test.go b/alert_rules_test.go index d6d5e08..fa11556 100644 --- a/alert_rules_test.go +++ b/alert_rules_test.go @@ -21,9 +21,11 @@ func TestAlertRuleUpdateV2PreservesInvestigationTargetsPresence(t *testing.T) { Kind: "dashboard", Dashboard: DashboardInvestigationTarget{ DashboardID: "01900000-0000-7000-8000-000000000001", + Variables: map[string]string{}, }, + TimeRange: InvestigationTimeRange{BeforeSeconds: 1800, AfterSeconds: 600}, }}, - want: `[{"dashboard":{"dashboard_id":"01900000-0000-7000-8000-000000000001"},"kind":"dashboard"}]`, + want: `[{"dashboard":{"dashboard_id":"01900000-0000-7000-8000-000000000001","variables":{}},"kind":"dashboard","time_range":{"after_seconds":600,"before_seconds":1800}}]`, }, } for _, tt := range tests { diff --git a/members.go b/members.go index 796ba58..9214b55 100644 --- a/members.go +++ b/members.go @@ -69,7 +69,7 @@ func (s *MembersService) MemberList(ctx context.Context, req *MemberListRequest) // Notify members. // -// Send an email to account members on behalf of the caller, with content the caller supplies. Only callable with a credential minted for an AI SRE session; any other credential is rejected with `AccessDenied`. Delivery is asynchronous — `accepted` means the email was queued, not that it was delivered. Call it with `dry_run` set to `true` before sending: `html` in the response is the email exactly as recipients will get it, so you can confirm the sanitizer kept everything the message depends on. +// Send an email to account members on behalf of the caller, with content the caller supplies. Only callable with a credential minted for an AI SRE session; any other credential is rejected with `AccessDenied`. Delivery is asynchronous — `accepted` means the email was queued, not that it was delivered. // // API: POST /member/notify (memberNotify). func (s *MembersService) MemberNotify(ctx context.Context, req *MemberNotifyRequest) (*MemberNotifyResponse, *Response, error) { diff --git a/models_gen.go b/models_gen.go index 275c59a..e8f7765 100644 --- a/models_gen.go +++ b/models_gen.go @@ -808,59 +808,59 @@ type AlertPipelineUpsertRequest struct { // AlertRule is generated from the Flashduty OpenAPI schema. type AlertRule struct { // Account ID. Filled by the server from the authenticated identity; do not provide. - AccountID uint64 `json:"account_id,omitempty" toon:"account_id,omitempty"` + AccountID uint64 `json:"account_id" toon:"account_id"` // Annotation key-value pairs delivered with alert events; keys must not start with `$` (reserved for query fields). - Annotations map[string]string `json:"annotations,omitempty" toon:"annotations,omitempty"` + Annotations map[string]string `json:"annotations" toon:"annotations"` // Channel IDs to send alerts to. - ChannelIDs []uint64 `json:"channel_ids,omitempty" toon:"channel_ids,omitempty"` + ChannelIDs []uint64 `json:"channel_ids" toon:"channel_ids"` // Creation time as a Unix timestamp in seconds. Generated by the server; do not provide. - CreatedAt int64 `json:"created_at,omitempty" toon:"created_at,omitempty"` + CreatedAt Timestamp `json:"created_at" toon:"created_at"` // Creator user ID. Filled by the server from the current user; do not provide. - CreatorID uint64 `json:"creator_id,omitempty" toon:"creator_id,omitempty"` + CreatorID uint64 `json:"creator_id" toon:"creator_id"` // Creator name. Filled by the server; do not provide. - CreatorName string `json:"creator_name,omitempty" toon:"creator_name,omitempty"` + CreatorName string `json:"creator_name" toon:"creator_name"` // Schedule expression: a 6-field cron (with seconds) or an `@every 30s` interval descriptor. Must not start with `CRON_TZ=` or `TZ=`; use the `timezone` field instead. CronPattern string `json:"cron_pattern" toon:"cron_pattern"` // Whether to enable debug logging; the edge emits detailed evaluation logs, useful for troubleshooting rules that do not trigger as expected. - DebugLogEnabled bool `json:"debug_log_enabled,omitempty" toon:"debug_log_enabled,omitempty"` + DebugLogEnabled bool `json:"debug_log_enabled" toon:"debug_log_enabled"` // Seconds to shift the evaluation query window backward, compensating for data ingestion latency. - DelaySeconds int64 `json:"delay_seconds,omitempty" toon:"delay_seconds,omitempty"` + DelaySeconds int64 `json:"delay_seconds" toon:"delay_seconds"` // Rule description, in Markdown. - Description string `json:"description,omitempty" toon:"description,omitempty"` + Description string `json:"description" toon:"description"` // Format for the description. Defaults to `text` when omitted or empty. `text` = plain text; `markdown` = Markdown, rendered as Markdown in alert details. - DescriptionType string `json:"description_type,omitempty" toon:"description_type,omitempty"` + DescriptionType string `json:"description_type" toon:"description_type"` // Datasource IDs, merged with `ds_list` to decide which datasources the rule monitors; IDs survive datasource renames. At least one of `ds_list` and `ds_ids` must be provided. - DsIDs []uint64 `json:"ds_ids,omitempty" toon:"ds_ids,omitempty"` + DsIDs []uint64 `json:"ds_ids" toon:"ds_ids"` // Data source name patterns (supports wildcards). At least one of `ds_list` / `ds_ids` must be non-empty; the two are merged to decide which datasources the rule monitors. - DsList []string `json:"ds_list,omitempty" toon:"ds_list,omitempty"` + DsList []string `json:"ds_list" toon:"ds_list"` // Datasource type identifier (e.g. `prometheus`, `elasticsearch`). DsType string `json:"ds_type" toon:"ds_type"` // Whether the rule is enabled. Updating to `false` makes the server clean up the rule's active alerts. - Enabled bool `json:"enabled,omitempty" toon:"enabled,omitempty"` + Enabled bool `json:"enabled" toon:"enabled"` // Time windows when the rule is active. Defaults to all days from 00:00 to 23:59 when omitted or empty. - EnabledTimes []AlertRuleEnabledTimesItem `json:"enabled_times,omitempty" toon:"enabled_times,omitempty"` + EnabledTimes []AlertRuleEnabledTimesItem `json:"enabled_times" toon:"enabled_times"` // ID of the folder the rule belongs to. Obtainable via `POST /monit/folder/list`. FolderID uint64 `json:"folder_id" toon:"folder_id"` // Rule ID. Required for update; omit for create (assigned by the server). - ID uint64 `json:"id,omitempty" toon:"id,omitempty"` + ID uint64 `json:"id" toon:"id"` // Custom labels. - Labels map[string]string `json:"labels,omitempty" toon:"labels,omitempty"` + Labels map[string]string `json:"labels" toon:"labels"` // Rule name. Must be unique within the same folder. Name string `json:"name" toon:"name"` // Notification repeat interval in seconds. - RepeatInterval int64 `json:"repeat_interval,omitempty" toon:"repeat_interval,omitempty"` + RepeatInterval int64 `json:"repeat_interval" toon:"repeat_interval"` // Max number of repeat notifications. - RepeatTotal int64 `json:"repeat_total,omitempty" toon:"repeat_total,omitempty"` + RepeatTotal int64 `json:"repeat_total" toon:"repeat_total"` // Check configuration: query list plus trigger/recovery conditions. Structure see `RuleConfigs`. RuleConfigs RuleConfigs `json:"rule_configs" toon:"rule_configs"` // Timezone in which the rule executes. Determines how the cron schedule and effective time windows are interpreted. Only IANA timezone names are accepted (e.g. `Asia/Shanghai`, `UTC`, `Europe/London`); shortcuts and offsets such as `Local`, `UTC+8`, or `CST` are rejected. Treated as `Asia/Shanghai` if empty. - Timezone string `json:"timezone,omitempty" toon:"timezone,omitempty"` + Timezone string `json:"timezone" toon:"timezone"` // Last update time as a Unix timestamp in seconds. Generated by the server; do not provide. - UpdatedAt int64 `json:"updated_at,omitempty" toon:"updated_at,omitempty"` + UpdatedAt Timestamp `json:"updated_at" toon:"updated_at"` // Last updater user ID. Filled by the server; do not provide. - UpdaterID uint64 `json:"updater_id,omitempty" toon:"updater_id,omitempty"` + UpdaterID uint64 `json:"updater_id" toon:"updater_id"` // Last updater name. Filled by the server; do not provide. - UpdaterName string `json:"updater_name,omitempty" toon:"updater_name,omitempty"` + UpdaterName string `json:"updater_name" toon:"updater_name"` } // AlertRuleAnyDataV2 is generated from the Flashduty OpenAPI schema. @@ -1318,7 +1318,7 @@ type AuditLog struct { CreatedAt TimestampMilli `json:"created_at" toon:"created_at"` // ID of the credential (the app key ID) when `credential_type` is `app_key`; 0 otherwise. CredentialID uint64 `json:"credential_id" toon:"credential_id"` - // Credential type used for the call. `app_key` when authenticated with an app key; empty string for member sessions. + // Credential type used for the call. `app_key` for a long-lived console app key, `ephemeral_app_key` for a short-lived key issued to AI SRE, and an empty string for member sessions. CredentialType string `json:"credential_type" toon:"credential_type"` // Client IP address of the caller. IP string `json:"ip" toon:"ip"` @@ -2731,8 +2731,20 @@ type DashboardInvestigationTarget struct { DashboardID string `json:"dashboard_id" toon:"dashboard_id"` // Panel ID inside the dashboard; must be a canonical UUIDv7. Optional. TargetID string `json:"target_id,omitempty" toon:"target_id,omitempty"` - // Dashboard variable bindings, keyed by dashboard variable name. - VariableBindings map[string]InvestigationVariableBinding `json:"variable_bindings,omitempty" toon:"variable_bindings,omitempty"` + // Dashboard variable values, keyed by variable name. Values may reference event labels through `{{ }}` templates; defaults to an empty object. + Variables map[string]string `json:"variables" toon:"variables"` +} + +// DashboardQuery is generated from the Flashduty OpenAPI schema. +type DashboardQuery struct { + // Named query arguments; defaults to an empty object. Values are passed through verbatim and must not contain `{{ }}` templates. + Args map[string]string `json:"args" toon:"args"` + // Query expression in the target data source's language. May reference event labels through `{{ }}` templates. + Expr string `json:"expr" toon:"expr"` + // Minimum step, in seconds. Only accepted when `mode` is `range`, and must be greater than zero; omit or pass null to let the server decide. + MinStepSeconds *int64 `json:"min_step_seconds,omitempty" toon:"min_step_seconds,omitempty"` + // Evaluation mode: `instant` evaluates at a single timestamp, `range` evaluates a stepped series, `window` returns raw rows inside a time window. + Mode string `json:"mode" toon:"mode"` } // DataSourceItem is generated from the Flashduty OpenAPI schema. @@ -3776,6 +3788,8 @@ type FeedDetailWorkItemUpdated struct { type FeedItem struct { // Account ID. AccountID int64 `json:"account_id" toon:"account_id"` + // AI SRE session that produced the entry. Omitted when no agent wrote it. + AgentSessionID string `json:"agent_session_id" toon:"agent_session_id"` // Creation timestamp in Unix epoch milliseconds. CreatedAt TimestampMilli `json:"created_at" toon:"created_at"` // Member ID of the creator. 0 for system-generated entries. @@ -3789,6 +3803,8 @@ type FeedItem struct { Type AlertFeedType `json:"type" toon:"type"` // Last update timestamp in Unix epoch milliseconds. UpdatedAt TimestampMilli `json:"updated_at" toon:"updated_at"` + // Surface that wrote the entry on a user's behalf; currently only `ai_sre`. Omitted when a user created the entry directly. + Via string `json:"via" toon:"via"` } // FieldDeleteReference is generated from the Flashduty OpenAPI schema. @@ -4583,16 +4599,20 @@ type InsightTopkAlertByLabelRequest struct { type InvestigationTarget struct { // Configuration for the `dashboard` kind; required when `kind` is `dashboard`. Dashboard DashboardInvestigationTarget `json:"dashboard,omitzero" toon:"dashboard,omitempty"` - // Entry type; currently only `dashboard` is supported. + // Entry kind: `dashboard` opens a dashboard panel, `query` opens an Explore query. It decides whether `dashboard` or `query` must be supplied; supplying the other one is rejected. Kind string `json:"kind" toon:"kind"` + // Configuration for the `query` kind; required when `kind` is `query`, and rejected when `kind` is `dashboard`. + Query QueryInvestigationTarget `json:"query,omitzero" toon:"query,omitempty"` + // Window around the event time, required on every saved entry. A zero-length window is rejected; defaults belong to the editor. + TimeRange InvestigationTimeRange `json:"time_range" toon:"time_range"` } -// InvestigationVariableBinding is generated from the Flashduty OpenAPI schema. -type InvestigationVariableBinding struct { - // Alert event label name; must follow Prometheus label naming rules and must not be a reserved label. - Key string `json:"key" toon:"key"` - // Where the bound value comes from; currently only `event_label` (the alert event's label value) is supported. - Source string `json:"source" toon:"source"` +// InvestigationTimeRange is generated from the Flashduty OpenAPI schema. +type InvestigationTimeRange struct { + // Seconds to look forward from the event time, so behaviour after the event stays visible. + AfterSeconds int64 `json:"after_seconds" toon:"after_seconds"` + // Seconds to look back from the event time. + BeforeSeconds int64 `json:"before_seconds" toon:"before_seconds"` } // InviteMemberItem is generated from the Flashduty OpenAPI schema. @@ -5782,9 +5802,7 @@ type MemberListResponse struct { // MemberNotifyRequest is generated from the Flashduty OpenAPI schema. type MemberNotifyRequest struct { - // Check without sending. When `true`, every check runs and the response returns the exact email in `html`, but nothing is queued and neither the hourly limit nor the per-turn duplicate check is consumed. Defaults to `false`. - DryRun bool `json:"dry_run,omitempty" toon:"dry_run,omitempty"` - // Email body as an HTML fragment (no ``/`
`/`` wrapper needed); recipients receive it as the whole email body. Required, up to 102,400 bytes of raw UTF-8 input (larger messages are clipped by common email clients), and must be non-empty after sanitization. Sanitized server-side: `