UNPKG

n8n

Version:

n8n Workflow Automation Tool

115 lines 5.38 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.MessageEventBusDestinationSyslog = exports.isMessageEventBusDestinationSyslogOptions = void 0; const syslog_client_1 = __importDefault(require("syslog-client")); const MessageEventBusDestination_ee_1 = require("./MessageEventBusDestination.ee"); const EventMessageGeneric_1 = require("../EventMessageClasses/EventMessageGeneric"); const typedi_1 = __importDefault(require("typedi")); const Logger_1 = require("../../Logger"); const isMessageEventBusDestinationSyslogOptions = (candidate) => { const o = candidate; if (!o) return false; return o.host !== undefined; }; exports.isMessageEventBusDestinationSyslogOptions = isMessageEventBusDestinationSyslogOptions; class MessageEventBusDestinationSyslog extends MessageEventBusDestination_ee_1.MessageEventBusDestination { constructor(eventBusInstance, options) { var _a, _b, _c, _d, _e, _f, _g, _h, _j; super(eventBusInstance, options); this.__type = (_a = options.__type) !== null && _a !== void 0 ? _a : "$$MessageEventBusDestinationSyslog"; this.label = (_b = options.label) !== null && _b !== void 0 ? _b : 'Syslog Server'; this.host = (_c = options.host) !== null && _c !== void 0 ? _c : 'localhost'; this.port = (_d = options.port) !== null && _d !== void 0 ? _d : 514; this.protocol = (_e = options.protocol) !== null && _e !== void 0 ? _e : 'udp'; this.facility = (_f = options.facility) !== null && _f !== void 0 ? _f : syslog_client_1.default.Facility.Local0; this.app_name = (_g = options.app_name) !== null && _g !== void 0 ? _g : 'n8n'; this.eol = (_h = options.eol) !== null && _h !== void 0 ? _h : '\n'; this.expectedStatusCode = (_j = options.expectedStatusCode) !== null && _j !== void 0 ? _j : 200; this.client = syslog_client_1.default.createClient(this.host, { appName: this.app_name, facility: syslog_client_1.default.Facility.Local0, port: this.port, transport: options.protocol !== undefined && options.protocol === 'tcp' ? syslog_client_1.default.Transport.Tcp : syslog_client_1.default.Transport.Udp, }); this.logger.debug(`MessageEventBusDestinationSyslog with id ${this.getId()} initialized`); this.client.on('error', function (error) { typedi_1.default.get(Logger_1.Logger).error(`${error.message}`); }); } async receiveFromEventBus(emitterPayload) { const { msg, confirmCallback } = emitterPayload; let sendResult = false; if (msg.eventName !== EventMessageGeneric_1.eventMessageGenericDestinationTestEvent) { if (!this.license.isLogStreamingEnabled()) return sendResult; if (!this.hasSubscribedToEvent(msg)) return sendResult; } try { const serializedMessage = msg.serialize(); if (this.anonymizeAuditMessages) { serializedMessage.payload = msg.anonymize(); } delete serializedMessage.__type; this.client.log(JSON.stringify(serializedMessage), { severity: msg.eventName.toLowerCase().endsWith('error') ? syslog_client_1.default.Severity.Error : syslog_client_1.default.Severity.Debug, msgid: msg.id, timestamp: msg.ts.toJSDate(), }, async (error) => { if (error === null || error === void 0 ? void 0 : error.message) { this.logger.debug(error.message); } else { confirmCallback(msg, { id: this.id, name: this.label }); sendResult = true; } }); } catch (error) { if (error.message) this.logger.debug(error.message); } if (msg.eventName === EventMessageGeneric_1.eventMessageGenericDestinationTestEvent) { await new Promise((resolve) => setTimeout(resolve, 500)); } return sendResult; } serialize() { const abstractSerialized = super.serialize(); return { ...abstractSerialized, expectedStatusCode: this.expectedStatusCode, host: this.host, port: this.port, protocol: this.protocol, facility: this.facility, app_name: this.app_name, eol: this.eol, }; } static deserialize(eventBusInstance, data) { if ('__type' in data && data.__type === "$$MessageEventBusDestinationSyslog" && (0, exports.isMessageEventBusDestinationSyslogOptions)(data)) { return new MessageEventBusDestinationSyslog(eventBusInstance, data); } return null; } toString() { return JSON.stringify(this.serialize()); } async close() { await super.close(); this.client.close(); } } exports.MessageEventBusDestinationSyslog = MessageEventBusDestinationSyslog; //# sourceMappingURL=MessageEventBusDestinationSyslog.ee.js.map