@johnny-joster/n9e-plugin 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,10 @@
2
2
  "permissions": {
3
3
  "allow": [
4
4
  "Bash(npx tsc:*)",
5
- "Bash(npm install)"
5
+ "Bash(npm install)",
6
+ "Bash(export KUBECONFIG=/Users/yaobinze/workarea/youdao/k8s/k8s-prod-maintain1)",
7
+ "Bash(kubectl get:*)",
8
+ "Bash(kubectl logs:*)"
6
9
  ]
7
10
  }
8
11
  }
package/index-full.ts ADDED
@@ -0,0 +1,58 @@
1
+ import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
2
+ import {
3
+ activeAlertsToolInputSchema,
4
+ activeAlertsToolHandler
5
+ } from "./src/tools/active-alerts.ts";
6
+ import {
7
+ historicalAlertsToolInputSchema,
8
+ historicalAlertsToolHandler
9
+ } from "./src/tools/historical-alerts.ts";
10
+ import {
11
+ alertRulesToolInputSchema,
12
+ alertRulesToolHandler
13
+ } from "./src/tools/alert-rules.ts";
14
+ import {
15
+ alertMutesToolInputSchema,
16
+ alertMutesToolHandler
17
+ } from "./src/tools/alert-mutes.ts";
18
+
19
+ export default function(api: OpenClawPluginApi) {
20
+ try {
21
+ // Register tool: Query active alerts
22
+ api.registerTool({
23
+ name: "n9e_query_active_alerts",
24
+ description: "查询夜莺平台当前活跃的告警事件。支持按严重级别(1=严重,2=警告,3=提示)、规则名称筛选。用于回答\"当前有哪些告警\"、\"最近的告警\"、\"有没有严重告警\"等问题。",
25
+ inputSchema: activeAlertsToolInputSchema,
26
+ handler: activeAlertsToolHandler
27
+ });
28
+
29
+ // Register tool: Query historical alerts
30
+ api.registerTool({
31
+ name: "n9e_query_historical_alerts",
32
+ description: "查询夜莺平台历史告警事件。支持按时间范围、严重级别、规则名称筛选。用于回答\"昨天有哪些告警\"、\"过去一周的告警趋势\"、\"历史告警记录\"等问题。",
33
+ inputSchema: historicalAlertsToolInputSchema,
34
+ handler: historicalAlertsToolHandler
35
+ });
36
+
37
+ // Register tool: Query alert rules
38
+ api.registerTool({
39
+ name: "n9e_query_alert_rules",
40
+ description: "查询夜莺平台配置的告警规则。支持按规则名称、数据源、启用状态筛选。用于回答\"有哪些告警规则\"、\"CPU相关的规则配置\"、\"查看内存监控规则\"等问题。",
41
+ inputSchema: alertRulesToolInputSchema,
42
+ handler: alertRulesToolHandler
43
+ });
44
+
45
+ // Register tool: Query alert mutes
46
+ api.registerTool({
47
+ name: "n9e_query_alert_mutes",
48
+ description: "查询夜莺平台告警屏蔽配置。用于回答\"哪些告警被屏蔽了\"、\"查看告警屏蔽规则\"、\"为什么没有收到告警\"等问题。",
49
+ inputSchema: alertMutesToolInputSchema,
50
+ handler: alertMutesToolHandler
51
+ });
52
+
53
+ api.logger.info("N9e plugin loaded successfully");
54
+ } catch (error) {
55
+ api.logger.error("Failed to load N9e plugin:", error);
56
+ throw error;
57
+ }
58
+ }
@@ -0,0 +1,14 @@
1
+ import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
2
+
3
+ export default function(api: OpenClawPluginApi) {
4
+ try {
5
+ api.logger.info("N9e plugin loading...");
6
+
7
+ // 不注册任何工具,只是测试插件能否加载
8
+
9
+ api.logger.info("N9e plugin loaded successfully");
10
+ } catch (error) {
11
+ api.logger.error("Failed to load N9e plugin:", error);
12
+ throw error;
13
+ }
14
+ }
package/index.ts CHANGED
@@ -1,53 +1,14 @@
1
1
  import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
2
- import {
3
- activeAlertsToolInputSchema,
4
- activeAlertsToolHandler
5
- } from "./src/tools/active-alerts.ts";
6
- import {
7
- historicalAlertsToolInputSchema,
8
- historicalAlertsToolHandler
9
- } from "./src/tools/historical-alerts.ts";
10
- import {
11
- alertRulesToolInputSchema,
12
- alertRulesToolHandler
13
- } from "./src/tools/alert-rules.ts";
14
- import {
15
- alertMutesToolInputSchema,
16
- alertMutesToolHandler
17
- } from "./src/tools/alert-mutes.ts";
18
2
 
19
3
  export default function(api: OpenClawPluginApi) {
20
- // Register tool: Query active alerts
21
- api.registerTool({
22
- name: "n9e_query_active_alerts",
23
- description: "查询夜莺平台当前活跃的告警事件。支持按严重级别(1=严重,2=警告,3=提示)、规则名称筛选。用于回答\"当前有哪些告警\"、\"最近的告警\"、\"有没有严重告警\"等问题。",
24
- inputSchema: activeAlertsToolInputSchema,
25
- handler: activeAlertsToolHandler
26
- });
4
+ try {
5
+ api.logger.info("N9e plugin loading...");
27
6
 
28
- // Register tool: Query historical alerts
29
- api.registerTool({
30
- name: "n9e_query_historical_alerts",
31
- description: "查询夜莺平台历史告警事件。支持按时间范围、严重级别、规则名称筛选。用于回答\"昨天有哪些告警\"、\"过去一周的告警趋势\"、\"历史告警记录\"等问题。",
32
- inputSchema: historicalAlertsToolInputSchema,
33
- handler: historicalAlertsToolHandler
34
- });
7
+ // 不注册任何工具,只是测试插件能否加载
35
8
 
36
- // Register tool: Query alert rules
37
- api.registerTool({
38
- name: "n9e_query_alert_rules",
39
- description: "查询夜莺平台配置的告警规则。支持按规则名称、数据源、启用状态筛选。用于回答\"有哪些告警规则\"、\"CPU相关的规则配置\"、\"查看内存监控规则\"等问题。",
40
- inputSchema: alertRulesToolInputSchema,
41
- handler: alertRulesToolHandler
42
- });
43
-
44
- // Register tool: Query alert mutes
45
- api.registerTool({
46
- name: "n9e_query_alert_mutes",
47
- description: "查询夜莺平台告警屏蔽配置。用于回答\"哪些告警被屏蔽了\"、\"查看告警屏蔽规则\"、\"为什么没有收到告警\"等问题。",
48
- inputSchema: alertMutesToolInputSchema,
49
- handler: alertMutesToolHandler
50
- });
51
-
52
- api.logger.info("N9e plugin loaded successfully");
9
+ api.logger.info("N9e plugin loaded successfully");
10
+ } catch (error) {
11
+ api.logger.error("Failed to load N9e plugin:", error);
12
+ throw error;
13
+ }
53
14
  }
@@ -1,6 +1,5 @@
1
1
  {
2
2
  "id": "n9e-plugin",
3
- "skills": ["./skills"],
4
3
  "configSchema": {
5
4
  "type": "object",
6
5
  "properties": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@johnny-joster/n9e-plugin",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Nightingale alert platform query plugin for OpenClaw",
5
5
  "type": "module",
6
6
  "main": "index.ts",
@@ -32,12 +32,12 @@ export const activeAlertsToolInputSchema = {
32
32
  export const activeAlertsToolHandler: ToolHandler = async (input, context) => {
33
33
  try {
34
34
  // Parse and validate config
35
- const rawConfig = context.config.plugins?.entries?.["n9e-plugin"]?.config;
36
- if (!rawConfig) {
35
+ const rawConfig = context?.config?.plugins?.entries?.["n9e-plugin"]?.config;
36
+ if (!rawConfig || !rawConfig.apiBaseUrl || !rawConfig.apiKey) {
37
37
  return {
38
38
  content: [{
39
39
  type: "text",
40
- text: "❌ 插件配置未找到,请在配置文件中添加n9e-plugin配置"
40
+ text: "❌ 插件配置未找到或不完整,请在配置文件中添加 apiBaseUrl 和 apiKey"
41
41
  }],
42
42
  isError: true
43
43
  };
@@ -56,7 +56,12 @@ export const activeAlertsToolHandler: ToolHandler = async (input, context) => {
56
56
 
57
57
  // Format response
58
58
  const alerts = list.map(alert => {
59
- const tags = alert.tags ? JSON.parse(alert.tags) : {};
59
+ let tags = {};
60
+ try {
61
+ tags = alert.tags ? JSON.parse(alert.tags) : {};
62
+ } catch (e) {
63
+ // Ignore JSON parse errors
64
+ }
60
65
  return {
61
66
  id: alert.id,
62
67
  rule_name: alert.rule_name,