Hi Dojo,
I have a question, that derives from this thread.
I would like to use the alarm state of a view (respective the highest severity of alarms in all views below that view) as variable in an automation script. Is there a method to retrieve that value from a view? This should then finally used to set a value of a property for this view.
My scripts looks like this and is working well with a fixed value instead of the alarm severity variable and includes some exception handling already.
public class Script
{
public void Run(Engine engine)
{
ViewInfoEventMessage[] allViews = GetViews();
if(allViews == null)
{
engine.ExitFail("No views were found");
}
foreach(ViewInfoEventMessage view in allViews)
{
// do the filtering of views you want to update
if(view.Name.Equals("ABC"))
{
UpdateViewProperty(view,"ABC","12345",engine);
}
}
}
public void UpdateViewProperty(ViewInfoEventMessage view, string propertyName, string propertyValue, Engine engine)
{
SetDataMinerInfoMessage request = new SetDataMinerInfoMessage();
request.bInfo1 = Int32.MaxValue;
request.bInfo2 = Int32.MaxValue;
request.DataMinerID = -1;
request.ElementID = -1;
request.HostingDataMinerID = -1;
request.IInfo1 = Int32.MaxValue;
request.IInfo2 = Int32.MaxValue;
SA sa = new SA();
sa.Sa = new String[] { propertyName, "read-write", propertyValue };
PSA psa = new PSA();
psa.Psa = new SA[] { sa };
request.Psa2 = psa;
request.StrInfo1 = $"view:{view.ID}";
request.What = 62;
SetDataMinerInfoResponseMessage response = engine.SendSLNetSingleResponseMessage(request) as SetDataMinerInfoResponseMessage;
if (response.iRet != 0)
{
engine.GenerateInformation($"Update of property {propertyName} on View {view.Name} was not OK");
}
}
public ViewInfoEventMessage[] GetViews()
{
var getViewsList = new GetInfoMessage
{
DataMinerID = -1,
Type = InfoType.ViewInfo
};
DMSMessage[] dmsma = Engine.SLNet.SendMessage(getViewsList);
if (dmsma == null)
{
return null;
}
return Array.ConvertAll(dmsma, input => (ViewInfoEventMessage)input);
}
}
Could you enlighten me?
Many thanks in advance and best regards
André
Hello and many thanks!
I merged the GetViewLevel function into the script and got it working now. The property updates according to the current alarm level of the view. I just have to tweak my correlation rule to only be triggered on a change of the alarm level and not on any change on an alarm on the elements below.
The purpose behind is, that an external system. reads the properties of this view and shows a traffic light summary alarm in its UI. It uses the GetViewProperty method on the DM WebService already for other purposes and we want to avoid to implement another method in the driver just to get one single value from DataMiner. Otherwise there would be suitable WebService methods available out of the box.