Ad Widget

Collapse

Full SNMP OID Import

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jcrocker
    Junior Member
    • Aug 2006
    • 2

    #1

    Full SNMP OID Import

    The author: Steven Dossett who created the zload_snmpwalk zload_snmpwalk provided a wonderful tool for importing snmp oid into the zabbix database.

    While handy, it wasn't importing oid names with spaces and odd ducks or full descriptions. So, I've tweaked the process a bit.

    I get the snmpwalk and associate a longer human readable name to the OID number before inserting into the zabbix template.


    The zabbix db schema as a field size limit. Therefore I truncate the last whole .*.*.whatever starting from the END of the text string that will fit within the field size. (As of zabbix 1.1.2)

    PREREQ1: SNMP installed with all the MIBS you could want.
    PREREQ2: You've already created the 'template' area within zabbix to load the oid info.


    Step 1: Apply this patch against zload_snmpwalk or fetch the copy from the attachments.

    2,42c2
    < ####################################
    < #
    < # zload_snmpwalk
    < # Author: Steven Dossett
    < # Email: sd at panath.com
    < #
    < ####################################
    < # Disclaimer:
    < # This script has only been used with ZABBIX 1.1alpha6. It isn't thoroughly
    < # tested. It isn't very efficient. It may eat your database or cause other
    < # unintentional harm. Be careful and use at your own risk.
    < # Please share bug fixes and improvements that you make...
    < #
    < # See usage instructions by running: zload_snmpwalk -h
    < #
    < # Description:
    < # Creating new ZABBIX host templates can be time consuming. This script
    < # automates some of the process by loading snmpwalk data into a ZABBIX
    < # template. It is very important to use a MIB so that keys and descriptions
    < # for the data are usable. MIBs can be specified on the command line or
    < # snmpwalk may find them via your MIBS environment variable. The template
    < # items will need modification from the ZABBIX UI after bulk loading. The
    < # script doesn't attempt to manage interesting things like 'units' or 'custom
    < # multipliers'. The script also has a limited notion of what qualifies as
    < # 'Character' data and defaults to 'Numeric' for just about everything.
    < # Update the script to properly identify more types.
    < #
    < # An example session might work like the following:
    < #
    < # 1 - Create a new host template in the Zabbix UI. Make note of the ID for the
    < # new template.
    < # 2 - Use an additional -T option to test the examples in 2a and 2b.
    < # 2a - Build an initial set of items for the template. In the example below
    < # the template id 10015 is used:
    < # zload_snmpwalk -m SOMEVENDOR-MASTER-MIB secretstring dbuser dbpass 10015 somehost .iso.org.dod.internet.private
    < # 2b - Alternatively, the template can be created from saved snmpwalk data:
    < # zload_snmpwalk -m SOMEVENDOR-MASTER-MIB secretstring dbuser dbpass 10015 somefile
    < # For the option above, the data must be in 'snmpwalk -Of' format.
    < # 3 - Next, the template should be tweaked and tested from the Zabbix UI before
    < # applying to hosts.
    < #
    ---
    >
    53c13
    < $PROG = "zload_snmpwalk";
    ---
    > $PROG = "zload_snmp";
    57d16
    < $PROG [OPTIONS] <community> <dbuser> <dbpasswd> <zabbix_id> <agent> <oid>
    109c68
    < sub get_zabbix_description
    ---
    > sub get_zabbix_key
    113a73,76
    > my $slice;
    > my $length = length($raw_oid);
    >
    > # get last 64 char. Get from next '.' Satisfies Zabbix table constraint on the key_
    115,117c78,82
    < # Step back 2 positions for a description string and key
    < $pos = rindex($raw_oid,'.');
    < $pos = rindex($raw_oid,'.',$pos - 1);
    ---
    > if ($length > 64) {
    > $slice = substr $raw_oid, -64, $length;
    > $pos = index($slice,'.');
    > $raw_oid = substr $slice, $pos + 1;
    > }
    119c84
    < return substr($raw_oid, $pos + 1);
    ---
    > return $raw_oid;
    139a105
    > print $snmp_type."\n";
    142c108
    < if ($snmp_type eq "STRING")
    ---
    > if ($snmp_type =~ /STRING/)
    223a190
    > my $zabbix_key;
    225c192
    < next if ($line !~ /(.iso.org.dod.*) = (.*):/ );
    ---
    > next if ($line !~ /^([\d\.]+)\a(\S+)\s+=\s+(\S+)\s+/ );
    230,232c197,200
    < $zabbix_description = get_zabbix_description($1);
    < $zabbix_oid = get_zabbix_oid($1);
    < $zabbix_value_type = get_zabbix_value_type($2);
    ---
    > $zabbix_description = $2;
    > $zabbix_key = get_zabbix_key($2);
    > $zabbix_oid = $1;
    > $zabbix_value_type = get_zabbix_value_type($3);
    245c213
    < "$zabbix_description\t$zabbix_delay\t",
    ---
    > "$zabbix_key\t$zabbix_delay\t",
    253c221
    < $zabbix_id, $zabbix_description, $zabbix_description,
    ---
    > $zabbix_id, $zabbix_description, $zabbix_key,
    Step 2: SNMPWalking
    Walk the snmp device and collect the numerical information and then the human readable form to temporary files for merging. For all the following examples I'm assuming a public community.
    • ByNumber:
      snmpwalk -On -v1 -c public <host> > /tmp/oidnum
    • ByName:
      snmpwalk -Of -v1 -c public <host> > /tmp/oidname


    Step 3: Merge the names and numbers
    Now that you have all the OID information by name and the associated number we need to merge them. I've got a simple perl snip to do just that. Making a HUGE assumption that the name and number generated files are matched one to one.
    mergeOID /tmp/oidnum /tmp/oidname > /tmp/mergedOID
    Step 4: Run a TEST Import
    With the merged file of OID name and numbers try a test import.
    ./zload_snmp -T -s <dbserver> -v 1 public <dbuser> <dbname> <templateID#> /tmp/mergedOID
    Step 5: Run an Import
    If happy with the test run do the real deal. (Deleting from the template with the DB admin and simple SQL DELETE FROM WHERE TEMPLATENAME was easy enough should you munge it up.)
    ./zload_snmp -s <dbserver> -v 1 public <dbuser> <dbname> <templateID#> /tmp/mergedOID
    Note While this will import whatever objects you fetched from the walk a large percentage may be of no use or relevance to monitoring and will collect in the DB history all the same. So, weed out whatever isn't important.

    PERL Merge Code
    #!/usr/bin/perl

    # Merge OID number with short name.

    open (NUM, "< $ARGV[0]");
    open (NAME, "< $ARGV[1]");

    @num;
    @name;

    while (<NUM>) {

    if (/^([\.\d]+)\s+=/ios) { push(@num, $1) };

    }

    $i = 0;

    while (<NAME>) {

    next if (!/(.iso.org.dod.*) = (.*):/ );
    if (/\.iso\.org\.dod\.internet\.mgmt\.mib-2\./ios || /\.iso\.org\.dod\.internet\.private\.enterprises\./ios) {

    print $num[$i]."\a".$';
    $i++;

    }

    }
    Last edited by jcrocker; 16-11-2006, 20:19. Reason: Added info. to original post from Steven. Fixed URL
  • crayons
    Junior Member
    • Oct 2006
    • 21

    #2
    patch zload_snmpwalk diff_file
    patching file zload_snmpwalk
    patch: **** `>' expected at line 44 of patch


    Am using the wrong parameters or something for patch?

    Comment

    • xsion
      Junior Member
      • Dec 2006
      • 1

      #3
      same error here

      Comment

      • krelac
        Junior Member
        • Oct 2006
        • 24

        #4
        Originally posted by xsion
        same error here

        x2

        Comment

        Working...