Read logs from within an Azure Function - c#

I have an Azure function that runs a few times a day. I'd like to email myself a daily list of log messages, and wondered if I could use another Azure function for that?
Is it possible to read an Azure function logs from within an Azure function? Or is there another way to achieve the above?

Or is there another way to achieve the above?
Yes, you can use Azure Logic apps to get the logs of Function app recurrently.
I have created a logic app in Consumption plan, then created a workflow with Recurrence Trigger like below:
Then in next step I have chosen the Azure Applications insights like below:
Then I have opted send an email action and then I got the logs to my email :
Then in email I received logs:

I would propose two possible solutions in the realm of Azure.
In both cases I would suggest to include application insights.
It is a general recommendation by Microsoft.
Then goes what Peter Bons called "use case".
If it is enough for you get the critical information about recurring issues with N minutes of frequency, then you could make us of alerts. Last time I checked one needed to pay extra for each email, please double-check that.
If for some reason you want to have more control over what logs you want to send and fetch, you can fetch data directly from application insights through the REST API. To complete the idea you could use bindings that allow send emails (see here for practical points). I would say that there variations on how you can achieve fetching data, although the feature will be deprecated in two years.

Related

Azure B2C One time access to secured API

I have a web app (rest API) on azure, and I have a B2C setup that is securing it, requiring you to be signed in to access the API. This is good, as i wanted the API to be restricted to members. Basically, the entire web app requires authentication, and will prompt you for a sign in.
Heres the problem - my app has users (who have accounts) and clients (who do not have accounts). These clients might receive an email about a new appointment being set up with one of the users - this email should have one or more links/buttons (ie, a button to Confirm appointment, one to Decline, and one to request a reschdeule) and upon clicking this link I would like to update a field in my database via the rest api, so the USER knows the CLIENT's response. The trouble is, since the client wont have an account, I have no idea how I can give them a link they would be allowed to go to, and have the update happen.
I have tried to do a bunch of research - ive looked into AD external identities with a one time passcode - but i cant seem to find any info on how i would actually get this to work for my purposes.
Does anyone know how I might implement this in azure? Is there a way to call to azure form c# to generate a one time authentication that i can encode into a URL or something?
Any thoughts would be greatly appreciated.
Thanks!
You could do an anonymous authentication by using a magic link. The users account won’t even need to live in the directory. The link can be short lived, and potentially one time use. We call it id_token_hint or a magic link.
Sample here
https://github.com/azure-ad-b2c/samples/tree/master/policies/invite
And reference here
https://learn.microsoft.com/en-us/azure/active-directory-b2c/id-token-hint

Receive notifications when a user increase the SQL database size

We would like to receive notifications once the user change SQL Server size from S9 to S12 (increase). Is this possible natively or can we develop custom webhooks to receive notifications?
This action gets logged to the Activity Log. See here. So with this you should be able to create alerts following this tutorial: https://learn.microsoft.com/en-us/azure/azure-monitor/platform/alerts-activity-log
Use the Usage and the RateCard APIs to get estimated cloud consumption and charges.
Usage API will get you a metricID which you can use in query using RateCard to predict the price,
https://learn.microsoft.com/bs-cyrl-ba/azure/billing/billing-usage-rate-card-overview
Sample is here
Another Option would be to create custom Azure Policy to audit SQL SKUs and then create an alert once the resource is not compliant with the Azure policy to notify users.
https://learn.microsoft.com/en-us/azure/governance/policy/samples/allowed-sql-db-skus
#silent's answer is probably the best option today. On top of this, you can also use Resource Graph to identify changes: https://learn.microsoft.com/en-us/azure/governance/resource-graph/how-to/get-resource-changes.

Servicestack server sent events - email application

Can anyone guide me, where to find servicestack server sent event sample code.
First I explain my issue. I have created a restful service(using servicestack framework) to pull down list of emails for inbox folder using afterlogic mailbee object(external product). Now, each time if I do a pull, it takes more time to load list of emails because I am pulling down message body too.
Now I want to send down list of message headers first in the service, and then want the message body to load, because it take more time to pull down from imap object. I see server sent event is the only option here. If someone has a better solution for this, please suggest.
Now, if I have to use servicestack server sent events, I am unable to get any sample code, which I can look upon to implement in my case.
Please ask, if there is more clarification needed in my question.
Thanks for your time.
There is a sample for your requirement.
It is called Chat (it uses SSE).
Otherwise another project called EmailContacts can help you to develop the email app.
Server Events is to enable server/push real-time communication, if you want to optimize page loads you should separate your calls into 2 Services:
Fetch absolute minimum to render page
Fetch full details on demand

Asp.Net "Instant" PM System

I need to send "instant" messages (like forum PMs) between users with my asp.net application. As many others I use a webhotel to host my site. I have searched around for awhile and I can't find any solutions that would be a good fit with my system. I was thinking about writing a javascript that would call for each 30 seconds or so a .ashx handler to check the users message status (return true or false) if the correct credentials are supplied. However I dont know if this is a good solution, because of all the calls to the handler it might get picked up as spam or it might generate really bad performance? The thing is, I want to avoid the need to refresh the page just to see your latest messages.
Take a look at the C# SignalR library, it allows you send grouped or broadcast messages to clients using longpolling or websockets with minimal bandwidth and simple code
http://signalr.net/
You can use an updatepanel for this. Put a textbox in an updatepanel in your page. When a user sends a message just append it to that textbox.You can put a refresh timer to refresh the contents in every second .

With a web app, how should I trigger jobs like, notifications, state changes, general repetivite tasks and checks

I am building a web application in asp.net MVC and am thinking how I can get certain conditional tests to happen regularly.
Currently I am planning on having a page such as /utility/runJobs that will have a function in it that will test the whole site for dates meeting certain conditions etc..
I would then trigger this page from a service or other trigger service.
I would probably run this every min incase new notifications had to be sent out, or a Log item had to be written, or a status updated.
Can anyone suggest a better way of doing this.
EDIT___________
Imagine how the notification emails for ebay are sent?
I guess that the badges on stack over flow are tested when a user comes to the site, and only for that user.
If you are planning to write a Service to trigger your Jobs then I would suggest that you execute your jobs in your Service.
With MVC you have hopefully already separated you logic from you Views so it should be easy to implement the service.
First big protip: what you are looking to do shouldn't require a single web page. Or, what you really need to think about here is services, command line apps and queuing, not having a page that gets hit once a minute.

Categories