mirror of
https://github.com/9technologygroup/patchmon.net.git
synced 2025-11-21 06:58:20 +00:00
Docker implementation
Profile fixes Hostgroup fixes TFA fixes
This commit is contained in:
@@ -10,6 +10,7 @@ const {
|
||||
requireManageHosts,
|
||||
requireManageSettings,
|
||||
} = require("../middleware/permissions");
|
||||
const { queueManager, QUEUE_NAMES } = require("../services/automation");
|
||||
|
||||
const router = express.Router();
|
||||
const prisma = getPrismaClient();
|
||||
@@ -1387,6 +1388,66 @@ router.delete(
|
||||
},
|
||||
);
|
||||
|
||||
// Force immediate report from agent
|
||||
router.post(
|
||||
"/:hostId/fetch-report",
|
||||
authenticateToken,
|
||||
requireManageHosts,
|
||||
async (req, res) => {
|
||||
try {
|
||||
const { hostId } = req.params;
|
||||
|
||||
// Get host to verify it exists
|
||||
const host = await prisma.hosts.findUnique({
|
||||
where: { id: hostId },
|
||||
});
|
||||
|
||||
if (!host) {
|
||||
return res.status(404).json({ error: "Host not found" });
|
||||
}
|
||||
|
||||
// Get the agent-commands queue
|
||||
const queue = queueManager.queues[QUEUE_NAMES.AGENT_COMMANDS];
|
||||
|
||||
if (!queue) {
|
||||
return res.status(500).json({
|
||||
error: "Queue not available",
|
||||
});
|
||||
}
|
||||
|
||||
// Add job to queue
|
||||
const job = await queue.add(
|
||||
"report_now",
|
||||
{
|
||||
api_id: host.api_id,
|
||||
type: "report_now",
|
||||
},
|
||||
{
|
||||
attempts: 3,
|
||||
backoff: {
|
||||
type: "exponential",
|
||||
delay: 2000,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
message: "Report fetch queued successfully",
|
||||
jobId: job.id,
|
||||
host: {
|
||||
id: host.id,
|
||||
friendlyName: host.friendly_name,
|
||||
apiId: host.api_id,
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Force fetch report error:", error);
|
||||
res.status(500).json({ error: "Failed to fetch report" });
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
// Toggle agent auto-update setting
|
||||
router.patch(
|
||||
"/:hostId/auto-update",
|
||||
@@ -1448,21 +1509,17 @@ router.post(
|
||||
return res.status(404).json({ error: "Host not found" });
|
||||
}
|
||||
|
||||
// Get queue manager
|
||||
const { QUEUE_NAMES } = require("../services/automation");
|
||||
const queueManager = req.app.locals.queueManager;
|
||||
|
||||
if (!queueManager) {
|
||||
return res.status(500).json({
|
||||
error: "Queue manager not available",
|
||||
});
|
||||
}
|
||||
|
||||
// Get the agent-commands queue
|
||||
const queue = queueManager.queues[QUEUE_NAMES.AGENT_COMMANDS];
|
||||
|
||||
if (!queue) {
|
||||
return res.status(500).json({
|
||||
error: "Queue not available",
|
||||
});
|
||||
}
|
||||
|
||||
// Add job to queue
|
||||
await queue.add(
|
||||
const job = await queue.add(
|
||||
"update_agent",
|
||||
{
|
||||
api_id: host.api_id,
|
||||
@@ -1480,6 +1537,7 @@ router.post(
|
||||
res.json({
|
||||
success: true,
|
||||
message: "Agent update queued successfully",
|
||||
jobId: job.id,
|
||||
host: {
|
||||
id: host.id,
|
||||
friendlyName: host.friendly_name,
|
||||
|
||||
Reference in New Issue
Block a user