Automate Sonus SBC (1000/2000) Management using PowerShell

In previous blog posts I discussed about connecting and querying Sonus SBC using cURL. This article discusses how you can connect to Sonus using PowerShell v3. Please be aware the SBC is already on at least R3.0 and you have created a REST user account. More information can be found here.

Massive thanks to Adrien Pleiss from Sonus who provided most of the examples below.

Define variables

$uxhostname = “1.1.1.1”
$uxusername = “restuser”
$uxpassword = “Password01”

Log on to SBC

$args1 = “Username=$uxusername&Password=$uxpassword”
$url = “https://$uxhostname/rest/login”
Invoke-RestMethod -Uri $url -Method Post -Body $args1 -SessionVariable ps
If the login is successful you will receive 200 OK message as below. If you do not receive 200 OK verify your REST credentials.

Up to this point we have logged on to the Sonus SBC and created a session (in $ps variable) which we can reuse for GET, DELETE, POST, etc. requests.


Up to this point we have logged on to the Sonus SBC and created a session (in $ps variable) which we can reuse for GET, DELETE, POST, etc. requests.

Query the SBC (GET)

Use the code below to perform a GET operation on Sonus SBC

add-type @”
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
public bool CheckValidationResult(
ServicePoint srvPoint, X509Certificate certificate,
WebRequest request, int certificateProblem) {
return true;
}
}
“@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy

#Query System Configuration
$args1 = “”
$url = “https://$uxhostname/rest/system”
Invoke-RestMethod -Uri $url -Method GET -WebSession $ps

You can change $url variable to whatever resource you would like to query.

Create a resource (PUT)

$args1 = “Description=Default SIP Server”
$url = “https://$uxhostname/rest/sipservertable/8”
Invoke-RestMethod -Uri $url -Method PUT -Body $args1 -WebSession $ps

Modify a resource (POST)

$args1 = “Description=Default SIP TOTO”
$url = “https://$uxhostname/rest/sipservertable/8”
Invoke-RestMethod -Uri $url -Method POST -Body $args1 -WebSession $ps

Delete a resource (DELETE)

$args1 = “”
$url = “https://$uxhostname /rest/sipservertable/5”
Invoke-RestMethod -Uri $url -Method DELETE -Body $args1 -WebSession $ps

Backup Sonus SBC

$args1 = “”
$dest = “\backup.tar.gz”
$url = “https://$uxhostname/rest/system?action=backup”
Invoke-RestMethod -Uri $url -Method POST -Body $args1 -WebSession $ps -OutFile $dest

Reboot Sonus SBC

$args1 = “”
$url = “https://$uxhostname/rest/system?action=reboot”
Invoke-RestMethod -Uri $url -Method POST -Body $args1 -WebSession $ps

Scripting with REST

##Basic Handler
$Result = Invoke-RestMethod -Uri $url -Method DELETE -Body $args1 -WebSession $ps
if($Result.contains(“<http_code>200”)) {
# That’s a success !!!
$FinalResult = “Success”
} else {
# That’s failure !!!!
$FinalResult = “Failure”
}
$FinalResult

Leave a Reply

Your email address will not be published. Required fields are marked *

Solve this to prove you are not a bot * Time limit is exhausted. Please reload the CAPTCHA.

Post Navigation