I have built a protocol that can remotely set/remove alarm template for selected elements/services. It works fine with elements but for some reason it does not always work with services although I used the underlying element Id instead of the service Id. I am getting "Value does not fall within the expected range" error when running IDmsElement.Update() when IDmsElement being an underlying element of a service.
I even tried building a automation script like below but it's still giving parameter is incorrect error when it tries to set alarm templates for the service. Again, it works fine with elements.
Could someone please advise on how to resolve this problem or if it's not possible to set an alarm template for a service remotely in a reliable fashion. Thanks.
Hi Paul
Instead of IDmsElement, you can use IDmsService when working with services (dms.GetService(serviceName)). That has it's own property for setting the alarm template.
Property ServiceElementAlarmTemplate | DataMiner Docs
EDIT:
A fix has been released in version 1.1.1.7 of the Skyline.DataMiner.Core.DataMinerSystem NuGet package. By following below code you can assign an alarm template to an enhanced service:
// Get service
IDmsService dmsService = dms.GetService("MyService");// Get template from the protocol from the service
IDmsAlarmTemplate dmsAlarmTemplate = dmsService.AdvancedSettings.ServiceElementProtocol.GetAlarmTemplate("MyTemplate");// Update the template property with the new template
dmsService.AdvancedSettings.ServiceElementAlarmTemplate = dmsAlarmTemplate;// Update the service
dmsService.Update();
At first glance, this seems ok. Are you getting any exceptions or errors?
Yes I’m getting Object reference not set to an instance of an object. exception
I don’t have a service on my system, so I can’t quickly test, but NullReferenceExceptions are doable to debug.
I would maybe try changing the line of retrieving the alarm template to this:
IDmsAlarmTemplate template = dmsService.AdvancedSettings.ServiceElementProtocol.GetAlarmTemplate(
If this doesn’t work, then I’ll try to see if I can test locally next week (unless someone can figure it out beforehand)
Thanks for the suggestion Oda, I have tried the line and it did not give any exceptions. However, it did not actually assign the template to the service unfortunately. Also, assigning null value to the template did not remove the template from the service either. Thanks in advance for testing this next week. Much appreciated.
Hi Michiel, thanks for your reply. I also have tried below code but it did not work either. Could you please tell me if I’m using it in a correct way?
IDms dms = protocol.GetDms();
var dmsService = dms.GetService(new DmsServiceId(dmaId, serviceId));
IDmsAlarmTemplate template = dmsService.AdvancedSettings.ServiceElementAlarmTemplate.Protocol.GetAlarmTemplate(strAlarmTemplateName);
dmsService.AdvancedSettings.ServiceElementAlarmTemplate = template;
dmsService.Update();