Azure VM Monitoring

0 votes
Hi,

I am looking for heads up, to write python code to get my Azure VM status in my email or in Vm, like whether it is live or not and since how many days like the type of information.

This code i am going to write in Python. Looking for support for the same.
Apr 4, 2020 in Python by Mukund
• 120 points
999 views

1 answer to this question.

0 votes

Hi, @Mukund,

For an Azure Virtual Machine, we need to have several Azure resources. Before starting with anything, make sure you have an Active Directory service principal. You also need to have the application ID, the authentication key, and the tenant ID that you need in a later.

  • Open myPythonProject.py file that was created, and then add this code to enable your application to run:
if __name__ == "__main__":
  • To import the code that is needed, add these statements to the top of the .py file:

from azure.common.credentials import ServicePrincipalCredentials 

from azure.mgmt.resource import ResourceManagementClient 

from azure.mgmt.compute import ComputeManagementClient

 from azure.mgmt.network import NetworkManagementClient

 from azure.mgmt.compute.models import DiskCreateOption
  • Next in the .py file, add variables after the import statements to specify common values used in the code:
SUBSCRIPTION_ID = 'subscription-id'

 GROUP_NAME = 'myResourceGroup' 

LOCATION = 'westus' 

VM_NAME = 'myVM'
  • To create the Active Directory credentials that you need to make requests, add this function after the variables in the .py file:

def get_credentials():

 credentials = ServicePrincipalCredentials( 

client_id = 'application-id', secret = 'authentication-key',

 tenant = 'tenant-id'

)

  return credentials
  • To call the function that you previously added, add this code under the if statement at the end of the .py file:

credentials = get_credentials()

To learn more about your query you can go through this: https://docs.microsoft.com/en-us/azure/virtual-machines/windows/python

answered Apr 6, 2020 by Gitika
• 65,770 points

Related Questions In Python

0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,422 views
0 votes
1 answer
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
4,042 views
0 votes
1 answer

what is vm options ? I installed Pycharm on my pc but it shows no vm options file found . What should i do please help me to fix it

Hi, @Mushfiqkhantrial, It is important to run pycharm.sh from the bin folder. The VM ...READ MORE

answered Oct 4, 2020 in Python by Gitika
• 65,770 points
1,819 views
+1 vote
2 answers

When do we use Chef or Azure SDK to create VM and deploy in automation

The solution to the automated deployment in ...READ MORE

answered Aug 21, 2018 in Other DevOps Questions by Priyaj
• 58,020 points
1,138 views
0 votes
2 answers

Azure IoT Hub Operations Monitoring

Hi, Can you tell which device you ...READ MORE

answered Jan 4, 2019 in IoT (Internet of Things) by Varul
• 140 points
1,670 views
+2 votes
2 answers

Access denied: Root login Ubuntu VM on Azure

I have the same issue. Any help? READ MORE

answered Sep 27, 2018 in Azure by anonymous
3,624 views
0 votes
1 answer

Playbook to create a VM on Azure

Hey @Bob, try something like this to ...READ MORE

answered Mar 27, 2019 in Ansible by Jason
1,066 views
0 votes
1 answer

Playbook to create VM with managed disk - ansible with azure

Hey @Kavya, try something like this: - name: ...READ MORE

answered Mar 27, 2019 in Ansible by Jobin
2,471 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP