2015-04-16 22 views

回答

1

不幸的是,您現在無法通過腳本來完成......餘額(或帳單)未通過Azure REST API(或Azure PowerShell)公開。

+0

你好! Ty回答!當我從Azure獲得計費警報時,運行關閉腳本可能是一些解決方案? –

+0

是的,您可以嘗試運行一個腳本,當一個計費警報郵件到達您的郵件服務器時......它可能在理論上工作:) – Guy

+1

對於電子郵件上的腳本,我們過去曾成功使用過IMAP。 NICE easy c#API(我忘記了我們使用的.NET API,但有很多)..但是您可能能夠與警報交互(不會自己嘗試)http://blogs.technet.com/b/keithmayer/ archive/2014/11/08/scripts-to-tools-automate-monitoring-alert-rules-in-microsoft-azure -with-powershell-and-the-azure-service-management-rest-api.aspx –

0

對於關機,我們使用一個RUNBOOK,裏面有下面的代碼。

我們每天在晚上8點運行。 (你可以從另一個警報http://www.matthewjbailey.com/create-azure-billing-alert-email/觸發此)

workflow ShutDown-AllVMs { 
    param (
     [parameter(Mandatory=$true)] 
     [String] $VMCredentialName = "[email protected]" 
    ) 

     $Credential = Get-AutomationPSCredential -Name $VMCredentialName 

     if ($Credential -eq $null) { 
      throw "Could not retrieve '$VMCredentialName' credential asset. Check that you created this asset in the Automation service." 
     }  

     Add-AzureAccount -Credential $Credential 

     Select-AzureSubscription BizSpark 

     InlineScript {    
      Get-azurevm | ? { $_.Status -ne "StoppedDeallocated"} | Stop-AzureVM -Force    
     } 
} 

對於警報

設置提示

http://www.matthewjbailey.com/create-azure-billing-alert-email/

監控警報

http://blogs.technet.com/b/keithmayer/archive/2014/11/08/scripts-to-tools-automate-monitoring-alert-rules-in-microsoft-azure-with-powershell-and-the-azure-service-management-rest-api.aspx

我公頃我沒有嘗試所有這一切,所以你可能有一個2 + 2 = 5的問題:)但有一個博客的閱讀,你可能會發現你得到4 :)

+0

嗨! Ty回答!我知道這種腳本,但是當我的平衡約爲0美元時,我需要關閉我的虛擬機。 –

+0

好的,這是否有幫助http://www.matthewjbailey.com/create-azure-billing-alert-email/ –

+0

我已更新了A更多關於警報的詳細信息。 –