Ad Widget

Collapse

Help with external LLD

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bbs2web
    Junior Member
    • Apr 2016
    • 22

    #1

    Help with external LLD

    I have a switch which includes it's firmware version in the 'ifDescr' output. The 'ifName' output references the SNMP OID index so I wanted to write an external LLD script to reformat the returned 'ifDescr' values.

    Code:
    [root@zabbix ~]# snmpwalk -v3 -l AuthPriv -u <context> -a SHA -A <secret1> -x DES -X <secret2> <switchip>:161 -O fn IF-MIB::ifDescr | head
    .1.3.6.1.2.1.2.2.1.2.1 = STRING: D-Link DGS-3120-24SC R4.00.015 Port 1 on Unit 1
    .1.3.6.1.2.1.2.2.1.2.2 = STRING: D-Link DGS-3120-24SC R4.00.015 Port 2 on Unit 1
    .1.3.6.1.2.1.2.2.1.2.3 = STRING: D-Link DGS-3120-24SC R4.00.015 Port 3 on Unit 1
    .1.3.6.1.2.1.2.2.1.2.4 = STRING: D-Link DGS-3120-24SC R4.00.015 Port 4 on Unit 1
    .1.3.6.1.2.1.2.2.1.2.5 = STRING: D-Link DGS-3120-24SC R4.00.015 Port 5 on Unit 1
    .1.3.6.1.2.1.2.2.1.2.6 = STRING: D-Link DGS-3120-24SC R4.00.015 Port 6 on Unit 1
    .1.3.6.1.2.1.2.2.1.2.7 = STRING: D-Link DGS-3120-24SC R4.00.015 Port 7 on Unit 1
    .1.3.6.1.2.1.2.2.1.2.8 = STRING: D-Link DGS-3120-24SC R4.00.015 Port 8 on Unit 1
    .1.3.6.1.2.1.2.2.1.2.9 = STRING: D-Link DGS-3120-24SC R4.00.015 Port 9 on Unit 1
    .1.3.6.1.2.1.2.2.1.2.10 = STRING: D-Link DGS-3120-24SC R4.00.015 Port 10 on Unit 1
    Output when I run my external SNMP LLD script manually (reformats the long interface description to eg 1:1):
    Code:
    [root@zabbix externalscripts]# ./snmpwalk_dgs3120.sh <context> <secret1> <secret2> <switchip> IF-MIB::ifDescr
    {
            "data": [
                    { "{#SNMPINDEX}": "1",  "{#SNMPVALUE}": "1:1" },
                    { "{#SNMPINDEX}": "2",  "{#SNMPVALUE}": "1:2" },
                    { "{#SNMPINDEX}": "3",  "{#SNMPVALUE}": "1:3" },
                    { "{#SNMPINDEX}": "4",  "{#SNMPVALUE}": "1:4" },
                    { "{#SNMPINDEX}": "5",  "{#SNMPVALUE}": "1:5" },
                    { "{#SNMPINDEX}": "6",  "{#SNMPVALUE}": "1:6" },
                    { "{#SNMPINDEX}": "7",  "{#SNMPVALUE}": "1:7" },
                    { "{#SNMPINDEX}": "8",  "{#SNMPVALUE}": "1:8" },
                    { "{#SNMPINDEX}": "9",  "{#SNMPVALUE}": "1:9" },
                    { "{#SNMPINDEX}": "10", "{#SNMPVALUE}": "1:10" },
                    { "{#SNMPINDEX}": "11", "{#SNMPVALUE}": "1:11" },
                    { "{#SNMPINDEX}": "12", "{#SNMPVALUE}": "1:12" },
                    { "{#SNMPINDEX}": "13", "{#SNMPVALUE}": "1:13" },
                    { "{#SNMPINDEX}": "14", "{#SNMPVALUE}": "1:14" },
                    { "{#SNMPINDEX}": "15", "{#SNMPVALUE}": "1:15" },
                    { "{#SNMPINDEX}": "16", "{#SNMPVALUE}": "1:16" },
                    { "{#SNMPINDEX}": "17", "{#SNMPVALUE}": "1:17" },
                    { "{#SNMPINDEX}": "18", "{#SNMPVALUE}": "1:18" },
                    { "{#SNMPINDEX}": "19", "{#SNMPVALUE}": "1:19" },
                    { "{#SNMPINDEX}": "20", "{#SNMPVALUE}": "1:20" },
                    { "{#SNMPINDEX}": "21", "{#SNMPVALUE}": "1:21" },
                    { "{#SNMPINDEX}": "22", "{#SNMPVALUE}": "1:22" },
                    { "{#SNMPINDEX}": "23", "{#SNMPVALUE}": "1:23" },
                    { "{#SNMPINDEX}": "24", "{#SNMPVALUE}": "1:24" },
                    { "{#SNMPINDEX}": "897",        "{#SNMPVALUE}": "Link Aggregation Group ID 1" },
                    { "{#SNMPINDEX}": "1024",       "{#SNMPVALUE}": "802.1Q Encapsulation Tag 0001" },
                    { "{#SNMPINDEX}": "1025",       "{#SNMPVALUE}": "802.1Q Encapsulation Tag 0002" },
                    { "{#SNMPINDEX}": "1026",       "{#SNMPVALUE}": "802.1Q Encapsulation Tag 0003" },
                    { "{#SNMPINDEX}": "1027",       "{#SNMPVALUE}": "802.1Q Encapsulation Tag 0004" },
                    { "{#SNMPINDEX}": "1028",       "{#SNMPVALUE}": "802.1Q Encapsulation Tag 0005" },
                    { "{#SNMPINDEX}": "1029",       "{#SNMPVALUE}": "802.1Q Encapsulation Tag 0006" },
                    { "{#SNMPINDEX}": "1030",       "{#SNMPVALUE}": "802.1Q Encapsulation Tag 0007" },
                    { "{#SNMPINDEX}": "5121",       "{#SNMPVALUE}": "rif0(198.19.25.2)" }
            ]
    }
    I've successfully validated the JSON output using http://jsonlint.com/ but Zabbix doesn't do anything with it as it simply doesn't appear to receive any output...


    Zabbix debug log:
    Code:
     25939:20160409:162629.485 End of substitute_key_macros():SUCCEED data:'snmpwalk_dgs3120.sh[<context>, <secret1>, <secret2>, <switchip>, "IF-MIB::ifDescr"]'
     25939:20160409:162629.485 In get_value() key:'snmpwalk_dgs3120.sh[{$SNMPV3_SECNAME}, {$SNMPV3_SHA_KEY}, {$SNMPV3_DES_KEY}, {HOST.CONN}, "IF-MIB::ifDescr"]'
     25939:20160409:162629.485 In get_value_external() key:'snmpwalk_dgs3120.sh[{$SNMPV3_SECNAME}, {$SNMPV3_SHA_KEY}, {$SNMPV3_DES_KEY}, {HOST.CONN}, "IF-MIB::ifDescr"]'
     25939:20160409:162629.486 In zbx_popen() command:'/usr/lib/zabbix/externalscripts/snmpwalk_dgs3120.sh "<context>" "<secret1>" "<secret2>" "<switchip>" "IF-MIB::ifDescr"'
     25939:20160409:162629.486 End of zbx_popen():7
     25939:20160409:162630.047 In zbx_waitpid()
     25939:20160409:162630.047 zbx_waitpid() exited, status:0
     25939:20160409:162630.047 End of zbx_waitpid():26398
     25939:20160409:162630.047 End of get_value_external():SUCCEED
     25939:20160409:162630.047 End of get_value():SUCCEED
     25939:20160409:162630.047 In activate_host() hostid:10187 itemid:38307 type:10
     25939:20160409:162630.047 End of activate_host()
     25939:20160409:162630.048 In lld_process_discovery_rule() itemid:38307
     25939:20160409:162630.048 query [txnlev:0] [select hostid,key_,state,evaltype,formula,error,lifetime from items where itemid=38307]
     25939:20160409:162630.048 In substitute_simple_macros() data:'0'
     25939:20160409:162630.048 query [txnlev:0] [select item_conditionid,macro,value from item_condition where itemid=38307]
     25939:20160409:162630.048 In lld_rows_get()
     25939:20160409:162630.048 End of lld_rows_get():FAIL
     25939:20160409:162630.048 End of lld_process_discovery_rule()
     25939:20160409:162630.049 End of get_values():1

    Herewith my simple bash script:
    Code:
    #!/bin/sh
    
    # Usage: snmpwalk_dgs3120.sh <SNMPv3 username> <auth secret> <priv secret> <SNMP Host> <SNMP OID>
    # LLD Key: snmpwalk_dgs3120.sh[{$SNMPV3_SECNAME}, {$SNMPV3_SHA_KEY}, {$SNMPV3_DES_KEY}, {HOST.CONN}, "IF-MIB::ifDescr"]
    
    output=`mktemp /tmp/snmpwalk_dgs3120.XXXXXX`;
    error=`mktemp /tmp/snmpwalk_dgs3120.XXXXXX`;
    
    snmpwalk -v3 -l AuthPriv -u $1 -a SHA -A $2 -x DES -X $3 $4:161 -O fn $5 > $output 2> $error;
    return=$?;
    
    if [ $return -eq 0 ]; then
      echo -e '{\n\t"data": [';
      first=1;
      cat $output | while read index t t value; do
        value=`echo $value | perl -pe 's/D-Link.*Port (\d+) on Unit (\d+)/\2:\1/'`;
        [ $first -eq 0 ] && echo -ne ',\n';
        echo -ne '\t\t{ "{#SNMPINDEX}": "'${index##.*.}'",\t';
        echo -ne '"{#SNMPVALUE}": "'$value'" }';
        first=0;
      done
      echo -e '\n\t]\n}';
    else
      cat $error >&2;
    fi
    
    find /tmp -type f -name 'snmpwalk_dgs3120.*' -mtime +1 -print0 | xargs -r0 rm -f;
    rm -f $output $error;
    
    exit $return;
  • bbs2web
    Junior Member
    • Apr 2016
    • 22

    #2
    Working

    My paranoia about cleaning up previous temp files caused the problem here. The standard user account Zabbix runs as doesn't have permissions to enumerate the /tmp folder.

    Herewith my final scrip which essentially renames discovered interfaces (including padding the interface port to sort things nicely. It is a drop in replacement for the built-in SNMP LLD:
    Code:
    #!/bin/sh
    
    # Usage: snmpwalk_dgs3120.sh <SNMPv3 username> <auth secret> <priv secret> <SNMP Host> <SNMP OID>
    #    eg: snmpwalk_dgs3120.sh snmp-user-secure1 VYDH5YHvILUc1 nJfKO3zIT4LDX 192.168.1.5 IF-MIB::ifDescr
    
    # LLD Key: snmpwalk_dgs3120.sh[{$SNMPV3_SECNAME}, {$SNMPV3_SHA_KEY}, {$SNMPV3_DES_KEY}, {HOST.CONN}, "IF-MIB::ifDescr"]
    # Filters: {#SNMPVALUE} ^[0-9]+:[0-9]+$
    
    
    script=`basename $0`;
    output=`mktemp /tmp/$script.XXXXXX`;
    error=`mktemp /tmp/$script.XXXXXX`;
    
    snmpwalk -v3 -l AuthPriv -u $1 -a SHA -A $2 -x DES -X $3 $4:161 -O fn $5 > $output 2> $error;
    return=$?;
    
    if [ $return -eq 0 ]; then
      echo -e '{\n\t"data": [';
      first=1;
      cat $output | while read index t t value; do
        value=`echo $value | perl -pe 's/D-Link.*Port (\d+) on Unit (\d+)/\2:00\1/'`;
        value=`echo $value | perl -pe 's/^(\d+:)0*(\d{2,})$/\1\2/'`;
        [ $first -eq 0 ] && echo -ne ',\n';
        echo -ne '\t\t{ "{#SNMPINDEX}": "'${index##.*.}'",';
        echo -ne '\t"{#SNMPVALUE}": "'$value'" }';
        first=0;
      done
      echo -e '\n\t]\n}';
    else
      cat $error >&2;
    fi
    
    #find /tmp -type f -name $script'.*' -mtime +1 -print0 | xargs -r0 rm -f;
    rm -f $output $error;
    
    exit $return;

    Comment

    • bbs2web
      Junior Member
      • Apr 2016
      • 22

      #3
      Retaining previous interface information

      The script posted in reply 2 essentially renames discovered interfaces as the original format included the switch firmware version and was extremely long. Interface names when using 'IF-MIB::ifDescr' using the built-in SNMP LLD:
      Code:
      {
              "data": [
                      { "{#SNMPINDEX}": "1",  "{#SNMPVALUE}": "D-Link DGS-3120-24SC R4.00.015 Port 1 on Unit 1" },
                      { "{#SNMPINDEX}": "2",  "{#SNMPVALUE}": "D-Link DGS-3120-24SC R4.00.015 Port 2 on Unit 1" },
                      { "{#SNMPINDEX}": "3",  "{#SNMPVALUE}": "D-Link DGS-3120-24SC R4.00.015 Port 3 on Unit 1" },
                      { "{#SNMPINDEX}": "4",  "{#SNMPVALUE}": "D-Link DGS-3120-24SC R4.00.015 Port 4 on Unit 1" },
                      { "{#SNMPINDEX}": "5",  "{#SNMPVALUE}": "D-Link DGS-3120-24SC R4.00.015 Port 5 on Unit 1" },
                      { "{#SNMPINDEX}": "6",  "{#SNMPVALUE}": "D-Link DGS-3120-24SC R4.00.015 Port 6 on Unit 1" },
                      { "{#SNMPINDEX}": "7",  "{#SNMPVALUE}": "D-Link DGS-3120-24SC R4.00.015 Port 7 on Unit 1" },
                      { "{#SNMPINDEX}": "8",  "{#SNMPVALUE}": "D-Link DGS-3120-24SC R4.00.015 Port 8 on Unit 1" },
                      { "{#SNMPINDEX}": "9",  "{#SNMPVALUE}": "D-Link DGS-3120-24SC R4.00.015 Port 9 on Unit 1" },
                      { "{#SNMPINDEX}": "10", "{#SNMPVALUE}": "D-Link DGS-3120-24SC R4.00.015 Port 10 on Unit 1" },
                      { "{#SNMPINDEX}": "11", "{#SNMPVALUE}": "D-Link DGS-3120-24SC R4.00.015 Port 11 on Unit 1" },
                      { "{#SNMPINDEX}": "12", "{#SNMPVALUE}": "D-Link DGS-3120-24SC R4.00.015 Port 12 on Unit 1" },
                      { "{#SNMPINDEX}": "13", "{#SNMPVALUE}": "D-Link DGS-3120-24SC R4.00.015 Port 13 on Unit 1" },
                      { "{#SNMPINDEX}": "14", "{#SNMPVALUE}": "D-Link DGS-3120-24SC R4.00.015 Port 14 on Unit 1" },
                      { "{#SNMPINDEX}": "15", "{#SNMPVALUE}": "D-Link DGS-3120-24SC R4.00.015 Port 15 on Unit 1" },
                      { "{#SNMPINDEX}": "16", "{#SNMPVALUE}": "D-Link DGS-3120-24SC R4.00.015 Port 16 on Unit 1" },
                      { "{#SNMPINDEX}": "17", "{#SNMPVALUE}": "D-Link DGS-3120-24SC R4.00.015 Port 17 on Unit 1" },
                      { "{#SNMPINDEX}": "18", "{#SNMPVALUE}": "D-Link DGS-3120-24SC R4.00.015 Port 18 on Unit 1" },
                      { "{#SNMPINDEX}": "19", "{#SNMPVALUE}": "D-Link DGS-3120-24SC R4.00.015 Port 19 on Unit 1" },
                      { "{#SNMPINDEX}": "20", "{#SNMPVALUE}": "D-Link DGS-3120-24SC R4.00.015 Port 20 on Unit 1" },
                      { "{#SNMPINDEX}": "21", "{#SNMPVALUE}": "D-Link DGS-3120-24SC R4.00.015 Port 21 on Unit 1" },
                      { "{#SNMPINDEX}": "22", "{#SNMPVALUE}": "D-Link DGS-3120-24SC R4.00.015 Port 22 on Unit 1" },
                      { "{#SNMPINDEX}": "23", "{#SNMPVALUE}": "D-Link DGS-3120-24SC R4.00.015 Port 23 on Unit 1" },
                      { "{#SNMPINDEX}": "24", "{#SNMPVALUE}": "D-Link DGS-3120-24SC R4.00.015 Port 24 on Unit 1" },
                      { "{#SNMPINDEX}": "65", "{#SNMPVALUE}": "D-Link DGS-3120-24SC R4.00.015 Port 1 on Unit 2" },
                      { "{#SNMPINDEX}": "66", "{#SNMPVALUE}": "D-Link DGS-3120-24SC R4.00.015 Port 2 on Unit 2" },
                      { "{#SNMPINDEX}": "67", "{#SNMPVALUE}": "D-Link DGS-3120-24SC R4.00.015 Port 3 on Unit 2" },
                      { "{#SNMPINDEX}": "68", "{#SNMPVALUE}": "D-Link DGS-3120-24SC R4.00.015 Port 4 on Unit 2" },
                      { "{#SNMPINDEX}": "69", "{#SNMPVALUE}": "D-Link DGS-3120-24SC R4.00.015 Port 5 on Unit 2" },
                      { "{#SNMPINDEX}": "70", "{#SNMPVALUE}": "D-Link DGS-3120-24SC R4.00.015 Port 6 on Unit 2" },
                      { "{#SNMPINDEX}": "71", "{#SNMPVALUE}": "D-Link DGS-3120-24SC R4.00.015 Port 7 on Unit 2" },
                      { "{#SNMPINDEX}": "72", "{#SNMPVALUE}": "D-Link DGS-3120-24SC R4.00.015 Port 8 on Unit 2" },
                      { "{#SNMPINDEX}": "73", "{#SNMPVALUE}": "D-Link DGS-3120-24SC R4.00.015 Port 9 on Unit 2" },
                      { "{#SNMPINDEX}": "74", "{#SNMPVALUE}": "D-Link DGS-3120-24SC R4.00.015 Port 10 on Unit 2" },
                      { "{#SNMPINDEX}": "75", "{#SNMPVALUE}": "D-Link DGS-3120-24SC R4.00.015 Port 11 on Unit 2" },
                      { "{#SNMPINDEX}": "76", "{#SNMPVALUE}": "D-Link DGS-3120-24SC R4.00.015 Port 12 on Unit 2" },
                      { "{#SNMPINDEX}": "77", "{#SNMPVALUE}": "D-Link DGS-3120-24SC R4.00.015 Port 13 on Unit 2" },
                      { "{#SNMPINDEX}": "78", "{#SNMPVALUE}": "D-Link DGS-3120-24SC R4.00.015 Port 14 on Unit 2" },
                      { "{#SNMPINDEX}": "79", "{#SNMPVALUE}": "D-Link DGS-3120-24SC R4.00.015 Port 15 on Unit 2" },
                      { "{#SNMPINDEX}": "80", "{#SNMPVALUE}": "D-Link DGS-3120-24SC R4.00.015 Port 16 on Unit 2" },
                      { "{#SNMPINDEX}": "81", "{#SNMPVALUE}": "D-Link DGS-3120-24SC R4.00.015 Port 17 on Unit 2" },
                      { "{#SNMPINDEX}": "82", "{#SNMPVALUE}": "D-Link DGS-3120-24SC R4.00.015 Port 18 on Unit 2" },
                      { "{#SNMPINDEX}": "83", "{#SNMPVALUE}": "D-Link DGS-3120-24SC R4.00.015 Port 19 on Unit 2" },
                      { "{#SNMPINDEX}": "84", "{#SNMPVALUE}": "D-Link DGS-3120-24SC R4.00.015 Port 20 on Unit 2" },
                      { "{#SNMPINDEX}": "85", "{#SNMPVALUE}": "D-Link DGS-3120-24SC R4.00.015 Port 21 on Unit 2" },
                      { "{#SNMPINDEX}": "86", "{#SNMPVALUE}": "D-Link DGS-3120-24SC R4.00.015 Port 22 on Unit 2" },
                      { "{#SNMPINDEX}": "87", "{#SNMPVALUE}": "D-Link DGS-3120-24SC R4.00.015 Port 23 on Unit 2" },
                      { "{#SNMPINDEX}": "88", "{#SNMPVALUE}": "D-Link DGS-3120-24SC R4.00.015 Port 24 on Unit 2" },
                      { "{#SNMPINDEX}": "897",        "{#SNMPVALUE}": "Link Aggregation Group ID 1" },
                      { "{#SNMPINDEX}": "898",        "{#SNMPVALUE}": "Link Aggregation Group ID 2" },
                      { "{#SNMPINDEX}": "1024",       "{#SNMPVALUE}": "802.1Q Encapsulation Tag 0001" },
                      { "{#SNMPINDEX}": "1025",       "{#SNMPVALUE}": "802.1Q Encapsulation Tag 0002" },
                      { "{#SNMPINDEX}": "1026",       "{#SNMPVALUE}": "802.1Q Encapsulation Tag 0003" },
                      { "{#SNMPINDEX}": "1027",       "{#SNMPVALUE}": "802.1Q Encapsulation Tag 0004" },
                      { "{#SNMPINDEX}": "1030",       "{#SNMPVALUE}": "802.1Q Encapsulation Tag 0007" },
                      { "{#SNMPINDEX}": "1031",       "{#SNMPVALUE}": "802.1Q Encapsulation Tag 0008" },
                      { "{#SNMPINDEX}": "1032",       "{#SNMPVALUE}": "802.1Q Encapsulation Tag 0009" },
                      { "{#SNMPINDEX}": "1033",       "{#SNMPVALUE}": "802.1Q Encapsulation Tag 0010" },
                      { "{#SNMPINDEX}": "1034",       "{#SNMPVALUE}": "802.1Q Encapsulation Tag 0011" },
                      { "{#SNMPINDEX}": "1122",       "{#SNMPVALUE}": "802.1Q Encapsulation Tag 0099" },
                      { "{#SNMPINDEX}": "5121",       "{#SNMPVALUE}": "rif0(198.19.21.3)" }
              ]
      }
      The renamed interfaces when using my custom script:
      Code:
      {
              "data": [
                      { "{#SNMPINDEX}": "1",  "{#SNMPVALUE}": "1:01" },
                      { "{#SNMPINDEX}": "2",  "{#SNMPVALUE}": "1:02" },
                      { "{#SNMPINDEX}": "3",  "{#SNMPVALUE}": "1:03" },
                      { "{#SNMPINDEX}": "4",  "{#SNMPVALUE}": "1:04" },
                      { "{#SNMPINDEX}": "5",  "{#SNMPVALUE}": "1:05" },
                      { "{#SNMPINDEX}": "6",  "{#SNMPVALUE}": "1:06" },
                      { "{#SNMPINDEX}": "7",  "{#SNMPVALUE}": "1:07" },
                      { "{#SNMPINDEX}": "8",  "{#SNMPVALUE}": "1:08" },
                      { "{#SNMPINDEX}": "9",  "{#SNMPVALUE}": "1:09" },
                      { "{#SNMPINDEX}": "10", "{#SNMPVALUE}": "1:10" },
                      { "{#SNMPINDEX}": "11", "{#SNMPVALUE}": "1:11" },
                      { "{#SNMPINDEX}": "12", "{#SNMPVALUE}": "1:12" },
                      { "{#SNMPINDEX}": "13", "{#SNMPVALUE}": "1:13" },
                      { "{#SNMPINDEX}": "14", "{#SNMPVALUE}": "1:14" },
                      { "{#SNMPINDEX}": "15", "{#SNMPVALUE}": "1:15" },
                      { "{#SNMPINDEX}": "16", "{#SNMPVALUE}": "1:16" },
                      { "{#SNMPINDEX}": "17", "{#SNMPVALUE}": "1:17" },
                      { "{#SNMPINDEX}": "18", "{#SNMPVALUE}": "1:18" },
                      { "{#SNMPINDEX}": "19", "{#SNMPVALUE}": "1:19" },
                      { "{#SNMPINDEX}": "20", "{#SNMPVALUE}": "1:20" },
                      { "{#SNMPINDEX}": "21", "{#SNMPVALUE}": "1:21" },
                      { "{#SNMPINDEX}": "22", "{#SNMPVALUE}": "1:22" },
                      { "{#SNMPINDEX}": "23", "{#SNMPVALUE}": "1:23" },
                      { "{#SNMPINDEX}": "24", "{#SNMPVALUE}": "1:24" },
                      { "{#SNMPINDEX}": "65", "{#SNMPVALUE}": "2:01" },
                      { "{#SNMPINDEX}": "66", "{#SNMPVALUE}": "2:02" },
                      { "{#SNMPINDEX}": "67", "{#SNMPVALUE}": "2:03" },
                      { "{#SNMPINDEX}": "68", "{#SNMPVALUE}": "2:04" },
                      { "{#SNMPINDEX}": "69", "{#SNMPVALUE}": "2:05" },
                      { "{#SNMPINDEX}": "70", "{#SNMPVALUE}": "2:06" },
                      { "{#SNMPINDEX}": "71", "{#SNMPVALUE}": "2:07" },
                      { "{#SNMPINDEX}": "72", "{#SNMPVALUE}": "2:08" },
                      { "{#SNMPINDEX}": "73", "{#SNMPVALUE}": "2:09" },
                      { "{#SNMPINDEX}": "74", "{#SNMPVALUE}": "2:10" },
                      { "{#SNMPINDEX}": "75", "{#SNMPVALUE}": "2:11" },
                      { "{#SNMPINDEX}": "76", "{#SNMPVALUE}": "2:12" },
                      { "{#SNMPINDEX}": "77", "{#SNMPVALUE}": "2:13" },
                      { "{#SNMPINDEX}": "78", "{#SNMPVALUE}": "2:14" },
                      { "{#SNMPINDEX}": "79", "{#SNMPVALUE}": "2:15" },
                      { "{#SNMPINDEX}": "80", "{#SNMPVALUE}": "2:16" },
                      { "{#SNMPINDEX}": "81", "{#SNMPVALUE}": "2:17" },
                      { "{#SNMPINDEX}": "82", "{#SNMPVALUE}": "2:18" },
                      { "{#SNMPINDEX}": "83", "{#SNMPVALUE}": "2:19" },
                      { "{#SNMPINDEX}": "84", "{#SNMPVALUE}": "2:20" },
                      { "{#SNMPINDEX}": "85", "{#SNMPVALUE}": "2:21" },
                      { "{#SNMPINDEX}": "86", "{#SNMPVALUE}": "2:22" },
                      { "{#SNMPINDEX}": "87", "{#SNMPVALUE}": "2:23" },
                      { "{#SNMPINDEX}": "88", "{#SNMPVALUE}": "2:24" },
                      { "{#SNMPINDEX}": "897",        "{#SNMPVALUE}": "Link Aggregation Group ID 1" },
                      { "{#SNMPINDEX}": "898",        "{#SNMPVALUE}": "Link Aggregation Group ID 2" },
                      { "{#SNMPINDEX}": "1024",       "{#SNMPVALUE}": "802.1Q Encapsulation Tag 0001" },
                      { "{#SNMPINDEX}": "1025",       "{#SNMPVALUE}": "802.1Q Encapsulation Tag 0002" },
                      { "{#SNMPINDEX}": "1026",       "{#SNMPVALUE}": "802.1Q Encapsulation Tag 0003" },
                      { "{#SNMPINDEX}": "1027",       "{#SNMPVALUE}": "802.1Q Encapsulation Tag 0004" },
                      { "{#SNMPINDEX}": "1030",       "{#SNMPVALUE}": "802.1Q Encapsulation Tag 0007" },
                      { "{#SNMPINDEX}": "1031",       "{#SNMPVALUE}": "802.1Q Encapsulation Tag 0008" },
                      { "{#SNMPINDEX}": "1032",       "{#SNMPVALUE}": "802.1Q Encapsulation Tag 0009" },
                      { "{#SNMPINDEX}": "1033",       "{#SNMPVALUE}": "802.1Q Encapsulation Tag 0010" },
                      { "{#SNMPINDEX}": "1034",       "{#SNMPVALUE}": "802.1Q Encapsulation Tag 0011" },
                      { "{#SNMPINDEX}": "1122",       "{#SNMPVALUE}": "802.1Q Encapsulation Tag 0099" },
                      { "{#SNMPINDEX}": "5121",       "{#SNMPVALUE}": "rif0(198.19.21.3)" }
              ]
      }
      I only want to monitor physical ports and not VLANs or LACP trunks so I configure a LLD filter:
      {#SNMPVALUE} matches ^[0-9]+:[0-9]+$


      I updated the discovery rule and then shutdown the Zabbix server process so that I could rename the existing item keys so that I wouldn't loose the historical information:
      Code:
      mysql -u username -psecret zabbix -e 'SELECT itemid,key_ FROM items WHERE key_ LIKE "%D-Link DGS-3120-24SC R4.00.015 Port%";' -N > /root/update-sql;
      cat update-sql | perl -pe 's/D-Link.*Port (\d+) on Unit (\d+)/\2:00\1/g;s/(\[\d+:)0*(\d{2,}\])/\1\2/g' | \
        while read id value; do
          mysql -u username -psecret zabbix -e "UPDATE items SET key_='$value' WHERE itemid='$id';";
        done

      Comment

      Working...