November 23, 2017


Create a Vulnerability Scan Request for a SoftLayer_Virtual_Guest.

This example shows how to create a scan request for a SoftLayer_Virtual_Guest object. First, we'll
retrieve data like accountId, guestId 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 virtual guest you wish to create a scan request
	guestId := 31003555

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

	// Get Account, Virtual_Guest, and Network_Security_Scanner_Request services
	accountService      := services.GetAccountService(sess)
	virtualGuestService := services.GetVirtualGuestService(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 virtual guest.
	guestMask := "id;primaryIpAddress;primaryBackendIpAddress"

	// Call to SoftLayer_Virtual_Guest::getObject in order to get id and ip addresses.
	guest, err := virtualGuestService.Id(guestId).Mask(guestMask).GetObject()
	if err != nil {
		fmt.Printf("\n Unable to get Virtual Guest 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),
		GuestId:   sl.Int(*guest.Id),
		IpAddress: sl.String(*guest.PrimaryIpAddress),

	// Object-Mask in order to get specific data from response.
	scanMask := "accountId;createDate;id;ipAddress;guestId;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