如何从azure门户网站获取邮件中的azure web job运行警报?

时间:2017-05-05 10:38:42

标签: azure azure-webjobs

我已将我的控制台应用程序安排为azure portal中的Web作业。

如何让azure web作业中的azure web作业运行警报,告知它是否成功运行或发生任何故障。

2 个答案:

答案 0 :(得分:0)

  

如何让azure web作业中的azure web作业运行警报,告知它是否成功运行或发生任何故障。

我还没有找到任何方法在Azure门户网站上做到这一点。您可以修改代码来实现它。

正如我提到的original posts之一,WebJobs状态取决于您的WebJob / Function是否在没有任何异常的情况下执行。我建议你把所有代码都放在try代码块中。如果抛出任何异常,则表示此运行的状态将失败。否则状态将成功。

try
{
    //Put all your code here
    //If no exception throws, the status of this run will be success
    //Send success status to your mail
}
catch
{
    //If any exception throws, the status of this run will be failure
    //Send failure status to your mail
}

要在WebJob中发送邮件,您可以使用SendGrid组件或任何其他SMTP客户端库。以下是使用SmtpClient从hotmail发送邮件的示例。

MailMessage mail = new MailMessage("frommail@hotmail.com", "tomail@hotmail.com");
SmtpClient client = new SmtpClient();
client.Port = 587;
client.EnableSsl = true;
client.Credentials = new NetworkCredential("frommail@hotmail.com", "mail_password");
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Host = "smtp.live.com";
mail.Subject = "this is a test email.";
mail.Body = "this is my test email body";
client.Send(mail);

答案 1 :(得分:0)

我无法使用" pure"找到一种在工作运行时发送电子邮件甚至失败的方法。天蓝色的工具(没有我写任何代码)。但是,您可以使用Kudu Web Hooks完成工作:https://github.com/projectkudu/kudu/wiki/Web-hooks(Kudu是Azure的一部分)。

例如,您可以创建另一个Web作业或具有HTTP触发器的函数,该函数将在每个Web挂钩调用上运行,将检查作业完成状态,并在发生故障时发送电子邮件。因此,您可以拥有所有其他Web作业的单个Web作业处理错误。

用于配置Web挂钩的Web UI位于https://your_web_app_name.scm.azurewebsites.net/WebHooks,您可以在此处找到Web挂钩消息正文的模型:https://github.com/projectkudu/kudu/blob/master/Kudu.Contracts/Jobs/TriggeredJobRun.cs