Ad Widget

Collapse

command-line import/export facility dynamic items, triggers and graphs

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DB601
    Member
    • Jun 2010
    • 30

    #31
    NET::SNMP perl help

    hello,

    i'm searching a way to use NET::SNMP in a script to return the name of each OID of NBAR protocols like SNMPwalk does

    I read the perldoc, it's not very clear for me because i don't control very well objects in perl.


    i found this:


    use strict;

    ## Validate the version of Perl

    BEGIN
    {
    die('Perl version 5.6.0 or greater is required') if ($] < 5.006);
    }

    ## Version of the Net::SNMP module

    our $VERSION = v5.2.0;

    ## Load our modules

    use Net::SNMP:ispatcher();
    use Net::SNMP::PDU qw( :ALL );
    use Net::SNMP::Security();
    use Net::SNMP::Transport qw( orts );
    ## Handle importing/exporting of symbols

    use Exporter();

    our @ISA = qw( Exporter );

    our @EXPORT = qw(
    INTEGER INTEGER32 OCTET_STRING OBJECT_IDENTIFIER IPADDRESS COUNTER
    COUNTER32 GAUGE GAUGE32 UNSIGNED32 TIMETICKS OPAQUE COUNTER64 NOSUCHOBJECT
    NOSUCHINSTANCE ENDOFMIBVIEW snmp_dispatcher
    );

    our @EXPORT_OK = qw( snmp_event_loop oid_context_match );

    our %EXPORT_TAGS = (
    asn1 => [
    qw( INTEGER INTEGER32 OCTET_STRING NULL OBJECT_IDENTIFIER SEQUENCE
    IPADDRESS COUNTER COUNTER32 GAUGE GAUGE32 UNSIGNED32 TIMETICKS
    OPAQUE COUNTER64 NOSUCHOBJECT NOSUCHINSTANCE ENDOFMIBVIEW
    GET_REQUEST GET_NEXT_REQUEST GET_RESPONSE SET_REQUEST TRAP
    GET_BULK_REQUEST INFORM_REQUEST SNMPV2_TRAP REPORT )
    ],
    debug => [
    qw( DEBUG_ALL DEBUG_NONE DEBUG_MESSAGE DEBUG_TRANSPORT DEBUG_DISPATCHER
    DEBUG_PROCESSING DEBUG_SECURITY snmp_debug )
    ],
    generictrap => [
    qw( COLD_START WARM_START LINK_DOWN LINK_UP AUTHENTICATION_FAILURE
    EGP_NEIGHBOR_LOSS ENTERPRISE_SPECIFIC )
    ],
    snmp => [
    qw( SNMP_VERSION_1 SNMP_VERSION_2C SNMP_VERSION_3 SNMP_PORT
    SNMP_TRAP_PORT snmp_debug snmp_dispatcher snmp_dispatch_once
    snmp_type_ntop oid_base_match oid_lex_sort ticks_to_time )
    ],
    translate => [
    qw( TRANSLATE_NONE TRANSLATE_OCTET_STRING TRANSLATE_NULL
    TRANSLATE_TIMETICKS TRANSLATE_OPAQUE TRANSLATE_NOSUCHOBJECT
    TRANSLATE_NOSUCHINSTANCE TRANSLATE_ENDOFMIBVIEW TRANSLATE_UNSIGNED
    TRANSLATE_ALL )
    ]
    );

    Exporter::export_ok_tags( qw( asn1 debug generictrap snmp translate ) );

    $EXPORT_TAGS{ALL} = [ @EXPORT_OK ];

    ## Debugging bit masks

    sub DEBUG_ALL() { 0xff } # All
    sub DEBUG_NONE() { 0x00 } # None
    sub DEBUG_MESSAGE() { 0x02 } # Message/PDU encoding/decoding
    sub DEBUG_TRANSPORT() { 0x04 } # Transport Layer
    sub DEBUG_DISPATCHER() { 0x08 } # Dispatcher
    sub DEBUG_PROCESSING() { 0x10 } # Message Processing
    sub DEBUG_SECURITY() { 0x20 } # Security

    ## Package variables

    our $DEBUG = DEBUG_NONE; # Debug mask

    our $DISPATCHER; # Dispatcher instance

    our $BLOCKING = 0; # Count of blocking objects

    our $NONBLOCKING = 0; # Count of non-blocking objects

    BEGIN
    {
    # Validate the creation of the Dispatcher object.

    if (!defined($DISPATCHER = Net::SNMP:ispatcher->instance)) {
    die('FATAL: Failed to create Dispatcher instance');
    }
    }



    How may i use it to have the name of my protocol ??

    Comment

    • dima_dm
      Senior Member
      • Dec 2009
      • 2697

      #32
      14.07.2010 New version (see file cisco_xml.20100714.zip in Comment #5)
      New graphs (Packets per Second for all ports) is added

      Comment

      • Alex_D
        Member
        • Jun 2010
        • 30

        #33
        I had problems with template import in zabbix 1.8.2. At import I receive an error

        Code:
        Error in query [INSERT INTO items (itemid,description,key_,hostid,delay,history,status,type,snmp_community,snmp_oid,value_type,data_type,trapper_hosts,snmp_port,units,multiplier,delta,snmpv3_securityname,snmpv3_securitylevel,snmpv3_authpassphrase,snmpv3_privpassphrase,formula,trends,logtimefmt,valuemapid,delay_flex,params,ipmi_sensor,templateid,authtype,username,password,publickey,privatekey) VALUES (22680,'sysUpTime','sysUpTimeInstance',10054,180*5,5,0,4,'asiacom','1.3.6.1.2.1.1.3.0',3,0,'localhost',161,'sec',1,0,'',0,'','','0.01',Templates,'',0,'','','',0,0,'','','','')] [Unknown column 'Templates' in 'field list']
        Internal zabbix error
        How I can solve this problem?
        I start a script in a following format

        ./cisco_xml.pl Hostname HostIP 75 5 public 5 lab-cisco

        I think that not correctly I transfer parameters to a script, because parametrs in this version of a script are:

        Code:
        Usage: $0 HOSTNAME IP [PORTLOAD] [MEMLOAD] [COMMUNITY] [History] [Trends] [MINUTES] [FocusOn] [FocusedPortMinutes] [NormalPortMinutes] [PortStatus] [GROUPS]\n"
        I use last version of a script. Prompt, please that each parameter there means, except Hostname, HostIP and lab-cisco.

        Comment

        • DB601
          Member
          • Jun 2010
          • 30

          #34
          my idea is to export one of your template from zabbix, and try to import it
          if it works then your problem come from the script (may be you have to complete by some elements of the version 1.8.2)

          Comment

          • Alex_D
            Member
            • Jun 2010
            • 30

            #35
            I have tried to import the built in template 3COM. Import has come to the end successfully. I mean not correctly I use a script....

            Comment

            • colloque
              Member
              • Feb 2010
              • 72

              #36
              Great job dima_dm
              (zabbix version 1.8.3)

              Thanks

              Comment

              • truenegative
                Junior Member
                • May 2010
                • 1

                #37
                Script works great. Thanks! I'm on 1.8.3.

                There's a couple things I'd tweak, but it might just be specific to me. It's almost too much information to have.

                Comment

                • a.yurtaykin
                  Junior Member
                  • Jan 2011
                  • 5

                  #38
                  First of all, thanks Dmitry for your work, you`re really a savior!

                  And some notes:
                  Script using 32-bit counters, so to minitor gigabit ports you should replace them with 64-bit ones.

                  Code:
                  ifHCInOctets(1.3.6.1.2.1.31.1.1.1.6)
                  ifHCInUcastPkts(.1.3.6.1.2.1.31.1.1.1.7)
                  ifHCInMulticastPkts(1.3.6.1.2.1.31.1.1.1.8)
                  ifHCInBroadcastPkts(1.3.6.1.2.1.31.1.1.1.9)
                  ifHCOutOctets(1.3.6.1.2.1.31.1.1.1.10)
                  ifHCOutUcastPkts(1.3.6.1.2.1.31.1.1.1.11)
                  ifHCOutMulticastPkts(1.3.6.1.2.1.31.1.1.1.12)
                  ifHCOutBroadcastPkts(1.3.6.1.2.1.31.1.1.1.13)
                  And second: if your port description has a "<" or ">" symbols you will fail, zabbix won`t accept them cause they broke xml syntax.

                  Comment

                  • dima_dm
                    Senior Member
                    • Dec 2009
                    • 2697

                    #39
                    Originally posted by a.yurtaykin
                    First of all, thanks Dmitry for your work, you`re really a savior!

                    And some notes:
                    Script using 32-bit counters, so to minitor gigabit ports you should replace them with 64-bit ones.

                    Code:
                    ifHCInOctets(1.3.6.1.2.1.31.1.1.1.6)
                    ifHCInUcastPkts(.1.3.6.1.2.1.31.1.1.1.7)
                    ifHCInMulticastPkts(1.3.6.1.2.1.31.1.1.1.8)
                    ifHCInBroadcastPkts(1.3.6.1.2.1.31.1.1.1.9)
                    ifHCOutOctets(1.3.6.1.2.1.31.1.1.1.10)
                    ifHCOutUcastPkts(1.3.6.1.2.1.31.1.1.1.11)
                    ifHCOutMulticastPkts(1.3.6.1.2.1.31.1.1.1.12)
                    ifHCOutBroadcastPkts(1.3.6.1.2.1.31.1.1.1.13)
                    I know this. 64-bit counters will be use in next release (if 64-bit counters is not supported, will be use 32-bit counters).
                    Originally posted by a.yurtaykin
                    And second: if your port description has a "<" or ">" symbols you will fail, zabbix won`t accept them cause they broke xml syntax.
                    Add in
                    $portdesc = $$iftable{$ifdesc.'.'.$port};
                    $portdesc=~s/&/&amp;/g;
                    $portdesc=~s/</_/g;
                    $portdesc=~s/>/_/g;

                    or
                    $portdesc =~ s#[^a-zA-Z0-9_&;]#_#g;
                    Last edited by dima_dm; 14-01-2011, 12:06.

                    Comment

                    • nima0102
                      Senior Member
                      • May 2010
                      • 106

                      #40
                      Originally posted by dima_dm
                      This script build xml configuration file for Zabbix. You can import file Template_<You_Name>.xml in Zabbix server.
                      Hi
                      Thanks a lot for this script.my question is, Does this script generate template or host xml?
                      because when I import generated xml,zabbix detects it as template,because in template list, it's in template category of group not hosts.

                      Thanks in advance

                      Comment

                      • dima_dm
                        Senior Member
                        • Dec 2009
                        • 2697

                        #41
                        Originally posted by nima0102
                        Hi
                        Thanks a lot for this script.my question is, Does this script generate template or host xml?
                        because when I import generated xml,zabbix detects it as template,because in template list, it's in template category of group not hosts.

                        Thanks in advance
                        This script generate template for host. Template is located in host group with name GROUPS from args of scripts.

                        Comment

                        • georgew
                          Member
                          • Mar 2008
                          • 50

                          #42
                          Best add-on award goes to...

                          Dima,

                          You have made me love Zabbix even more! Of course that means I love your script too... I spent days creating templates for large Cisco switches, I used scripts to do it, but nothing as sophisticated as your creation. I can now do in seconds what would take weeks before. I got so much work done so quickly (I created templates for 1300 switches in one day) that I finished my contract early and under budget...

                          I'm in a new environment now with gig and 10gig interfaces, so 32 bit counters are rolling over too fast to capture meaningful data. I know you already said 64 bit counters are coming, but I was wondering if you had an estimate of when they would ship in a release?

                          I'm starting a new job as senior infrastructure engineer, and they have no tools set-up at all, in fact they don't even have IP addresses on half of the Cisco switches! So I have my work cut out for me. My plan is to implement Zabbix here, but not until your 64 bit counters version ships. Is there anything I can do to help? Do you accept cash contributions? Do you need money for pizza and beer? I considered trying to re-write your script, but so far I haven't had the time.

                          Keep up the great work!
                          George

                          Comment

                          • szettervall
                            Junior Member
                            • Feb 2006
                            • 9

                            #43
                            I need 64bit counters as well. I have subscribed to this thread, so let us know when the new version is available =) Thanks.

                            Comment

                            • nima0102
                              Senior Member
                              • May 2010
                              • 106

                              #44
                              I have used this script.with this script I have saved time in adding cisco devices.
                              I have on suggestion:
                              If this script can create host instead template, we do not have to first created template and then create host.we can directly add needed hosts.
                              Is it possible you can add this feature to create host instead of template?

                              Thanks in advance

                              Comment

                              • georgew
                                Member
                                • Mar 2008
                                • 50

                                #45
                                64 bit support

                                As a temporary solution, I'm going to try and hand-edit the XML of the template and see if I can turn the 32 bit OID's into 64 bit OID's.

                                As for template VS host file creation... 90% of the time, I'm working on fixed-function devices, so a template makes a lot more sense than a host. It might be nice to have a host option, but the template is the right thing to create most of the time.

                                Of course I'm speaking from the point of view of someone that manages thousands of similar devices. People running smaller enterprises won't have the same experience that I do.

                                George

                                Comment

                                Working...