Ad Widget

Collapse

Tool for bulkloading a template with snmpwalk data

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • zhanghui8059
    Junior Member
    • May 2011
    • 6

    #31
    Getting an error with the latest version. can anyone help with why?zabbix version is 1.8.5.
    thks!

    .DBD::mysql::st execute failed: Duplicate entry '0' for key 1 at ./snmpwalk.pl line 314, <SWALK> line 2.
    Insert Failure: DBI::st=HASH(0xb91760)->strerror

    Comment

    • george04
      Junior Member
      • Jul 2011
      • 9

      #32
      zhanghui8059
      Junior Member

      Join Date: May 2011
      Posts: 2

      Getting an error with the latest version. can anyone help with why?zabbix version is 1.8.5.
      thks!

      .DBD::mysql::st execute failed: Duplicate entry '0' for key 1 at ./snmpwalk.pl line 314, <SWALK> line 2.
      Insert Failure: DBI::st=HASH(0xb91760)->strerror
      No dont tell me that, i was about to try it to.. hope it dont give me the same problem, ...
      ill be posting in few days to tell how it went with me.

      thanks for this tread its greate..

      Comment

      • george04
        Junior Member
        • Jul 2011
        • 9

        #33
        Hi there i finaly , try this script but i got a problema.
        Once i type the command with all its arguments this is the answer
        MIB search path: /home/zabbix/.snmp/mibs:/usr/share/mibs/site:/usr/share/snmp/mibs:/usr/share/mibs/iana:/usr/share/mibs/ietf:/usr/share/mibs/netsnmp
        Cannot find module (SNMP-FRAMEWORK-MIB): At line 9 in /usr/share/mibs/netsnmp/NET-SNMP-AGENT-MIB
        Cannot find module (SNMPv2-SMI): At line 8 in /usr/share/mibs/netsnmp/NET-SNMP-MIB
        Did not find 'enterprises' in module #-1 (/usr/share/mibs/netsnmp/NET-SNMP-MIB)
        Unlinked OID in NET-SNMP-MIB: netSnmp ::= { enterprises 8072 }
        Undefined identifier: enterprises near line 10 of /usr/share/mibs/netsnmp/NET-SNMP-MIB
        Looks like im not conecting NEtSNMP..
        or something else , ill thankful if you tellme something about this problem, im really new and its my first week on this,...
        thanks by the way

        Comment

        • cheezus
          Member
          • Nov 2011
          • 35

          #34
          problem

          Trying to use this a juniper srx240h. Have the junos enterprise mibs loaded into /usr/share/snmp/mibs

          But getting the following errors:


          [root@zenoss scripts]# /usr/bin/perl zload_snmpwalk.pl -v 2c -m ALL -x public SRX240H 10.10.254.2 1.3.6.1.4.1.2636.3.39.
          <zabbix_export version="1.0" date="13.12.11" time="15:28">
          <hosts>
          <host name="SRX240H">
          <status>3</status>
          Cannot find module (ENTITY-MIB): At line 15 in /usr/share/snmp/mibs/mib-rfc2922.txt
          Did not find 'PhysicalIndex' in module #-1 (/usr/share/snmp/mibs/mib-rfc2922.txt)
          1.3.6.1.4.1.2636.3.39.: Unknown Object Identifier (Sub-id not found: jnxJsMibRoot -> )
          </host>
          </hosts>
          </zabbix_export>
          [root@zenoss scripts]# service net-snmp restart
          net-snmp: unrecognized service
          [root@zenoss scripts]# /usr/bin/perl zload_snmpwalk.pl -v 2c -m ALL -x public SRX240H 10.10.254.2 1.3.6.1.4.1.2636.3.39.
          <zabbix_export version="1.0" date="13.12.11" time="15:29">
          <hosts>
          <host name="SRX240H">
          <status>3</status>
          Cannot find module (IPMROUTE-STD-MIB): At line 13 in /usr/share/snmp/mibs/mib-pimmib.txt
          Did not find 'ipMRouteGroup' in module #-1 (/usr/share/snmp/mibs/mib-pimmib.txt)
          Did not find 'ipMRouteSource' in module #-1 (/usr/share/snmp/mibs/mib-pimmib.txt)
          Did not find 'ipMRouteSourceMask' in module #-1 (/usr/share/snmp/mibs/mib-pimmib.txt)
          Did not find 'ipMRouteNextHopGroup' in module #-1 (/usr/share/snmp/mibs/mib-pimmib.txt)
          Did not find 'ipMRouteNextHopSource' in module #-1 (/usr/share/snmp/mibs/mib-pimmib.txt)
          Did not find 'ipMRouteNextHopSourceMask' in module #-1 (/usr/share/snmp/mibs/mib-pimmib.txt)
          Did not find 'ipMRouteNextHopIfIndex' in module #-1 (/usr/share/snmp/mibs/mib-pimmib.txt)
          Did not find 'ipMRouteNextHopAddress' in module #-1 (/usr/share/snmp/mibs/mib-pimmib.txt)
          Cannot find module (ATM-MIB): At line 23 in /usr/share/snmp/mibs/mib-jnx-atm.txt
          Did not find 'atmInterfaceConfEntry' in module #-1 (/usr/share/snmp/mibs/mib-jnx-atm.txt)
          Did not find 'atmVclEntry' in module #-1 (/usr/share/snmp/mibs/mib-jnx-atm.txt)
          Did not find 'atmVplEntry' in module #-1 (/usr/share/snmp/mibs/mib-jnx-atm.txt)
          Cannot find module (ATM-MIB): At line 17 in /usr/share/snmp/mibs/mib-jnx-atm-cos.txt
          Did not find 'atmVclVpi' in module #-1 (/usr/share/snmp/mibs/mib-jnx-atm-cos.txt)
          Did not find 'atmVclVci' in module #-1 (/usr/share/snmp/mibs/mib-jnx-atm-cos.txt)
          Cannot find module (DISMAN-PING-MIB): At line 28 in /usr/share/snmp/mibs/mib-jnx-ping.txt
          Did not find 'pingResultsEntry' in module #-1 (/usr/share/snmp/mibs/mib-jnx-ping.txt)
          Did not find 'pingProbeHistoryEntry' in module #-1 (/usr/share/snmp/mibs/mib-jnx-ping.txt)
          Did not find 'pingCtlTargetAddressType' in module #-1 (/usr/share/snmp/mibs/mib-jnx-ping.txt)
          Did not find 'pingCtlTargetAddress' in module #-1 (/usr/share/snmp/mibs/mib-jnx-ping.txt)
          Did not find 'pingResultsOperStatus' in module #-1 (/usr/share/snmp/mibs/mib-jnx-ping.txt)
          Did not find 'pingResultsIpTargetAddressType' in module #-1 (/usr/share/snmp/mibs/mib-jnx-ping.txt)
          Did not find 'pingResultsIpTargetAddress' in module #-1 (/usr/share/snmp/mibs/mib-jnx-ping.txt)
          Did not find 'pingResultsMinRtt' in module #-1 (/usr/share/snmp/mibs/mib-jnx-ping.txt)
          Did not find 'pingResultsMaxRtt' in module #-1 (/usr/share/snmp/mibs/mib-jnx-ping.txt)
          Did not find 'pingResultsAverageRtt' in module #-1 (/usr/share/snmp/mibs/mib-jnx-ping.txt)
          Did not find 'pingResultsProbeResponses' in module #-1 (/usr/share/snmp/mibs/mib-jnx-ping.txt)
          Did not find 'pingResultsSentProbes' in module #-1 (/usr/share/snmp/mibs/mib-jnx-ping.txt)
          Did not find 'pingResultsRttSumOfSquares' in module #-1 (/usr/share/snmp/mibs/mib-jnx-ping.txt)
          Did not find 'pingResultsLastGoodProbe' in module #-1 (/usr/share/snmp/mibs/mib-jnx-ping.txt)
          Did not find 'OperationResponseStatus' in module #-1 (/usr/share/snmp/mibs/mib-jnx-ping.txt)
          Cannot find module (PPVPN-TC-MIB): At line 23 in /usr/share/snmp/mibs/mib-l3vpnmib.txt
          Did not find 'VPNId' in module #-1 (/usr/share/snmp/mibs/mib-l3vpnmib.txt)
          Cannot find module (MPLS-TC-STD-MIB): At line 33 in /usr/share/snmp/mibs/mib-jnx-mpls-ldp.txt
          Did not find 'MplsLabel' in module #-1 (/usr/share/snmp/mibs/mib-jnx-mpls-ldp.txt)
          Did not find 'MplsLabelDistributionMethod' in module #-1 (/usr/share/snmp/mibs/mib-jnx-mpls-ldp.txt)
          Did not find 'MplsLdpIdentifier' in module #-1 (/usr/share/snmp/mibs/mib-jnx-mpls-ldp.txt)
          Did not find 'MplsLdpLabelType' in module #-1 (/usr/share/snmp/mibs/mib-jnx-mpls-ldp.txt)
          Did not find 'MplsLspType' in module #-1 (/usr/share/snmp/mibs/mib-jnx-mpls-ldp.txt)
          Did not find 'MplsLsrIdentifier' in module #-1 (/usr/share/snmp/mibs/mib-jnx-mpls-ldp.txt)
          Did not find 'MplsRetentionMode' in module #-1 (/usr/share/snmp/mibs/mib-jnx-mpls-ldp.txt)
          Cannot find module (BRIDGE-MIB): At line 10 in /usr/share/snmp/mibs/mib-jnx-l2cp-features.txt
          Did not find 'dot1dStpPort' in module #-1 (/usr/share/snmp/mibs/mib-jnx-l2cp-features.txt)
          Did not find 'dot1dStpPortEntry' in module #-1 (/usr/share/snmp/mibs/mib-jnx-l2cp-features.txt)
          Cannot find module (PerfHist-TC-MIB): At line 17 in /usr/share/snmp/mibs/mib-jnx-pwatm.txt
          Cannot find module (ATM-TC-MIB): At line 30 in /usr/share/snmp/mibs/mib-jnx-pwatm.txt
          Did not find 'PerfCurrentCount' in module #-1 (/usr/share/snmp/mibs/mib-jnx-pwatm.txt)
          Did not find 'PerfIntervalCount' in module #-1 (/usr/share/snmp/mibs/mib-jnx-pwatm.txt)
          Did not find 'AtmVpIdentifier' in module #-1 (/usr/share/snmp/mibs/mib-jnx-pwatm.txt)
          Did not find 'AtmVcIdentifier' in module #-1 (/usr/share/snmp/mibs/mib-jnx-pwatm.txt)
          Cannot find module (PerfHist-TC-MIB): At line 24 in /usr/share/snmp/mibs/mib-jnx-pwtdm.txt
          Did not find 'PerfCurrentCount' in module #-1 (/usr/share/snmp/mibs/mib-jnx-pwtdm.txt)
          Did not find 'PerfIntervalCount' in module #-1 (/usr/share/snmp/mibs/mib-jnx-pwtdm.txt)
          Cannot find module (RMON2-MIB): At line 23 in /usr/share/snmp/mibs/mib-lldp.txt
          Did not find 'TimeFilter' in module #-1 (/usr/share/snmp/mibs/mib-lldp.txt)
          Did not find 'ZeroBasedCounter32' in module #-1 (/usr/share/snmp/mibs/mib-lldp.txt)
          Cannot find module (DISMAN-PING-MIB): At line 20 in /usr/share/snmp/mibs/mib-jnx-rpm.txt
          Did not find 'pingCtlOwnerIndex' in module #-1 (/usr/share/snmp/mibs/mib-jnx-rpm.txt)
          Did not find 'pingCtlTestName' in module #-1 (/usr/share/snmp/mibs/mib-jnx-rpm.txt)
          Did not find 'pingProbeHistoryIndex' in module #-1 (/usr/share/snmp/mibs/mib-jnx-rpm.txt)
          1.3.6.1.4.1.2636.3.39.: Unknown Object Identifier (Sub-id not found: jnxJsMibRoot -> )
          </host>
          </hosts>
          </zabbix_export>


          Surely I'm missing something stupid... can anyone see it might be?

          Comment

          • qix
            Senior Member
            Zabbix Certified SpecialistZabbix Certified Professional
            • Oct 2006
            • 423

            #35
            Originally posted by cheezus

            [root@zenoss scripts]#


            Surely I'm missing something stupid... can anyone see it might be?
            You're using the wrong monitoring tool?
            With kind regards,

            Raymond

            Comment

            • cheezus
              Member
              • Nov 2011
              • 35

              #36
              Originally posted by qix
              You're using the wrong monitoring tool?
              Funny, I knew someone would comment on that

              Just reusing a vm that was going to be testing some zenoss stuff. We currently have both running (zenoss came first) but are hoping to ditch zenoss and switch over to zabbix entirely.

              If I could figure out what stupid thing I'm doing wrong...

              Comment

              • qix
                Senior Member
                Zabbix Certified SpecialistZabbix Certified Professional
                • Oct 2006
                • 423

                #37
                Seriously though, you don't need the snmp deamons since you are using the tools only. In most distros it is a different package, pleas check if you have the proper tools installed.
                With kind regards,

                Raymond

                Comment

                • cheezus
                  Member
                  • Nov 2011
                  • 35

                  #38
                  Originally posted by qix
                  Seriously though, you don't need the snmp deamons since you are using the tools only. In most distros it is a different package, pleas check if you have the proper tools installed.
                  zabbix is running fine, even catching traps. Only zabbix is running and it's a clean setup of centos. That's just the host name you are seeing.

                  Comment

                  • qix
                    Senior Member
                    Zabbix Certified SpecialistZabbix Certified Professional
                    • Oct 2006
                    • 423

                    #39
                    It could also be a missing perl dependency
                    With kind regards,

                    Raymond

                    Comment

                    • qix
                      Senior Member
                      Zabbix Certified SpecialistZabbix Certified Professional
                      • Oct 2006
                      • 423

                      #40
                      Originally posted by cheezus
                      zabbix is running fine, even catching traps. Only zabbix is running and it's a clean setup of centos. That's just the host name you are seeing.
                      Yes I know, but really, for this tool you dont need the snmp deamons, it is a client based. I'm not sure if it uses the snmp tools or the perl modules though.
                      With kind regards,

                      Raymond

                      Comment

                      • cheezus
                        Member
                        • Nov 2011
                        • 35

                        #41
                        Originally posted by qix
                        Yes I know, but really, for this tool you dont need the snmp deamons, it is a client based. I'm not sure if it uses the snmp tools or the perl modules though.
                        We have the snmp tools installed. We needed that to use the cisco template builder script that's on this site. Which we used to make templates for our 3750x stack and our 7204vxr npe-g2's. That worked great.

                        Sorry if I'm being dense and not getting what you're saying about the daemons. I thought we needed that for the way we are catching traps and then tossing them over through the zabbix script into zabbix. Either way I remember installing the snmp tools package to get the cisco template builder working.

                        Comment

                        • qix
                          Senior Member
                          Zabbix Certified SpecialistZabbix Certified Professional
                          • Oct 2006
                          • 423

                          #42
                          In your log you showed that starting the snmp deamon works correctly, but strictly speaking you dont neef that for this script.

                          Of course you do need it for trap handeling, but that is unrelated.


                          Weird that the script did work for your catalysts. Can you do a normal snmpwalk from the zabbix macine to the Juni?
                          With kind regards,

                          Raymond

                          Comment

                          • cheezus
                            Member
                            • Nov 2011
                            • 35

                            #43
                            Originally posted by qix
                            In your log you showed that starting the snmp deamon works correctly, but strictly speaking you dont neef that for this script.

                            Of course you do need it for trap handeling, but that is unrelated.


                            Weird that the script did work for your catalysts. Can you do a normal snmpwalk from the zabbix macine to the Juni?
                            It was a different script, one for cisco devices and not this particular one.

                            snmpwalk seems fine:

                            [root@zenoss mibs]# snmpwalk -v 2c -c public 10.10.254.2 SNMPv2-MIB::sysContact.0
                            SNMPv2-MIB::sysContact.0 = STRING: [email protected]
                            [root@zenoss mibs]#

                            Comment

                            • netmon_
                              Junior Member
                              • Apr 2012
                              • 1

                              #44
                              For some reason I cannot post to the wiki.
                              Maybe someone else can post this update to the zload_snmpwalk wiki entry?


                              I've updated the previous versions to 1.2.
                              Changes:
                              - No DB Connect in Test Mode
                              - Description is taken from MIB if available (only first line)
                              - OID is used as Item Key (not Description)


                              Code:
                              #!/usr/bin/perl
                              ####################################
                              #
                              #       zload_snmpwalk
                              #   Version 1.2
                              #       Author: Steven Dossett
                              #               Dennis Ploeger
                              #               Nicola Canepa
                              #       Email: sd at panath.com
                              #              develop at dieploegers.de
                              #              nicola.canepa.74 at gmail.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...
                              #
                              # The XML-part has been tested with ZABBIX 1.4.2. I don't know, if it works
                              # from the beginning of 1.4
                              #
                              # 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 (prior 1.4) 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.
                              #
                              # For Zabbix 1.4 use the following workflow:
                              #
                              # 1 - Create a new host template and note the name.
                              # 2 - Run the script with the -x Option to output XML
                              # 3 - Check, if the XML looks valid and remove items you don't want to import
                              # 4 - Switch over to the WEB ui and use the XML importer to import the file
                              #
                              use Getopt::Std;
                              use DBI;
                               
                              use strict;
                              use vars qw($PROG $VERSION $community $host $mib $usagetxt %OPTS
                                      $dbhost $dbuser $dbpass $zabbix_db $zabbix_id $translate $dbh
                                      $zabbix_port $zabbix_delay $zabbix_history $zabbix_trends
                                      $TEST $mode $debug $zabbix_right $zabbix_type);
                               
                              $VERSION = "1.0";
                              $PROG = "zload_snmpwalk";
                               
                              $usagetxt = qq {
                              USAGE:
                               $PROG [OPTIONS] <community> <zabbix_id> <agent> <oid>
                               $PROG [OPTIONS] <community> <zabbix_id> <file>
                               
                              Version: $VERSION
                              snmpwalk the target <agent> from the starting <oid> and then store the results
                              in the ZABBIX template <zabbix_id>. Alternatively, a <file> containing the
                              output of a previous snmpwalk can be used. The data is expected in the format
                              generated by 'smpwalk -Of' and should be generated using the appropriate MIB(s)
                              so that meaningful descriptions can be created for ZABBIX. Without using a
                              MIB, the attempt will likely fail as the descriptions used for ZABBIX keys will
                              be duplicated.
                              Be sure to test your data with the -T option first!
                              For Zabbix > 1.4 a XML-output suitable for importing over the WEB frontend is supported (-x).
                              To use it, specify the hosts name rather than the hosts id as <zabbix_id>.
                               
                              BASIC ENVIRONMENT REQUIREMENTS:
                              Zabbix 1.1alpha6        - Not tested with any other versions.
                              perl                    - Tested with 5.8.0
                              Mysql & perl DBI        - Might work with postgres after minor changes.
                              net-snmp                - Tested with net-snmp 5.0.8
                               
                              PRIMARY ARGUMENTS:
                              <community>     SNMP community string
                              <dbuser>        DB user that can update ZABBIX tables
                              <dbpasswd>      DB password for the user
                              <zabbix_id>     Zabbix template id for a template created from the UI
                               
                              DATA SOURCES:
                              <agent>         Target SNMP host/agent
                              <oid>           Beginning oid - example: .iso.org.dod.internet.private
                                      OR
                              <file>          File containing snmpwalk data in '-Of' format to be loaded
                               
                              OPTIONS:
                                      -T              Test Mode. No DB updates and no DB connection - just view the new records.
                                      -v 1|2c|3       SNMP version
                                      -m MIB[:...]    load given list of MIBs (ALL loads everything)
                                      -p port         SNMP port, default is 161
                                      -x              Output XML suitable for import rather than doing SQL.
                                      -D              Output debugging information
                               
                                Database or ZABBIX data related options:
                                      -r delay        SNMP polling delay, default is 60
                                      -h history      How long to keep polling history, default is 7
                                      -t trends       How long to keep polling trends, default is 365
                                      -s server       Database server, default is localhost
                                  -R num          Use num indexes from the right as the description (default: 2)
                                      -d database   Database, default is zabbix
                                      -u user         Database-user
                                      -P password     Database-password
                              };
                               
                              sub connect_db {
                                      my $db = "DBI:mysql:$zabbix_db:$dbhost";
                                      $dbh = DBI->connect($db, $dbuser, $dbpass) ||
                                              die "Can't connect to DB: $dbh->errstr\n";
                                      $dbh->{AutoCommit} = 0;
                              }
                               
                              sub get_zabbix_description
                              {
                                      my $raw_oid = shift(@_);
                                      my $desc;
                              
                                      # let's get the description from the MIB
                                      foreach my $line (`$translate -Td $raw_oid`) {
                                        # we'll only use the first line of the description 
                                        $desc = $1 if($line =~ m/.*DESCRIPTION(.*)/g);
                                      }
                              
                              	# replace " and tabulators 
                                      if ($desc) {
                                              $desc =~ s/["\t]*//g;
                                      }
                              
                                      # if we couldn't get a description from the MIB we'll use the old way..
                                      if (!$desc) {
                                              print "DEBUG:\n\tcouldnt get description for\n\t\traw_oid:$raw_oid" if($debug);
                                           my $pos;
                                           # Step back 2 positions for a description string and key
                                           $pos = length($raw_oid);
                                           for (my $i=0; $i<$zabbix_right;$i++) {
                                              $pos = rindex($raw_oid,'.', $pos - 1);
                                           }
                                           $desc = substr($raw_oid, $pos + 1);
                                      }
                              
                                      return $desc;
                              }
                               
                              sub get_zabbix_oid
                              {
                                      my $raw_oid = shift(@_);
                                      my $zabbix_oid = `$translate $raw_oid`;
                                      chomp($zabbix_oid);
                                      return $zabbix_oid;
                              }
                               
                              sub get_zabbix_value_type
                              {
                                      my $snmp_type = shift(@_);
                                      my $zabbix_value_type;
                               
                                      # Zabbix types
                                      # 0 = Numeric
                                      # 1 = Character
                                      # Add additional character types as needed. More are needed..
                                      SWITCH:
                                      {
                                              if ($snmp_type eq "STRING")
                                                      { $zabbix_value_type = 1;  last SWITCH; }
                                              $zabbix_value_type = 0;
                                      }
                               
                                      return $zabbix_value_type;
                              }
                               
                              sub usage
                              {
                                      print $usagetxt;
                                      exit 0;
                              }
                               
                              MAIN:
                              $| = 1; # no print delay
                               
                              my $input;
                              my $sql;
                              my $tcounter = 0;
                               
                              if (!getopts('d:h:m:p:r:s:t:u:v:Txu:P:R:D', \%OPTS))
                              {
                                      usage();
                              }
                               
                               
                              if (@ARGV == 3 || @ARGV == 4)
                              {
                                      $TEST = exists($OPTS{T}) ? "1" : "0";
                               
                                      $community = $ARGV[0];
                                      $dbuser = exists($OPTS{u}) ? ($OPTS{u}) : "";
                                      $dbpass = exists($OPTS{P}) ? ($OPTS{P}) : "";
                                      $zabbix_id = $ARGV[1];
                               
                                      $dbhost = exists($OPTS{s}) ? ($OPTS{s}) : "localhost";
                                      $zabbix_db = exists($OPTS{d}) ? ($OPTS{d}) : "zabbix";
                               
                                      $zabbix_port = exists($OPTS{p}) ? ($OPTS{p}) : "161";
                                      $zabbix_delay = exists($OPTS{r}) ? ($OPTS{r}) : "60";
                                      $zabbix_history = exists($OPTS{h}) ? ($OPTS{h}) : "7";
                                      $zabbix_trends = exists($OPTS{t}) ? ($OPTS{t}) : "365";
                               
                                      $translate = "snmptranslate -Ofn ";
                                      $translate .= exists($OPTS{m}) ? ("-m $OPTS{m} ") : "";
                               
                                      $mode = exists($OPTS{x}) ? 'xml' : 'sql';
                                      $debug = exists($OPTS{D}) ? 1 : 0;
                               
                                  $zabbix_right = exists($OPTS{R}) ? ($OPTS{R}) : 2;
                               
                                      # Input from file by default, might change below
                                      $input = "<$ARGV[2]";
                              }
                              else
                              {
                                      usage();
                              };
                               
                              if ($OPTS{v} eq "1") {
                               
                                  $zabbix_type = 1;
                               
                              } elsif ($OPTS{v} eq "2c") {
                               
                                  $zabbix_type = 4;
                               
                              } elsif ($OPTS{v} eq "3") {
                               
                                  $zabbix_type = 6;
                               
                              }
                               
                              # Data from live snmpwalk
                              if (@ARGV == 4)
                              {
                                      $host = $ARGV[2];
                               
                                      $input = "snmpwalk -c $community ";
                                      $input .= exists($OPTS{m}) ? ("-m $OPTS{m} ") : "";
                                      $input .= exists($OPTS{v}) ? ("-v $OPTS{v} ") : "";
                                      # Host
                                      $input .= "-Of $host";
                                      $input .= exists($OPTS{p}) ? (":$OPTS{p} ") : ":161 ";
                                      # OID
                                      $input .= "$ARGV[3]|";
                              }
                               
                              if ($mode eq "sql") {
                                if (!$TEST) { 
                                  connect_db();
                               
                                  $sql = $dbh->prepare("INSERT INTO items (type, snmp_community, snmp_oid, snmp_port, hostid, description, key_, delay, history, trends, value_type) VALUES (?,?,?,?,?,?,?,?,?,?,?)");
                                }
                              } else {
                               
                                  my $date = `date +%d.%m.%y`;
                                  my $time = `date +%H:%M`;
                               
                                  chop($date);
                                  chop($time);
                               
                                  print '<zabbix_export version="1.0" date="'.$date.'" time="'.$time.'">'."\n";
                                  print "\t<hosts>\n";
                                  print "\t\t".'<host name="'.$zabbix_id.'">'."\n";
                                  print "\t\t\t<status>3</status>\n";
                               
                              }
                               
                              open(SWALK,$input) or die "Can't open $input\n";
                               
                              if ($debug) { print "Processing Data from $input "; }
                               
                              while(my $line = <SWALK>)
                              {
                                      my $zabbix_value_type;
                                      my $zabbix_description;
                                      my $zabbix_oid;
                               
                                      next if ($line !~ /(.iso.org.dod.*) = (.*):/ );
                                      #$1 = oid string to translate
                                      #$2 = integer, string or other snmp type
                                      #More snmp "character" types should be added
                               
                                      $zabbix_description = get_zabbix_description($1);
                                      $zabbix_oid = get_zabbix_oid($1);
                                      $zabbix_value_type = get_zabbix_value_type($2);
                               
                               
                                      if ($TEST)
                                      {
                                              if (($tcounter++ % 10) == 0)
                                              {
                                                      print "\ntype\tsnmp_community\tsnmp_oid\tsnmp_port\t",
                                                              "hostid\tdescription\tkey_\tdelay\t",
                                                              "history\ttrends\tvalue_type\n";
                                              }
                              		$zabbix_description = "'".$zabbix_description."'";
                                              print "$zabbix_type\t$community\t$zabbix_oid\t$zabbix_port\t",
                                                      "$zabbix_id\t$zabbix_description\t",
                                                      "$zabbix_oid\t$zabbix_delay\t",
                                                      "$zabbix_history\t$zabbix_trends\t",
                                                      "$zabbix_value_type\n";
                                      }
                                      elsif ($mode eq 'sql')
                                      {
                                              print "." if (($tcounter++ % 10) == 0 );
                              		$zabbix_description = "'".$zabbix_description."'";
                                              $sql->execute($zabbix_type, $community, $zabbix_oid, $zabbix_port,
                                              $zabbix_id, $zabbix_description, $zabbix_oid,
                                              $zabbix_delay, $zabbix_history, $zabbix_trends,
                                              $zabbix_value_type) || die "Insert Failure: $sql->strerror\n";
                                      } else {
                               
                                              # Output XML
                               
                                              print "\t\t\t<groups><group>Templates</group></groups>\n";
                                              print "\t\t\t<items>\n";
                                              print "\t\t\t".'<item type="'.$zabbix_type.'" key="'.$zabbix_oid.'" value_type="'.$zabbix_value_type.'">'."\n";
                                              print "\t\t\t\t<description>$zabbix_description</description>\n";
                                              print "\t\t\t\t<delay>$zabbix_delay</delay>\n";
                                              print "\t\t\t\t<history>$zabbix_history</history>\n";
                                              print "\t\t\t\t<trends>$zabbix_trends</trends>\n";
                                              print "\t\t\t\t<snmp_community>$community</snmp_community>\n";
                                              print "\t\t\t\t<snmpv3_securityname>$community</snmpv3_securityname>\n";
                                              print "\t\t\t\t<snmpv3_securitylevel>0</snmpv3_securitylevel>\n";
                                              print "\t\t\t\t<snmpv3_authpassphrase></snmpv3_authpassphrase>\n";
                                              print "\t\t\t\t<snmpv3_privpassphrase></snmpv3_privpassphrase>\n";
                                              print "\t\t\t\t<snmp_oid>$zabbix_oid</snmp_oid>\n";
                                              print "\t\t\t\t<snmp_port>$zabbix_port</snmp_port>\n";
                                              print "\t\t\t</item>\n";
                                              print "\t\t\t</items>\n";
                               
                                      }
                              }
                              close(SWALK);
                               
                              if ($mode eq "sql") {
                               
                                  $dbh->commit();
                                  $dbh->disconnect();
                               
                              } else {
                               
                                  print "\t\t</host>\n";
                                  print "\t</hosts>\n";
                                  print "</zabbix_export>\n";
                               
                              }
                               
                              if ($debug) { print "Finished\n"; }
                              exit 0;

                              Comment

                              • douglastl
                                Junior Member
                                • Jul 2015
                                • 1

                                #45
                                zload_snmpwalk doesn`t work

                                Hi guys,

                                i know some guy edited the script before.

                                Someone could send an email for me with the edited script?

                                I have the version 2.2.9 of zabbix. And i can`t install snmpbuilber.

                                Thanks a lot.

                                Comment

                                Working...