Hello,
I have a problem with a provision script which calls an EXT script.
The provision script makes a request via an External script with an IMSI.
The remote API does not return information directly, but returns a Token.
This Token is subsequently used to retrieve the information necessary for provisioning the device.
However, the provisioning script runs several times (to detect a stable state? cf. Administration FAQ — GenieACS Documentation 1.2.9 documentation) therefore I obtain a new Token each time
How can I make the script only run once?
Thank you in advance for your help
Laurent
const DEBUG = false;
const now = Date.now();
let provisioned = declare("Tags.Basic_Provisioned", {value: 1});
if (provisioned.value !== undefined) {
DEBUG && log('CPE is (already) provisioned, returning');
return;
}
let device = declare("DeviceID.ID", {value: 1}).value[0];
DEBUG && log('DeviceID: ' + device);
device = encodeURI(device);
DEBUG && log('DeviceID encoded: ' + device);
let ProductClass = declare("DeviceID.ProductClass", {value: 1}).value[0];
let imsi = declare("InternetGatewayDevice.WANDevice.2.X_ATP_WANUMTSInterfaceConfig.IMSI", {value: 1}).value[0];
let token_sdm_info = declare("VirtualParameters.TokenSdmInfo", {value: now}).value[0];
let msisdn = '--';
if(!imsi){ // If imsi is empty => exit
DEBUG && log('No IMSI returned by the CPE, ');
return;
}
let args = {device: device , imsi: imsi };
DEBUG && log('Args ' + JSON.stringify(args));
if(!token_sdm_info){ // If token_sdm_info is empty launch request_sdm_info else query_sdm_info
DEBUG && log('TokenSdmInfo est vide, launch request_sdm_info()');
request_sdm_info(args);
} else{
DEBUG && log('TokenSdmInfo est PRESENT, EXIT');
return;
}
function request_sdm_info(args){ // Demande les infos radius
//Get the params from api
DEBUG && log('Launch ext script fnt request_sdm_info');
let config = ext('cpe-config-new', 'request_sdm_info', JSON.stringify(args));
DEBUG && log('Config values from API: ' + JSON.stringify(config));
if (!config) {
DEBUG && log('No config returned from API');
push_metrics('Basic_Provisioning_request', JSON.stringify({ "msg": "No answer from NEP", "status": "ko" }));
return;
}
if (config.code !== 202) {
DEBUG && log('No config returned from API (' + config.message + ')');
push_metrics('Basic_Provisioning_request', JSON.stringify({ "code": config.code, "msg": config.message, "status": "ko" }));
return;
}
let Token = config.data.token;
DEBUG && log('New Token value ' + Token);
declare("VirtualParameters.TokenSdmInfo", {value: now}, {value: Token}); // Set Token in VirtualParameters.TokenSdmInfo
commit();
DEBUG && log('End Fnt request_sdm_info ');
push_metrics('Basic_Provisioning_request', JSON.stringify({ "code": config.code, "msg": config.message,"token":Token, "status": "ok" }));
return;
}
function push_metrics(event_value, datajson) {
let metrics_data = { "table": 'acs_events', data: { time: Math.floor(now / 1000), "device_id": device, "dept": 0, "idur": '', "event_type": "basic_provisioning", "event_value": event_value, "data": datajson } };
DEBUG && log('Metrics_data ' + JSON.stringify(metrics_data));
let config = ext('push-metrics-tms', 'metrics', JSON.stringify(metrics_data));
DEBUG && log('Callback from API: ' + JSON.stringify(config));
}