Documentation
¶
Overview ¶
Package sentryapi is the typed REST client for the ɳSentry cloud API.
Purpose: One client for both worlds — the hosted SaaS (api.sentry.nself.org)
and a self-hosted / local sentry bundle (NSELF_SENTRY_API_URL).
Contract (v1, consumed by `nself sentry *` and the MCP sentry tools):
Auth: Authorization: Bearer nsk_<key> (API keys issued per tenant, W1)
GET /v1/me → {"tenant_id","email","tier","quotas":{dim:{"used","limit"}}}
GET /v1/monitors → {"monitors":[Monitor]}
POST /v1/monitors → 201 {"monitor":Monitor}
DELETE /v1/monitors/{id} → 204
POST /v1/monitors/{id}/pause|resume → {"monitor":Monitor}
GET /v1/incidents?status=<s> → {"incidents":[Incident]}
POST /v1/incidents/{id}/ack|resolve → {"incident":Incident}
GET /v1/status-pages → {"status_pages":[StatusPage]}
POST /v1/status-pages → 201 {"status_page":StatusPage}
GET /v1/alerts/channels → {"channels":[AlertChannel]}
POST /v1/alerts/channels/{id}/test → {"delivered":bool,"detail":string}
Errors: non-2xx {"error":{"code","message"}}; 401 → ErrUnauthorized,
402/429 → ErrQuotaExceeded (upgrade hint).
Constraints: no cobra imports here; pure HTTP + JSON so MCP and commands share it. SPORT: CLI-PKG-SENTRYAPI-001
Index ¶
- Constants
- Variables
- func DeleteCredentials() error
- func Resolve(flagURL, flagKey string) (apiURL, apiKey string)
- func ValidateKeyFormat(key string) error
- func WriteCredentials(c *Credentials) error
- type Account
- type AlertChannel
- type Client
- func (c *Client) AckIncident(ctx context.Context, id string) (*Incident, error)
- func (c *Client) CreateMonitor(ctx context.Context, req CreateMonitorRequest) (*Monitor, error)
- func (c *Client) CreateStatusPage(ctx context.Context, req CreateStatusPageRequest) (*StatusPage, error)
- func (c *Client) DeleteMonitor(ctx context.Context, id string) error
- func (c *Client) ListAlertChannels(ctx context.Context) ([]AlertChannel, error)
- func (c *Client) ListIncidents(ctx context.Context, status string) ([]Incident, error)
- func (c *Client) ListMonitors(ctx context.Context) ([]Monitor, error)
- func (c *Client) ListStatusPages(ctx context.Context) ([]StatusPage, error)
- func (c *Client) PauseMonitor(ctx context.Context, id string, pause bool) (*Monitor, error)
- func (c *Client) ResolveIncident(ctx context.Context, id string) (*Incident, error)
- func (c *Client) TestAlertChannel(ctx context.Context, id string) (*TestChannelResult, error)
- func (c *Client) WhoAmI(ctx context.Context) (*Account, error)
- type CreateMonitorRequest
- type CreateStatusPageRequest
- type Credentials
- type Incident
- type Monitor
- type QuotaUsage
- type StatusPage
- type TestChannelResult
Constants ¶
const ( EnvAPIURL = "NSELF_SENTRY_API_URL" EnvAPIKey = "NSELF_SENTRY_API_KEY" )
EnvAPIURL / EnvAPIKey are the environment overrides for the client config.
const DefaultAPIURL = "https://api.sentry.nself.org"
DefaultAPIURL is the hosted ɳSentry SaaS API endpoint.
const KeyPrefix = "nsk_"
KeyPrefix is the required prefix for ɳSentry API keys.
Variables ¶
var ErrNotLoggedIn = errors.New("not logged in to ɳSentry — run 'nself sentry login'")
ErrNotLoggedIn is returned when no credentials file exists.
var ErrQuotaExceeded = errors.New("quota exceeded for your tier — upgrade at https://sentry.nself.org/billing")
ErrQuotaExceeded is returned on HTTP 402/429 quota responses.
ErrUnauthorized is returned on HTTP 401 — the caller should suggest `nself sentry login`.
Functions ¶
func DeleteCredentials ¶
func DeleteCredentials() error
DeleteCredentials removes the stored credentials (no-op when absent).
func Resolve ¶
Resolve computes the effective (apiURL, apiKey) using precedence: explicit args (flags) → env vars → credentials file → defaults. A missing key is not an error here — the API returns 401 and the client maps it to ErrUnauthorized with the login hint.
func ValidateKeyFormat ¶
ValidateKeyFormat checks the nsk_ prefix without hitting the network.
func WriteCredentials ¶
func WriteCredentials(c *Credentials) error
WriteCredentials persists credentials at 0600 (dir 0700).
Types ¶
type Account ¶
type Account struct {
TenantID string `json:"tenant_id"`
Email string `json:"email"`
Tier string `json:"tier"` // free | bundle | nself-plus
Quotas map[string]QuotaUsage `json:"quotas"`
}
Account is the response of GET /v1/me — identity, tier, and quota usage.
type AlertChannel ¶
type AlertChannel struct {
ID string `json:"id"`
Kind string `json:"kind"` // email | webhook | slack | telegram
Target string `json:"target"`
Enabled bool `json:"enabled"`
}
AlertChannel is a notification target (email/webhook/slack/telegram).
type Client ¶
Client is a typed REST client for the ɳSentry API.
func (*Client) AckIncident ¶
AckIncident acknowledges an open incident.
func (*Client) CreateMonitor ¶
CreateMonitor creates a monitor and returns the created record.
func (*Client) CreateStatusPage ¶
func (c *Client) CreateStatusPage(ctx context.Context, req CreateStatusPageRequest) (*StatusPage, error)
CreateStatusPage creates a status page.
func (*Client) DeleteMonitor ¶
DeleteMonitor removes a monitor by id.
func (*Client) ListAlertChannels ¶
func (c *Client) ListAlertChannels(ctx context.Context) ([]AlertChannel, error)
ListAlertChannels returns the tenant's alert channels.
func (*Client) ListIncidents ¶
ListIncidents returns incidents, optionally filtered by status (open | acknowledged | resolved; empty = all).
func (*Client) ListMonitors ¶
ListMonitors returns all monitors for the tenant.
func (*Client) ListStatusPages ¶
func (c *Client) ListStatusPages(ctx context.Context) ([]StatusPage, error)
ListStatusPages returns the tenant's status pages.
func (*Client) PauseMonitor ¶
PauseMonitor pauses (paused=true) or resumes (paused=false) a monitor.
func (*Client) ResolveIncident ¶
ResolveIncident resolves an incident.
func (*Client) TestAlertChannel ¶
TestAlertChannel sends a test notification through a channel.
type CreateMonitorRequest ¶
type CreateMonitorRequest struct {
Name string `json:"name"`
URL string `json:"url"`
Kind string `json:"kind"`
IntervalSeconds int `json:"interval_seconds"`
}
CreateMonitorRequest is the body of POST /v1/monitors.
type CreateStatusPageRequest ¶
CreateStatusPageRequest is the body of POST /v1/status-pages.
type Credentials ¶
Credentials is the on-disk shape of ~/.nself/sentry.json.
func ReadCredentials ¶
func ReadCredentials() (*Credentials, error)
ReadCredentials loads the stored credentials, or ErrNotLoggedIn.
type Incident ¶
type Incident struct {
ID string `json:"id"`
MonitorID string `json:"monitor_id"`
Title string `json:"title"`
Status string `json:"status"` // open | acknowledged | resolved
Severity string `json:"severity"`
StartedAt string `json:"started_at"`
AcknowledgedAt string `json:"acknowledged_at,omitempty"`
ResolvedAt string `json:"resolved_at,omitempty"`
}
Incident is a monitoring incident (open → acknowledged → resolved).
type Monitor ¶
type Monitor struct {
ID string `json:"id"`
Name string `json:"name"`
URL string `json:"url"`
Kind string `json:"kind"` // http | tcp | ping
IntervalSeconds int `json:"interval_seconds"`
Status string `json:"status"` // up | down | paused | pending
Paused bool `json:"paused"`
CreatedAt string `json:"created_at"`
}
Monitor is an uptime monitor owned by the authenticated tenant.
type QuotaUsage ¶
QuotaUsage is used/limit for a single quota dimension.
type StatusPage ¶
type StatusPage struct {
ID string `json:"id"`
Name string `json:"name"`
Slug string `json:"slug"`
URL string `json:"url"`
Public bool `json:"public"`
CreatedAt string `json:"created_at"`
}
StatusPage is a public status page owned by the tenant.
type TestChannelResult ¶
TestChannelResult is the response of POST /v1/alerts/channels/{id}/test.