通过API

时间:2017-03-20 12:23:17

标签: monitoring ibm-cloud-infrastructure

是否可以通过Softlayer API添加监控包。在门户网站上,我可以进入监控部分并订购“监控包 - 基本”,它将与虚拟客户关联。

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

我试图查看示例,但他们都认为有一个监控代理可用,但它不是我的情况。我也研究了Going Further with Softlayer part 3但不确定如何从Product_Package服务中提取Basic Monitoring包。

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

提前致谢!

1 个答案:

答案 0 :(得分: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)

这是创建网络监控的示例

{{1}}

此致