Skip to content

Instantly share code, notes, and snippets.

@softlayer
Created February 9, 2012 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save softlayer/1780685 to your computer and use it in GitHub Desktop.
Save softlayer/1780685 to your computer and use it in GitHub Desktop.
# Create a network monitor
# So we can talk to the SoftLayer API:
import SoftLayer.API
# For nice debug output:
import pprint
pp = pprint.PrettyPrinter(indent=4)
# Your SoftLayer API username and key.
#
# Generate an API key at the SoftLayer Customer Portal:
# https://manage.softlayer.com/Administrative/apiKeychain
apiUsername = 'SET ME'
apiKey = 'SET ME'
# The ID of the server you wish to mointor
serverId = 0
# ID of the query type which can be found with SoftLayer_Network_Monitor_Version1_Query_Host_Stratum/getAllQueryTypes.
# This exmaple uses SERVICE PING: Test ping to address, will not fail on slow server response due to high latency or
# high server load
queryTypeId = 1
# IP address on the previsously defined server to monitor
ipAddress = '127.0.0.1'
# Create an instance of the SoftLayer_Network_Monitor_Version1_Query_Host service
client = SoftLayer.API.Client('SoftLayer_Network_Monitor_Version1_Query_Host', None, apiUsername, apiKey)
# Define the SoftLayer_Network_Monitor_Version1_Query_Host templateObject.
newMonitor = {
'hardwareId': serverId,
'queryTypeId': queryTypeId,
'ipAddress': ipAddress
}
# Send the request for object creation and display the return value
result = client.createObject(newMonitor)
pp.pprint(result)
@renier
Copy link

renier commented Oct 16, 2014

Will hardwareId work if you want to create a monitor for a virtual guest? Or do you have to use guestId instead?

@rurena
Copy link

rurena commented Oct 22, 2014

I can't get the line:
client = SoftLayer.API.Client('SoftLayer_Network_Monitor_Version1_Query_Host', None, apiUsername, apiKey)
to work I get an error about apiKey being a literal instead of a float. I also tried it wit a url at the end:
client = SoftLayer.API.Client('SoftLayer_Network_Monitor_Version1_Query_Host', None, apiUsername, apiKey, url)
can anyone help?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment