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

Azure Python SDK - get info of update management in automation account #6487

Closed
shashankpai opened this issue Jul 25, 2019 · 9 comments
Closed
Labels
customer-reported Issues that are reported by GitHub users external to the Azure organization. Mgmt This issue is related to a management-plane library. Service Attention This issue is responsible by Azure service team.

Comments

@shashankpai
Copy link

My requirement is to extract info about update management in automation account . I need to get the details of machines in update management. Is there a way i can get info about these machines . I have tried a couple of things in below code . But still not able to get to update management.

from azure.common.credentials import UserPassCredentials
from azure.mgmt.resource import ResourceManagementClient
from azure.mgmt.compute import ComputeManagementClient
from azure.mgmt.automation import AutomationClient
from azure.mgmt.automation.operations.automation_account_operations import AutomationAccountOperations
from azure.mgmt.automation import operations


GROUP_NAME = 'patching'
AUTOMATION_ACCOUNT_NAME = 'account-name'

subscription_id = '111111-11111111-1111-111111'

credentials = UserPassCredentials(
    'account_name@abc.com',
    '123456'
)


client = ResourceManagementClient(credentials, subscription_id)
compute_client = ComputeManagementClient(credentials,subscription_id)
automation_client = AutomationClient(credentials,subscription_id)

def get_automation_details():
    for item in automation_client.automation_account.list_by_resource_group(GROUP_NAME):
        print(item.name)

def get_job_details():
    for item in automation_client.job.list_by_automation_account(GROUP_NAME,AUTOMATION_ACCOUNT_NAME):
        print("job name:" ,item.name,"job id:",item.job_id,"job status:",item.status)

def get_hybrid_runbook_workers():
    item =automation_client.hybrid_runbook_worker_group.list_by_automation_account(GROUP_NAME,AUTOMATION_ACCOUNT_NAME)
    for items in item:
        print(items)

I am able to get nodes using hybrid_runbook_worker_group , but not the properties of those nodes in update management. I need a method to query Update management and the info of machines in it . Is there a way to do so.

Thanks

@lmazuel lmazuel added Automation customer-reported Issues that are reported by GitHub users external to the Azure organization. Mgmt This issue is related to a management-plane library. Service Attention This issue is responsible by Azure service team. labels Jul 25, 2019
@ghost
Copy link

ghost commented Jul 25, 2019

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @zjalexander

1 similar comment
@ghost
Copy link

ghost commented Jul 25, 2019

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @zjalexander

@zjalexander
Copy link
Member

The data is stored in Log Analytics. So you would need to use this API with these queries

@shashankpai
Copy link
Author

thanks @zjalexander . I have applied what you said. But getting errors. Below is code and error

from azure.common.credentials import UserPassCredentials
from azure.mgmt.resource import ResourceManagementClient
from azure.mgmt.compute import ComputeManagementClient
from azure.mgmt.automation import AutomationClient
from azure.mgmt.automation.operations.automation_account_operations import AutomationAccountOperations
from azure.mgmt.automation import operations
from azure.mgmt.automation.operations import HybridRunbookWorkerGroupOperations
from azure.loganalytics.log_analytics_data_client import LogAnalyticsDataClient
from azure.loganalytics.models import QueryBody

GROUP_NAME = 'patching'
AUTOMATION_ACCOUNT_NAME = 'account-name'

subscription_id = '111111-11111111-1111-111111'

credentials = UserPassCredentials(
'account_name@abc.com',
'123456'
)

client = ResourceManagementClient(credentials, subscription_id)
compute_client = ComputeManagementClient(credentials,subscription_id)
automation_client = AutomationClient(credentials,subscription_id)

query = """search in (Update) "error" """

loganalys_client = LogAnalyticsDataClient(credentials=credentials)

query_body = QueryBody(query=query)
print(query_body)
q_result = loganalys_client.query(workspace_id=workspace_id,body=query_body)
print(q_result)

ERROR:

File "/usr/local/lib/python3.6/dist-packages/azure/loganalytics/log_analytics_data_client.py", line 120, in query
raise models.ErrorResponseException(self._deserialize, response)
azure.loganalytics.models.error_response_py3.ErrorResponseException: (InvalidTokenError) The provided authentication is not valid for this resource

the credential authentication works perfectly for automation client or hybrdrunbookworkergroup.

@zjalexander zjalexander self-assigned this Jul 30, 2019
@zjalexander
Copy link
Member

But you definitely have RBAC access to the Log Analytics workspace, with that user account, right? If so I need to kick this over to the Log Analytics folks.
I did find this document about authentication methods: https://docs.microsoft.com/en-us/azure/python/python-sdk-azure-authenticate#mgmt-auth-legacy

@shashankpai
Copy link
Author

Yes @zjalexander i am able to use loganalytics in azure portal and query the update manager . I wil check the document in the meantime. Thanks

@shashankpai
Copy link
Author

any update on this issue ?

@shashankpai
Copy link
Author

shashankpai commented Aug 7, 2019

Hi i tried implementing the solution in this issue. here they were using ServicePrincipalCredentials as authentication method but in my case i am using UserPassCredentials as authentication method. I am getting the same error. So is there a solution for UserPassCredentials?

@zjalexander
Copy link
Member

According to this link :

In previous version of the SDK, ADAL was not yet available and we provided a UserPassCredentials class. This is considered deprecated and should not be used anymore.

@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
customer-reported Issues that are reported by GitHub users external to the Azure organization. Mgmt This issue is related to a management-plane library. Service Attention This issue is responsible by Azure service team.
Projects
None yet
Development

No branches or pull requests

4 participants