
- I am old, and writing in Perl brings back memories of my youthful glory days.
- I am stubborn, and they said Perl wasn't the right tool for this job so I had to prove them wrong.
- It underscores the flexibility of the Orion API—if your programming language supports REST, then you can use it.
- I have a custom property called "Polling_Level"
- The "Polling_Level" values and their availability (in seconds) / statistics (in minutes) frequency are:
- Decommissioned (600/60)
- Training (300/30)
- Build (300/15)
- Dev (120/15)
- Prod-Sev-5 (300/10)
- Prod-Sev-4 (240/5)
- Prod-Sev-3 (120/5)
- Prod-Sev-2 (60/2)
- Prod-Sev-1 (30/2)
- Scrutiny (10/1)
$response = $client->POST('/SolarWinds/InformationService/v3/Json/'.$clienturi, $newpolljson, {"Content-Type"=>"application/json"} );
- The URI of the object you want to update, including the SolarWinds Information Service (SWIS) prefix
- The value(s) you want to set the object to
- The content-type
- "/SolarWinds/InformationService/v3/Json/" plus the URI of the node (which is the variable $clienturi in my sample code)
- The field StatCollection set to a certain number of minutes, and the field PollInterval set to a certain number of seconds
- The content type is "application/json." Period. No decisions here, it just has to be included for the command to work.
- '/SolarWinds/InformationService/v3/Json/'.$clienturi combines (concatenates) the $clienturi variable with the SWIS prefix elements
- To create an array of values to update, the format in Perl is: '
StatCollection'=>"5", "PollInterval"=>"60"
(SEE NOTE BELOW) - The content type gets enclosed in French brackets like this:
{Content-Type"=>"application/json"}
%newpollvalue = ('StatCollection'=>"5", "PollInterval"=>"60");
my $newpolljson = encode_json \%newpollvalue;
use REST::Client;
my $client = REST::Client->new();
use MIME::Base64;
encode_base64("$username:$password", ''));
use Crypt::RC4;
use URI::Encode qw(uri_encode);
uri_encode($query));
use JSON::Parse ':all';
parse_json $client->responseContent();
use JSON;
my $newpolljson = encode_json \%newpollvalue;
- The quick and dirty way that makes security professionals weep and likely gets you in trouble with the auditors.
- The safe and correct way that will let you (and your company) sleep easier at night knowing you haven’t thrown the gates of security wide open to the ravenous hordes of hackers that lurk just outside.
my $username = 'knightswhosayni';
my $password = 'icky-icky-ptang-ptang';
my $hostname = '10.110.69.72';
my $client = REST::Client->new();
$client->getUseragent()->ssl_opts(verify_hostname => 0);
$client->getUseragent()->ssl_opts(SSL_verify_mode => 'SSL_VERIFY_NONE');
$client->setHost('https://' . $hostname . ':17778');
$client->addHeader('Authorization', 'Basic ' . encode_base64("$username:$password", ''));
$keyfile = "swkeyfile.txt";
open($fh1, '<', $keyfile) or die "Could not open file '$keyfile' $!";
while ($row = <$fh1>) {
chomp $row;
$key=$row;
}
close $fh1;
$hashfile = "swhashfile.txt";
open($fh2, '<', $hashfile) or die "Could not open file '$hashfile' $!";
while ($row = <$fh2>) {
chomp $row;
$enc_hash=$row;
}
close $fh2;
$decoded = decode_base64($enc_hash);
$swpassword = RC4($key, $decoded);
#Set up the REST connection to the server
$client = REST::Client->new();
$client->getUseragent()->ssl_opts(verify_hostname => 0);
$client->getUseragent()->ssl_opts(SSL_verify_mode => 'SSL_VERIFY_NONE');
$client->setHost('https://' . $hostname . ':17778');
$client->addHeader('Authorization', 'Basic ' . encode_base64("$username:$swpassword", ''));
#!/usr/bin/perl
use strict;
use warnings;
use Crypt::RC4;
use MIME::Base64;
use Bytes::Random::Secure qw(random_bytes random_bytes_base64 random_bytes_hex);
#see metacpan.org/.../Secure.pm for full usage
#Generate random key and store it in a file
my $keyfile = "swkeyfile.txt";
my $key = random_bytes(32); # A string of 32 random bytes.
open(my $fh1, '>', $keyfile) or die "Could not open file '$keyfile' $!";
print $fh1 $key;
close $fh1;
#Now take the SolarWinds user password and encrypt it using the key
my $swpassword = "YOUR PASSWORD GOES HERE";
my $encrypted = RC4($key, $swpassword);
my $encoded = encode_base64($encrypted);
my $hashfile = "swhashfile.txt";
open(my $fh2, '>', $hashfile) or die "Could not open file '$hashfile' $!";
print $fh2 $encoded;
close $fh2;
- The Orion SDK forum on THWACK
: https://thwack.solarwinds.com/community/resources/orion-sdk
- The Orion SDK repository on Github: https://github.com/solarwinds/OrionSDK
- The Orion SDK Wiki: https://github.com/solarwinds/OrionSDK/wiki