Initial commit
This commit is contained in:
124
server/models/AlertRule.js
Normal file
124
server/models/AlertRule.js
Normal file
@@ -0,0 +1,124 @@
|
||||
const { DataTypes } = require('sequelize');
|
||||
|
||||
module.exports = (sequelize) => {
|
||||
const AlertRule = sequelize.define('AlertRule', {
|
||||
id: {
|
||||
type: DataTypes.UUID,
|
||||
defaultValue: DataTypes.UUIDV4,
|
||||
primaryKey: true
|
||||
},
|
||||
user_id: {
|
||||
type: DataTypes.UUID,
|
||||
allowNull: false,
|
||||
references: {
|
||||
model: 'users',
|
||||
key: 'id'
|
||||
}
|
||||
},
|
||||
name: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
comment: 'Human-readable name for the alert rule'
|
||||
},
|
||||
description: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: true,
|
||||
comment: 'Description of what triggers this alert'
|
||||
},
|
||||
is_active: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
defaultValue: true
|
||||
},
|
||||
device_ids: {
|
||||
type: DataTypes.JSON,
|
||||
allowNull: true,
|
||||
comment: 'Array of device IDs to monitor (null = all devices)'
|
||||
},
|
||||
drone_types: {
|
||||
type: DataTypes.JSON,
|
||||
allowNull: true,
|
||||
comment: 'Array of drone types to alert on (null = all types)'
|
||||
},
|
||||
min_rssi: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: true,
|
||||
comment: 'Minimum RSSI threshold for alert'
|
||||
},
|
||||
max_rssi: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: true,
|
||||
comment: 'Maximum RSSI threshold for alert'
|
||||
},
|
||||
frequency_ranges: {
|
||||
type: DataTypes.JSON,
|
||||
allowNull: true,
|
||||
comment: 'Array of frequency ranges to monitor [{min: 20, max: 30}]'
|
||||
},
|
||||
time_window: {
|
||||
type: DataTypes.INTEGER,
|
||||
defaultValue: 300,
|
||||
comment: 'Time window in seconds to group detections'
|
||||
},
|
||||
min_detections: {
|
||||
type: DataTypes.INTEGER,
|
||||
defaultValue: 1,
|
||||
comment: 'Minimum number of detections in time window to trigger alert'
|
||||
},
|
||||
cooldown_period: {
|
||||
type: DataTypes.INTEGER,
|
||||
defaultValue: 600,
|
||||
comment: 'Cooldown period in seconds between alerts for same drone'
|
||||
},
|
||||
alert_channels: {
|
||||
type: DataTypes.JSON,
|
||||
defaultValue: ['sms'],
|
||||
comment: 'Array of alert channels: sms, email, webhook'
|
||||
},
|
||||
webhook_url: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true,
|
||||
comment: 'Webhook URL for custom integrations'
|
||||
},
|
||||
active_hours: {
|
||||
type: DataTypes.JSON,
|
||||
allowNull: true,
|
||||
comment: 'Active hours for alerts {start: "09:00", end: "17:00"}'
|
||||
},
|
||||
active_days: {
|
||||
type: DataTypes.JSON,
|
||||
defaultValue: [1, 2, 3, 4, 5, 6, 7],
|
||||
comment: 'Active days of week (1=Monday, 7=Sunday)'
|
||||
},
|
||||
priority: {
|
||||
type: DataTypes.ENUM('low', 'medium', 'high', 'critical'),
|
||||
defaultValue: 'medium',
|
||||
comment: 'Alert priority level'
|
||||
},
|
||||
created_at: {
|
||||
type: DataTypes.DATE,
|
||||
defaultValue: DataTypes.NOW
|
||||
},
|
||||
updated_at: {
|
||||
type: DataTypes.DATE,
|
||||
defaultValue: DataTypes.NOW
|
||||
}
|
||||
}, {
|
||||
tableName: 'alert_rules',
|
||||
timestamps: true,
|
||||
createdAt: 'created_at',
|
||||
updatedAt: 'updated_at',
|
||||
indexes: [
|
||||
{
|
||||
fields: ['user_id']
|
||||
},
|
||||
{
|
||||
fields: ['is_active']
|
||||
},
|
||||
{
|
||||
fields: ['priority']
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
return AlertRule;
|
||||
};
|
||||
Reference in New Issue
Block a user