domotz-remote-pawn
Version:
Domotz Agent
65 lines (54 loc) • 2.32 kB
JavaScript
/** This file is part of Domotz Agent.
* Copyright (C) 2020 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/>.
*
*
*/
var counter = 1;
var isStartup = true;
var currentNumberOfFastDiscoveryCycle = 1;
var snmpMibDiscovery = function (resourceLocator) {
var logger = resourceLocator.log.decorateLogs();
var numberOfFastDiscoveryCycle;
var nonStartupNumberOfFastDiscoveryCycle = resourceLocator.settingsManager.getMibDiscoveryInterval();
var startupNumberOfFastDiscoveryCycle = resourceLocator.settingsManager.getMibDiscoveryStartupInterval();
if (isStartup) {
numberOfFastDiscoveryCycle = startupNumberOfFastDiscoveryCycle;
} else {
numberOfFastDiscoveryCycle = nonStartupNumberOfFastDiscoveryCycle;
}
currentNumberOfFastDiscoveryCycle = numberOfFastDiscoveryCycle;
logger.info('counter => %s / %s ', counter, numberOfFastDiscoveryCycle);
if (!numberOfFastDiscoveryCycle) {
logger.info('avoiding snmp check discovery by settings value %s ', numberOfFastDiscoveryCycle);
return;
}
if (counter === 0) {
logger.info('Performing SNMP MIB discovery ...');
resourceLocator.discovery.snmp_mib_discovery.discover();
isStartup = false;
}
counter++;
if (counter >= numberOfFastDiscoveryCycle) {
counter = 0;
}
};
var discoveryForcing = function (log) {
var myConsole = log.decorateLogs();
myConsole.info('Forcing Mib Discovery, currentNumberOfFastDiscoveryCycle %s, counter %s', currentNumberOfFastDiscoveryCycle, counter);
counter = currentNumberOfFastDiscoveryCycle - 1;
};
module.exports.handler = snmpMibDiscovery;
module.exports.discoveryForcing = discoveryForcing;