Skip to main content

PagerDuty support, mostly reporting alerts

Project description

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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pagerdutyapi-0.4.1.tar.gz (5.9 kB view details)

Uploaded Source

File details

Details for the file pagerdutyapi-0.4.1.tar.gz.

File metadata

  • Download URL: pagerdutyapi-0.4.1.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pagerdutyapi-0.4.1.tar.gz
Algorithm Hash digest
SHA256 17495e0d85a7abd7bdf54eb228216809fe12911498054c67a44f687683e5681e
MD5 9beb4eb7cdda7e0311c47ff45070dd22
BLAKE2b-256 a9d4b846b2b2ec5597e4fdfa53117f20523058232f658251d7c60aab6fa3970b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page