alarmageddon.publishing package

Submodules

alarmageddon.publishing.emailer module

Support for publishing via e-mail.

Please refer to the [SPHINX DOCUMENTATION] for a detailed usage explanation

class alarmageddon.publishing.emailer.EmailPublisher(config, email_notifications_config_key=None, name='EmailPublisher', defaults=None, priority_threshold=None, connect_timeout_seconds=10)[source]

Bases: alarmageddon.publishing.emailer.SimpleEmailPublisher

A publisher that publishes incidents to e-mail.

For validations to be published by this publisher, they must be enriched with additional data. See :py:func:.emailer.enrich

Parameters:
  • config – A config object containing email config information. See below for a detailed description.
  • email_notifications_config_key – The config key that contains the email configuration.
  • name – The name of the publisher.
  • defaults – Default email templating values.
  • priority_threshold – Will publish validations of this priority or higher if they are appropriately enriched.
  • connect_timeout_seconds – How long to attempt to connect to the SMTP server.

config is an Alarmageddon config object that contains at least the following:

{email_template_directory : Directory containing the e-mail templates.
Can be relative to the location of the alarmageddon script or an absolute directory location,

environment : EMAIL_NOTIFICATIONS

Where EMAIL_NOTIFICATIONS is a dictionary of the form:
“email_notifications” : {
EMAIL_TYPE: {
“email_recipients” : [
{“real_name” : “Some other recipient”,
“address” : “email@address.com“},...

], “email_custom_message” : “Custom email message. Can contain

Jinja replacement tokens.”

},...

}

}

and EMAIL_TYPE is a name that will identify which validations should use that config.

EMAIL_NOTIFICATIONS_CONFIG_KEY = 'email_notifications'
configure_replacement_context(result)[source]

Configures the replacement context for this email publisher

Supported template variables:

{{test_name}} The name of the test.

{{test_description}} The description of the failure.

{{env}} The environment name.

{{email_custom_message}} A custom message used in email alerts. This field can be used to summarize a particular type of alert or include additional details

Runtime Context: All dictionary items contained in runtime context are available.

Parameters:result – The test result whose values will populate the replacement context.
get_email_settings(result)[source]

Returns the email settings of the given result.

get_runtime_context(result)[source]

Returns the runtime context of the given result.

replace_tokens(template, token_dictionary)[source]

Replace templated values with their contents.

Loops multiple times, to handle the case of a template that contains templates.

Templates should be valid Jinja templates:
http://jinja.pocoo.org/
Parameters:
  • template – The template string.
  • token_dictionary – A mapping from template names to values.
send(result)[source]

Constructs a message from a result and send it as an email.

This will only send if the priority threshold is met and the original validation was appropriately enriched.

Parameters:result – The result to publish.
class alarmageddon.publishing.emailer.SilentUndefined(hint=None, obj=missing, name=None, exc=<class 'jinja2.exceptions.UndefinedError'>)[source]

Bases: jinja2.runtime.Undefined

Dont break pageloads because vars arent there!

class alarmageddon.publishing.emailer.SimpleEmailPublisher(sender_address, recipient_addresses, host=None, port=None, name='EmailPublisher', priority_threshold=None, connect_timeout_seconds=10)[source]

Bases: alarmageddon.publishing.publisher.Publisher

A publisher that publishes incidents to e-mail.

Parameters:
  • config – A config object containing email config information. See below for a detailed description.
  • email_notifications_config_key – The config key that contains the email configuration.
  • name – The name of the publisher.
  • defaults – Default email templating values.
  • priority_threshold – Will publish validations of this priority or higher if they are appropriately enriched.
  • connect_timeout_seconds – How long to attempt to connect to the SMTP server.
configure_message(sender_address, recipient_addresses, subject, body)[source]

Creates a MIMEMultipart message with a plain-text body.

Parameters:
  • sender_address – The address the message will be sent from.
  • recipient_addresses – The addresses the message will be sent to.
  • subject – The subject of the email.
  • body – The body of the email.
configure_recipients(recipients)[source]

Properly formats the list of recipient addresses.

Parameters:recipients – A list containing dictionaries of information about the recipients.
configure_sender(sender)[source]

Properly formats the sender address.

Parameters:sender – A dictionary containing information about the sender.
configure_smtp_object(host, port)[source]

Helper method to configure the SMTP object.

send(result)[source]

Constructs a message from a result and send it as an email.

This will only send if the priority threshold is met and the original validation was appropriately enriched.

Parameters:result – The result to publish.
alarmageddon.publishing.emailer.enrich(validation, email_settings, runtime_context=None)[source]

Enriches the validation with a custom email message.

Parameters:
  • validation – The validation object.
  • email_settings – A dictionary object containing settings for email subject, body, sender and recipients. See below for details.
  • runtime_context
    • Additional replacement context settings available

    at runtime. See below for details.

email_settings should be a dictionary of the form:
{
“email_type”: “An environment-specific e-mail type as
defined in the email publisher config”,

“subject”: “The name of the Jinja template for the e-mail subject”,

“body”: “The name of the Jinja template for the e-mail body”,

“sender”: “A dictionary of the form
{“real_name”: “Real Name”, “address”: “email@address.com“}”,
“recipients”: “An iterable of dicionaries of the form
{“real_name”: “Real Name”, “address”: “email@address.com“}”

}

Note that the location of the Jinja templates is defined in the email publisher config.

runtime_context is a dictionary whose values are consumed at runtime inside the Jinja templates defined in email_settings.

alarmageddon.publishing.exceptions module

Exceptions related to publishing TestResults

exception alarmageddon.publishing.exceptions.EnrichmentFailure(publisher, validation, values)[source]

Bases: exceptions.Exception

An exception thrown when the enrichment of a validation fails.

Parameters:
  • publisher – The publisher the validation was enriched for.
  • validation – The validation that failed to be enriched.
  • values – The values that the validation was enriched with.
publisher()[source]

Returns the publisher that the enrichment was for.

validation()[source]

Returns the validation that failed to enrich.

values()[source]

Returns the enrichment values.

exception alarmageddon.publishing.exceptions.PublishFailure(publisher, result)[source]

Bases: exceptions.Exception

An exception thrown when sending a test result to a publisher fails.

Parameters:
  • publisher – The publisher that failed to publish.
  • result – The result that failed to publish.
publisher()[source]

Returns the publisher that could not be published to.

result()[source]

Returns the result that could not be published.

alarmageddon.publishing.graphite module

Support for publishing to Graphite.

class alarmageddon.publishing.graphite.GraphitePublisher(host, port, failed_tests_counter='failed', passed_tests_counter='passed', prefix='alarmageddon', priority_threshold=None)[source]

Bases: alarmageddon.publishing.publisher.Publisher

A Publisher that sends results to Graphite.

Logs the number of successes and failures, and potentially logs how long a validation takes.

Parameters:
  • host – The graphite host.
  • port – The port that graphite is listening on.
  • failed_tests_counter – Name of the graphite counter for failed tests.
  • passed_tests_counter – Name of the graphite coutner for successful tests.
  • prefix – Prefix applied to all graphite fields this publisher will write to.
  • priority_threshold – Will publish validations of this priority or higher.
send(result)[source]

Sends a result to Graphite.

Logs the result as either a success or a failure. Additionally, logs how long the validation took, if a timer_name field is present on the result.

alarmageddon.publishing.hipchat module

Suppport for publishing to HipChat

class alarmageddon.publishing.hipchat.HipChatPublisher(api_end_point, api_token, environment, room_name, priority_threshold=None)[source]

Bases: alarmageddon.publishing.publisher.Publisher

A Publisher that sends results to HipChat.

Publishes all failures to the designated HipChat room. Will publish all results in a single message, collapsings similar errors together to save space.

Parameters:
  • api_end_point – The HipChat API endpoint.
  • api_token – A HipChat API token.
  • environment – The environment that tests are being run in.
  • room_name – The HipChat room to publish results to.
  • priority_threshold – Will publish validations of this priority or higher.
send(result)[source]

sends a result to HipChat if the result is a Failure.

send_batch(results)[source]

Send a batch of results to HipChat.

Collapses similar failures together to save space.

alarmageddon.publishing.http module

A Publisher that publishes to a web application using HTTP

class alarmageddon.publishing.http.HttpPublisher(url=None, success_url=None, failure_url=None, method='POST', headers=None, auth=None, attempts=1, retry_after_seconds=2, timeout_seconds=5, publish_successes=False, expected_status_code=200, name=None, priority_threshold=None)[source]

Bases: alarmageddon.publishing.publisher.Publisher

Creates an HTTP Publisher that publishes successes and/or failures to either one or two HTTP end points.

If you want the same URL to be published to whether or not the the Validation result being published failed or succeeded, please supply only the url parameter and omit the failure_url and success_url parameters.

Conversely, if you want different URLs to be requested based on whether or not the Validation result being published succeeded, please omit the url parameter and supply the success_url and failure_url parameters. The HttpPublisher will use the same method, headers, and authentication parameters when requesting both of those URLs. If that is not acceptable, please override the relevent getter methods.

Parameters:
  • url – The URL that this publisher should publish successful and failed Validation results to.
  • success_url – The URL that this publisher should publish successful Validation results to.
  • failure_url – The URL that this publisher should publish failed Validation results to.
  • method – The HTTP method to use when posting. POST is the default because it is the only HTTP method that allows you to send the results of the published Validation. The GET method is allowed but cannot send the details of the Validation result along with the request.
  • headers – headers to send along with the request
  • auth – if your URLs require authentication you can supply a value like the following: auth=('user', 'pass')
  • attempts – the number of times to try to publish to your URL(s).
  • retry_after_seconds – how many seconds to wait after a failed attempt.
  • timeout_seconds – how long a single attempt can take before it is considered a failed attempt.
  • publish_successes – specify True if you want this HTTP Publisher to publish successful results too. If you provide a success_url, then this HttpPublisher will assume you want to publish successes.
  • expected_status_code – the HTTP status code to expect from your HTTP server if the Validation result was successfully published.
  • name – The name of this publisher.
  • priority_threshold – Will publish validations of this priority or higher.
send(result)[source]

Publish a test result.

Parameters:result – The TestResult of a test.

alarmageddon.publishing.pagerduty module

Support for publishing to PagerDuty.

class alarmageddon.publishing.pagerduty.PagerDutyPublisher(api_end_point, api_key, priority_threshold=None)[source]

Bases: alarmageddon.publishing.publisher.Publisher

A publisher that publishes incidents to PagerDuty.

A unique ID is generated for each failure, built from the failure message. This means that repeated failures for the same test will not cause multiple pages if the original failure has not yet been resolved.

Parameters:
  • api_end_point – The PagerDuty API endpoint.
  • api_token – A PagerDuty API token.
  • priority_threshold – Will publish validations of this priority or higher.
send(result)[source]

Creates an incident in pager duty.

Performs exponential backoff and retry in the case of 403 or 5xx responses.

alarmageddon.publishing.publisher module

The common interface and tools for all Publishers

class alarmageddon.publishing.publisher.Publisher(name=None, priority_threshold=None)[source]

Bases: object

Base class for all test result publishers.

Publishers take test results and publish them to another service.

Parameters:
  • name – The name of this publisher.
  • priority_threshold – Will publish validations of this priority or higher.
name()[source]

Return the name of the publisher.

send(result)[source]

Publish a test result.

Parameters:result – The TestResult of a test.
send_batch(results)[source]

Publish a collection of test results.

Directly called by the Reporter .

Parameters:result – An iterable of TestResult objects.
will_publish(result)[source]

Determine if the publisher will publish the result

To publish a result, the publisher must both be able to publish (_can_publish) and have its priority threshold met (_should_publish).

Parameters:result – The TestResult of a test.

Module contents

This package contains classes that publish test results to different places (e.g. HipChat, PagerDuty, etc.)