VariablesTo further extend the use of Add-ins we have the possibility to use variables. These can be used as read-only values within Add-in scripts. A variable consists of Variables can be created in the Add-in menu by selecting the variables button.
A variable can be set the following places and follows a hierarchy where the last one overrides the previous ones. - global
- network
- location
- device
For this, open the respective Variables view, and add the defined variables. As an example, here you can find the Variables menu on a device.
Defining a Variable TypeA variable is either of type string or can have a custom type. To define a new type click on the Variable Types button.
Next, click on Add new type.
Give the type a name (e.g. Switch), and add a number of selectable variable values, for example: - enabled →
on - disabled →
off
Click on Save to save your variable type.
We also support regular expression for variable types to limit the input for variables. Instead of String selection select Regular expression and use one of the four options offered: Regular expression | description |
---|
IPv4 | Only a valid IP address is allowed for variables with that variable-type. | Subnet mask | Only a valid subnet mask is allowed for variables with that variable-type. | [A-Z a-z]* | Only ASCII characters in the range from A-Z and a-z are allowed for variables with that variable-type | User defined | You are able to create your own regular expression to limit the input. |
Defining a VariableTo define a new variable click on the Variable definition button. Provide a variable name and select the variable type from the drop down list.
Select the default value of the variable from the previously defined selections of the variable type. Select the checkbox Use as password if you want to hide the contents within the UI with asterisks (*** ).
Click on the checkbox to save your variable definition.
Using variablesVariable values can be used using the object context.vars :
exports.main = function (config, context) {
if (context.vars.deviceName) {
context.setScalarByOid("1.2.1" , config.vars.deviceName);
}
};
System variablesSystem variables manage specific aspects of the smart configuration. - All System variables (with the exception of the variable UF_DEFAULT_IF) can be modified in the Project specifications.
- System variables cannot be modified by Add-in scripts (Read-Only).
- System variables are only available for the Network and Device layers.
- System variables can only be used for status queries (the configuration is to be rolled out, if the System variable equals a certain value).
Example for a status query: The following code snippet shows the general approach for a status query. Change the variables “Systemvariable” and “Value” according to your needs. Enter the actual Addin code under the commented line “Code will be executed, if variable is met.”.
exports.main = function (config, context) {
if Systemvariable == ("Value"){
};
};
Available System variables: ValuesWritingTo modify the configuration that is sent to a device you can use config.setScalarByOid :
exports.main = function (config, context) {
config.setScalarByOid("1.2.9.11", "Comment 1");
config.setScalarByOid("1.2.9.12", "Comment 2");
};
Changes made by config.setScalarByOid will be visible in the config preview, as they are applied to the configuration before it is sent to the device.
The same can be achieved by using config.addScriptLine :
exports.main = function (config, context) {
config.addScriptLine('set /Setup/SNMP/Comment-1 "Hello"');
config.addScriptLine('set /Setup/SNMP/Comment-2 "World"');
};
Changes made by config.addScriptLine are NOT visible in the config preview, as they are only run on the device. This method only works on LCOS based devices.
Reading
exports.main = function (config, context) {
var comment1 = config.getScalarByOid("1.2.9.11");
var comment2 = config.getScalarByOid("1.2.9.12");
};
There is no equivalent config.addScriptLine to read data from the device. |