UNPKG

domotz-remote-pawn

Version:

Domotz Agent

87 lines (69 loc) 2.73 kB
/** This file is part of Domotz Agent. * Copyright (C) 2016 Domotz UK LLP * * Domotz Agent is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Domotz Agent is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Domotz Agent. If not, see <http://www.gnu.org/licenses/>. **/ /** * * Created by Massimiliano Cuzzoli <massi@domotz.com> on 06/10/16. * */ const PHYSICAL_INTERFACE_TYPES = [0, 6, 62, 69, 117]; const OID_FOR_INTERFACE_TYPE = '1.3.6.1.2.1.2.2.1.3'; var renderSnmpBasicData = function (resourceLocator, data) { "use strict"; var sortedHashTable = resourceLocator.utils.dataStructure.sortedHashTable; var rendered = data.error ? {error: true, description: sortedHashTable(data.error)} : {error: false}; if (!rendered.error) { rendered['oids'] = sortedHashTable(data.oids); } return rendered; }; var _extractPhysicalInterfaceIndexList = function (ifTypeList) { var physicalInterfaces = []; if (ifTypeList) { for (var ifIndex in ifTypeList) { if (ifTypeList.hasOwnProperty(ifIndex) && PHYSICAL_INTERFACE_TYPES.indexOf(ifTypeList[ifIndex]) > -1) { physicalInterfaces.push(ifIndex); } } } return physicalInterfaces; }; var renderSnmpInterfaceData = function (data) { "use strict"; var renderedData = {oids:{}, timestamp: data.timestamp}; var oidMap = data.oids; var interfacesToSelect = _extractPhysicalInterfaceIndexList(oidMap[OID_FOR_INTERFACE_TYPE]); // We skip snmp data without any valid interface type if (interfacesToSelect.length === 0) { return undefined; } // We allow partially unsupported oids interfacesToSelect.push("error"); for (var oid in oidMap) { if (oidMap.hasOwnProperty(oid)) { renderedData.oids[oid] = {}; for (var itfIndex in oidMap[oid]) { if (oidMap[oid].hasOwnProperty(itfIndex) && interfacesToSelect.indexOf(itfIndex) > -1) { renderedData.oids[oid][itfIndex] = oidMap[oid][itfIndex]; } } } } return renderedData; }; module.exports.renderSnmpBasicData = renderSnmpBasicData; module.exports.renderSnmpInterfaceData = renderSnmpInterfaceData;