Skip to main content

pagerdutyapi

Very basic wrapper for PagerDuty API

Current functionality:

  • create trigger for known service key, with incident key,

  • handle all documented errors,

  • attach context (links, images) to trigger,

  • logging functionality to send alerts to PagerDuty facilities,

  • ability to add logging handler configurable from config dict,

TODO:

  • write tests for the above,

  • write examples on how it is done,

Possible further features:

  • other functionality (not only sending alerts, but also reading/changing other resources),

  • convenience shortcuts for various frameworks,

  • make pagerdutyapi do not have dependencies except six,

Logging configuration

Logging configuration can make use of this module. Sample dict config could look like this:

{
    'version': 1,
    'handlers': {
        'pagerduty': {
            'class': 'pagerdutyapi.handlers.PagerDutyHandler',
            'service_id': 'YOUR_SERVICE_ID',
            'level': 'ERROR',  # process only errors
        },
    },
    'loggers': {
        'pd_logger': {
            'propagate': True,  # call other loggers
            'handlers': ['pagerduty'],
        },
    },
}

And then you could use it like this:

import logging

logger = logging.getLogger('pd_logger')
logger.error(
    'Error level on instance %s above threshold: %s',
    instance_id,
    current_level,
)

where instance_id and current_level are some variables.

By default the incident will be created based on the template message (in this case “Error level on instance %s above threshold: %s”), so it is important to pass variable parts as positional arguments to logging method.

Alternatively you could pass incident_key specifically as part of extra param during logging call:

logger.error(
    'Error level on instance %s above threshold: %s',
    instance_id,
    current_level,
    extra={
        'incident_key': 'THRESHOLD_ALERTS_INSTANCE_{}'.format(instance_id),
    },
)

You can also override incident key during handler configuration:

{
    ...
    'handlers': {
        'pagerduty': {
            'class': 'pagerdutyapi.handlers.PagerDutyHandler',
            'service_id': 'YOUR_SERVICE_ID',
            'incident_key': 'YOUR_INCIDENT_KEY',  # override incident keys
            'level': 'ERROR',  # process only errors
        },
    },
    ...
}

This way, incident keys will be overwritten for all logging calls.

Release files for pagerdutyapi 0.4.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pagerdutyapi 0.4.1
File Size Uploaded Provenance Actions
pagerdutyapi-0.4.1.tar.gz 5.9 kB Without provenance Details for pagerdutyapi-0.4.1.tar.gz

Release files / pagerdutyapi-0.4.1.tar.gz

Download URL pagerdutyapi-0.4.1.tar.gz
Size 5.9 kB
Tags Source
SHA-256 checksum
How to use checksums
17495e0d85a7abd7bdf54eb228216809fe12911498054c67a44f687683e5681e
BLAKE2b-256 checksum
How to use checksums
a9d4b846b2b2ec5597e4fdfa53117f20523058232f658251d7c60aab6fa3970b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for pagerdutyapi 0.4.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page