The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Net::SolarWinds::REST - SolarWinds Rest interface

SYNOPSIS

use strict;
use warnings;
use Net::SolarWinds::REST;
use Data::Dumper;

my $rest=new Net::SolarWinds::REST();

my $result=$rest->DiscoverInterfacesOnNode(444);

if($result) {
  print Dumper($result->get_data);
} else {
  print $result,"\n";
}

DESCRIPTION

Anyone who has used SOAP::Lite to try to interface with solarwinds knows how difficult and frustrating it can be. This collection of modules provides a restful interface to SolarWinds. Methods provided are tested and working in the Charter Communcations production enviroment.

GLOBAL OBJECTS

  • $Net::SolarWinds::REST::JSON

    This is a JSON object with the following options endabled: JSON->new->allow_nonref->utf8

  • my $json=$class->get_json;

    Returns the class level JSON object.

  • $Net::SolarWinds::REST::UA

    This is a LWP::UserAgent used to talk to CPM servers

  • my $ua=$class->get_ua;

    Returns the Class level UA object.

Class Constants

The following constants are accessable via: Net::SolarWinds::REST->CONSTANT

DEFAULT_USER=>'admin';
DEFAULT_PASS=>'ChangeMe';
DEFAULT_SERVER=>'SolarWindsServer';
DEFAULT_PORT=>17778;
DEFAULT_PROTO=>'https';
BASE_URI=>'%s://%s:%i/SolarWinds/InformationService/v3/Json/%s';
LOG_CLASS=>'Net::SolarWinds::Log';

OO Methods

This section covers the OO Methods of the class.

  • Object Constructor.

    The object constructor takes key=>value pairs all aguments are optional, default values are pulled from the constants DEFAULT_*.

    my $sw=new Net::SolarWinds::REST(
      USER   =>'User',
      PASS   =>'Passxxx',
      SERVER =>'SolarwindsServer',
      PORT   =>17778,
      PROTO  =>'https',
      # Logging is not enabled by default!
      log=>  Net::SolarWinds::Log->new('/var/log/Solarwinds.log')
    );
  • my $request=$self->build_request('GET|POST|PUT|DELETE',$path,undef|$ref);

    Creates an HTTP::Request object with the default options set.

  • my $request=$self->NodeUnmanage($nodeID,$start,$end,$state);

    Used to manage and unmanage a node.

    Optional Arguments: $start '11/18/2015 11:37:25' $end '11/20/2015 11:37:25' $state To Manage: JSON::false To UnManage: JSON::true

    Default interal values are

    $start=now
    $end=now + 10 years
    $state=JSON::true
  • my $now=$self->now_timestamp;

    Returns a timestamp of now.

  • my $future=$self->future_timestamp;

    Returns a timestamp of 10 years for now ( plus or minus a few seconds )

  • my $result=$self->run_request($request);

    Takes a given HTTP::Request object and runs it returing a Net::SolarWinds::Result object. What the object contains is relative to the request run.. If the result code of the request was not a 20x value then the object is false.

  • my $result=$self->DiscoverInterfacesOnNode($nodeId)

    Returns a Net::SolarWinds::Result Object: When true it contains the results, when false it contains the error.

  • my $result=$self->DiscoverInterfaceMap($nodeId);

    Returns a Net::SolarWinds::Result object:

    When true it contains an anonymous hash that maps interface objects to interface names. When false it contains why it failed.

  • my $result=$self->build_interface_result_map($result);

    Internals of DiscoverInterfaceMap

  • my @names=$self->InterfaceCaptionTranslation($Caption);

    Takes an interface caption and converts it to a list of valid interface names that should match what is on a given device.

  • my $result=$self->NodeInterfaceAddDefaultPollers($nodeId,$interfaec_ref);

    Returns a Net::SolarWinds::Result Object: When true it contains the results, when false it contains the error. $interface_ref represents object listed from the DiscoverInterfacesOnNode that need to be added to the default pollers.

  • my $result=$self->NodeAddInterface($node_id,[$interface]);

    Adds an interface to the cpm for the node but does not add any pollers.

  • my $result=$self->NodeInterfaceCustomProperties($nodeId,$interfaceId,$hash_ref|undef);

    Used to get or set custom properties of an interfaec on a node. Returns a Net::SolarWinds::Result Object: When true it contains the results, when false it contains the error.

  • my $query=$self->query_finder(@args);

    Returns formatted SWQL query within a given function. It finds the corrisponding constant via the $self->LOG_CLASS->lookback(2) call back.

  • my $prepared=$self->prepare_query($query,@args);

    Just a wrapper for: sprintf $query,@args

  • my $raw_query=$self->get_query($method);

    Does an internal method lookup of SWQL_$method and returns the results of the method

  • my $result=$self->getInterfacesOnNode($NodeID);

    Returns a Net::SolarWinds::Result Object

    when true: Gets the interfaces from the node when false: returns why it failed

  • my $result=$self->GetAlertSettings($nodeid);

    Returns a Net::SolarWinds::Result Object

    when true: Contains the list of Orion.ForecastCapacity, for the given node when false: returns why it failed

  • my $result=$self->NodeCustomProperties($nodeId,$hash_ref|undef);

    Used to get or set custom properties of a node. Returns a Net::SolarWinds::Result Object: When true it contains the results, when false it contains the error.

  • my $result=$self->Query($sql);

  • my $result=$self->Query({"query"=>"SELECT Uri FROM Orion.Pollers WHERE PollerID=@p ORDER BY PollerID WITH ROWS 1 TO 3 WITH TOTALROWS","parameters"=>{"p"=>9}});

    Used to run an sql query against CPM. Returns a Net::SolarWinds::Result Object: When true it contains the results, when false it contains the error.

  • my $result=$self->BulkUpdate({uris=>["swis://dev-che-mjag-01./Orion/Orion.Nodes/NodeID=4/Volumes/VolumeID=1", "swis://dev-che-mjag-01./Orion/Orion.Nodes/NodeID=4/Volumes/VolumeID=2", "swis://dev-che-mjag-01./Orion/Orion.Nodes/NodeID=4/Volumes/VolumeID=3"],properties=>{"NextPoll"=>"7/1/2014 9:06:19 AM","NextRediscovery"=>"7/1/2014 2:59:09 PM"}});

    Used to update uris in bulk, returns a Net::SolarWinds::Result object.

  • my $result=$self->BulkDelete({uris=>["swis://dev-che-mjag-01./Orion/Orion.Nodes/NodeID=4/Volumes/VolumeID=1", "swis://dev-che-mjag-01./Orion/Orion.Nodes/NodeID=4/Volumes/VolumeID=2", "swis://dev-che-mjag-01./Orion/Orion.Nodes/NodeID=4/Volumes/VolumeID=3"]});

    Used to delete uris in bulk, returns a Net::SolarWinds::Result object.

  • my $result=$self->getNodesByIp($ip);

    Find a list of nodes by a given ip. Returns a Net::SolarWinds::Result Object: When true it contains an array ref of the results, when false it contains the error.

  • my $result=$self->getNodesByDisplayName($hostname);

    Find a list of nodes by a given hostname. Returns a Net::SolarWinds::Result Object: When true it contains an array ref of the results, when false it contains the error.

  • my $result=$self->getNodesByID($nodeid);

    Returns a Net::SolarWinds::Result object that contains a list of objects that matched that nodeid

  • my $result=$self->createNode(key=>value);

    Creates a node. Returns a Carter::Result Object: Retuns a data structure on sucess returns why it faield on false.

    Note, there are no presets when using this method!

  • my $result=$self->createNode(key=>value);

    Creates a node. Returns a Carter::Result Object: Retuns a data structure on sucess returns why it faield on false.

    # the defautl key/value list is
      qw(
        ObjectSubType      SNMP
        EntityType         Orion.Nodes
        DynamicIP          false
        EngineID           1
        Status             1
        UnManaged          false
        Allow64BitCounters true
        ObjectSubType      SNMP
        SNMPVersion        2
        Community          public
        VendorIcon         8072.gif
        NodeDescription    Hardware
    
      ),
        IOSImage=>"",
        IOSVersion=>"",
        Pollinterval=>60,
        SysObjectID=>"1.3.6.1.4.1.8072.3.2.10",
        MachineType=>"net-snmp - Linux",
        StatCollection=>10,
        CPULoad=>"-2",
        MemoryUsed=>"-2",
        PercentMemoryUsed=>"-2",
        BufferNoMemThisHour=>"0",
        BufferNoMemToday=>"0",
        BufferSmMissThisHour=>"0",
        BufferSmMissToday=>"0",
        BufferMdMissThisHour=>"0",
        BufferMdMissToday=>"0",
        BufferBgMissThisHour=>"0",
        BufferBgMissToday=>"0",
        BufferLgMissThisHour=>"0",
        BufferLgMissToday=>"0",
        BufferHgMissThisHour=>"0",
        BufferHgMissToday=>"0",
  • my $result=$self->getNodeUri($node_id);

    When true the Net::SolarWinds::Result object contains the node uri. When false it contains why it failed.

  • my $result=$self->deleteSwis($uri);

    Returns a charter result object showing status.

  • my $result=$self->deleteNode($node_id);

    Deletes a given node.

  • my $result=$self->getApplicationTemplate(@names);

    This is a wrapper for the Query interface. Returns the results that match applications by this name.

  • my $result=$self->addTemplateToNode($node_id,$template_id);

  • my $result=$self->addTemplateToNode($node_id,$template_id,$cred_id);

    Adds a monitoring template with the default credentals to the node. Returns true on success false on failure.

  • my $result=$self->getTemplatesOnNode($node_id);

    Returns a Net::SolarWinds::Result object When true it contains the templates on the node when false it contains why it failed.

  • my $result=$self->UpdateNodeProps($nodeID,key=>values);

    Has 2 use cases Read/Write: When called with just the $nodeID the result object is populated with the node properties. When called with a hash the given values are pushed to the node. Returns a Net::SolarWinds::Result object: true on success false on failure.

  • my $result=$self->AddPollerToNode($nodeID,$Poller);

    Adds a poller to a node.

  • my $result=$self->add_poller($node_id,$t,$poller)

    Returns a Net::SolarWinds::Result object when true it returns the result information that shows the results of the poller being added.

  • my $result=$self->add_volume(key=>value);

    Creates a volume given the arguments passed in.

    Returns a Net::SolarWinds::Result object: When false it contains why it failed When true it returns a swis uri

  • my $result=$self->getVolumeTypeMap;

    Returns a Net::SolarWinds::Result Object When true Returns the volume type map. When false it returns why it failed.

  • my $result=$self->getEngines;

    Returns a Net::SolarWinds::Result object: When true it contains the list of poller engins. When false it contains why it failed.

  • my $result=$self->getEngine($engine);

    Returns a Net::SolarWinds::Result Object: When true it contains the list of matching engines. When false it cointains why it failed.

    Notes: if no matching engines were found the result object can be true.. but will not contain any data.

  • my $result=$self->getVolumeMap($nodeID);

    Returns a Net::SolarWinds::Result object: When true it contains a hash that maps volumes to objects. When false it returns why it failed.

  • my $result=$self->getSwisProps($uri);

    Returns a Net::SolarWinds::Result object: When true it the uri is set in the result hash when false the explanation as to why it failed is gven.

  • my $result=$self->GetNodePollers($node_id,"N|V|I");

    Returns a Net::SolarWinds::Result Object that contains the nodes when true when false it contains why it failed.

  • my $result=$self->UpdateUri($uri,%args);

    Read/Write Interface used update or get the contents of $uri. Returns a Net::SolarWinds::Result object. Write Mode is used when %args contains values Read Mode is used when %args is empty

SEE ALSO

Net::SolarWinds::REST::Batch

AUTHOR

Michael Shipper

COPYRIGHT AND LICENSE

Copyright (C) 2016 by Mike Shipper

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.1 or, at your option, any later version of Perl 5 you may have available.