简体   繁体   中英

See if Azure Virtual Machine is down using python

I am trying to write a python program that will alert me when a VM is down. I know PowerShell might be better but would prefer python.

Why do you think it would be better with PowerShell :). Python rules ;)

If you want a more reactive programming, you should look at EventGrid + LogicApp + WebApp/Function first. It's like IFTTT for Azure, EventGrid will trigger an event, and LogicApp will be able to consume this event and send it to a WebApp or Function (that you can write in Python). Example: https://docs.microsoft.com/en-us/azure/event-grid/monitor-virtual-machine-changes-event-grid-logic-app

If you want a more "I pull every minute" experience, just use the azure-mgmt-compute package: https://pypi.org/project/azure-mgmt-compute/

Basic sample: https://github.com/Azure-Samples/virtual-machines-python-manage

You will need the instance view of the VM, to get the power state, with instance_view

Hope this helps!

(I work at MS in the Azure SDK for Python team)

EDIT:

It seems EventGrid does not support trigger from VM power state yet, you could still use LogicApp with a poll schedule for solution 1: https://docs.microsoft.com/en-us/azure/connectors/connectors-native-recurrence

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM