Versionen im Vergleich

Schlüssel

  • Diese Zeile wurde hinzugefügt.
  • Diese Zeile wurde entfernt.
  • Formatierung wurde geändert.
Seiteneigenschaften



Deutsch

Beschreibung:

Dieses Skript zeigt, wie man mit Listen von Werten in Variablen umgeht.

Liste der verwendeten Variablen:

VariableBeschreibung




Add-

In

in Code:

/**
 * @param {Config} config
 * @param {Context} context
 * Do not edit this comment or parameter types. Required for code suggestions
*/
exports.main = function (config, context) {



    //
Function to create VRRP Entry
 Variables
 
  var addVRRPEntry = function (routerID, routerIP, mainPrio, backupPrio, remoteSite, comment) {
        var table1_2_8_21_2 = config.getTableByOid("1.2.8.21.2");
        var table_1_2_8_21_2_row_1 = table1_2_8_21_2.createNewRow();
        table_1_2_8_21_2_row_1.setByOid(1, routerID);
        table_1_2_8_21_2_row_1.setByOid(2, routerIP);
        table_1_2_8_21_2_row_1.setByOid(3, mainPrio);
        table_1_2_8_21_2_row_1.setByOid(4, backupPrio);
        table_1_2_8_21_2_row_1.setByOid(5, remoteSite);
        table_1_2_8_21_2_row_1.setByOid(6, comment);
        table1_2_8_21_2.addOrMerge(table_1_2_8_21_2_row_1);
    };
    // If Statement to only create VRRP Entry, if device has the variable VRRP_Prio
    if (context.vars.VRRP_PRIO != "") {
        config.setScalarByOid("1.2.8.21.1", "1");
        // Function Call to create a new Entry
        addVRRPEntry("1", "10.10.10.254", context.vars.VRRP_PRIO, "0", "INTERNET", "");
    }
};
Addin als JSON-Datei
   // Store lists as comma (,) separated values:
    // REMOTE_SERIALS  = 001,002,003,004,...
    // REMOTE_NAMES = name001,name002,name003,name004,...
    // HINT: no spaces in the above!
    // HINT: make sure both lists have the same length!
    // HINT: both lists need to be ordered, such that each entry at position 'index' corresponds to the other (001 -> name001, ...)

    // split the lists into javascript arrays:
    var serials = context.vars.REMOTE_SERIALS.split(",");
    var names = context.vars.REMOTE_NAMES.split(",");

    // iterate over one list
    serials.forEach(function (serial, index) {

        // Exmaple: Set add a table row for each serial:
        // /Setup/VPN/Certificates-and-Keys/IKE-Keys -> 1.2.19.5.3
        var ikeKeysTable = config.getTableByOid("1.2.19.5.3");
        var ikeKeysTableRow = ikeKeysTable.createNewRow();
        ikeKeysTableRow.setByOids({
            // access the other list via index:
            1: names[index],                // Name            : 16 chars from ABCDEFGHIJKLMNOPQRSTUVWXYZ@{|}~!$%&'()+-,/:;<=>?[\]^_.0123456789
            6: "9",                         // Local-ID-Type   : No-Identity (0), IPv4-Address (1), IPv6-Address (5), Domain-Name (2), Email-Address (3), Distinguished-Name (9), Key-ID (11)
            7: "VPN3",                      // Local-Identity  : 254 chars from #ABCDEFGHIJKLMNOPQRSTUVWXYZ@{|}~!"$%&'()*+-,/:;<=>?[\]^_.0123456789abcdefghijklmnopqrstuvwxyz `
            5: "9",                         // Remote-ID-Type  : No-Identity (0), IPv4-Address (1), IPv6-Address (5), Domain-Name (2), Email-Address (3), Distinguished-Name (9), Key-ID (11)
            2: "serialNumber=" + serial,     // Remote-Identity : 254 chars from #ABCDEFGHIJKLMNOPQRSTUVWXYZ@{|}~!"$%&'()*+-,/:;<=>?[\]^_.0123456789abcdefghijklmnopqrstuvwxyz `
            3: "",                          // Shared-Sec      : 64 chars from #ABCDEFGHIJKLMNOPQRSTUVWXYZ@{|}~!$%&'()*+-,/:;<=>?[\]^_.0123456789abcdefghijklmnopqrstuvwxyz `
            4: ""                           // Shared-Sec-File : 20 chars from ABCDEFGHIJKLMNOPQRSTUVWXYZ@{|}~!$%&'()+-,/:;<=>?[\]^_.0123456789abcdefghijklmnopqrstuvwxyz`
        });
        ikeKeysTable.addOrMerge(ikeKeysTableRow);
    });

};

Add-in als JSON-Datei:

View file
namevariable_as_list.json
height150

 

english
Englisch

Description:

This script shows a way to handle lists of values inside variables.

List of used variables:

VariableDescription




Add-in code:


/**


 *

@param

{Config}

config


 *

@param

{Context}

context


 *

Do

not

edit

this

comment

or

parameter

types.

Required

for

code

suggestions


*/


exports.main

=

function

(config,

context)

{



    // Variables

 
  // Store lists as comma (,) separated values:

 
  
// REMOTE_SERIALS 
 = 001,002,003,004,...

   
// REMOTE_NAMES = name001,name002,name003,name004,...

 
  // HINT: no spaces in the above!

   
// HINT: make sure both lists have the same length!

 
  
// HINT: both lists need to be ordered, such that each entry at position 'index' corresponds to the other (001 -> name001, ...)


 
  
// split the lists into javascript arrays:

 
  var serials = context.vars.REMOTE_SERIALS.split(",");

   
var names = context.vars.REMOTE_NAMES.split(",");


   
// iterate over one list

 
  serials.forEach(function (serial, index) {


     
  // Exmaple: Set add a table row for each serial:

     
  
// /Setup/VPN/Certificates-and-Keys/IKE-Keys -> 1.2.19.5.3

     
  var ikeKeysTable = config.getTableByOid("1.2.19.5.3");

     
  var ikeKeysTableRow = ikeKeysTable.createNewRow();

       
ikeKeysTableRow.setByOids({

       
    // access the other list via index:

           
1: names[index],             
   // Name         
   : 16 chars from ABCDEFGHIJKLMNOPQRSTUVWXYZ@{|}~!$%&'()+-,/:;<=>?[\]^_.0123456789

         
  6: "9",                       
  // Local-ID-Type 
  : No-Identity (0), IPv4-Address (1), IPv6-Address (5), Domain-Name (2), Email-Address (3), Distinguished-Name (9), Key-ID (11)

         
  7: "VPN3",                   
   // Local-Identity 
 : 254 chars from #ABCDEFGHIJKLMNOPQRSTUVWXYZ@{|}~!"$%&'()*+-,/:;<=>?[\]^_.0123456789abcdefghijklmnopqrstuvwxyz `

           
5: "9",                     
    // Remote-ID-Type 
 : No-Identity (0), IPv4-Address (1), IPv6-Address (5), Domain-Name (2), Email-Address (3), Distinguished-Name (9), Key-ID (11)

       
    2: "serialNumber=" + serial,   
  // Remote-Identity : 254 chars from #ABCDEFGHIJKLMNOPQRSTUVWXYZ@{|}~!"$%&'()*+-,/:;<=>?[\]^_.0123456789abcdefghijklmnopqrstuvwxyz `

           
3: "",                       
   // Shared-Sec     
 : 64 chars from #ABCDEFGHIJKLMNOPQRSTUVWXYZ@{|}~!$%&'()*+-,/:;<=>?[\]^_.0123456789abcdefghijklmnopqrstuvwxyz `

       
    4: ""                       
    // Shared-Sec-File : 20 chars from ABCDEFGHIJKLMNOPQRSTUVWXYZ@{|}~!$%&'()+-,/:;<=>?[\]^_.0123456789abcdefghijklmnopqrstuvwxyz`

     
  
});

     
  ikeKeysTable.addOrMerge(ikeKeysTableRow);

 
  });
};


};

Add-in as JSON file:

View file
namevariable_as_list.json
height150