mirror of
https://github.com/9technologygroup/patchmon.net.git
synced 2025-11-12 18:06:39 +00:00
fix: manual host creation and improve host identification
- Add machine_id support for manual host creation from GUI
- Generate temporary 'pending-{uuid}' machine_id for new hosts
- Agent now collects and sends machine_id on every update
- Backend replaces pending machine_id with real one on first agent connection
- Remove unnecessary duplicate name check (friendly_name can be duplicated)
- Add get_machine_id() function to agent (reads from /etc/machine-id, /var/lib/dbus/machine-id, or generates fallback)
- Display IP address in Network tab on host details page
- Fix network tab visibility conditions to include host.ip
This ensures proper host identification using machine_id while maintaining backwards compatibility with API credentials as the primary authentication method.
This commit is contained in:
@@ -172,15 +172,6 @@ router.post(
|
||||
// Generate unique API credentials for this host
|
||||
const { apiId, apiKey } = generateApiCredentials();
|
||||
|
||||
// Check if host already exists
|
||||
const existingHost = await prisma.hosts.findUnique({
|
||||
where: { friendly_name: friendly_name },
|
||||
});
|
||||
|
||||
if (existingHost) {
|
||||
return res.status(409).json({ error: "Host already exists" });
|
||||
}
|
||||
|
||||
// If hostGroupId is provided, verify the group exists
|
||||
if (hostGroupId) {
|
||||
const hostGroup = await prisma.host_groups.findUnique({
|
||||
@@ -196,6 +187,7 @@ router.post(
|
||||
const host = await prisma.hosts.create({
|
||||
data: {
|
||||
id: uuidv4(),
|
||||
machine_id: `pending-${uuidv4()}`, // Temporary placeholder until agent connects with real machine_id
|
||||
friendly_name: friendly_name,
|
||||
os_type: "unknown", // Will be updated when agent connects
|
||||
os_version: "unknown", // Will be updated when agent connects
|
||||
@@ -321,6 +313,10 @@ router.post(
|
||||
.optional()
|
||||
.isArray()
|
||||
.withMessage("Load average must be an array"),
|
||||
body("machineId")
|
||||
.optional()
|
||||
.isString()
|
||||
.withMessage("Machine ID must be a string"),
|
||||
],
|
||||
async (req, res) => {
|
||||
try {
|
||||
@@ -338,6 +334,11 @@ router.post(
|
||||
updated_at: new Date(),
|
||||
};
|
||||
|
||||
// Update machine_id if provided and current one is a placeholder
|
||||
if (req.body.machineId && host.machine_id.startsWith("pending-")) {
|
||||
updateData.machine_id = req.body.machineId;
|
||||
}
|
||||
|
||||
// Basic system info
|
||||
if (req.body.osType) updateData.os_type = req.body.osType;
|
||||
if (req.body.osVersion) updateData.os_version = req.body.osVersion;
|
||||
|
||||
Reference in New Issue
Block a user