Scripts are executed by presets.
This preset runs when a CPE is bootstraped (turned on for the very first time, or factory defaulted).
.
This preset here runs when a CPE informs without the 0 BOOTSTRAP event, and is not Disabled, Provisioned and the desired state is Managed. Those tags are added to the CPE by a different preset
.
This provision script queries our subscriber management server to get the desired configuration of a CPE. The ext() func calls an external script (that reside in the genieacs/config/ext dir). External scripts are how you can get data from external services.
log("Set_Config_Mode");
let serialNumber = declare("DeviceID.SerialNumber", {value: 1}).value[0];
let productClass = declare("DeviceID.ProductClass", {value: 1}).value[0];
let oui = declare("DeviceID.OUI", {value: 1}).value[0];
let deviceId = declare("DeviceID.ID", {value: 1}).value[0];
let params = {serial: serialNumber, productClass: productClass, oui: oui, deviceId: deviceId};
//Get the cpe config mode
let cpeConfig = ext('cpe-config', 'getConfig', JSON.stringify(params));
if (cpeConfig && cpeConfig.config) {
log('Set_Config_Mode - Config? ' + cpeConfig.config);
declare("Tags." + cpeConfig.config, null, {value: true});
if (cpeConfig.tags && cpeConfig.tags.toLength > 0) {
for (let [tag] of cpeConfig.tags) {
declare("Tags." + tag.replace(' ', '_'), null, {value: true});
}
}
}