Ad Widget

Collapse

Help with JavaScript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • WhoASK
    Junior Member
    • May 2024
    • 3

    #1

    Help with JavaScript

    Hi Guys,
    I've got question about JS in zabbix preprocessing. So... I want to read Serial number from Cisco switch. I've got lot of them in my company. So I prepared a template and added a few items, one of them is a serial number. I entered the OID, but it displays everything, not just the SN. Is there anyone who knows how to program in JS and can cut the characters before the STRING and after the serial number?

    I prepared a template and added a few items, one of which is a serial number. I entered the OID, but it displays everything, not just the SN(screenshot 1). Is there anyone who knows how to program in JS and can cut the characters before the STRING and after the serial number? I know I could use the discovery function, but I want the SN to move into the inventory automatically
    Below JS code that does not execute- error "SyntaxError: parse error (line 5)"

    Code:
    function extractValues(inputString) {
    var lines = inputString.split('\n'); //Splitting the input string into lines
    var values = [];
    
    for (var line of lines) {
    //Finding the occurrence index of 'STRING:'
    var stringIndex = line.indexOf('STRING:');
    
    if (stringIndex !== -1) {
    // Extracting the value after 'STRING:'
    var value = line.substring(stringIndex + 7).trim();
    //Checking if the value starts with 'DN'
    if (value.startsWith('DN')) {
    values.push(value);
    }
    }
    }
    
    return values;
    }
    Thanks for your help​

    Click image for larger version

Name:	image.png
Views:	317
Size:	30.8 KB
ID:	484091Click image for larger version

Name:	image.png
Views:	209
Size:	149.2 KB
ID:	484092


  • markfree
    Senior Member
    • Apr 2019
    • 868

    #2
    The OID "1.3.6.1.2.1.47.1.1.1.1.11" is a vendor-specific serial number string. The Cisco IOS by SNMP template already has an "Entity Serial Numbers discovery" and they are set in the inventory. You could try that.
    Last edited by markfree; 17-05-2024, 23:57.

    Comment

    Working...