//key is device, value = str let sentValues= {}; function sendError(func, device, weight, str, extra, tb_output, instance, type) { // if ((weight === ERRWEIGHT.DEBUG) && (instance.CONFIG.debug === false)){ // return; // Allow debug messages only if CONFIG.debug is active // } let key = device; if(type != undefined) key = type; if(sentValues.hasOwnProperty(key)) { if(sentValues[key] == str) { return; } } sentValues[key] = str; let content = { "type": weight, "status": "new", "source": { "func":func, "component":instance.id, "component_name":instance.name, "edge":device }, "message":str, "message_data": extra }; let msg = {}; msg[device] = [ { "ts": Date.now(), "values": { "_event":content } } ]; // Msg can be outputted from components only after configuration /*if (canSendErrData()){ sendBufferedErrors(); } else { bufferError(msg); }*/ instance.send(tb_output, msg); // Even if error server is unavailable, send this message to output, for other possible component connections } let ERRWEIGHT = { EMERGENCY: "emergency", // System unusable ALERT: "alert", // Action must be taken immidiately CRITICAL: "critical", // Component unable to function ERROR: "error", // Error, but component able to recover from it WARNING: "warning", // Possibility of error, system running futher NOTICE: "notice", // Significant message but not an error, things user might want to know about INFO: "informational", // Info DEBUG: "debug" // Debug - only if CONFIG.debug is enabled }; module.exports = { sendError, ERRWEIGHT }