Hi All,
I am struggling to set value on “Device.DeviceInfo.ProvisioningCode”, it is a writable parameter.
Whilst playing with external script and provision, i didn’t see any extension error in the log message though after some adjustment in the external file, i did see such error like “no such function getValue in the file”. sometime i do not see faultcode in the log, i have no idea whether or not is working, but running the node script looks to be okay.
Restarted cwmp, fs, nbi services after the external script update.
Channel has faulted; channel=“default” retries=4 faultCode=“ext” faultMessage=“No such function ‘getValue’ in extension ‘get_option82’”
The logic is that the external script connects to the database which returns the ip address and username (please see below node script output). The provision script calls the external script to use the data, if IP == matched with the device IP, SET the username value in “Device.DeviceInfo.ProvisioningCode” when device is rebooted. (reboot : testing purpose)
I actually tried all the examples from the forum, none help at all please.
Runs the presets when the device matches the conditions.
Here is the presets-
Name: Provision
Channel:
Weight:0
Schedule:
Events:1 BOOT
Precondition: DeviceID.ProductClass = "xyz123"
Provision: BootUp
Arguments:
Here is the external script. location path : /opt/genieacs/ext
The script should return the result to the provision script.
"use strict";
const mysql = require('mysql2');
require('dotenv').config()
//const process = require('process');
//create connections
const connection = mysql.createConnection({
host: process.env.MYSQL_HOST,
user: process.env.MYSQL_USER,
password: process.env.MYSQL_PASSWORD,
database: process.env.MYSQL_DATABASE
});
//sql query command
let queryString = "SELECT username, framedipaddress FROM acct ORDER BY acctstarttime DESC Limit 5";
//connect to the database
connection.connect((err) => {
if (err) {
console.error("Error : " + err);
return;
}
console.log("Connected to the database.")
});
function getValue(){
connection.connect((err) => {
if (err) throw new Error("Unexpected Error Code: ", err);
//let queryString = "SELECT username, framedipaddress FROM radacct ORDER BY acctstarttime DESC LIMIT 1";
connection.query(queryString, function(err, result) {
if (err) throw err;
console.log(result);
return result;
//result.forEach(function(value){
// return(value[0]);
//callback(null, result);
//});
});
});
};
//export the query function
//getValue()
exports.getValue = getValue;
//function to execute a query
//function getValue(params, callback){
// connection.query(queryString, (error, results) => {
// if (error) {
// callback(error, mull);
// return;
// }
// let data = JSON.stringify(results);
// const result = JSON.parse(data);
// console.log(result);
// //return(result);
//
// //result.forEach(function(value) {
// console.log(value);
// if (value["username"] == params.ip)
// circuitId = value["framedipaddress"];
// //value = result + 1
// //console.log("This is value: ", value.username);
// //console.log("This is value: ", value.framedipaddress);
// //console.log("This is item value: ", index);
// return callback(null, circuitId);
//
//});
// Readable streams emit 'data' events once a listener is added.
//connection.on('data', function (chunk) {
// data += chunk.toString();
//});
//
//console.log(data);
//respond to the callback
// The 'end' event indicates that the entire body has been received.
//connection.on('end', function(){
// const result = JSON.parse(data.toString());
// //result.forEach((values) => {
// // console.log(values);
// callback(null, result);
// console.log(result);
// //});
// //console.log(result);
//
//});
//data = JSON.stringify(results);
// });
//}
Here is the provision script.
The provision script calls the external script using ext() function. The value does not set. Tried for loop to iterate the information, None, does not look like the value was passed to the provision function please. None seen in the log messages. (Just reboot and getparam messages).
let now = Date.now();
let bootEvent = declare("Events.1_BOOT", {value: 1});
let ipAddress = declare("Device.IP.Interface.1.IPv4Address.1.IPAddress", {value: now}).value[0];
//Query database to retrieve the information.
//let params = {ip:ipAddress}//, username:circuitId}
let getValue = ext("get_option82", "getValue"); // JSON.stringify(params));
//let data = JSON.stringify(getValue);
log(JSON.stringify(getValue));
log("This is the external script value: ", getValue.username, getValue.framedipaddress);
if (!getvalue) {
log('No values returned from the server!.');
return;
}
//setValue(getValue);
//function setValue(getValue){
// if (ipAddress == getValue.framedipaddress){
//let circuitId = getValue.username
// declare("Device.DeviceInfo.ProvisioningCode", {value: now}, {value: getValue.circuitId});
// }
//}
if (getValue.size) {
log(getValue.size);
for (let p of data) {
log(p);
if (ipAddress == p.framedipaddress){
//let username = p.username;
declare("Device.DeviceInfo.ProvisioningCode", {value: now}, {value: p.username});
}
}
}
commit();
log("Successfull");
Here is the node script output:
node get_option82.js
Connected to the database.
[
{
username: 'xyz123',
framedipaddress: '192.168.10.1'
},
{
username: 'xyz456',
framedipaddress: '192.168.10.2'
},
{
username: 'xyz789',
framedipaddress: '192.168.10.3'
},
{
username: 'xyz123456',
framedipaddress: '192.168.10.4'
},
{
username: 'xyz456789',
framedipaddress: '192.168.10.5'
}
]
^C
Can anyone please help?
Thanks.
Kind regards,
Shishir