External script to query MariaDB sometime return an error

HI all,

I’m using 1.2.8 and I have an external script that query MySQL to return specific information about wifi (SSID, password) or voip (sip user, sip password).

The problem, is that it work maybe 1/3 of the times, jugging from trying to summon back the device after every error return, and the 2/3 of the times, it return the following error.

name: Error
message: |-
  Cannot execute new commands: connection closed
  sql: select * from genieacs.voip where serial = ? - parameters:['xxxx12345678']
stack: |-
  Error: Cannot execute new commands: connection closed
  sql: select * from genieacs.voip where serial = ? - parameters:['xxxx12345678']
      at Object.module.exports.createError (/opt/genieacs/ext/node_modules/mariadb/lib/misc/errors.js:61:10)
      at Query.throwNewError (/opt/genieacs/ext/node_modules/mariadb/lib/cmd/command.js:63:16)
      at _addCommandDisabled (/opt/genieacs/ext/node_modules/mariadb/lib/connection.js:1265:9)
      at ConnectionCallback.Connection._queryCallback (/opt/genieacs/ext/node_modules/mariadb/lib/connection.js:579:5)
      at Object.getVoip (/opt/genieacs/ext/voip.js:11:8)

It don’t seems to be a problem related to the DB since, I’ve done a second node script for debug purpose that call the same “external” node script than GACS (voip.js or wifi.js) to pass the search parameter and print the output from the db in objects / values path format. By exemple:

$node test.js xxxx12345678 getVoip
InternetGatewayDevice.Services.VoiceService.1.VoiceProfile.1.Line.1.Enable = Enabled
InternetGatewayDevice.Services.VoiceService.1.VoiceProfile.1.Line.1.SIP.AuthUserName = sipuser1
InternetGatewayDevice.Services.VoiceService.1.VoiceProfile.1.Line.1.SIP.AuthPassword = passw1
InternetGatewayDevice.Services.VoiceService.1.VoiceProfile.1.Line.2.Enable = Enabled
InternetGatewayDevice.Services.VoiceService.1.VoiceProfile.1.Line.2.SIP.AuthUserName = sipuser2
InternetGatewayDevice.Services.VoiceService.1.VoiceProfile.1.Line.2.SIP.AuthPassword = passw2

And, if I use this script back to back several times in a row, no matter how many time, it seems to always work without any issue. I read somewhere that if a connection is already open, I have to wait for it to close but I’m not sure of how to do it in a GACS provisioning script.

Can anybody help ?


So, if I understand well, instead of doing a query to the DB, you write a JSON text file directly on the GACS server and query this text file instead. Right ?

yeah. But that’s my way of doing things. You simply read the file from the extension and pass the content to the provision. Something like this:

const fs = require( 'fs' );

function extension( myargs, callback ){
    var json = JSON.parse( myargs[0] );
    var file = "/data/acs/json/" + json["serialnum"] + ".json";
    fs.readFile( file, 'utf8', function( err, data ){
        if( err !== null ){
            console.log( "read file !" + err );
            return callback( null, err );
        return callback( null, data );
    } );

1 Like

free sample:

root@acs3:/data/acs/json# cat 4857544388C33DA6.json
    "InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.SSID": "37Sur.com-sample",
    "InternetGatewayDevice.LANDevice.1.WLANConfiguration.5.SSID": "37Sur.com-sample-5GHz",
    "InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.PreSharedKey.1.KeyPassphrase": "samplePWD",
    "InternetGatewayDevice.LANDevice.1.WLANConfiguration.5.PreSharedKey.1.KeyPassphrase": "samplePWD"

this way the only thing you need to do is to JSON.parse() the content into a javascript object, then Object.keys() to get the key for each pair of the object.

1 Like