更正参数以创建 DiagnosticSettingsOperations 对象
Correct arguments to create DiagnosticSettingsOperations object
我想为 Azure 资源配置诊断设置,因此我正在使用 DiagnosticSettingsOperations
class。我能够创建 MonitorManagementClient
Class 的客户端(DiagnosticSettingsOperations class 的第一个参数)。但是,我无法获取我需要传递给 DiagnosticSettingsOperations
.
的其他三个参数
构造函数:
DiagnosticSettingsOperations(client, config, serializer, deserializer)
因为我不知道要传什么,所以我只给了空字符串''
。
下面是我的示例代码:
azureCredential = authenticateToAzureUsingServicePrincipal()
monitorManagerClient = MonitorManagementClient(azureCredential, 'xxx-xxxx-xxxx-xxxx-xxxxxx')
diagnosticSettingsOperationsClient = DiagnosticSettingsOperations(monitorManagerClient, '', '','')
resource_uri = '<AZURE RESOURCE ID OF SQL DATABASE>'
name = 'coemonitoreu'
workspace_id = 'AZURE RESOURCE ID OF LOG ANALYTICS WORKSPACE'
metrics = ["WorkloadManagement"]
logs = ["SQLInsights"]
parameter_list = {
'workspace_id': workspace_id,
'metrics': metrics,
'logs': logs
}
diagnosticSettingsOperationsClient.create_or_update(resource_uri=resource_uri, name=name, parameters=parameter_list)
我知道我的 class 调用是错误的,谁能指出创建 DiagnosticSettingsOperations
客户端的正确方法,这样我就可以使用它的 create_or_update
方法来配置诊断设置。
当我 运行 代码时出错:
<azure.mgmt.monitor._monitor_management_client.MonitorManagementClient object at 0x000002053F7BD448>
Traceback (most recent call last):
File "C:\Users\manjug\source\repos\ExtolloConfigDatabase\ExtolloConfigDatabase\anotherPythonFile.py", line 35, in <module>
diagnosticSettingsOperationsClient.create_or_update(resource_uri=resource_uri, name=name, parameters=parameter_list)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\azure\mgmt\monitor\v2017_05_01_preview\operations\_diagnostic_settings_operations.py", line 139, in create_or_update
'resourceUri': self._serialize.url("resource_uri", resource_uri, 'str', skip_quote=True),
AttributeError: 'str' object has no attribute 'url'
请尝试如下设置:
#for log
logs = [{"category":"SQLInsights","enabled":true,"retentionPolicy":{"days":0,"enabled":false}}]
#to set more catetories, you can use a "," symbol in the [],like below:
logs = [{"category":"SQLInsights","enabled":true,"retentionPolicy":{"days":0,"enabled":false}},{other category}]
#for metrics
metrics = [{"enabled":true,"retentionPolicy":{"days":0,"enabled":false},"category":"WorkloadManagement"}]
我想为 Azure 资源配置诊断设置,因此我正在使用 DiagnosticSettingsOperations
class。我能够创建 MonitorManagementClient
Class 的客户端(DiagnosticSettingsOperations class 的第一个参数)。但是,我无法获取我需要传递给 DiagnosticSettingsOperations
.
构造函数:
DiagnosticSettingsOperations(client, config, serializer, deserializer)
因为我不知道要传什么,所以我只给了空字符串''
。
下面是我的示例代码:
azureCredential = authenticateToAzureUsingServicePrincipal()
monitorManagerClient = MonitorManagementClient(azureCredential, 'xxx-xxxx-xxxx-xxxx-xxxxxx')
diagnosticSettingsOperationsClient = DiagnosticSettingsOperations(monitorManagerClient, '', '','')
resource_uri = '<AZURE RESOURCE ID OF SQL DATABASE>'
name = 'coemonitoreu'
workspace_id = 'AZURE RESOURCE ID OF LOG ANALYTICS WORKSPACE'
metrics = ["WorkloadManagement"]
logs = ["SQLInsights"]
parameter_list = {
'workspace_id': workspace_id,
'metrics': metrics,
'logs': logs
}
diagnosticSettingsOperationsClient.create_or_update(resource_uri=resource_uri, name=name, parameters=parameter_list)
我知道我的 class 调用是错误的,谁能指出创建 DiagnosticSettingsOperations
客户端的正确方法,这样我就可以使用它的 create_or_update
方法来配置诊断设置。
当我 运行 代码时出错:
<azure.mgmt.monitor._monitor_management_client.MonitorManagementClient object at 0x000002053F7BD448>
Traceback (most recent call last):
File "C:\Users\manjug\source\repos\ExtolloConfigDatabase\ExtolloConfigDatabase\anotherPythonFile.py", line 35, in <module>
diagnosticSettingsOperationsClient.create_or_update(resource_uri=resource_uri, name=name, parameters=parameter_list)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\azure\mgmt\monitor\v2017_05_01_preview\operations\_diagnostic_settings_operations.py", line 139, in create_or_update
'resourceUri': self._serialize.url("resource_uri", resource_uri, 'str', skip_quote=True),
AttributeError: 'str' object has no attribute 'url'
请尝试如下设置:
#for log
logs = [{"category":"SQLInsights","enabled":true,"retentionPolicy":{"days":0,"enabled":false}}]
#to set more catetories, you can use a "," symbol in the [],like below:
logs = [{"category":"SQLInsights","enabled":true,"retentionPolicy":{"days":0,"enabled":false}},{other category}]
#for metrics
metrics = [{"enabled":true,"retentionPolicy":{"days":0,"enabled":false},"category":"WorkloadManagement"}]