feat: implement history push mutation and enhanced MCP logging
- Implement pushHistory mutation to support pushing telemetry data to Zabbix trapper items. - Add VERBOSITY and MCP_LOG_* environment variables for controllable request/response logging in both API and MCP server. - Enhance ZabbixRESTDataSource with better session handling and error logging. - Update ZabbixHistory datasource to support history push operations. - Expand documentation with new cookbook recipes and MCP integration guides. - Add integration tests for history pushing (src/test/history_push*). - Reorganize documentation, moving technical product info PDF to docs/use-cases/. - Update GraphQL generated types and VCR templates.
This commit is contained in:
parent
b646b8c606
commit
7c2dee2b6c
28 changed files with 6036 additions and 3088 deletions
66
src/test/history_push.test.ts
Normal file
66
src/test/history_push.test.ts
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
import {ZabbixHistoryPushParams, ZabbixHistoryPushRequest} from "../datasources/zabbix-history.js";
|
||||
import {zabbixAPI} from "../datasources/zabbix-api.js";
|
||||
import {GraphQLError} from "graphql";
|
||||
|
||||
// Mocking ZabbixAPI
|
||||
jest.mock("../datasources/zabbix-api.js", () => ({
|
||||
zabbixAPI: {
|
||||
post: jest.fn(),
|
||||
}
|
||||
}));
|
||||
|
||||
describe("ZabbixHistoryPushRequest", () => {
|
||||
let request: ZabbixHistoryPushRequest;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
request = new ZabbixHistoryPushRequest("token");
|
||||
});
|
||||
|
||||
test("createZabbixParams - transformation", () => {
|
||||
const values = [
|
||||
{ timestamp: "2024-01-01T10:00:00Z", value: { key: "value" } },
|
||||
{ timestamp: "2024-01-01T10:00:01.500Z", value: "simple value" }
|
||||
];
|
||||
const params = new ZabbixHistoryPushParams(values, "1", "item.key", "host.name");
|
||||
const zabbixParams = request.createZabbixParams(params);
|
||||
|
||||
expect(zabbixParams).toHaveLength(2);
|
||||
expect(zabbixParams[0]).toEqual({
|
||||
itemid: "1",
|
||||
value: JSON.stringify({ key: "value" }),
|
||||
clock: 1704103200,
|
||||
ns: 0
|
||||
});
|
||||
expect(zabbixParams[1]).toEqual({
|
||||
itemid: "1",
|
||||
value: "simple value",
|
||||
clock: 1704103201,
|
||||
ns: 500000000
|
||||
});
|
||||
});
|
||||
|
||||
test("createZabbixParams - transformation without itemid", () => {
|
||||
const values = [
|
||||
{ timestamp: "2024-01-01T10:00:00Z", value: { key: "value" } }
|
||||
];
|
||||
const params = new ZabbixHistoryPushParams(values, undefined, "item.key", "host.name");
|
||||
const zabbixParams = request.createZabbixParams(params);
|
||||
|
||||
expect(zabbixParams).toHaveLength(1);
|
||||
expect(zabbixParams[0]).toEqual({
|
||||
host: "host.name",
|
||||
key: "item.key",
|
||||
value: JSON.stringify({ key: "value" }),
|
||||
clock: 1704103200,
|
||||
ns: 0
|
||||
});
|
||||
});
|
||||
|
||||
test("prepare - throw error if item missing", async () => {
|
||||
const values = [{ timestamp: "2024-01-01T10:00:00Z", value: "val" }];
|
||||
const params = new ZabbixHistoryPushParams(values, undefined, undefined, "host.name");
|
||||
|
||||
await expect(request.prepare(zabbixAPI, params)).rejects.toThrow("if itemid is empty both key and host must be filled");
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue