Created
January 27, 2014 20:55
-
-
Save bortels/8657137 to your computer and use it in GitHub Desktop.
Add Host Record (A and PTR) to infoblox via WAPI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# Add an IP to infoblox | |
# Note a valid login is required. You can use your own for testing, but for | |
# long term use, please request a svc_ service account for your script. | |
use LWP::UserAgent; | |
use JSON; | |
# We expect a fully-qualified DNS name and IP on the command line | |
$name = shift @ARGV; | |
$ip = shift @ARGV; | |
$comment = join(' ', @ARGV); | |
if (($ip eq '') or ($name eq '')) { | |
print "Syntax: add-ip FQDN IPADDRESS\n"; | |
print "Example: add-ip hello.dca.diginsite.net 1.2.3.4 'Tom's test'"; | |
exit; | |
} | |
# Set up API call | |
my $base_uri = "https://infoblox1.dca.diginsite.net/wapi/v1.2.1/"; | |
my $browser = LWP::UserAgent->new; | |
$browser->credentials( | |
'infoblox1.dca.diginsite.net:443', | |
'InfoBlox ONE Platform', | |
'infoblox-login-name' => 'infoblox-login-password' # Change this to a valid login/password | |
); | |
#Payload | |
my @ipv4addrs = { 'ipv4addr' => $ip }; | |
my %data = (); | |
$data{'name'} = $name; | |
$data{'ipv4addrs'} = \@ipv4addrs; | |
$data{'comment'} = $comment; | |
my $json = encode_json \%data; | |
# Make the call | |
my $req = HTTP::Request->new( 'POST', $base_uri . "record:host" ); | |
$req->header('Content-Type' => 'application/json'); | |
$req->content($json); | |
my $r = $browser->request($req); | |
print "Provisioned $ip as $name ($comment) : " . $r->content; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment