In this post, we'll walk you to the process of creating a custom Notification Agent for your maintenance jobs.
Out of the box, there's a email agent that sends some information when a maintenance job has completed or failed.
| XML |
1
2
3
|
<engines>
<add name="MaintenanceJobEmailAgent" type="Adam.Core.Maintenance.MaintenanceJobEmailAgent, Adam.Core" />
</engines>
|
In this post, we'll write a similar custom notification agent that will send a basic email by means of a web service.
Writing a simple Web Service
Our email will be sent through a web service. Below you see a very simple (and rather naive) webmethod that will send an email with some basic status information of the maintenance job.
| C# |
1
2
3
4
5
6
7
8
9
10
11
|
[WebMethod]
public void NotifyMaintenanceJob(string status, int totalTargets, int succeededTargets, int failedTargets)
{
string body = string.Format("Total targets: {0}\r\nSucceeded targets: {1}\r\nFailed targets: {2}",
totalTargets, succeededTargets, failedTargets);
SmtpClient mailClient = new SmtpClient("smtp.yoursmtpserver.com");
mailClient.Send(@"noreply@mycompany.com",
@"kevin@mycompany.com",
"Maintenance Job " + status,
body);
}
|
Writing a custom Notification Agent
Writing a custom notification agent is also really simple: just create a new class that inherits from MaintenanceJobNotificationAgent and implement its abstract method Execute.
In the Execute method we will call the webmethod we created in our web service and pass the maintenance job parameters.
| C# |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
public class WebServiceNotificationAgent : MaintenanceJobNotificationAgent
{
public WebServiceNotificationAgent(Application app) : base(app)
{
}
public override void Execute(MaintenanceJob job)
{
NotificationServiceSoapClient client =
new NotificationServiceSoapClient(
new BasicHttpBinding(),
new EndpointAddress(@"http://localhost:62196/NotificationService.asmx"));
client.NotifyMaintenanceJob(job.Status.ToString(), job.Targets.Count, job.SucceededTargets.Count, job.FailedTargets.Count);
}
}
|
Note: make sure you have deployed your webservice so it can be called by the notification agent.
Register the Notification Agent
When you are finished coding you only need to register and activate your custom provider into ADAM.
First you need to register your custom assembly.
Secondly, you need to add your notification agent to the list of registered notification agents in the .maintenanceJobNotificationAgents setting.
| XML |
1
2
3
4
|
<engines>
<add name="MaintenanceJobEmailAgent" type="Adam.Core.Maintenance.MaintenanceJobEmailAgent, Adam.Core" />
<add name="WebServiceNotificationAgent" type="BlogNotificationAgent.WebServiceNotificationAgent, BlogNotificationAgent" />
</engines>
|
That's all there is to it! Next time your maintenance jobs are executed, you should receive a simple notification email looking something like this: