domotz-remote-pawn
Version:
Domotz Agent
67 lines (59 loc) • 2.39 kB
JavaScript
/** This file is part of Domotz Agent.
* Copyright (C) 2016 Domotz Ltd
*
* 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 Tommaso Latini <tommaso@domotz.com> on 27/08/15.
*/
module.exports.factory = function(fileUtils, configuration, interfacesBindingStorage) {
function getDeviceToExcludeFilePath(discovery) {
var defaultPath = process.env.DOMOTZ_CONF_DIR + '/devices_to_exclude.conf';
return discovery && discovery.blacklist_file ? discovery.blacklist_file : defaultPath;
}
var filePath = getDeviceToExcludeFilePath(configuration.discovery),
content = fileUtils.readFile(filePath),
blackList = [],
ipList = [];
if (content) {
content.toString('utf8').split('\n').forEach(function contentFilter(e) {
console.silly('DISCOVERY - Processed elem: ' + e);
if (e) {
blackList.push(e.toUpperCase());
}
});
}
if (blackList.length) {
console.info('DISCOVERY - Devices to be excluded from monitoring: %s', blackList.join(', '));
} else {
console.debug('DISCOVERY - No devices in blacklist');
}
return {
getDeviceToExclude: function() {
if (blackList.length !== ipList.length) {
var devicesSnapshot = interfacesBindingStorage.getInterfaceInfo();
for (var i = 0; i < blackList.length; i++) {
var mac = blackList[i];
var ip = devicesSnapshot[mac];
console.silly('DISCOVERY - LookUP of MAC [%s]. Found IP: %s', mac, ip);
if (ip) {
ipList.push(ip);
}
}
}
return ipList;
}
};
};