Dojo Community, I'm trying to figure how to get the service alarm level inside of a C# script. Something like.
Service testService = engine.FindServiceByKey("123/123");
if ( testService alarm level == critical)
{
// do something
}
Hi Cyrus,
There's an SLNET call called GetServiceStateMessage that you can use which will allow you to get the alarm state of the service.
Note that this is an internal call and we do not recommend using this, as it is not officially supported and we cannot guarantee that it will still work in the future. As a rule, you should avoid using SLNet calls, as these are subject to change without notice.
Hi Cyrus,
In these cases, normally we trigger the Automation script from a Correlation rule.
- In the Correlation rule, you can configure a filter based on the service name and alarm severity.
- In the action, you can point to the Automation script that you want to execute.
Please keep in mind that you can pass information from the Correlation rule to the Automation script. For more information, refer to How do I parse Correlation Alarm Info data? in the DataMiner Help.
In addition to the already proposed solutions, there is also the possibility to work with an enhanced service. In case you assign a service protocol to the service, you can expose a parameter which holds the service state.
With our standard "Skyline Service Definition Basic" protocol, the service state will be exposed in parameter with id 2.
Through an automation script, it is then possible to fetch the parameter value.
---
ElementFilter filter = new ElementFilter { IncludeServiceElements=true, NameFilter="serviceName" };
Element[] els = engine.FindElements(filter);
double severityLevel = Convert.ToDouble(els[0].GetParameter(2));
---
The advantage of this approach over the proposed alternatives:
- Not using SLNet calls, which are not documented and not guaranteed to be backwards compatible.
- Not having to use correlation and having to rely on individual alarms in order to draw conclusions on the overall service state, which could quickly get quite complex.
The downside is that an enhanced service consumes some system resources. Especially if you're working on a large scale - a lot of service objects - you'll need to carefully consider if this is the right approach.