mirror of
https://github.com/9technologygroup/patchmon.net.git
synced 2025-11-21 06:58:20 +00:00
Fixing critical bug on agent version handling causing agents to fill up deisk
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "patchmon-backend",
|
"name": "patchmon-backend",
|
||||||
"version": "1.3.4",
|
"version": "1.3.5",
|
||||||
"description": "Backend API for Linux Patch Monitoring System",
|
"description": "Backend API for Linux Patch Monitoring System",
|
||||||
"license": "AGPL-3.0",
|
"license": "AGPL-3.0",
|
||||||
"main": "src/server.js",
|
"main": "src/server.js",
|
||||||
|
|||||||
@@ -170,32 +170,17 @@ router.get("/agent/version", async (req, res) => {
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// Go agent version check
|
// Go agent version check
|
||||||
// Detect server architecture and map to Go architecture names
|
// Always check the server's local binary for the requested architecture
|
||||||
const os = require("node:os");
|
// The server's agents folder is the source of truth, not GitHub
|
||||||
const { exec } = require("node:child_process");
|
const { exec } = require("node:child_process");
|
||||||
const { promisify } = require("node:util");
|
const { promisify } = require("node:util");
|
||||||
const execAsync = promisify(exec);
|
const execAsync = promisify(exec);
|
||||||
|
|
||||||
const serverArch = os.arch();
|
|
||||||
// Map Node.js architecture to Go architecture names
|
|
||||||
const archMap = {
|
|
||||||
x64: "amd64",
|
|
||||||
ia32: "386",
|
|
||||||
arm64: "arm64",
|
|
||||||
arm: "arm",
|
|
||||||
};
|
|
||||||
const serverGoArch = archMap[serverArch] || serverArch;
|
|
||||||
|
|
||||||
// If requested architecture matches server architecture, execute the binary
|
|
||||||
if (architecture === serverGoArch) {
|
|
||||||
const binaryName = `patchmon-agent-linux-${architecture}`;
|
const binaryName = `patchmon-agent-linux-${architecture}`;
|
||||||
const binaryPath = path.join(__dirname, "../../../agents", binaryName);
|
const binaryPath = path.join(__dirname, "../../../agents", binaryName);
|
||||||
|
|
||||||
if (!fs.existsSync(binaryPath)) {
|
if (fs.existsSync(binaryPath)) {
|
||||||
// Binary doesn't exist, fall back to GitHub
|
// Binary exists in server's agents folder - use its version
|
||||||
console.log(`Binary ${binaryName} not found, falling back to GitHub`);
|
|
||||||
} else {
|
|
||||||
// Execute the binary to get its version
|
|
||||||
try {
|
try {
|
||||||
const { stdout } = await execAsync(`${binaryPath} --help`, {
|
const { stdout } = await execAsync(`${binaryPath} --help`, {
|
||||||
timeout: 10000,
|
timeout: 10000,
|
||||||
@@ -211,8 +196,7 @@ router.get("/agent/version", async (req, res) => {
|
|||||||
const agentVersion = req.query.currentVersion || serverVersion;
|
const agentVersion = req.query.currentVersion || serverVersion;
|
||||||
|
|
||||||
// Proper semantic version comparison: only update if server version is NEWER
|
// Proper semantic version comparison: only update if server version is NEWER
|
||||||
const hasUpdate =
|
const hasUpdate = compareVersions(serverVersion, agentVersion) > 0;
|
||||||
compareVersions(serverVersion, agentVersion) > 0;
|
|
||||||
|
|
||||||
return res.json({
|
return res.json({
|
||||||
currentVersion: agentVersion,
|
currentVersion: agentVersion,
|
||||||
@@ -226,55 +210,25 @@ router.get("/agent/version", async (req, res) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (execError) {
|
} catch (execError) {
|
||||||
// Execution failed, fall back to GitHub
|
// Execution failed, but binary exists - try to get version another way
|
||||||
console.log(
|
console.warn(
|
||||||
`Failed to execute binary ${binaryName}: ${execError.message}, falling back to GitHub`,
|
`Failed to execute binary ${binaryName} to get version: ${execError.message}`,
|
||||||
);
|
);
|
||||||
}
|
// Fall through to error response
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fall back to GitHub if architecture doesn't match or binary execution failed
|
// Binary doesn't exist or couldn't get version - return error
|
||||||
try {
|
// Don't fall back to GitHub - the server's agents folder is the source of truth
|
||||||
const versionInfo = await agentVersionService.getVersionInfo();
|
const agentVersion = req.query.currentVersion || "unknown";
|
||||||
const latestVersion = versionInfo.latestVersion;
|
return res.status(404).json({
|
||||||
const agentVersion =
|
error: `Agent binary not found for architecture: ${architecture}. Please ensure the binary is in the server's agents folder.`,
|
||||||
req.query.currentVersion || latestVersion || "unknown";
|
|
||||||
|
|
||||||
if (!latestVersion) {
|
|
||||||
return res.status(503).json({
|
|
||||||
error: "Unable to determine latest version from GitHub releases",
|
|
||||||
currentVersion: agentVersion,
|
currentVersion: agentVersion,
|
||||||
latestVersion: null,
|
latestVersion: null,
|
||||||
hasUpdate: false,
|
hasUpdate: false,
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Proper semantic version comparison: only update if latest version is NEWER
|
|
||||||
const hasUpdate =
|
|
||||||
latestVersion !== null &&
|
|
||||||
compareVersions(latestVersion, agentVersion) > 0;
|
|
||||||
|
|
||||||
res.json({
|
|
||||||
currentVersion: agentVersion,
|
|
||||||
latestVersion: latestVersion,
|
|
||||||
hasUpdate: hasUpdate,
|
|
||||||
downloadUrl: `/api/v1/hosts/agent/download?arch=${architecture}`,
|
|
||||||
releaseNotes: `PatchMon Agent v${latestVersion}`,
|
|
||||||
minServerVersion: null,
|
|
||||||
architecture: architecture,
|
architecture: architecture,
|
||||||
agentType: "go",
|
agentType: "go",
|
||||||
});
|
});
|
||||||
} catch (serviceError) {
|
|
||||||
console.error(
|
|
||||||
"Failed to get version from agentVersionService:",
|
|
||||||
serviceError.message,
|
|
||||||
);
|
|
||||||
return res.status(500).json({
|
|
||||||
error: "Failed to get agent version from service",
|
|
||||||
details: serviceError.message,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Version check error:", error);
|
console.error("Version check error:", error);
|
||||||
|
|||||||
@@ -6,5 +6,5 @@ VITE_API_URL=http://localhost:3001/api/v1
|
|||||||
|
|
||||||
# Application Metadata
|
# Application Metadata
|
||||||
VITE_APP_NAME=PatchMon
|
VITE_APP_NAME=PatchMon
|
||||||
VITE_APP_VERSION=1.3.4
|
VITE_APP_VERSION=1.3.5
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "patchmon-frontend",
|
"name": "patchmon-frontend",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "1.3.4",
|
"version": "1.3.5",
|
||||||
"license": "AGPL-3.0",
|
"license": "AGPL-3.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "patchmon",
|
"name": "patchmon",
|
||||||
"version": "1.3.4",
|
"version": "1.3.5",
|
||||||
"description": "Linux Patch Monitoring System",
|
"description": "Linux Patch Monitoring System",
|
||||||
"license": "AGPL-3.0",
|
"license": "AGPL-3.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
|
|||||||
Reference in New Issue
Block a user