Server.Slack.Clients.Online
Type: Server event (monitoring)
Sends a Slack notification when clients with a target label appear online.
By default, this artifact searches for all clients that carry the label “Slack”, and if they have appeared online in the last 5 minutes, it sends a message to Slack and removes the label from the client.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
LabelGroup |
string | Slack |
|
SlackToken |
string | The token URL obtained from Slack. Leave blank to use server metadata. e.g. https://hooks.slack.com/services/XXXX/YYYY/ZZZZ |
Source
Defined in artifacts/definitions/Server/Slack/Clients/Online.yaml.
name: Server.Slack.Clients.Online
description: |
Sends a Slack notification when clients with a target label appear
online.
By default, this artifact searches for all clients that carry the
label "Slack", and if they have appeared online in the last 5
minutes, it sends a message to Slack and removes the label from the
client.
type: SERVER_EVENT
parameters:
- name: LabelGroup
default: Slack
- name: SlackToken
description: The token URL obtained from Slack. Leave blank to use server metadata. e.g. https://hooks.slack.com/services/XXXX/YYYY/ZZZZ
sources:
- query: |
LET token_url = if(
condition=SlackToken,
then=SlackToken,
else=server_metadata().SlackToken)
LET hits = SELECT client_id,
os_info.fqdn as Hostname ,
now() - last_seen_at / 1000000 AS LastSeen,
label(client_id=client_id, labels=LabelGroup, op="remove")
FROM clients(search="label:" + LabelGroup)
WHERE LastSeen < 300
LET send_message = SELECT * FROM foreach(row=hits,
query={
SELECT client_id, Hostname, LastSeen, Content, Response
FROM http_client(
data=serialize(item=dict(
text=format(format="Client %v (%v) has appeared online %v seconds ago",
args=[Hostname, client_id, LastSeen])),
format="json"),
headers=dict(`Content-Type`="application/json"),
method="POST",
url=token_url)
})
// Check every minute
SELECT * FROM foreach(
row={SELECT * FROM clock(period=60)},
query=send_message)