feat: add domain models and EF Core DbContext with jsonb support
This commit is contained in:
22
Backend/src/NexusRMM.Core/Models/Agent.cs
Normal file
22
Backend/src/NexusRMM.Core/Models/Agent.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
namespace NexusRMM.Core.Models;
|
||||
|
||||
public class Agent
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public string Hostname { get; set; } = string.Empty;
|
||||
public OsType OsType { get; set; }
|
||||
public string OsVersion { get; set; } = string.Empty;
|
||||
public string IpAddress { get; set; } = string.Empty;
|
||||
public string MacAddress { get; set; } = string.Empty;
|
||||
public string AgentVersion { get; set; } = string.Empty;
|
||||
public AgentStatus Status { get; set; } = AgentStatus.Pending;
|
||||
public List<string> Tags { get; set; } = [];
|
||||
public DateTime LastSeen { get; set; }
|
||||
public DateTime EnrolledAt { get; set; }
|
||||
public string? MeshAgentId { get; set; }
|
||||
|
||||
public ICollection<AgentMetric> Metrics { get; set; } = [];
|
||||
public ICollection<TaskItem> Tasks { get; set; } = [];
|
||||
public ICollection<Ticket> Tickets { get; set; } = [];
|
||||
public ICollection<Alert> Alerts { get; set; } = [];
|
||||
}
|
||||
13
Backend/src/NexusRMM.Core/Models/AgentMetric.cs
Normal file
13
Backend/src/NexusRMM.Core/Models/AgentMetric.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System.Text.Json;
|
||||
|
||||
namespace NexusRMM.Core.Models;
|
||||
|
||||
public class AgentMetric
|
||||
{
|
||||
public long Id { get; set; }
|
||||
public Guid AgentId { get; set; }
|
||||
public DateTime Timestamp { get; set; }
|
||||
public JsonElement Metrics { get; set; }
|
||||
|
||||
public Agent Agent { get; set; } = null!;
|
||||
}
|
||||
15
Backend/src/NexusRMM.Core/Models/Alert.cs
Normal file
15
Backend/src/NexusRMM.Core/Models/Alert.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
namespace NexusRMM.Core.Models;
|
||||
|
||||
public class Alert
|
||||
{
|
||||
public long Id { get; set; }
|
||||
public int RuleId { get; set; }
|
||||
public Guid AgentId { get; set; }
|
||||
public string Message { get; set; } = string.Empty;
|
||||
public AlertSeverity Severity { get; set; }
|
||||
public bool Acknowledged { get; set; }
|
||||
public DateTime CreatedAt { get; set; }
|
||||
|
||||
public AlertRule Rule { get; set; } = null!;
|
||||
public Agent Agent { get; set; } = null!;
|
||||
}
|
||||
14
Backend/src/NexusRMM.Core/Models/AlertRule.cs
Normal file
14
Backend/src/NexusRMM.Core/Models/AlertRule.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
namespace NexusRMM.Core.Models;
|
||||
|
||||
public class AlertRule
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string MetricPath { get; set; } = string.Empty;
|
||||
public string Operator { get; set; } = ">";
|
||||
public double Threshold { get; set; }
|
||||
public AlertSeverity Severity { get; set; }
|
||||
public bool Enabled { get; set; } = true;
|
||||
|
||||
public ICollection<Alert> Alerts { get; set; } = [];
|
||||
}
|
||||
9
Backend/src/NexusRMM.Core/Models/Enums.cs
Normal file
9
Backend/src/NexusRMM.Core/Models/Enums.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace NexusRMM.Core.Models;
|
||||
|
||||
public enum AgentStatus { Online, Offline, Degraded, Pending }
|
||||
public enum OsType { Windows, Linux }
|
||||
public enum TaskStatus { Pending, InProgress, Completed, Failed, Cancelled }
|
||||
public enum TaskType { Shell, InstallSoftware, UninstallSoftware, UpdateAgent, NetworkScan }
|
||||
public enum TicketStatus { Open, InProgress, Resolved, Closed }
|
||||
public enum TicketPriority { Low, Medium, High, Critical }
|
||||
public enum AlertSeverity { Info, Warning, Critical }
|
||||
17
Backend/src/NexusRMM.Core/Models/TaskItem.cs
Normal file
17
Backend/src/NexusRMM.Core/Models/TaskItem.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System.Text.Json;
|
||||
|
||||
namespace NexusRMM.Core.Models;
|
||||
|
||||
public class TaskItem
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public Guid AgentId { get; set; }
|
||||
public TaskType Type { get; set; }
|
||||
public JsonElement? Payload { get; set; }
|
||||
public TaskStatus Status { get; set; } = TaskStatus.Pending;
|
||||
public JsonElement? Result { get; set; }
|
||||
public DateTime CreatedAt { get; set; }
|
||||
public DateTime? CompletedAt { get; set; }
|
||||
|
||||
public Agent Agent { get; set; } = null!;
|
||||
}
|
||||
15
Backend/src/NexusRMM.Core/Models/Ticket.cs
Normal file
15
Backend/src/NexusRMM.Core/Models/Ticket.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
namespace NexusRMM.Core.Models;
|
||||
|
||||
public class Ticket
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Title { get; set; } = string.Empty;
|
||||
public string Description { get; set; } = string.Empty;
|
||||
public TicketStatus Status { get; set; } = TicketStatus.Open;
|
||||
public TicketPriority Priority { get; set; } = TicketPriority.Medium;
|
||||
public Guid? AgentId { get; set; }
|
||||
public DateTime CreatedAt { get; set; }
|
||||
public DateTime UpdatedAt { get; set; }
|
||||
|
||||
public Agent? Agent { get; set; }
|
||||
}
|
||||
62
Backend/src/NexusRMM.Infrastructure/Data/RmmDbContext.cs
Normal file
62
Backend/src/NexusRMM.Infrastructure/Data/RmmDbContext.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using NexusRMM.Core.Models;
|
||||
|
||||
namespace NexusRMM.Infrastructure.Data;
|
||||
|
||||
public class RmmDbContext : DbContext
|
||||
{
|
||||
public RmmDbContext(DbContextOptions<RmmDbContext> options) : base(options) { }
|
||||
|
||||
public DbSet<Agent> Agents => Set<Agent>();
|
||||
public DbSet<AgentMetric> AgentMetrics => Set<AgentMetric>();
|
||||
public DbSet<TaskItem> Tasks => Set<TaskItem>();
|
||||
public DbSet<Ticket> Tickets => Set<Ticket>();
|
||||
public DbSet<AlertRule> AlertRules => Set<AlertRule>();
|
||||
public DbSet<Alert> Alerts => Set<Alert>();
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<Agent>(e =>
|
||||
{
|
||||
e.HasKey(a => a.Id);
|
||||
e.Property(a => a.Tags).HasColumnType("jsonb");
|
||||
e.HasIndex(a => a.Hostname);
|
||||
e.HasIndex(a => a.MacAddress);
|
||||
});
|
||||
|
||||
modelBuilder.Entity<AgentMetric>(e =>
|
||||
{
|
||||
e.HasKey(m => m.Id);
|
||||
e.Property(m => m.Metrics).HasColumnType("jsonb");
|
||||
e.HasIndex(m => m.Timestamp);
|
||||
e.HasOne(m => m.Agent).WithMany(a => a.Metrics).HasForeignKey(m => m.AgentId);
|
||||
});
|
||||
|
||||
modelBuilder.Entity<TaskItem>(e =>
|
||||
{
|
||||
e.HasKey(t => t.Id);
|
||||
e.Property(t => t.Payload).HasColumnType("jsonb");
|
||||
e.Property(t => t.Result).HasColumnType("jsonb");
|
||||
e.HasOne(t => t.Agent).WithMany(a => a.Tasks).HasForeignKey(t => t.AgentId);
|
||||
});
|
||||
|
||||
modelBuilder.Entity<Ticket>(e =>
|
||||
{
|
||||
e.HasKey(t => t.Id);
|
||||
e.HasOne(t => t.Agent).WithMany(a => a.Tickets).HasForeignKey(t => t.AgentId);
|
||||
});
|
||||
|
||||
modelBuilder.Entity<AlertRule>(e =>
|
||||
{
|
||||
e.HasKey(r => r.Id);
|
||||
});
|
||||
|
||||
modelBuilder.Entity<Alert>(e =>
|
||||
{
|
||||
e.HasKey(a => a.Id);
|
||||
e.HasIndex(a => a.CreatedAt);
|
||||
e.HasOne(a => a.Rule).WithMany(r => r.Alerts).HasForeignKey(a => a.RuleId);
|
||||
e.HasOne(a => a.Agent).WithMany(a => a.Alerts).HasForeignKey(a => a.AgentId);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user