microsoftgraph / microsoftgraph/msgraph-beta-sdk-python
Resource not found for the segment 'partner'
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 44
- Fork
- 16
- Merge trung bình
- 20 giờ 39 phút
- Pull request đã merge (30 ngày)
- 3
Mô tả
Describe the bug
I am encountering an error attempting to perform a "List" or "Get" operation for Partner Security Alerts.
Expected behavior
A response object should be returned as indicated in the Microsoft docs:
{
"id": "d8b202fc-a216-3404-69ef-bdffa445eff6",
"displayName": "Action Required: Virtual machine connecting to crypto currency mining pool Detected",
"description": "Analysis of Azure resource network activity detected the resource was connecting to a crypto currency mining pool. This would often be an indication that your Azure resource is compromised.",
"alertType": "networkConnectionsToCryptoMiningPools",
"status": "active",
"severity": "high",
"confidenceLevel": "medium",
"customerTenantId": "1889e718-414b-4bad-8bbe-c1135bd39a41",
"subscriptionId": "5f6e6521-6e5f-4b0b-80aa-bd44fad7a398",
"valueAddedResellerTenantId": "c296b2ce-8cd1-4346-9e82-d8eccca70d65",
"catalogOfferId": "MS-AZR-0017G",
"detectedDateTime": "2024-01-23T16:03:33.05Z",
"firstObservedDateTime": "2024-01-23T16:03:33.05Z",
"lastObservedDateTime": "2024-01-23T16:03:33.05Z",
"resolvedReason": "fraud",
"resolvedOnDateTime": "2024-02-23T16:03:33.05Z",
"resolvedBy": "danas@contoso.com",
"isTest": false,
"affectedResources": [
{
"resourceId": "/subscriptions/subscription-id/resourceGroups/resourcegroup-name/providers/Microsoft.Compute/virtualMachines/vm-name",
"resourceType": "AzureResource"
}
],
"activityLogs": [
{
"statusFrom": "active",
"statusTo": "investigating",
"updatedBy": "samanthab@contoso.com",
"updatedDateTime": "2023-08-10T08:47:10.8454142Z"
},
{
"statusFrom": "investigating",
"statusTo": "resolved",
"updatedBy": "samanthab@contoso.com",
"updatedDateTime": "2023-08-10T08:47:25.2089246Z"
}
],
"additionalDetails": {
"VM_IP": "[ \"vm-ip\"]",
"MiningPool_IP": "[ \"mining-pool-ip\"]",
"ConnectionCount": "5",
"CryptoCurrencyMiningPoolDomainName": "pool-name.com"
}
}
How to reproduce
- Installed the msgraph-beta-sdk using pip
- Attempted to run the below code snippets :
### List all active security alerts
from msgraph_beta import GraphServiceClient
from azure.identity import DefaultAzureCredential
from azure.identity.aio import ClientSecretCredential
from azure.keyvault.secrets import SecretClient
import asyncio
import json
def main():
alerts = asyncio.run(list_security_alerts())
print(alerts)
async def list_security_alerts():
"""Returns a list of all active security alerts"""
credential = DefaultAzureCredential()
secret_client = SecretClient(
vault_url="https://kv-demo-zan-prod-004.vault.azure.net/", credential=credential
)
client_id = secret_client.get_secret(
"clientId"
).value
client_secret = secret_client.get_secret(
"clientSecret"
).value
tenant_id = secret_client.get_secret(
"tenantId"
).value
credentials = ClientSecretCredential(tenant_id, client_id, client_secret)
scopes = ["https://graph.microsoft.com/.default"]
graph_client = GraphServiceClient(credentials=credentials, scopes=scopes)
result = await graph_client.security.partner.security_alerts.get()
active_alerts = [item.id for item in result.value if item.status == "active"]
return active_alerts
if __name__ == "__main__":
main()
### Retrieve individual alert
from msgraph_beta import GraphServiceClient
from azure.identity import DefaultAzureCredential
from azure.identity.aio import ClientSecretCredential
from azure.keyvault.secrets import SecretClient
import asyncio
def main():
alert_id = ""
alert = asyncio.run(get_security_alert(alert_id))
print(alert)
async def get_security_alert(alert_id):
"""Get individual security alert"""
credential = DefaultAzureCredential()
secret_client = SecretClient(
vault_url="https://kv-demo-zan-prod-004.vault.azure.net/", credential=credential
)
client_id = secret_client.get_secret(
"clientId"
).value
client_secret = secret_client.get_secret(
"clientSecret"
).value
tenant_id = secret_client.get_secret(
"tenantId"
).value
credentials = ClientSecretCredential(tenant_id, client_id, client_secret)
scopes = ["https://graph.microsoft.com/.default"]
graph_client = GraphServiceClient(credentials, scopes)
result = await graph_client.security.partner.security_alerts.by_partner_security_alert_id(alert_id).get()
return result
if __name__ == "__main__":
main()
SDK Version
1.25.0
Latest version known to work for scenario above?
No response
Known Workarounds
No response
Debug output
Click to expand log
```Traceback (most recent call last):
File "C:\Users\Developer\Partner-Center-Events\CodeSnippets\list_security_alerts.py", line 48, in
main()
File "C:\Users\Developer\Partner-Center-Events\CodeSnippets\list_security_alerts.py", line 11, in main
alerts = asyncio.run(list_security_alerts())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.2544.0_x64__qbz5n2kfra8p0\Lib\asyncio\runners.py", line 190, in run
return runner.run(main)
^^^^^^^^^^^^^^^^
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.2544.0_x64__qbz5n2kfra8p0\Lib\asyncio\runners.py", line 118, in run
return self._loop.run_until_complete(task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.2544.0_x64__qbz5n2kfra8p0\Lib\asyncio\base_events.py", line 654, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "C:\Users\Developer\Partner-Center-Events\CodeSnippets\list_security_alerts.py", line 40, in list_security_alerts
result = await graph_client.security.partner.security_alerts.get()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Developer\Partner-Center-Events\CodeSnippets.venv\Lib\site-packages\msgraph_beta\generated\security\partner\security_alerts\security_alerts_request_builder.py", line 69, in get
return await self.request_adapter.send_async(request_info, PartnerSecurityAlertCollectionResponse, error_mapping)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Developer\Partner-Center-Events\CodeSnippets.venv\Lib\site-packages\kiota_http\httpx_request_adapter.py", line 193, in send_async
await self.throw_failed_responses(response, error_map, parent_span, parent_span)
File "C:\Users\Developer\Partner-Center-Events\CodeSnippets.venv\Lib\site-packages\kiota_http\httpx_request_adapter.py", line 575, in throw_failed_responses
raise exc
msgraph_beta.generated.models.o_data_errors.o_data_error.ODataError:
APIError
Code: 400
message: None
error: MainError(additional_data={}, code='BadRequest', details=None, inner_error=InnerError(additional_data={}, client_request_id='redacted', date=datetime.datetime(2025, 3, 12, 13, 14, 58), odata_type=None, request_id='redacted'), message="Resource not found for the segment 'partner'.", target=None)
</details>
### Configuration
### Configuration
- OS: Windows 11
- architecture: x64
### Other information
_No response_
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với các entry point đang bị lỗi graph_client.security.partner.security_alerts.get() và by_partner_security_alert_id(), sau đó kiểm tra generated/security/partner/security_alerts/security_alerts_request_builder.py. Tái hiện request dựa trên các thao tác Partner Security Alerts đã được tài liệu hóa và so sánh path được tạo với tài liệu Microsoft Graph. Được xem là hoàn tất khi cả các lệnh gọi liệt kê và lệnh gọi cảnh báo riêng lẻ đều trả về response được tài liệu hóa thay vì lỗi thiếu segment.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- api
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100