Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion plugins/signoz/hooks/hooks.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"description": "Auto-allow WebFetch for official SigNoz HTTPS URLs",
"description": "SigNoz plugin hooks: auto-allow WebFetch for official URLs, monitor query generation via Slack",
"hooks": {
"PreToolUse": [
{
Expand All @@ -11,6 +11,17 @@
}
]
}
],
"PostToolUse": [
{
"matcher": "Skill",
"hooks": [
{
"type": "command",
"command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/scripts/post-query-to-slack.js\""
}
]
}
]
}
}
105 changes: 105 additions & 0 deletions plugins/signoz/hooks/scripts/post-query-to-slack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#!/usr/bin/env node

import { request } from "https";

const SKILL_NAME = "signoz-clickhouse-query";

function postToSlack(webhookUrl, message) {
return new Promise((resolve) => {
const url = new URL(webhookUrl);
const body = JSON.stringify(message);

const req = request(
{
hostname: url.hostname,
path: url.pathname,
method: "POST",
headers: {
"Content-Type": "application/json",
"Content-Length": Buffer.byteLength(body),
},
},
() => resolve(),
);

req.on("error", () => resolve());
req.setTimeout(5000, () => {
req.destroy();
resolve();
});

req.write(body);
req.end();
});
}

function extractQuery(toolResponse) {
if (typeof toolResponse === "string") {
return toolResponse;
}

if (toolResponse?.content) {
return typeof toolResponse.content === "string"
? toolResponse.content
: JSON.stringify(toolResponse.content);
}

return JSON.stringify(toolResponse);
}

const chunks = [];

process.stdin.setEncoding("utf8");
process.stdin.on("data", (chunk) => chunks.push(chunk));
process.stdin.on("end", async () => {
const webhookUrl = process.env.SLACK_WEBHOOK_URL;
if (!webhookUrl) {
process.exit(0);
}

try {
const payload = JSON.parse(chunks.join(""));

if (payload?.tool_name !== "Skill") {
process.exit(0);
}

const skillName = payload?.tool_input?.skill;
if (skillName !== SKILL_NAME) {
process.exit(0);
}

const query = extractQuery(payload?.tool_response);
const slackMessage = {
blocks: [
{
type: "header",
text: {
type: "plain_text",
text: "ClickHouse Query Generated",
},
},
{
type: "section",
text: {
type: "mrkdwn",
text: `*Skill:* \`${skillName}\`\n*Session:* \`${payload?.session_id || "unknown"}\``,
},
},
{
type: "section",
text: {
type: "mrkdwn",
text: `*Generated Output:*\n\`\`\`\n${query.slice(0, 2900)}\n\`\`\``,
},
},
],
};

await postToSlack(webhookUrl, slackMessage);
} catch {
// Fail silently — monitoring should never block the workflow.
}

process.exit(0);
});