const { getSNMP } = require('../models/snmpModel');
const cardOids = require('../models/oids/cardOids');
const { host, community } = require('../config/snmpConfig');
const statusMap = {
1: 'inService',
2: 'notInService',
3: 'hwOnline',
4: 'hwOffline',
5: 'configuring',
6: 'configFailed',
7: 'MIB value mismatch',
8: 'deactived',
9: 'faulty',
10: 'invalid',
11: 'noPower'
};
async function getCardInfo(req, res) {
try {
const cardInfo = [];
for (const card of cardOids) {
const data = { slot: card.slot }; // Tambahkan nomor slot
for (const [key, oid] of Object.entries(card)) {
if (key !== 'slot') { // Abaikan kunci slot untuk SNMP query
let value = await getSNMP(host, community, oid);
if (key === 'status' && !isNaN(value)) {
value = statusMap[Number(value)] || 'unknown'; // Ubah status numerik ke teks
}
data[key] = value;
}
}
cardInfo.push(data);
}
res.json(cardInfo);
} catch (error) {
res.status(500).json({ error: error.message });
}
}
module.exports = { getCardInfo };
Comments