Skip to content

Virtual Parameters

Zaid Abdulla edited this page Jan 18, 2019 · 8 revisions

Virtual parameters are user-defined parameters whose values are generated using custom Javascript code. Virtual parameters behave just like regular parameters and appear in the data model under "VirtualParameters." path. Virtual parameter names cannot contain a period (.).

The execution environment for virtual parameters is almost identical to that of provisions. See provisions for more details and examples. The only differences between the scripts of provisions and virtual parameters are:

  • Virtual parameter scripts don't have the variable args.
  • Virtual parameter scripts have the variables TIMESTAMPS and VALUES. These variables are objects where the key is the attribute name and the value is the declared threshold timestamp, or in the case of VALUES, the value being set.
  • Virtual parameter scripts must return an object containing the attributes of this parameter.
// Example: Unified MAC parameter across different device models
let m = "00:00:00:00:00:00";
let d = declare(
  "Device.WANDevice.*.WANConnectionDevice.*.WANIPConnection.*.MACAddress",
  {value: Date.now()});
let igd = declare(
  "InternetGatewayDevice.WANDevice.*.WANConnectionDevice.*.WANPPPConnection.*.MACAddress",
  {value: Date.now()});

if (d.size) {
  for (let p of d) {
    if (p.value[0]) {
      m = p.value[0];
      break;
    }
  }  
}
else if (igd.size) {
  for (let p of igd) {
    if (p.value[0]) {
      m = p.value[0];
      break;
    }
  }  
}

return {writable: false, value: [m, "xsd:string"]};
// Example: Expose an external value as a virtual parameter
let serial = declare("DeviceID.SerialNumber", {value: 1});
if (values.value) {
  ext("example-ext", "set", serial.value[0], values.value[0]);
  return {writable: true, value: [values.value[0], "xsd:string"]};
}
else {
  let v = ext("example-ext", "get", serial.value[0]);
  return {writable: true, value: [v, "xsd:string"]};
}
// Example: Create an editable virtual parameter for WPA passphrase
let m = "";
if (VALUES && VALUES.value) {
   m = VALUES.value[0];
   declare("Device.WiFi.AccessPoint.1.Security.KeyPassphrase", null, {value: m});
   declare("InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.KeyPassphrase", null, {value: m});
}
else {
   let d = declare("Device.WiFi.AccessPoint.1.Security.KeyPassphrase", {value: Date.now()});
   let igd = declare("InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.KeyPassphrase", {value: Date.now()});

   if (d.size) {
     m = d.value[0];
   }
   else if (igd.size) {
     m = igd.value[0];  
   }
}

return {writable: true, value: [m, "xsd:string"]};

Creating a Virtual Parameter does not automatically add the parameter to the parameter list for a device. To do this, a provisioning script will need to be created to refresh the values. Call this provisioning script "Refresh_VParams"

declare("VirtualParameters.*", {value: Date.now()});

This script tells GenieACS to refresh all VirtualParameters that have a last updated time of less than now. If you change "Date.now()" to 1, then the virtual parameters will only be refreshed 1 time.

To execute the script, create a Preset to execute the "Refresh_VParams" provision.

You can’t perform that action at this time.