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
}
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.