From 53b214c7f953592e86517255895ce510fc430b1f Mon Sep 17 00:00:00 2001 From: Tim Danner Date: Wed, 30 May 2018 10:28:28 -0500 Subject: [PATCH] Add sample code for setting a custom property from perl --- Samples/Perl/query.pl | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Samples/Perl/query.pl b/Samples/Perl/query.pl index c0cb2a600..d724a1a62 100755 --- a/Samples/Perl/query.pl +++ b/Samples/Perl/query.pl @@ -4,15 +4,16 @@ use REST::Client; use MIME::Base64; use URI::Encode qw(uri_encode); +use JSON; use JSON::Parse ':all'; ################################################################################ # Configuration ################################################################################ -my $username = 'domain\username'; # user/pass works too for local SW accounts -my $password = 'password_here'; -my $hostname = 'your_hostname'; +my $username = 'admin'; # user/pass works too for local SW accounts +my $password = ''; +my $hostname = 'tim.swdev.local'; ################################################################################ # Execution @@ -29,7 +30,7 @@ $client->addHeader('Authorization', 'Basic ' . encode_base64("$username:$password", '')); # build query string -my $query = sprintf("SELECT Caption, IPAddress FROM Orion.Nodes WHERE Vendor = '%s'", 'Cisco'); +my $query = sprintf("SELECT Caption, IPAddress, Uri FROM Orion.Nodes WHERE Vendor = '%s'", 'Cisco'); my $response = $client->GET('/SolarWinds/InformationService/v3/Json/Query?query=' . uri_encode($query)); # examine response @@ -46,3 +47,11 @@ print "\n"; } +# Set a custom property on the first node that was returned +my $nodeUri = $results->{results}[0]->{Uri}; +my $nodeCustomPropertiesUri = "$nodeUri/CustomProperties"; +print $nodeCustomPropertiesUri; +my %customProperties = (Comments => "perl test comment"); +$response = $client->POST("/SolarWinds/InformationService/v3/Json/$nodeCustomPropertiesUri", + encode_json \%customProperties, + {'Content-Type' => 'application/json'});