How to query or export alarm history from the database