NAME

WebService::DataDog::Alert - Interface to Alert functions in DataDog's API.

VERSION

Version 1.0.3

SYNOPSIS

This module allows you interact with the Alert endpoint of the DataDog API.

Per DataDog: "Alerts allow you to watch a particular metric query and receive a notification when the value either exceeds or falls below the pre-defined threshold."

METHODS

retrieve_all()

Retrieve details for all alerts.

my $alert = $datadog->build('Alert');
my $alert_list = $alert->retrieve_all();

Parameters: None

create()

Create new DataDog alert for specified metric query. If successful, returns created alert id.

NOTE: 'silenced' seems to have no effect in create mode, but works fine in update/edit mode.

my $alert = $datadog->build('Alert');
my $alert_id = $alert->create(
	query    => $query,      # Metric query to alert on
	name     => $alert_name, # Optional. default=dynamic, based on query
	message  => $message,    # Optional. default=None
	silenced => $boolean,    # Optional. default=0
);

Example:
my $alert_id = $alert->create(
		query    => "sum(last_1d):sum:system.net.bytes_rcvd{host:host0} > 100",
		name     => "Bytes received on host0",
		message  => "We may need to add web hosts if this is consistently high.",
	);

Parameters:

  • query

    Metric query to alert on.

  • name

    Optional. Name of the alert. Default = dynamic, based on query.

  • message

    Optional. A message to include with notifications for this alert. Email notifications can be sent to specific users by using the same '@username' notation as events.

  • silenced

    Optional. Default = false. Whether the alert should notify by email and in the event stream. An alert with 'silenced' set to True is effectively muted. The alert will continue to detect state changes, but they will only be visible on the alert list page.

retrieve()

Retrieve details for specified alert. NOTE: a 404 response typically indicates you specified an incorrect alert id.

my $alert = $datadog->build('Alert');
my $alert_data = $alert->retrieve( id => $alert_id );

Parameters:

  • id

    Id of alert you want to retrieve the details for.

update()

Update existing DataDog alert for specified alert id. NOTE: a 404 response typically indicates you specified an incorrect alert id.

my $alert = $datadog->build('Alert');
$alert->update(
	id       => $alert_id,   # ID of alert to modify
	query    => $query,      # Metric query to alert on
	name     => $alert_name, # Optional.
	message  => $message,    # Optional.
	silenced => $boolean,    # Optional.
);

Example:
# Change name of existing alert
$alert->update(
	id    => $alert_id,
	name  => "Bytes received on host0",
);

Parameters:

  • id

    ID of alert you want to modify.

  • query

    Metric query to alert on.

  • name

    Optional. Name of the alert.

  • message

    Optional. A message to include with notifications for this alert. Email notifications can be sent to specific users by using the same '@username' notation as events.

  • silenced

    Optional.Whether the alert should notify by email and in the event stream. An alert with 'silenced' set to True is effectively muted. The alert will continue to detect state changes, but they will only be visible on the alert list page.

mute_all()

Mute all alerts. "Muting will prevent all alerts from notifying through email and posts to the event stream. State changes will only be visible by checking the alert page."

my $alert = $datadog->build('Alert');
$alert->mute_all();

Parameters: None

unmute_all()

Unmute all alerts.

my $alert = $datadog->build('Alert');
$alert->unmute_all();

Parameters: None

delete()

Delete specified alert.

my $alert = $datadog->build('Alert');
$alert->delete( id => $alert_id );

Parameters:

  • id

    Dashboard id you want to delete.

INTERNAL FUNCTIONS

_error_checks()

Common error checking for creating/updating alerts.