Search code examples
javaazure-webjobsazure-monitoring

How to set an alert for webjobs without SDK


I have created a triggered webjob using Java as a technology stack and it is running fine after deployment. But now I want to monitor this webjob using alert notification. I tried multiple things, like adding app insights dependencies in POM file and using instrumentation key but nothing is working out. If anyone can guide me how to set an alert for webjob failure, it will be so helpful. Thanks.


Solution

  • Update:

    As Sdcoder commented:

    I am calling application-insight agent jar from the run.sh file. It solved my problem, I am able to see the logs in the app insights now. my run.sh file looks like this: set PATH=%PATH%;%JAVA_HOME%/bin java -javaagent:applicationinsights-agent-3.0.2.jar -jar app.jar


    As suggested by ahmelsayed:

    • If you are NOT using the WebJob SDK, then unfortunately there aren't any events for continuous webjobs. There is only one way for triggered jobs.
     private async void ReportTriggeredJobFinished(string jobName, string jobRunId)
            {
                TriggeredJobRun triggeredJobRun = GetJobRun(jobName, jobRunId);
                if (triggeredJobRun == null)
                {
                    return;
                }
    
                await _hooksManager.PublishEventAsync(HookEventTypes.TriggeredJobFinished, triggeredJobRun);
            }
        }
    

    You can refer to Azure WebJob, how to be notified if it stops? and Best way to set up alerts on azure web job