Introduction
You can use Slack to monitor for events that happen on the Halon, like when rate limits are exceeded for example.
Setting up the webhook
Begin by registering an incoming webhook as described here.
After doing this, you'll get unique webhook URL that you can then use when posting messages to Slack.
Sending the notifications
Below is an HSL example showing how you can post a message to Slack when a rate limit has been exceeded. Note how it's using a second rate-limit to ensure that no more than one message can be generated per entry and hour.
$limit = 250;
if (rate("per-hour", $senderdomain, $limit, 3600) === false) {
if (rate("per-hour-report", $senderdomain, 1, 3600) === true) {
$data = [
"text" => "Rate limit exceeded",
"attachments" => [[
"title" => "Messages per hour limit exceeded",
"fallback" => "Messages per hour limit exceeded",
"author_name" => gethostname(),
"text" => "$senderdomain has sent more than $limit messages per hour."
]]
];
http("https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX", ["tls_default_ca" => true], [], json_encode($data));
}
Defer("$senderdomain has sent more than $limit messages per hour.");
}
Comments
0 comments
Article is closed for comments.