我想使用python客户端创建Nessus Security Scanner并通过getStatus检查状态,并通过getReport方法获取结果。虽然,我已经通过php(SoftLayer API Nessus Scan Status / Report via PHP)阅读了这些帮助。但是如何通过python客户端使用这些? 当我通过python调用setInitParameter(scan_id)时,异常如flow: SoftLayerAPIError(客户端):函数(" setInitParameter")不是此服务的有效方法
答案 0 :(得分:0)
我建议您先阅读客户的文档:
https://github.com/softlayer/softlayer-python https://softlayer-api-python-client.readthedocs.io/en/latest/
init参数设置如下:
clientService.getObject(id=myInitParameter)
在这里您可以找到使用客户端的更多示例:
https://softlayer.github.io/python/
您可以在此处找到其他文档:
http://sldn.softlayer.com/blog
并重新说明,使用Softlayer的python客户端不像php客户端,数据以json格式发送,因此请求:
$client = SoftLayer_SoapClient::getClient('SoftLayer_Account', null, $apiUsername, $apiKey);
$accountInfo = $client->getObject();
$hardware = $client->getHardware();
foreach ($hardware as $server){
$scanclient = SoftLayer_SoapClient::getClient('SoftLayer_Network_Security_Scanner_Request', '', $apiUsername, $apiKey)
$scantemplate = new stdClass();
$scantemplate->accountId = $accountInfo->id;
$scantemplate->hardwareId = $server->id;
$scantemplate->ipAddress = $server->primaryIpAddress;
try{
// Successfully creates new scan
$scan = $scanclient->createObject($scantemplate);
} catch (Exception $e){
echo $e->getMessage() . "\n\r";
}
会是这样的:
clientAccount = client['SoftLayer_Account']
accountInfo = clientAccount.getObject() #for this case we do not need init parameter
hardware = clientAccount.getHardware() #for this case we do not need init parameter
for server in hardware:
scanclient = client['SoftLayer_Network_Security_Scanner_Request']
scantemplate = {
"accountId": accountInfo["id"],
"hardwareId": server["id"],
"ipAddress": server["primaryIpAddress"]
}
scanclient.createObject(scantemplate)