Send alert on failure of webjobs in azure portal - azure

There is one requirement to send an email upon unsuccessful web-jobs only. There are 16 web-jobs which are deployed and running successfully on azure portal. I have suggested to modify the code for existing web-job but client does not want to modify web-jobs. He wants to add something extra which does not require to modify web-jobs anymore. I am confused, without modifying web-jobs, how can I send an email? I searched a lot on google and stack-overflow but didn't get anything.
How can I implement this?

Few of the workarounds for getting the notification to email for WebJobs Status:
Using ErroTrigger and SendGrid extensions. you can do the Notifications sending to email for the WebJob SDK.
check this article on how to set that up which uses both extensions to send an email if an error occurred 10 times in 30 minutes window with a throttle up to 1 hour.
public static void ErrorMonitor(
[ErrorTrigger("0:30:00", 10, Throttle = "1:00:00") TraceFilter filter,
[SendGrid] SendGridMessage message)
{
message.Subject = "WebJobs Error Alert";
message.Text = filter.GetDetailedMessage(5)
}
If you aren't using the WebJob SDK, then unfortunately there aren't any events for continuous webjobs. There is only one for triggered jobs.
Also, visit this MSFT Doc and SO Thread for information on setting up the email alerts with App Services.

Related

The Azure Alerts using webhook to Slack is not working

I'm using Azure Alerts to use webhooks. I added the webhook in the action group. The URL I used is the one from Slack.
I also added a Notification Type Email. The notification email gets triggered but I am not receiving any message in the Slack channel.
I was able to push messages to the webhooks using postman hence I know my webhook is correct. But Azure Alert is not able to trigger the webhook. I am not receiving any messages in the Slack channel.
Azure Monitor sends a notification with its own schema definition. Slack doesn't recognize it, so you cannot see any notifications in the channel. It is possible to create a Logic App or Azure Function to transform the default schema.
Here the more information about it:
https://learn.microsoft.com/en-us/azure/azure-monitor/alerts/alerts-common-schema
Slack expect a json object when using webhooks. When sending directly from azure alert you will get bad request.
Every slack channel has an e-mail adress. You can post messages to the channel using that email in azure alerts
Anyone looking for using Slack and Azure Alerts. This seems to work fine:
...
webhook_receiver {
name = "Slack"
service_uri = "https://hooks.slack.com/services/secret"
use_common_alert_schema = false
}
Then in the scheduled query rules alert:
...
action {
action_group = [data.azurerm_monitor_action_group.actiongroup.id]
email_subject = "Disk storage at less than 10%"
custom_webhook_payload = "{ \"text\" : \"Warning: Storage has less than 10% diskspace remaining!\"}"
}

How to receive messages from azure queue subscription using go

I trying to pull messages from azure service bus queue using Go.Queue topic name,subscription name,service name and shared access key value are the credentials.I'm not getting proper sample code for this.Please help me!!
The Go Cloud Development Kit Pub/Sub API is still a work in progress (it's one of our newer APIs). As of 2019-01-30, there is a pull request out for review that adds support, so stay tuned!
from azure.servicebus.control_client
import ServiceBusService
bus_service=ServiceBusService(service_namespace='<namespace>',
shared_access_key_name='<key_name>',
shared_access_key_value='<acess_key>')
topic_name = "<topic_name>"
subscription_name = "<subscription_name>"
message = bus_service.receive_subscription_message(topic_name,
subscription_name, peek_lock=True)

Bot deployed on azure suddenly became non-responsive

I have a bot deployed on Azure using Bot Framework. Nothing was changed on the code. But today the bot became completely unresponsive. Any message I try to send results invariably in a "Couldn't Send. Retry?" message. Occasionally in past I could see the bot was slower to reply to one or other message, but this time is a different thing, the bot is completely mute. On inspecting the issues for web chat channel on azure dashboard I can see that the errors are all the same "There was an error sending this message to your bot: HTTP status code GatewayTimeout". What may I be doing wrong?
Just in case it is relevant, the bot uses LUIS services and also a database both deployed in azure. Tried to access these services separately and they are working fine with good response time. Anyway, I don't think the bot program reaches the point of trying to communicate with any of them. I doesn't even reach the first IDialogContext.PostAsync() which is the very first instruction on the StartAsync() method in the root dialog. Help with this much appreciated
the errors are all the same "There was an error sending this message to your bot: HTTP status code GatewayTimeout". What may I be doing wrong?
Firstly, I do a test with the following sample, and if the request take a long time to get response, which might cause " Gateway Timeout" issue. You can turn on Application Insights with your bot application to trace the request(s) sent from your bot, and check if some requests take too long time.
Example:
private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> result)
{
var activity = await result as Activity;
// calculate something for us to return
int length = (activity.Text ?? string.Empty).Length;
if (activity.Text.ToLower().Contains("timeout test"))
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://xxxxx/api/values/xxx");
request.Method = "GET";
request.ContentType = "application/json";
//I set a 30s delay for returning response in my external api
var response = request.GetResponse();
string content = string.Empty;
using (var stream = response.GetResponseStream())
{
using (var sr = new StreamReader(stream))
{
content = sr.ReadToEnd();
}
}
activity.Text = content.ToString();
// return our reply to the user
await context.PostAsync($"API returned {activity.Text}");
}
else
{
// return our reply to the user
await context.PostAsync($"You sent {activity.Text} which was {length} characters");
}
context.Wait(MessageReceivedAsync);
}
Test result:
Secondly, if your Bot Service pricing tier is free, please check if your bot service reached 10,000 messages/month limit (for Premium channels). In this SO thread, another community member reported reaching that limit would cause " Gateway Timeout" error.
Besides, if possible, you can create a new bot service on Azure portal and then publish your bot application to that corresponding new Azure web app that you specified as messaging endpoint, and check if your bot app can work as expected on new Azure environment.
Note:
I also checked the status history of Azure services and found:
6/27 RCA - App Service - West Europe
Summary of impact: Between 16:00 UTC on 27 Jun 2018 and 13:00 UTC on 28 Jun 2018, a subset of customers using App Service in West Europe may have received HTTP 500-level response codes, timeouts or high latency when accessing App Service (Web, Mobile and API Apps) deployments hosted in this region.
6/25 RCA - Multiple Services - South Central US
Summary of impact: Between 19:40 and 20:52 UTC on 25 Jun 2018, a subset of customers in South Central US may have experienced difficulties connecting to resources and/or 500-level errors hosted in this region. Virtual Machines may have rebooted unexpectedly. Impacted services included: Storage, Virtual Machines, Key Vault, Site Recovery, Machine Learning, Cloud Shell, Logic Apps, Redis Cache, Visual Studio Team Services, Service Bus, ExpressRoute, Application Insights, Backup, Networking, API Management, App Service (Linux) and App Service.
Not sure if above issue causes the problem, if you tried all approaches that you can do to troubleshoot the issue, but the issue with your bot service is still not mitigated, you can try to create support request to report it.
Try enabling [botauthentication] in message controller. Also try to open outgoing connection also from your IIS server to internet. By the way there can be some other problems as well like :
1)Your web.config file contains an App ID that does not match the one you posted.
2)Your server's time is incorrect. Tokens have 20 minutes of validity (5 minutes before the token was issued and 15 minutes after.) Is it possible your server time is different?
3)Your bot encountered a problem retrieving list of signing keys. Check to make sure you can access these URLs:
https://api.aps.skype.com/v1/keys
https://login.botframework.com/v1/.well-known/keys
You can also follow this issue to check if you're doing it correctly https://github.com/Microsoft/BotBuilder/issues/4389

how to get azure web job running alert in mail from azure portal?

I have scheduled my console application as a web job in azure portal.
how to get azure web job running alert in mail from azure portal that whether it runs successfully or any failure occurred.
how to get azure web job running alert in mail from azure portal that whether it runs successfully or any failure occurred.
I haven't found any way to do it on Azure portal. You could modify your code to implement it.
As one of my original posts mentioned, WebJobs status depends on whether your WebJob/Function is executed without any exceptions or not. I suggest you put all your code in a try code block. If any exception throws, it means the status of this run will be failure. Otherwise the status will be success.
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
}
To send a mail in your WebJob, you could use SendGrid component or any other SMTP client library. Here is a sample of using SmtpClient to send mail from 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);
I wasn't able to find a way to send emails on job run or even failure using only "pure" azure tools (without me writing any code). However, what you can do is use Kudu Web Hooks for job completion: https://github.com/projectkudu/kudu/wiki/Web-hooks (Kudu is part of Azure).
For example, you can create another web job or a function with an HTTP trigger which will run on each web hook call, will check job completion status, and will send emails on failure. Thus, you can have single web job handling errors of all other web jobs you have.
Web UI for configuring web hooks is at https://your_web_app_name.scm.azurewebsites.net/WebHooks, and you can find the model of the web hook message body here: https://github.com/projectkudu/kudu/blob/master/Kudu.Contracts/Jobs/TriggeredJobRun.cs.

Issue with sending Notification to Windows Store app using Service bus

I use Notification Hubs to send Notifications to IPhone and Windows Store app. The IPhone is working perfectly fine, but there is some issue with Windows Store when sending the notification.
Error: The Push Notification System handle for the registration is invalid.
Template:
String WindowsTemplateStr = #"<toast><visual><binding template=""ToastImageAndText03""><image id=""1"" src=""https://"" alt=""Customer""/><text id=""1"">$(headlineText)</text><text id=""2"">$(bodyText)</text></binding></visual></toast>";
I use this code to register:
registration = await hubClient.CreateWindowsTemplateRegistrationAsync(userDeviceInformation.ChannelUri, Templates.WindowsNotificationTemplate,
new string[]
{
userDeviceInformation.InstallationId,
userDeviceInformation.UserName
});
The registration goes through fine and I can see the tags properly associated using "Service Bus Explorer".
When I try to send the Notification this is what I do:
notification.Add("src", ImageUrl);
notification.Add("headlineText", String.Format("Message from {0}", fullName));
notification.Add("bodyText", String.Format("Message {0}", message));
When the notification is sent, nothing is received on the device; and I see the registration is also being deleted.
I can't seem to find what is causing this behavior.
Any ideas ?
If WNS returns invalid handle then the corresponding registration will be removed from the notification hubs.
You can use test send to check the error details:
http://msdn.microsoft.com/en-us/library/microsoft.servicebus.notifications.notificationhubclient.enabletestsend.aspx

Resources