简体   繁体   English

使用Python查看Azure虚拟机是否关闭

[英]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. 我正在尝试编写一个Python程序,当VM关闭时会提醒我。 I know PowerShell might be better but would prefer python. 我知道PowerShell可能更好,但更喜欢python。

Why do you think it would be better with PowerShell :). 为什么您认为使用PowerShell会更好:)。 Python rules ;) Python规则;)

If you want a more reactive programming, you should look at EventGrid + LogicApp + WebApp/Function first. 如果您希望进行更具响应性的编程,则应首先查看EventGrid + LogicApp + WebApp / Function。 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). 就像IFTTT for Azure一样,EventGrid将触发一个事件,而LogicApp将能够使用此事件并将其发送到WebApp或Function(可以用Python编写)。 Example: https://docs.microsoft.com/en-us/azure/event-grid/monitor-virtual-machine-changes-event-grid-logic-app 示例: https//docs.microsoft.com/zh-CN/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/ 如果您想获得更多“每分钟我都会拉”的体验,只需使用azure-mgmt-compute软件包: https : //pypi.org/project/azure-mgmt-compute/

Basic sample: https://github.com/Azure-Samples/virtual-machines-python-manage 基本示例: 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 你需要的虚拟机实例来看,让电源状态,与instance_view

Hope this helps! 希望这可以帮助!

(I work at MS in the Azure SDK for Python team) (我在Azure SDK for Python团队的MS上工作)

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 看来EventGrid还不支持从VM电源状态触发,您仍可以将LogicApp与解决方案1的轮询计划配合使用: https ://docs.microsoft.com/zh-cn/azure/connectors/connectors-native-recurrence

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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