I have saved a filter to get only the alarms that i want to see in dataminer cube. Im trying to fetch the alarms that are part of that alarm filter through automation script. Is there a way to get it?
Once i get hold of the filtered alarms im displaying it in table in low code app for monitoring purpose
Hi Baranisudha,
I believe for your use case the best approach is to use the alarm table component. This component allows you to display alarms based on saved filters.
Hope it helps.
Hi Miguel, Thanks for this suggestion.
Based on the need, first I want to display the counts of my filtered alarms and if I click for more details, I should display those values.
Hi Baranisudha,
I created some pseudo code; I do kindly want to ask to be careful with the code as it could impact your system. Why? such request call will be processed in the DataMiner system and the outcome could be that quite some data is transmitted between the processes, such as thousands or ten thousands of alarms, which is a scenario that nobody wants.
Working with repositories:
public void Run(Engine engine) { try { var alarmFilterKey = "MyFilter"; var getAlarmFilterReq = new GetAlarmFilterMessage { Key = alarmFilterKey }; var getAlarmFilterResponse = engine.SendSLNetSingleResponseMessage(getAlarmFilterReq) as GetAlarmFilterResponse; if (getAlarmFilterResponse?.Filter is AlarmFilter alarmFilter) { var endTime = DateTime.Now; var beginTime = endTime.AddDays(-1); var alarmRepo = SLDataGateway.API.Repositories.Registry.DatabaseRepositoryRegistryBuilder.Default.WithConnection(engine.SLNetRaw).Build().Get<SLDataGateway.API.Types.Repositories.IAlarmRepository>(); var alarmsFromDB = alarmRepo.Read(alarmFilter, beginTime, endTime).OfType<AlarmEventMessage>().ToArray(); foreach (var alarm in alarmsFromDB) { //... } } } catch (ScriptAbortException e) { engine.GenerateInformation(e.ToString()); throw; } catch (Exception ex) { engine.GenerateInformation(ex.ToString()); } }
Working with raw messages:
public void Run(Engine engine) { try { var alarmFilterKey = "MyFilter"; var getAlarmFilterReq = new GetAlarmFilterMessage { Key = alarmFilterKey }; var getAlarmFilterResponse = engine.SendSLNetSingleResponseMessage(getAlarmFilterReq) as GetAlarmFilterResponse; if (getAlarmFilterResponse?.Filter is AlarmFilter alarmFilter) { var endTime = DateTime.Now; var beginTime = endTime.AddDays(-1); var getAlarmsReq = new GetAlarmDetailsFromDbMessage(dataMinerID: -1, filter: alarmFilter, startTime: beginTime, endTime: endTime, alarmTable: true, infoTable: false); var getAlarmsResponse = engine.SendSLNetMessage(getAlarmsReq) as DMSMessage[]; if (getAlarmsResponse?.Length > 0) { foreach (var alarmResponse in getAlarmsResponse) { if (alarmResponse is AlarmEventMessage alarm) { } } } } } catch (ScriptAbortException e) { engine.GenerateInformation(e.ToString()); throw; } catch (Exception ex) { engine.GenerateInformation(ex.ToString()); } }
Hope this helps you further
UPDATE: Added second pseudo code
if i use GetAlarmDetailsFromDbMessage to get filtered alarms, im getting more alarms which are not actually present in my cluster. It is returning double the count.
Hi, I don't exactly know what your use case is; so try to play around with options such as setting the ALarmtable option to false and verify if alarms are distinct.
Instead of using messages, you can also use repositories in order to get alarms.
I have updated original answer with also pseudo code.
Hi Baranisudha,
Small question, what will be the outcome for your automation script?
Once you process the filtered alarms, are you planning to generate a report, execute an action?