API & Integration

Reply
Highlighted

Started working on a PowerShell module

AWahlqvist
Techie
Posts: 5
6207     0

So, I'm very new to Infoblox and just started exploring what it can do and how to use it. I'm a windows-admin so I wont be managing the Infoblox itself, just the data in the zones that end up there.

Therefore I've started on a PowerShell module for managing DNS-records. I would obviously love to add support for other things than DNS, for example interaction with IPAM, but since this will probably be a fairly time consuming task I would like to check if any other windows-admin has already started on this?

You can check what I've done so far at my blog:
http://dollarunderscore.azurewebsites.net/?p=2201

It also contains a link to the code, which is uploaded to PoshCode.Org at:

http://poshcode.org/5044
 

Thanks in advance!

Powershell interface for Infoblox REST API

Adviser
Posts: 194
6208     0

I had a separate thread started a few months ago that had some other functions for interfacing with the API using Powershell.  It looks like these two efforts could be merged if you're willing.

I have a respository on Github if you're okay posted your code there or allowing me to do so.

https://github.com/Infoblox-API/REST-PowerShell

Thank you for replying!

AWahlqvist
Techie
Posts: 5
6208     0

Thank you for replying!

I actually created a repository at Github aswell just after I posted this yesterday, it's at: https://github.com/DollarUnderscore/Infoblox-PowerShell-Module

We should absolutely try to merge our efforts!

IMHO I think it really helps new users when following the general guidelines for building cmdlets. That link is mostly focused on writing them in C# but the basic conecepts apply for "script cmdlets" or "advanced functions" aswell. (naming conventions (Verb+Noun), how to output results (objects), parameters etc.)

It makes new users more comfortable with the functions and makes them easier to find and use right away, at least if they are used to PowerShell. Also, always outputing objects makes it work better together with the rest of the powershell framework. If I for example want to write the output to a file, I just pipe it to the Export-Csv or Out-File cmdlets.

In this case, I think the best thing would be to try to mimic the windows dns cmdlets (for the DNS part of this).
At least if windows admins are the targeted audience :-) (You know we can be a bit slow... right? ;-) )

I noticed you have written quite a lot of code and functions for the infoblox in the "wrapper/Infoblox.ps1". So that will be a running start :-)

cmdlet names

Adviser
Posts: 194
6208     0

I originally thought of using the same naming convention and ultimately decided that putting the "IB-" first made it easier for me to remember I'm working with Infoblox.  I did attempt to keep the rest of the structure consistent (Add, Get, etc).  I'm not significantly invested either way and will go with concensus.  I'm not a regular user of these tools (at least, not like I expect Microsoft admins to be).

I'm definitely with you on simplifying some of the things I tried to do though.  Some functions were put in to help me with testing but I would definitely like to get to a point where I could leverage more of the "built-in" cmdlets.  I think things like the CSV export would be good but I'd prefer to do something that would let it be something we could do in Infoblox importable format rather than just regular CSV.  That's a tough one and will likely require a custom function (but one versus a bunch would be okay).

 

Sounds good!

AWahlqvist
Techie
Posts: 5
6208     0

I put the "IB" after the verb instead, like "Get-IBResourceRecord". So we had kind of the same idea :-)


This is why I need help! I dont have enough experience with Infoblox to know what formats it needs and so on... But I agree with you, a function for exporting data into a Infoblox-native format should absolutely be created, "Export-IBFile" or something :-)

I will speak with my network team here and ask them what formats the Infoblox wants and see if I can come up with something, or make a function that can write to straight to the appliance through the API, or both... :-)

Something that would help me a lot would be to get more examples of how the requests should be formatted, like it's published in this thread. Do you have any resource like that available?

Data formats

Adviser
Posts: 194
6208     0

We have a CSV reference manual that covers all of the varied formats for import/export files.  That may be a better start as it will list all available fields.  In most cases, we'd actually only deal with a subset of the fields for day-to-day tasks.

Let me know how I can help.  I'm still learning how to deal with the API through PowerShell and I'm finding that my biggest issue right now is handling the extensible attributes.  The default serializer doesn't seem to work with it the way I would expect it to so I'm stuck there.

Serializer

AWahlqvist
Techie
Posts: 5
6208     0

I also ran into a problem with the json converter when working with a object containing an array, like the IP-addresses of a host-object.

I ended up doing this to make it work:
$Data = "{`"ipv4addrs`":[{`"ipv4addr`":'$IPv4Address'}],`"name`":'$HostName'}" | ConvertFrom-Json | ConvertTo-Json

Something is definately off...

I might switch over to XML instead of json, which is better suited for PowerShell, but there are more examples of API-calls using json available.

I'll try to dig deeper into this as soon as I have more time!

Using Views

BRose
Techie
Posts: 3
6208     0
I just started working with your modules (Great job). We use "Views" in our environment. I found that when using Add-IBResourceRecordHost it would fail with bad request. I added a parameter for View and added it to the $Data section as well. This allows me to select a view (e.g. internal, external) so it creates the record in the appropriate view. [CmdletBinding()] param( [Parameter(Mandatory=$True, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] $IPv4Address, [Parameter(Mandatory=$True, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] [Alias('name')] $HostName, [Parameter(Mandatory=$True, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] [string] $GridServer, [Parameter(Mandatory = $True, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] [string]$View, [Parameter(Mandatory = $True, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] [System.Management.Automation.PSCredential] $Credential) BEGIN { } PROCESS { $InfobloxURI = "https://$GridServer/wapi/v1.2.1/record:host" $Data = "{`"ipv4addrs`":[{`"ipv4addr`":'$IPv4Address'}],`"name`":'$HostName',`"view`":'$View'}" | ConvertFrom-Json | ConvertTo-Json $WebReqeust = Invoke-WebRequest -Uri $InfobloxURI -Method Post -Body $Data -ContentType "application/json" -Credential $Credential if ($WebReqeust.StatusCode -ne 201) { Write-Error "Request to Infoblox failed for record $HostName!" return } } END { } } Thank you

Re: Using Views

ccrossen
Techie
Posts: 6
6208     0

I'm having problems adding a host record to Infoblox using PowerShell. Was hoping someone could help.

Here's my code in it's simplest form:

 

$InfobloxURI = "https://10.10.3.2/wapi/v1.3/record:host"
$Data = "{`"name`":'servername.domain.com',`"ipv4addrs`":[{`"ipv4addr`":'10.10.3.6'}]}" | ConvertFrom-Json | ConvertTo-Json
$WebReqeust = Invoke-WebRequest -Uri "$InfobloxURI" -Method Post -Body $Data -ContentType "application/json"

 it's erroring out with the following error:

 

Invoke-WebRequest : The remote server returned an error: (400) Bad Request.
At C:\Scripts\ConnectToInfoblox.ps1:44 char:15
+ ... ebReqeust = Invoke-WebRequest -Uri "$InfobloxURI" -Method Post -Body ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

 

Any ideas?

Thanks!

Re: Using Views

ccrossen
Techie
Posts: 6
6208     0

I've resolved my problem. First off, I switched to creating A records rather than Host records.

Here's the code I settled on that works for me. Hopefully this helps someone.

 

$IPv4Address = "10.10.6.100"
$HostName =  "servername.domain.net"
$Credential = Get-Credential
$InfobloxURI = "https://infobloxserver/wapi/v1.3/record:a"
$Data = "{`"ipv4addr`":'$IPv4Address',`"name`":'$HostName',`"view`":'default'}" | ConvertFrom-Json | ConvertTo-Json
$WebReqeust = Invoke-WebRequest -Uri $InfobloxURI -Method Post -Body $Data -ContentType "application/json" -Credential $Credential

Dont' forget to swap out "infobloxserver" in the URI with the name or IP address of your Infoblox Grid Master.

Showing results for 
Search instead for 
Do you mean 

Recommended for You