These are the new queries, which are working for our setup based on an MSSQL database. I hope it helps someone else to get the alarm analysis page going. I provide no guarantees, this is just to get through some of the issues I encountered quicker. You will have to verify for yourself that it does what you need it do and modify as required.
Note: as per earlier in the thread, the parameter “limit” cannot be passed as a value, it needs to be made a “QueryString”.
Also note: one of the queries didn’t have the start and end dates set as “DateTime” data type, can’t remember which it was, but it should be changed.
Alarm History:
SELECT TOP {limit}
FORMAT(e.eventTime, 'DD/MM/YYYY hh:mm:ss') eventTime,
e.displayPath,
LEFT(source,PATINDEX('%/alm:%',source)-2) name,
e.eventType,
CASE WHEN e.priority = 0 THEN 'Diagnostic' WHEN e.priority = 1 THEN 'Low' WHEN e.priority = 2 THEN 'Medium' WHEN e.priority = 3 THEN 'High' WHEN e.priority = 4 THEN 'Critical' ELSE '' END priority,
COALESCE(COALESCE(COALESCE(d.intvalue, d.floatvalue), d.strvalue), '') eventValue,
COALESCE(ack.strvalue, '') ackUser
FROM
alarm_events e
LEFT JOIN alarm_event_data d ON d.id = e.id AND d.propname = 'eventValue'
LEFT JOIN alarm_event_data ack ON ack.id = e.id AND ack.propname = 'ackUser'
WHERE
eventtime BETWEEN :startDate AND :endDate AND priority BETWEEN :minPriority AND :maxPriority AND
(((:active = 1) AND (e.eventtype = 0)) OR ((:clear = 1) AND (e.eventtype = 1)) OR ((:ack = 1 AND e.eventtype = 2)))
ORDER BY
e.eventTime DESC
Alarm Summary:
SELECT
a.priority,
SUM(CASE WHEN c.eventtime IS NULL THEN 1 ELSE 0 END) active,
SUM(CASE WHEN c.eventtime IS NULL THEN 0 ELSE 1 END) cleared,
SUM(CASE WHEN k.eventtime IS NULL THEN 1 ELSE 0 END) unacknowledged,
COUNT(*) total,
AVG(CASE WHEN k.eventtime IS NULL THEN 0 ELSE DATEDIFF(SECOND, a.eventtime, COALESCE(k.eventtime, CURRENT_TIMESTAMP)) END) acknowledgeTime,
AVG(CASE WHEN c.eventtime IS NULL THEN 0 ELSE DATEDIFF(SECOND, a.eventtime, COALESCE(c.eventtime, CURRENT_TIMESTAMP)) END) clearTime,
SUM(DATEDIFF(SECOND, a.eventtime, COALESCE(c.eventtime, CURRENT_TIMESTAMP))) totalTime
FROM
alarm_events a
LEFT JOIN alarm_events c ON c.eventid = a.eventid AND c.eventtype = 1
LEFT JOIN alarm_events k ON k.eventid = a.eventid AND k.eventtype = 2
WHERE
a.eventtime BETWEEN :startDate AND :endDate AND a.eventtype = 0
GROUP BY
a.priority
ORDER BY
a.priority ASC
Alarm Summary Table:
SELECT
CASE a.priority
WHEN 1 THEN 'Low'
WHEN 2 THEN 'Medium'
WHEN 3 THEN 'High'
WHEN 4 THEN 'Critical'
ELSE 'Diagnostic'
END as 'Priority',
SUM(CASE WHEN c.eventtime IS NULL THEN 1 ELSE 0 END) active,
SUM(CASE WHEN c.eventtime IS NULL THEN 0 ELSE 1 END) cleared,
SUM(CASE WHEN k.eventtime IS NULL THEN 1 ELSE 0 END) unacknowledged,
COUNT(*) total,
AVG(CASE WHEN k.eventtime IS NULL THEN 0 ELSE DATEDIFF(SECOND, a.eventtime, COALESCE(k.eventtime, CURRENT_TIMESTAMP)) END) acknowledgeTime,
AVG(CASE WHEN c.eventtime IS NULL THEN 0 ELSE DATEDIFF(SECOND, a.eventtime, COALESCE(c.eventtime, CURRENT_TIMESTAMP)) END) clearTime,
SUM(DATEDIFF(SECOND, a.eventtime, COALESCE(c.eventtime, CURRENT_TIMESTAMP))) totalTime
FROM
alarm_events a
LEFT JOIN alarm_events c ON c.eventid = a.eventid AND c.eventtype = 1
LEFT JOIN alarm_events k ON k.eventid = a.eventid AND k.eventtype = 2
WHERE
a.eventtime
BETWEEN :startDate AND :endDate
AND a.eventtype = 0
GROUP BY
a.priority
ORDER BY
a.priority ASC
Alarms By Hour:
SELECT
DATEPART(hour,a.eventtime) label,
COUNT(*) total,
SUM(DATEDIFF(SECOND, a.eventtime, COALESCE(c.eventtime, CURRENT_TIMESTAMP))) duration
FROM
alarm_events a
LEFT JOIN alarm_events c ON c.eventid = a.eventid AND c.eventtype = 1
WHERE
a.eventtime BETWEEN :startDate AND :endDate AND a.eventtype = 0
GROUP BY
DATEPART(hour,a.eventtime)
ORDER BY
DATEPART(hour,a.eventtime) ASC
Alarms Duration:
SELECT TOP {limit}
CASE WHEN a.displaypath = '' THEN 'Unknown' ELSE a.displaypath END displaypath,
SUM(DATEDIFF(SECOND, a.eventtime, COALESCE(c.eventtime, CURRENT_TIMESTAMP))) duration
FROM
alarm_events a
LEFT JOIN alarm_events c ON c.eventid = a.eventid AND c.eventtype = 1
WHERE
a.eventtime BETWEEN :startDate AND :endDate AND a.eventtype = 0
GROUP BY
a.displaypath
ORDER BY
duration DESC, a.displaypath ASC
Alarms Frequency:
SELECT TOP {limit}
CASE WHEN a.displaypath = '' THEN 'Unknown' ELSE a.displaypath END displaypath,
COUNT(*) total
FROM
alarm_events a
WHERE
a.eventtime BETWEEN :startDate AND :endDate AND a.eventtype = 0
GROUP BY
a.displaypath
ORDER BY total DESC , a.displaypath ASC
Longest Duration Alarm:
SELECT TOP 1
CASE WHEN a.displaypath = '' THEN 'Unknown' ELSE a.displaypath END displaypath,
SUM(DATEDIFF(SECOND, a.eventtime, COALESCE(c.eventtime, CURRENT_TIMESTAMP))) total
FROM
alarm_events a
LEFT JOIN alarm_events c ON c.eventid = a.eventid AND c.eventtype = 1
WHERE
a.eventtime BETWEEN :startDate AND :endDate AND a.eventtype = 0
GROUP BY
a.displaypath
ORDER BY total DESC
Most Frequent Alarm:
SELECT TOP 1
CASE WHEN a.displaypath = '' THEN 'Unknown' ELSE a.displaypath END displaypath,
COUNT(*) total
FROM
alarm_events a
WHERE
a.eventtime BETWEEN :startDate AND :endDate AND a.eventtype = 0
GROUP BY
a.displaypath
ORDER BY total DESC