Heartbeat¶
The Heartbeat module provides functionality to manage and interact with heartbeat monitors.
Features¶
- Create and manage heartbeat monitors
- Send heartbeat events
- Configure alert settings
- Manage maintenance windows
Examples¶
Basic Usage¶
Create and use a heartbeat monitor
import upassist
# Configure API key
upassist.config.API_KEY = 'your-api-key'
# Create a heartbeat instance
heartbeat = upassist.Heartbeat("my-heartbeat")
# Send a heartbeat event
heartbeat.event()
Advanced Configuration¶
Create a heartbeat with custom settings
from upassist.entities.heartbeat import Heartbeat, HeartbeatCreateSchema
from datetime import time
heartbeat = Heartbeat()
new_heartbeat = heartbeat.create(
HeartbeatCreateSchema(
name="Production Server Monitor",
description="Monitors the production server health",
group_id="prod-servers",
slug="prod-server-monitor",
fetch_interval=300, # Check every 5 minutes
confirmation_period=60, # Wait 1 minute before alerting
realert_period=3600, # Re-alert every hour
alerts_on=True,
maintenance_window_from=time(2, 0), # 02:00
maintenance_window_until=time(3, 0), # 03:00
maintenance_window_timezone="UTC",
alert_week_days=[1, 2, 3, 4, 5] # Monday to Friday
)
)
Managing Heartbeats¶
List, pause, and manage heartbeats
# List all heartbeats
heartbeats = heartbeat.list()
# Get details of a specific heartbeat
details = heartbeat.detail()
# Pause a heartbeat
heartbeat.pause()
# Resume a heartbeat
heartbeat.unpause()
# Delete a heartbeat
heartbeat.delete()
API Reference¶
Heartbeat
¶
Bases: BaseEntity
A class representing a heartbeat monitoring entity.
This class provides functionality to manage and interact with heartbeat monitors, including creating, listing, pausing, and managing heartbeat events.
Source code in upassist/entities/heartbeat/heartbeat.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | |
base_heartbeats_api_url
property
¶
Get the base URL for heartbeat API endpoints.
Returns:
| Type | Description |
|---|---|
str
|
Base URL for heartbeat API endpoints |
__init__(heartbeat_slug=None, api_key=None, api_version=None, api_client_cls=SyncAPIClient)
¶
Initialize a new Heartbeat instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
heartbeat_slug
|
str | None
|
Unique identifier for the heartbeat |
None
|
api_key
|
str | None
|
API key for authentication |
None
|
api_version
|
str | None
|
API version to use |
None
|
api_client_cls
|
type[AbstractAPIClient]
|
Class to use for API client implementation |
SyncAPIClient
|
Source code in upassist/entities/heartbeat/heartbeat.py
create(heartbeat)
¶
Create a new heartbeat.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
heartbeat
|
HeartbeatCreateSchema
|
The heartbeat configuration. |
required |
Returns:
| Type | Description |
|---|---|
HeartbeatSchema
|
HeartbeatSchema containing the created heartbeat information |
Source code in upassist/entities/heartbeat/heartbeat.py
delete()
¶
detail()
¶
Get detailed information about a specific heartbeat.
Returns:
| Type | Description |
|---|---|
HeartbeatDetailSchema
|
HeartbeatDetailSchema containing detailed heartbeat information |
Source code in upassist/entities/heartbeat/heartbeat.py
event()
¶
Get the current event status of the heartbeat.
Returns:
| Type | Description |
|---|---|
DetailResponse
|
DetailResponse containing the event status |
Source code in upassist/entities/heartbeat/heartbeat.py
list(q=None, page=None, per_page=None)
¶
List all heartbeats with optional filtering and pagination.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
q
|
str | None
|
Search query string |
None
|
page
|
int | None
|
Page number for pagination |
None
|
per_page
|
int | None
|
Number of items per page |
None
|
Returns:
| Type | Description |
|---|---|
HeartbeatPaginatedSchema
|
HeartbeatPaginatedSchema containing the list of heartbeats |
Source code in upassist/entities/heartbeat/heartbeat.py
pause()
¶
unpause()
¶
HeartbeatCreateSchema
¶
Bases: BaseModel
Schema for creating a new heartbeat.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Name of the heartbeat |
description |
str | None
|
Optional description of the heartbeat |
group_id |
UUID | None
|
Optional UUID of the group this heartbeat belongs to |
slug |
str | None
|
Optional custom slug for the heartbeat |
fetch_interval |
PositiveInt
|
Interval in seconds between heartbeat checks (60-100000) |
confirmation_period |
NonNegativeInt
|
Time in seconds to wait before confirming an incident (0-100000) |
realert_period |
int | None
|
Optional time in seconds before re-alerting about an incident |
alerts_on |
bool
|
Whether to send alerts on incidents |
paused |
bool
|
Whether the heartbeat is paused |
meta |
dict | None
|
Optional metadata dictionary |
call |
bool
|
Whether to make phone calls for alerts |
send_sms |
bool
|
Whether to send SMS alerts |
send_email |
bool
|
Whether to send email alerts |
send_push_notification |
bool
|
Whether to send push notifications |
maintenance_window_from |
time | None
|
Optional start time for maintenance window |
maintenance_window_until |
time | None
|
Optional end time for maintenance window |
maintenance_window_timezone |
TimeZoneName
|
Timezone for maintenance window times |
alert_week_days |
list[int] | None
|
List of days (0-6) when alerts should be sent |
Source code in upassist/entities/heartbeat/schemas.py
HeartbeatDetailSchema
¶
Bases: HeartbeatSchema
Schema for detailed heartbeat information.
Additional attributes beyond HeartbeatSchema
Source code in upassist/entities/heartbeat/schemas.py
HeartbeatListSchema
¶
Bases: HeartbeatSchema
Schema for heartbeat list items.
Additional attributes beyond HeartbeatSchema
Source code in upassist/entities/heartbeat/schemas.py
HeartbeatPaginatedSchema
¶
Bases: BasePaginatedSchema
Schema for paginated heartbeat list response.
Attributes:
| Name | Type | Description |
|---|---|---|
data |
list[HeartbeatListSchema]
|
List of HeartbeatListSchema items |
Source code in upassist/entities/heartbeat/schemas.py
For more information and to get started with monitoring your applications, visit Upassist Cloud