mirror of
https://github.com/donavon04/licensetrackerbackend.git
synced 2025-01-18 08:40:57 -07:00
Added a endpoint for zabbix
This commit is contained in:
parent
0956ba1776
commit
720ad56a7a
45
app.js
45
app.js
@ -309,6 +309,51 @@ const getLicenseCounts = async () => {
|
|||||||
return records;
|
return records;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
app.get('/api/zabbix', async (req, res) => {
|
||||||
|
try {
|
||||||
|
const programs = await getZabbixCounts();
|
||||||
|
res.json(programs); // Directly return the reshaped JSON
|
||||||
|
} catch (error) {
|
||||||
|
console.log("[ERROR]: There was an error retrieving licenses. More info: " + error);
|
||||||
|
res.status(500).json({ error: "Internal Server Error" });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const getZabbixCounts = async () => {
|
||||||
|
let n = (pollRate / 1000) + ((pollRate / 1000) * 0.25);
|
||||||
|
let records = {};
|
||||||
|
try {
|
||||||
|
const conn = await pool.getConnection();
|
||||||
|
try {
|
||||||
|
const query = `
|
||||||
|
SELECT ul.program, COUNT(*) as activecount, rl.total,
|
||||||
|
(rl.total - COUNT(*)) as available
|
||||||
|
FROM usedLicenses ul
|
||||||
|
JOIN requestedLicenses rl ON ul.program = rl.name
|
||||||
|
WHERE ul.date >= DATE_SUB(NOW(), INTERVAL ? SECOND)
|
||||||
|
GROUP BY ul.program, rl.total
|
||||||
|
`;
|
||||||
|
const results = await conn.query(query, [n]);
|
||||||
|
|
||||||
|
results.forEach(row => {
|
||||||
|
records[row.program] = {
|
||||||
|
activecount: String(row.activecount),
|
||||||
|
total: String(row.total),
|
||||||
|
available: String(row.available)
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.log("[ERROR]: There was an error reading from the database. More info: " + error);
|
||||||
|
} finally {
|
||||||
|
conn.release();
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log("[ERROR]: There was an error reading from the database. More info: " + error);
|
||||||
|
}
|
||||||
|
return records;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user