November 23, 2017


Create a Vulnerability Scan Request for a SoftLayer_Hardware_Server.

This example shows how to create a scan request for a SoftLayer_Hardware_Server object. First, we'll
retrieve data like accountId, hardwareId and ipAddress to build a object template and pass it to
SoftLayer_Network_Security_Scanner_Request::createObject method in order to create the scan request.
See below for more details.

Important manual pages:

Author: SoftLayer Technologies, Inc. <>

package main

import (

func main() {
	// SoftLayer API username and key
	username := "set me"
	apikey   := "set me"

	// The id of hardware server you wish to create a scan request
	hardwareId := 438878

	// Create a session
	sess := session.New(username, apikey)

	// Get Account, Hardware_Server, and Network_Security_Scanner_Request services
	accountService     := services.GetAccountService(sess)
	hardwareService    := services.GetHardwareServerService(sess)
	scanRequestService := services.GetNetworkSecurityScannerRequestService(sess)

	// Get SoftLayer_Account object
	account, err := accountService.GetObject()
	if err != nil {
		fmt.Printf("\n Unable to get Account object:\n - %s\n", err)

	// Following mask helps to get the id and ip addresses from hardware server.
	hardwareMask := "id;primaryIpAddress;primaryBackendIpAddress"

	// Call to SoftLayer_Hardware_Server::getObject in order to get id and ip addresses.
	hardware, err := hardwareService.Id(hardwareId).Mask(hardwareMask).GetObject()
	if err != nil {
		fmt.Printf("\n Unable to get Hardware Server object:\n - %s\n", err)

	Build the object template used to make a scan request. The Network_Security_Scanner_Request
	service can scan any Ip Address belonging to your account:
		- Primary Ip Address
		- Primary Backend Ip Address
		- Portable Ip Addresses
		- Static Secondary IPs
	If you have a firewall, SoftLayer's administrative networks need to be allowed for the
	vulnerability scan to be effective. If a firewall is blocking all ports, the report may not
	show any problems even if some exist.
	objectTemplate := datatypes.Network_Security_Scanner_Request{
		AccountId:  sl.Int(*account.Id),
		HardwareId: sl.Int(*hardware.Id),
		IpAddress:  sl.String(*hardware.PrimaryIpAddress),

	// Object-Mask in order to get specific data from response.
	scanMask := "accountId;createDate;id;ipAddress;hardwareId;status[name]"

	// Call to createObject() method to create a scan request.
	scanRequest, err := scanRequestService.Mask(scanMask).CreateObject(&objectTemplate)
	if err != nil {
		fmt.Printf("\n Unable to create a scan request:\n - %s\n", err)

	// Following helps to print the result in json format.
	jsonFormat, jsonErr := json.MarshalIndent(scanRequest,"","     ")
	if jsonErr != nil {


If this article contains any error, or leaves any of your questions unanswered, please help us out by opening up a github issue.
Open an issue