index.ts 2.33 KB
import { ActionCategoryComponentEnum } from '../../../enum/category';
import { useCreateNodeKey } from '../../../hook/useCreateNodeKey';
import type { NodeItemConfigType } from '../../../types/node';
import { RuleNodeTypeEnum } from '../../index.type';

const keys = useCreateNodeKey(ActionCategoryComponentEnum.CREATE_ALARM);

export interface CreateAlarmDataType {
  someConfiguration?: Recordable;
}

export const CreateAlarmConfig: NodeItemConfigType = {
  ...keys,
  clazz: 'org.thingsboard.rule.engine.action.TbCreateAlarmNode',
  categoryType: RuleNodeTypeEnum.ACTION,
  name: 'create alarm',
  configurationDescriptor: {
    nodeDefinition: {
      details:
        "Details - JS function that creates JSON object based on incoming message. This object will be added into Alarm.details field.\nNode output:\nIf alarm was not created, original message is returned. Otherwise new Message returned with type 'ALARM', Alarm object in 'msg' property and 'metadata' will contains one of those properties 'isNewAlarm/isExistingAlarm'. Message payload can be accessed via <code>msg</code> property. For example <code>'temperature = ' + msg.temperature ;</code>. Message metadata can be accessed via <code>metadata</code> property. For example <code>'name = ' + metadata.customerName;</code>.",
      description: 'Create or Update Alarm',
      inEnabled: true,
      outEnabled: true,
      relationTypes: ['Created', 'Updated', 'False', 'Failure'],
      customRelations: false,
      ruleChainNode: false,
      defaultConfiguration: {
        alarmType: 'General Alarm',
        alarmDetailsBuildJs:
          'var details = {};\nif (metadata.prevAlarmDetails) {\n    details = JSON.parse(metadata.prevAlarmDetails);\n    //remove prevAlarmDetails from metadata\n    delete metadata.prevAlarmDetails;\n    //now metadata is the same as it comes IN this rule node\n}\n\n\nreturn details;',
        severity: 'CRITICAL',
        propagate: false,
        propagateToOwner: false,
        propagateToTenant: false,
        useMessageAlarmData: false,
        overwriteAlarmDetails: false,
        dynamicSeverity: false,
        relationTypes: [],
      },
      uiResources: ['static/rulenode/rulenode-core-config.js'],
      configDirective: 'tbActionNodeCreateAlarmConfig',
      icon: 'material-symbols:notifications-active-sharp',
      iconUrl: '',
      docUrl: '',
    },
  },
};