Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partner Security Alerts ModuleNotFoundError #519

Closed
AdrianM10 opened this issue Sep 3, 2024 · 4 comments
Closed

Partner Security Alerts ModuleNotFoundError #519

AdrianM10 opened this issue Sep 3, 2024 · 4 comments
Assignees
Labels

Comments

@AdrianM10
Copy link

Describe the bug

I am encountering a ModuleNotFoundError when trying to import from msgraph_beta when attempting to update Partner Security Alerts.

Expected behavior

A response object should be returned as indicated in the Microsoft docs :

https://learn.microsoft.com/en-us/graph/api/partner-security-partnersecurityalert-update?view=graph-rest-beta&tabs=python

HTTP/1.1 200 OK
Content-Type: application/json

 {
  "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": "[email protected]",
  "isTest": false,
  "affectedResources": [
    {
      "resourceId": "/subscriptions/subscription-id/resourceGroups/resourcegroup-name/providers/Microsoft.Compute/virtualMachines/vm-name",
      "resourceType": "AzureResource"
    }
  ],
  "activityLogs": [
    {
      "statusFrom": "active",
      "statusTo": "investigating",
      "updatedBy": "[email protected]",
      "updatedDateTime": "2023-08-10T08:47:10.8454142Z"
    },
    {
      "statusFrom": "investigating",
      "statusTo": "resolved",
      "updatedBy": "[email protected]",
      "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

  1. Installed the msgraph-beta-sdk using pip
  2. Attempted to run the below code :
from msgraph_beta import GraphServiceClient
from msgraph_beta.generated.models.partner.security.partner_security_alert import PartnerSecurityAlert
from msgraph_beta.generated.models.security_alert_status import SecurityAlertStatus
from msgraph_beta.generated.models.security_alert_resolved_reason import SecurityAlertResolvedReason


from azure.identity import DefaultAzureCredential
from azure.identity.aio import ClientSecretCredential
from azure.keyvault.secrets import SecretClient
import asyncio


def main():

    asyncio.run(update_security_alert())


async def update_security_alert():
    """Update 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)

    request_body = PartnerSecurityAlert(
        status=SecurityAlertStatus.Resolved,
        resolved_reason=SecurityAlertResolvedReason.Ignore,
    )

    alert_id = ""

    result = await graph_client.security.partner.security_alerts.by_partner_security_alert_id(alert_id).patch(request_body)

    print(result)


if __name__ == "__main__":
    main()

SDK Version

1.5.3

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\update_security_alert.py", line 3, in
from msgraph_beta.generated.models.security_alert_status import SecurityAlertStatus
ModuleNotFoundError: No module named 'msgraph_beta.generated.models.security_alert_status'

</details>


### Configuration

- OS: Windows 11
- architecture: x64

### Other information

_No response_
@AdrianM10 AdrianM10 added status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience labels Sep 3, 2024
@shemogumbe
Copy link
Contributor

shemogumbe commented Sep 4, 2024

Hello @AdrianM10 thanks for using the SDK and for raising this.

There seems to be an issue with the snippet.

In your code:

from msgraph_beta.generated.models.security_alert_status import SecurityAlertStatus
from msgraph_beta.generated.models.security_alert_resolved_reason import SecurityAlertResolvedReason

Do not exist.
The path to Partner alert status is and alert reasolved reason are

from msgraph_beta.generated.models.partner.security.security_alert_status import SecurityAlertStatus
from msgraph_beta.generated.models.partner.security.security_alert_resolved_reason import SecurityAlertResolvedReason

As per the path msgraph_beta/generated/models/partner/security/

Investigating the reason for the invalid import path.

@shemogumbe shemogumbe added the status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close label Sep 4, 2024
@shemogumbe shemogumbe removed the status:waiting-for-triage An issue that is yet to be reviewed or assigned label Sep 4, 2024
@shemogumbe
Copy link
Contributor

Tracked here microsoftgraph/microsoft-graph-devx-api#2183

@AdrianM10
Copy link
Author

Thanks @shemogumbe

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs: Attention 👋 and removed status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close labels Sep 4, 2024
@shemogumbe
Copy link
Contributor

Closing as issues is tracked here microsoftgraph/microsoft-graph-devx-api#2183

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants