5 Replies Latest reply on Oct 2, 2014 10:15 AM by RichardLetts

    Making a node added through the SDK look like one added through the UI.

    RichardLetts

      I'm attempting to add nodes using the Orion SDK; I'd like them to be added to Orion just like they would in the UI (without discovering Interfaces, Volume, or Ports)

       

      When I add a node through the user interface it automatically adds the pollers, sets the 'Vendor', icon, and MachineType, and other properties.

      When I add a node through the SDK, even if I add the generic node pollers I'm not getting these populated (especially the MachineType)

      This is being done through Perl, since our CMDB is stored on a Linux system.

       

      Suggestions?

       

      Thanks

       

      /RjL

        • Re: Making a node added through the SDK look like one added through the UI.
          RichardLetts

          Here is what I came up with:

           

          #!/usr/bin/perl

           

           

          use DBI;

          use XML::Simple;

          use SW::InformationService;

           

           

          use strict;

           

           

          my %vendors = (

            '1.3.6.1.4.1.11.2.3.7.11.18'=>['ProCurve Switch 2512 J4812A','HP','11.gif'],

            '1.3.6.1.4.1.11.2.3.7.11.19'=>['ProCurve Switch 2524 J4813A','HP','11.gif'],

            '1.3.6.1.4.1.11.2.3.7.11.23'=>['ProCurve Switch 4108GL J4865A','HP','11.gif'],

            '1.3.6.1.4.1.11.2.3.7.11.27'=>['ProCurve Switch 4104GL J4887A','HP','11.gif'],

            '1.3.6.1.4.1.11.2.3.7.11.35'=>['ProCurve Switch 2650-PWR','HP','11.gif'],

            '1.3.6.1.4.1.11.2.3.7.11.36'=>['ProCurve Switch 2626-PWR','HP','11.gif'],

            '1.3.6.1.4.1.11.2.3.7.11.50'=>['ProCurve Switch 5406zl J8697A','HP','11.gif'],

            '1.3.6.1.4.1.11.2.3.7.11.8'=>['ProCurve Switch 1600M','HP','11.gif'],

            '1.3.6.1.4.1.11.2.3.7.11.9'=>['ProCurve Switch 4000M','HP','11.gif'],

            '1.3.6.1.4.1.171.10.101.1'=>['D-Link Systems, Inc.','D-Link Systems, Inc.','171.gif'],

            '1.3.6.1.4.1.171.10.67.2'=>['D-Link Systems, Inc.','D-Link Systems, Inc.','171.gif'],

            '1.3.6.1.4.1.171.10.69.3'=>['D-Link Systems, Inc.','D-Link Systems, Inc.','171.gif'],

            '1.3.6.1.4.1.171.10.70.8'=>['D-Link Systems, Inc.','D-Link Systems, Inc.','171.gif'],

            '1.3.6.1.4.1.171.10.70.9'=>['D-Link Systems, Inc.','D-Link Systems, Inc.','171.gif'],

            '1.3.6.1.4.1.171.10.71.1'=>['D-Link Systems, Inc.','D-Link Systems, Inc.','171.gif'],

            '1.3.6.1.4.1.171.10.71.3'=>['D-Link Systems, Inc.','D-Link Systems, Inc.','171.gif'],

            '1.3.6.1.4.1.171.10.71.4'=>['D-Link Systems, Inc.','D-Link Systems, Inc.','171.gif'],

            '1.3.6.1.4.1.202.20.32'=>['SMC','SMC','202.gif'],

            '1.3.6.1.4.1.202.20.33'=>['SMC','SMC','202.gif'],

            '1.3.6.1.4.1.202.20.37'=>['SMC','SMC','202.gif'],

            '1.3.6.1.4.1.202.20.57'=>['SMC','SMC','202.gif'],

            '1.3.6.1.4.1.2636.1.1.1.2.30'=>['Juniper EX3200','Juniper Networks, Inc.','2636.gif'],

            '1.3.6.1.4.1.2636.1.1.1.2.31'=>['Juniper EX4200','Juniper Networks, Inc.','2636.gif'],

            '1.3.6.1.4.1.2636.1.1.1.2.43'=>['Juniper EX2200 Switch','Juniper Networks, Inc.','2636.gif'],

            '1.3.6.1.4.1.2636.1.1.1.2.44'=>['Juniper EX4500 Switch','Juniper Networks, Inc.','2636.gif'],

            '1.3.6.1.4.1.318.1.3.2.10'=>['smartUPS 1400','American Power Conversion Corp.','318.gif'],

            '1.3.6.1.4.1.318.1.3.2.11'=>['smartUPS 2200','American Power Conversion Corp.','318.gif'],

            '1.3.6.1.4.1.318.1.3.2.13'=>['Smart-UPS RT 5000 RM XL','American Power Conversion Corp.','318.gif'],

            '1.3.6.1.4.1.318.1.3.27'=>['American Power Conversion Corp.','American Power Conversion Corp.','318.gif'],

            '1.3.6.1.4.1.318.1.3.2.7'=>['smartUPS 450','American Power Conversion Corp.','318.gif'],

            '1.3.6.1.4.1.318.1.3.2'=>['smartUPS','American Power Conversion Corp.','318.gif'],

          );

           

           

          #SWIS connect

          #database connect

           

           

          my ($ip,$rocid,$query,$query_handle);

           

           

          $query = 'SELECT ip,rocid FROM devices where monitor=true';

          $query_handle = $connect->prepare($query);

          $query_handle->execute();

          $query_handle->bind_columns(\$ip, \$rocid);

           

           

          while($query_handle->fetch) {

           

          #might check if the node is already in Orion

            

            # read the sysObjectOID from the device

            my $oid=&getOID($ip,$rocid);

           

           

            # get the MachineType, Vendor, and VendorIcon

            my ($MachineType, $Vendor,$VendorIcon)=&get_vendor($oid);

           

           

            if (!defined($Vendor)) {

                      # something new

                    print("\n* Add to SolarWinds Orion manually: $ip,$rocid,$oid\n");

                    next;

               } else {

                      print("\n* Adding to SolarWinds Orion\n");

               }

           

           

            my $AddedNode=$swis->Create('Orion.Nodes',

            {'Caption'=>$ip,

            'IPAddress'=>$ip,

            'DynamicIP'=>0,

            'EngineID'=>1,

            'Status'=>1,

            'Allow64BitCounters'=>1,

            'ObjectSubType'=>'SNMP',

            'SNMPVersion'=>2,

            'Community'=>$rocid,

          # 'Comments'=>'Added by noc', # and any other custom properties

            'SysObjectID'=>$oid,

            'MachineType'=>$MachineType,

            'Vendor'=>$Vendor,

            'VendorIcon'=>$VendorIcon,

            'BufferNoMemThisHour'=>-2,

            'BufferNoMemToday'=>-2,

            'BufferSmMissThisHour'=>-2,

            'BufferSmMissToday'=>-2,

            'BufferMdMissThisHour'=>-2,

            'BufferMdMissToday'=>-2,

            'BufferBgMissThisHour'=>-2,

            'BufferBgMissToday'=>-2,

            'BufferLgMissThisHour'=>-2,

            'BufferLgMissToday'=>-2,

            'BufferHgMissThisHour'=>-2,

            'BufferHgMissToday'=>-2

            });

           

           


          # add code to check return, add pollers, and to NCM here

           

            }

           

           

          # database disconnect

          exit(0);

           

           


          # functions

           

           

          sub getOID {

            my $ip=shift;

            my $rocid=shift;

           

           

            my $oid=`snmpget -OnvQ -v 2c -c '$rocid' $ip sysObjectID.0`;

            if ($? == -1) {

                 print "getSysOID failed to execute: $!\n";

                 exit(1);

            } elsif ($? & 127) {

                 printf "getSysOID died with signal %d\n", ($? & 127);

                 exit(1);

            }

            $oid=~s/^\.//;

            chomp $oid;

            return $oid

          }

           

           

           

           


          sub get_vendor {

            my $oid=shift;

           

           

            if (defined($vendors{$oid})) {

                 return ($vendors{$oid}[0],$vendors{$oid}[1],$vendors{$oid}[2]);

            } else {

                 return (undef,undef,undef);

            }

           

           

          }

            • Re: Making a node added through the SDK look like one added through the UI.
              thorumnz

              Where do you get that vendor hash from, and did you ever add the code for the pollers?

                • Re: Making a node added through the SDK look like one added through the UI.
                  RichardLetts

                  I did a query against the soalrwinds database an pulled the values from there.

                  The return values from adding a node includes the nodeid and I determined what type of device it was earlier (in $oid). my code then goes on:

                                  &add_poller($AddedNode,"N.Details.SNMP.Generic");
                                  &add_poller($AddedNode,"N.Uptime.SNMP.Generic");
                  
                                  if (index($oid,"1.3.6.1.4.1.2636")==0) {
                                          &add_poller($AddedNode,"N.Cpu.SNMP.JuniperJunOS");
                                          &add_poller($AddedNode,"N.Memory.SNMP.JuniperJunOS");
                                          &add_poller($AddedNode,'N.Topology_Layer3.SNMP.ipNetToMedia') if (index($oid,'1.3.6.1.4.1.2636.1.1.1.2.18')=
                  =0);
                                          &add_poller($AddedNode,'N.Topology_Layer3.SNMP.ipNetToMedia') if (index($oid,'1.3.6.1.4.1.2636.1.1.1.2.24')=
                  =0);
                                          &add_poller($AddedNode,'N.Topology_Layer3.SNMP.ipNetToMedia') if (index($oid,'1.3.6.1.4.1.2636.1.1.1.2.25')=
                  =0);
                                          &add_poller($AddedNode,'N.Topology_Layer3.SNMP.ipNetToMedia') if (index($oid,'1.3.6.1.4.1.2636.1.1.1.2.57')=
                  =0);
                                  }
                                  if (    (index($oid,"1.3.6.1.4.1.11")==0) ||
                                          (index($oid,"1.3.6.1.4.1.202")==0) ||
                                          (index($oid,"1.3.6.1.4.1.89")==0) ||
                                          (index($oid,"1.3.6.1.4.1.2636")==0) ||
                                          (index($oid,"1.3.6.1.4.1.171")==0)) {
                                     &add_L2_pollers($AddedNode);
                                  }
                  
                  ############ End Main Program
                  
                  
                  sub add_poller{
                          my $node=shift;
                          my $poller=shift;
                  
                          $swis->Create("Orion.Pollers", {
                          'PollerType'=>$poller,
                          'NetObject'=>"N:$node",
                          'NetObjectType'=>'N',
                          'NetObjectID'=>$node
                          });
                  }
                  
                  # really should detect the right MIB support and then turn this on,
                  # for our switches this works
                  sub add_L2_pollers {
                          my ($nodeid)=shift;
                           &add_poller($nodeid,'N.Topology_Layer2.SNMP.Dot1dTpFdbNoVLANs');
                           &add_poller($nodeid,'N.Topology_Layer2.SNMP.Dot1qTpFdbNoVLANs');
                           &add_poller($nodeid,'N.Topology_LLDP.SNMP.lldpRemoteSystemsData');
                           &add_poller($nodeid,'N.Topology_PortsMap.SNMP.Dot1dBaseNoVLANs');
                  }
                  
                  

                  From an API perspective I'd really like to invoke an 'addPollersToNode' to add the correct pollers to a node based on the sysObjectID rather than my less than perfect code.

                  1 of 1 people found this helpful
                • Re: Making a node added through the SDK look like one added through the UI.
                  swapnilm

                  when i am using above script i am getting below error.

                  Global symbol "$connect" requires explicit package name at test.pl line 86.

                  Global symbol "$swis" requires explicit package name at test.pl line 118.

                   

                  When i define $connect,$swis in below line.

                  my ($ip,$rocid,$query,$query_handle,$connect,$swis);

                  I am getting "Can't call method "prepare" on an undefined value at test.pl line 85".

                   

                  Please advice me what i am doing wrong.

                   

                  Thanks.

                    • Re: Re: Making a node added through the SDK look like one added through the UI.
                      RichardLetts


                      You have to replace these two lines


                      #SWIS connect

                      #database connect

                       

                      with the right commands to connect to your Solarwinds server, and your CMDB database that  contans the table 'devices'  table that has at least the following structure:

                      (our CMDB is on postgres)

                      > \d devices

                                          View "public.devices"

                         Column      |            Type           | Modifiers

                      ---------------+---------------------------+-----------

                      ip             | inet                      |

                      monitor        | boolean                   |

                      rocid          | character varying         |

                      ....

                       

                      $query = 'SELECT ip,rocid FROM devices where monitor=true';

                      $query_handle = $connect->prepare($query);


                      The main aim of this example was to show for completeness the attributes you need to set on a node to avoid random errors in the user interface

                      Soapbox...

                      As a programmer I find it disappointing that the database folks at Solarwinds do not like to set default values on database columns.

                      ...xobpaoS