前提
- CLIコマンド slcli を使える状態であること(インストールなどはリンク先をご覧くさだい)
- 仮想サーバーを例にしてやってみます
- 物理サーバーの場合は、「guestId」を「hardwareId」に置き換えるなど、適宜修正してください
仮想サーバー ID の確認
仮想サーバーのIDを覚えておきます。
$ slcli vs list | grep khayama
38048717 khayama-test01 161.202.86.27 10.132.75.115 tok02 NULL
Monitoring設定の確認
Public Uplink 付きのサーバーを Host Ping で注文すると、デフォルトで Public Primary IP に対する Monitoring が設定されていますよね。
$ slcli call-api SoftLayer_Virtual_Guest getNetworkMonitors --mask=guestId,id,ipAddress,status,waitCycles,queryType,responseAction --id=38048717
:..........:.........:...............:.........................................:......................................:........:............:
: guestId : id : ipAddress : queryType : responseAction : status : waitCycles :
:..........:.........:...............:.........................................:......................................:........:............:
: 38048717 : 6250550 : 161.202.86.27 : :..............:......................: : :...................:..............: : ON : 0 :
: : : : : name : value : : : name : value : : : :
: : : : :..............:......................: : :...................:..............: : : :
: : : : : monitorLevel : 0 : : : level : 0 : : : :
: : : : : description : Test ping to address : : : actionDescription : Notify Users : : : :
: : : : : name : SERVICE PING : : : id : 2 : : : :
: : : : : id : 1 : : :...................:..............: : : :
: : : : :..............:......................: : : : :
:..........:.........:...............:.........................................:......................................:........:............:
Monitoring設定の追加
こちらのpythonスクリプトをつくってみました。
createPrivateNetworkMonitor.py
import SoftLayer
import sys
import json
from prettytable import PrettyTable
import operator
parm=sys.argv
guestId=parm[1]
# account info
client = SoftLayer.create_client_from_env()
# Define VSI identifier
guestId=parm[1]
# Define Ip Address
ipAddress = client['Virtual_Guest'].getPrimaryBackendIpAddress(id=guestId)
print(ipAddress)
# Define Query Type (1 = SERVICE PING, 17 = SLOW PING)
queryTypeId = 1
#queryTypeId = 17
# Define Response action id (1 = Do Nothing, 2 = Notify Users)
#responseActionId = 1
responseActionId = 2
# Define waitCycles 0 = Immediately, 1 = 5 Minutes, 2 = 10 Minutes, etc
#waitCycles = 0
waitCycles = 1
#waitCycles = 2
# define templateObject
templateObject = {
'guestId': guestId,
'ipAddress': ipAddress,
'queryTypeId': queryTypeId,
'responseActionId': responseActionId,
'waitCycles': waitCycles
}
# create Monitor
result = client['Network_Monitor_Version1_Query_Host'].createObject(templateObject)
print('Completed!')
実行(仮想サーバーのIDを引数入力します)
$ python createPrivateNetworkMonitor.py 38048717
10.132.75.115
Completed!
確認(Private側のMonitorを追加しました)
$ slcli call-api SoftLayer_Virtual_Guest getNetworkMonitors --id=38048717 --mask=guestId,id,ipAddress,status,waitCycles,queryType,responseAction
:..........:.........:...............:.........................................:......................................:........:............:
: guestId : id : ipAddress : queryType : responseAction : status : waitCycles :
:..........:.........:...............:.........................................:......................................:........:............:
: 38048717 : 6250550 : 161.202.86.27 : :..............:......................: : :...................:..............: : ON : 0 :
: : : : : name : value : : : name : value : : : :
: : : : :..............:......................: : :...................:..............: : : :
: : : : : monitorLevel : 0 : : : level : 0 : : : :
: : : : : description : Test ping to address : : : actionDescription : Notify Users : : : :
: : : : : name : SERVICE PING : : : id : 2 : : : :
: : : : : id : 1 : : :...................:..............: : : :
: : : : :..............:......................: : : : :
: 38048717 : 6259394 : 10.132.75.115 : :..............:......................: : :...................:..............: : ON : 1 :
: : : : : name : value : : : name : value : : : :
: : : : :..............:......................: : :...................:..............: : : :
: : : : : monitorLevel : 0 : : : level : 0 : : : :
: : : : : description : Test ping to address : : : actionDescription : Notify Users : : : :
: : : : : name : SERVICE PING : : : id : 2 : : : :
: : : : : id : 1 : : :...................:..............: : : :
: : : : :..............:......................: : : : :
:..........:.........:...............:.........................................:......................................:........:............:
Monitoring設定の変更
こちらのpythonスクリプトをつくってみました。
editNetworkMonitor.py
import SoftLayer
import sys
import json
from prettytable import PrettyTable
import operator
parm=sys.argv
id=parm[1]
# account info
client = SoftLayer.create_client_from_env()
# Define Query Type (1 = SERVICE PING, 17 = SLOW PING)
queryTypeId = 1
#queryTypeId = 17
# Define Response action id (1 = Do Nothing, 2 = Notify Users)
#responseActionId = 1
responseActionId = 2
# Define waitCycles 0 = Immediately, 1 = 5 Minutes, 2 = 10 Minutes, etc
waitCycles = 0
#waitCycles = 1
#waitCycles = 2
# define templateObject
templateObject = {
'queryTypeId': queryTypeId,
'responseActionId': responseActionId,
'waitCycles': waitCycles
}
# edit Monitor
result = client['Network_Monitor_Version1_Query_Host'].editObject(templateObject,id=id)
print('Completed!')
実行(Monitor のIDを引数入力します)
$ python editNetworkMonitor.py 6259394
Completed!
確認(id 6259394 の Monitor を waitCycles を 1 から 0 にしました)
$ slcli call-api SoftLayer_Virtual_Guest getNetworkMonitors --id=38048717 --mask=guestId,id,ipAddress,status,waitCycles,queryType,responseAction
:..........:.........:...............:.........................................:......................................:........:............:
: guestId : id : ipAddress : queryType : responseAction : status : waitCycles :
:..........:.........:...............:.........................................:......................................:........:............:
: 38048717 : 6250550 : 161.202.86.27 : :..............:......................: : :...................:..............: : ON : 0 :
: : : : : name : value : : : name : value : : : :
: : : : :..............:......................: : :...................:..............: : : :
: : : : : monitorLevel : 0 : : : level : 0 : : : :
: : : : : description : Test ping to address : : : actionDescription : Notify Users : : : :
: : : : : name : SERVICE PING : : : id : 2 : : : :
: : : : : id : 1 : : :...................:..............: : : :
: : : : :..............:......................: : : : :
: 38048717 : 6259394 : 10.132.75.115 : :..............:......................: : :...................:..............: : ON : 0 :
: : : : : name : value : : : name : value : : : :
: : : : :..............:......................: : :...................:..............: : : :
: : : : : monitorLevel : 0 : : : level : 0 : : : :
: : : : : description : Test ping to address : : : actionDescription : Notify Users : : : :
: : : : : name : SERVICE PING : : : id : 2 : : : :
: : : : : id : 1 : : :...................:..............: : : :
: : : : :..............:......................: : : : :
:..........:.........:...............:.........................................:......................................:........:............:
Monitoring設定の削除
こちらのpythonスクリプトをつくってみました。
deleteNetworkMonitor.py
import SoftLayer
import sys
import json
from prettytable import PrettyTable
import operator
parm=sys.argv
id=parm[1]
# account info
client = SoftLayer.create_client_from_env()
# delete Monitor
result = client['Network_Monitor_Version1_Query_Host'].deleteObject(id=id)
print('Completed!')
実行(Monitor のIDを引数入力します)
$ python deleteNetworkMonitor.py 6259394
Completed!
確認(Private 側の Monitor を削除しました)
$ slcli call-api SoftLayer_Virtual_Guest getNetworkMonitors --id=38048717 --mask=guestId,id,ipAddress,status,waitCycles,queryType,responseAction
:..........:.........:...............:.........................................:......................................:........:............:
: guestId : id : ipAddress : queryType : responseAction : status : waitCycles :
:..........:.........:...............:.........................................:......................................:........:............:
: 38048717 : 6250550 : 161.202.86.27 : :..............:......................: : :...................:..............: : ON : 0 :
: : : : : name : value : : : name : value : : : :
: : : : :..............:......................: : :...................:..............: : : :
: : : : : monitorLevel : 0 : : : level : 0 : : : :
: : : : : description : Test ping to address : : : actionDescription : Notify Users : : : :
: : : : : name : SERVICE PING : : : id : 2 : : : :
: : : : : id : 1 : : :...................:..............: : : :
: : : : :..............:......................: : : : :
:..........:.........:...............:.........................................:......................................:........:............:
User ID の確認
$ slcli call-api Account getUsers --mask=id,username | grep khayama
480625 khayama-xxxxxxxxxx
Notify User 設定の確認
$ slcli call-api Virtual_Guest getObject --mask=fullyQualifiedDomainName,monitoringUserNotification[user.username] --id=38048717
:............................:............................:
: name : value :
:............................:............................:
: monitoringUserNotification : :
: fullyQualifiedDomainName : khayama-test01.bluemix.com :
:............................:............................:
Notify User の追加
こちらのpythonスクリプトをつくってみました。
addUserNotification_VSI.py
import SoftLayer
import sys
import json
from prettytable import PrettyTable
import operator
parm=sys.argv
# account info
client = SoftLayer.create_client_from_env()
# Define VSI identifier
guestId=parm[1]
# Define userid
userId=parm[2]
# define templateObject
templateObject = {
'guestId': guestId,
'userId': userId
}
# Add user
result = client['SoftLayer_User_Customer_Notification_Virtual_Guest'].createObject(templateObject)
print(result)
print('Completed!')
実行(仮想サーバーの ID、User IDを引数入力します)
$ python addUserNotification_VSI.py 38048717 480625
{'guestId': 38048717, 'userId': 480625, 'id': 10732161, 'guest': {'status': {'keyName': 'ACTIVE', 'name': 'Active'}, 'typeId': 1, 'domain': 'bluemix.com', 'maxMemory': 1024, 'maxCpuUnits': 'CORE', 'maxCpu': 1, 'metricPollDate': '', 'createDate': '2017-08-22T23:57:32+09:00', 'hostname': 'khayama-test01', 'startCpus': 1, 'uuid': 'faf130ab-41eb-e1f2-ab1b-d92a4852d583', 'lastPowerStateId': '', 'lastVerifiedDate': '', 'statusId': 1001, 'notes': u'khayama-xxxxxxxxxx, windows', 'dedicatedAccountHostOnlyFlag': False, 'provisionDate': '2017-08-23T00:21:57+09:00', 'modifyDate': '2017-08-23T00:31:16+09:00', 'accountId': 319556, 'id': 38048717, 'fullyQualifiedDomainName': 'khayama-test01.bluemix.com'}}
Completed!
確認(UserNotification を追加しました)
$ slcli call-api Virtual_Guest getObject --mask=fullyQualifiedDomainName,monitoringUserNotification[user.username] --id=38048717
:............................:......................................................................:
: name : value :
:............................:......................................................................:
: monitoringUserNotification : :..........:..........:...................................:........: :
: : : guestId : id : user : userId : :
: : :..........:..........:...................................:........: :
: : : 38048717 : 10732161 : :..........:....................: : 480625 : :
: : : : : : name : value : : : :
: : : : : :..........:....................: : : :
: : : : : : username : khayama-xxxxxxxxxx : : : :
: : : : : :..........:....................: : : :
: : :..........:..........:...................................:........: :
: fullyQualifiedDomainName : khayama-test01.bluemix.com :
:............................:......................................................................:
Notify User の削除
こちらのpythonスクリプトをつくってみました。
deleteUserNotification_VSI.py
import SoftLayer
import sys
import json
from prettytable import PrettyTable
import operator
parm=sys.argv
# account info
client = SoftLayer.create_client_from_env()
# Define id
id=parm[1]
# define templateObject
templateObjects = [{
'id': id,
'guestId': '',
'userId': ''
}]
# Delete user
result = client['SoftLayer_User_Customer_Notification_Virtual_Guest'].deleteObjects(templateObjects)
print(result)
print('Completed!')
実行(Notification の IDを引数入力します)
$ python deleteUserNotification_VSI.py 10732161
True
Completed!
確認(UserNotification を削除しました)
$ slcli call-api Virtual_Guest getObject --mask=fullyQualifiedDomainName,monitoringUserNotification[user.username] --id=38048717
:............................:............................:
: name : value :
:............................:............................:
: monitoringUserNotification : :
: fullyQualifiedDomainName : khayama-test01.bluemix.com :
:............................:............................:
参考
- SoftLayer_Virtual_Guest | SoftLayer Development Network
- getNetworkMonitors | SoftLayer Development Network
- createObject | SoftLayer Development Network
- SoftLayer_Network_Monitor_Version1_Query_Host | SoftLayer Development Network
- Authentication method exception for adding a monitor in Softlayer - Stack Overflow
- softlayer - Monitoring in SL - Stack Overflow
- SoftLayer_Network_Monitor_Version1_Query_Host | SoftLayer Development Network
- editObject | SoftLayer Development Network
- deleteObject | SoftLayer Development Network
- SoftLayer_Virtual_Guest | SoftLayer Development Network
- deleteObjects | SoftLayer Development Network
- createObject | SoftLayer Development Network