Advertisement
niammuddin

card info

Jan 18th, 2025
10
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. const { getSNMP } = require('../models/snmpModel');
  2. const cardOids = require('../models/oids/cardOids');
  3. const { host, community } = require('../config/snmpConfig');
  4.  
  5. const statusMap = {
  6. 1: 'inService',
  7. 2: 'notInService',
  8. 3: 'hwOnline',
  9. 4: 'hwOffline',
  10. 5: 'configuring',
  11. 6: 'configFailed',
  12. 7: 'MIB value mismatch',
  13. 8: 'deactived',
  14. 9: 'faulty',
  15. 10: 'invalid',
  16. 11: 'noPower'
  17. };
  18.  
  19. async function getCardInfo(req, res) {
  20. try {
  21. const cardInfo = [];
  22. for (const card of cardOids) {
  23. const data = { slot: card.slot }; // Tambahkan nomor slot
  24. for (const [key, oid] of Object.entries(card)) {
  25. if (key !== 'slot') { // Abaikan kunci slot untuk SNMP query
  26. let value = await getSNMP(host, community, oid);
  27. if (key === 'status' && !isNaN(value)) {
  28. value = statusMap[Number(value)] || 'unknown'; // Ubah status numerik ke teks
  29. }
  30. data[key] = value;
  31. }
  32. }
  33. cardInfo.push(data);
  34. }
  35. res.json(cardInfo);
  36. } catch (error) {
  37. res.status(500).json({ error: error.message });
  38. }
  39. }
  40.  
  41. module.exports = { getCardInfo };
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement