通过 API 将基本监控包添加到虚拟访客

Adding Basic Monitoring Package to Virtual Guest via API

是否可以通过Softlayer添加监控包API。在门户网站上,我可以进入“监控”部分并订购 "Monitoring Package - Basic",这会将其与该虚拟访客相关联。

是否可以在 placeOrder 调用期间或初始 placeOrder 调用之后执行此操作(即,如果客户希望在配置服务器后添加基本监控)。

我试图查看示例,但他们都认为有可用的监视代理,但我的情况并非如此。我还查看了 Going Further with Softlayer part 3 但不确定如何从 Product_Package 服务中提取基本监控包。

我正在使用 Python 执行此操作,因此在创建期间或创建后关联监控服务的任何指示都将非常有帮助。

提前致谢!

试试这个:

"""
Order a Monitoring Package

Build a SoftLayer_Container_Product_Order_Monitoring_Package object for a new
monitoring order and pass it to the SoftLayer_Product_Order API service to order it
In this care we'll order a Basic (Hardware and OS) package with Basic Monitoring Package - Linux
configuration for more details see below

Important manual pages:
https://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Product_Order_Monitoring_Package
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Product_Item_Price
http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/verifyOrder
http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/placeOrder
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Monitoring_Agent_Configuration_Template_Group

License: http://sldn.softlayer.com/article/License
Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
"""

import SoftLayer

USERNAME = 'set me'
API_KEY = 'set me'

"""
Build a skeleton SoftLayer_Container_Product_Order_Monitoring_Package object
containing the order you wish to place.
"""
oderTemplate = {
    'complexType': 'SoftLayer_Container_Product_Order_Monitoring_Package',
    'packageId': 0,  # the packageID for order monitoring packages is 0
    'prices': [
        {'id': 2302}  # this is the price for Monitoring Package - Basic ((Hardware and OS))
    ],
    'quantity': 0,  # the quantity for order a service (in this case monitoring package) must be 0
    'sendQuoteEmailFlag': True,
    'useHourlyPricing': True,
    'virtualGuests': [
        {'id': 4906034}  # the virtual guest ID where you want add the monitoring package
    ],
    'configurationTemplateGroups': [
        {'id': 3}  # the templateID for the monitoring group (in this case Basic Monitoring package for Unix/Linux operating system.)
    ]
}

# Declare the API client to use the SoftLayer_Product_Order API service
client = SoftLayer.Client(username=USERNAME, api_key=API_KEY)
productOrderService = client['SoftLayer_Product_Order']

"""
verifyOrder() will check your order for errors. Replace this with a call to
placeOrder() when you're ready to order. Both calls return a receipt object
that you can use for your records.

Once your order is placed it'll go through SoftLayer's provisioning process.
"""
try:
    order = productOrderService.verifyOrder(oderTemplate)
    print(order)
except SoftLayer.SoftLayerAPIError as e:
    print("Unable to verify the order! faultCode=%s, faultString=%s"
          % (e.faultCode, e.faultString))
    exit(1)

这是创建网络监控的例子

"""
Create network monitoring

The script creates a monitoring network with Service ping
in a determinate IP address

Important manual pages
http://sldn.softlayer.com/reference/services/SoftLayer_Network_Monitor_Version1_Query_Host
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Network_Monitor_Version1_Query_Host

License: http://sldn.softlayer.com/article/License
Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
"""
import SoftLayer.API
from pprint import pprint as pp

# Your SoftLayer API username and key.
USERNAME = 'set me'
API_KEY = 'set me'


# The ID of the server you wish to monitor
serverId = 7698842

"""
ID of the query type which can be found with SoftLayer_Network_Monitor_Version1_Query_Host_Stratum/getAllQueryTypes.
This example 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 previously defined server to monitor
ipAddress = '10.104.50.118'

# Declare the API client
client = SoftLayer.Client(username=USERNAME, api_key=API_KEY)
networkMonitorVersion = client['SoftLayer_Network_Monitor_Version1_Query_Host']

# Define the SoftLayer_Network_Monitor_Version1_Query_Host templateObject.
newMonitor = {
    'guestId': serverId,
    'queryTypeId': queryTypeId,
    'ipAddress': ipAddress
}

# Send the request for object creation and display the return value
try:
    result = networkMonitorVersion.createObject(newMonitor)
    pp(result)
except SoftLayer.SoftLayerAPIError as e:
    print("Unable to create new network monitoring "
          % (e.faultCode, e.faultString))
    exit(1)

此致