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 in Python by Mukund
• 120 points
65 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 by Gitika
• 29,170 points

Related Questions In Python

+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 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 939 views
0 votes
0 answers
+4 votes
6 answers
+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
• 57,530 points
208 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
307 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
625 views
0 votes
1 answer

Playbook to create a VM on Azure

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

answered Mar 26, 2019 in Ansible by Jason
145 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 26, 2019 in Ansible by Jobin
665 views
0 votes
1 answer

Playbook to create VM with existing storage account on Azure

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

answered Mar 26, 2019 in Ansible by Barbara
117 views