:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
from typing import Optional, cast
from products.warehouse_sources.sources.opsgenie._config import OpsgenieSourceConfig
from products.warehouse_sources.sources.opsgenie.opsgenie import (
OpsgenieResumeConfig,
opsgenie_source,
validate_credentials as validate_opsgenie_credentials,
)
from products.warehouse_sources.sources.opsgenie.settings import ENDPOINTS, OPSGENIE_ENDPOINTS
from products.warehouse_sources.sources.sdk import (
CanonicalDescriptions,
DataWarehouseSourceCategory,
ExternalDataSourceType,
FieldType,
ReleaseStatus,
ResumableSource,
ResumableSourceManager,
SourceConfig,
SourceFieldInputConfig,
SourceFieldInputConfigType,
SourceFieldSelectConfig,
SourceFieldSelectConfigOption,
SourceInputs,
SourceRegistry,
SourceResponse,
SourceSchema,
detect,
)
@SourceRegistry.register
class OpsgenieSource(ResumableSource[OpsgenieSourceConfig, OpsgenieResumeConfig]):
codebase_detection = detect(
env=("^OPSGENIE_",),
npm=("opsgenie-sdk",),
pypi=("opsgenie-sdk",),
go=("github.com/opsgenie/opsgenie-go-sdk-v2", "github.com/opsgenie/opsgenie-lamp"),
maven=("com.opsgenie.integration:sdk",),
)
lists_tables_without_credentials = True # static endpoint catalog — safe for public docs
@property
def source_type(self) -> ExternalDataSourceType:
return ExternalDataSourceType.OPSGENIE
@property
def get_source_config(self) -> SourceConfig:
return SourceConfig(
name=ExternalDataSourceType.OPSGENIE,
category=DataWarehouseSourceCategory.ENGINEERING___MONITORING,
label="Opsgenie",
caption="""Enter your Opsgenie API key to pull your Opsgenie data into the PostHog Data warehouse.
You can create an API key in Opsgenie under **Settings → API key management**. The key needs **Read** access; the `integrations` table additionally requires **Configuration access**.
Note that Atlassian has announced Opsgenie's end of support: its APIs are scheduled to shut down on April 5, 2027.""",
iconPath="/static/services/opsgenie.png",
docsUrl="https://posthog.com/docs/cdp/sources/opsgenie",
keywords=["atlassian", "on-call", "alerting"],
fields=cast(
list[FieldType],
[
SourceFieldInputConfig(
name="api_key",
label="API key",
type=SourceFieldInputConfigType.PASSWORD,
required=True,
placeholder="",
secret=True,
),
SourceFieldSelectConfig(
name="region",
label="Region",
required=True,
defaultValue="us",
options=[
SourceFieldSelectConfigOption(label="US (api.opsgenie.com)", value="us"),
SourceFieldSelectConfigOption(label="EU (api.eu.opsgenie.com)", value="eu"),
],
),
],
),
releaseStatus=ReleaseStatus.BETA,
)
def get_canonical_descriptions(self) -> CanonicalDescriptions:
from products.warehouse_sources.sources.opsgenie.canonical_descriptions import CANONICAL_DESCRIPTIONS
return CANONICAL_DESCRIPTIONS
def get_schemas(
self,
config: OpsgenieSourceConfig,
team_id: int,
with_counts: bool = False,
names: list[str] | None = None,
force_refresh: bool = False,
api_version: str | None = None,
) -> list[SourceSchema]:
schemas = [
SourceSchema(
name=endpoint,
supports_incremental=OPSGENIE_ENDPOINTS[endpoint].supports_search_window,
supports_append=False,
incremental_fields=OPSGENIE_ENDPOINTS[endpoint].incremental_fields,
)
for endpoint in ENDPOINTS
]
if names is not None:
names_set = set(names)
schemas = [s for s in schemas if s.name in names_set]
return schemas
def validate_credentials(
self,
config: OpsgenieSourceConfig,
team_id: int,
schema_name: Optional[str] = None,
api_version: str | None = None,
) -> tuple[bool, str | None]:
ok, status, error = validate_opsgenie_credentials(config.api_key, config.region, schema_name)
if ok:
return True, None
# A valid key may legitimately lack access for a specific endpoint (e.g. only
# `integrations` needs Configuration access). Accept 403 at source-create
# (schema_name is None) so users can connect with a key scoped to only the
# resources they want; re-raise it for per-schema checks.
if status == 403 and schema_name is None:
return True, None
return False, error
def get_non_retryable_errors(self) -> dict[str, str | None]:
errors: dict[str, str | None] = {}
for host in ("https://api.opsgenie.com", "https://api.eu.opsgenie.com"):
errors[f"401 Client Error: Unauthorized for url: {host}"] = (
"Your Opsgenie API key is invalid or expired. Please generate a new key and reconnect."
)
errors[f"403 Client Error: Forbidden for url: {host}"] = (
"Your Opsgenie API key does not have the required access. Please check the key's access rights and try again."
)
return errors
def get_resumable_source_manager(self, inputs: SourceInputs) -> ResumableSourceManager[OpsgenieResumeConfig]:
return ResumableSourceManager[OpsgenieResumeConfig](inputs, OpsgenieResumeConfig)
def source_for_pipeline(
self,
config: OpsgenieSourceConfig,
resumable_source_manager: ResumableSourceManager[OpsgenieResumeConfig],
inputs: SourceInputs,
) -> SourceResponse:
return opsgenie_source(
api_key=config.api_key,
region=config.region,
endpoint=inputs.schema_name,
team_id=inputs.team_id,
job_id=inputs.job_id,
resumable_source_manager=resumable_source_manager,
should_use_incremental_field=inputs.should_use_incremental_field,
db_incremental_field_last_value=inputs.db_incremental_field_last_value
if inputs.should_use_incremental_field
else None,
)