how to log alarms
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
how to log alarms
Hi,
I do create alerts for properties inside the things like the attached photo, is there a way to log these alerts when it happens into the database, and if yes, how i can query them back, like i want to query something that shows me the alert history for a certain property,
thank you,
Solved! Go to Solution.
- Labels:
-
Troubleshooting
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
To your questions,
1. Alerts are stored automatically,
2. The right way to query alert history is on the Thing which fired the alert. In this case it is somewhat similar to querying value streams -- you do it in the entity context. In your subscription the thing name is in the "source" parameter, so you'd do something like this:
// Parameters depend on the type of alert you need, see Help for details
let allAlerts = Things[source].QueryAlertHistory({
oldestFirst: undefined /* BOOLEAN */,
maxItems: undefined /* NUMBER {"defaultValue":500} */,
endDate: undefined /* DATETIME */,
query: undefined /* QUERY */,
startDate: undefined /* DATETIME */
});
Having said that, there's usually a better solution than querying alerts history in an alert subscription, which can be very inefficient, especially if your alerts fire frequently. We might be able to suggest you something better if you describe your use case in more detail.
/ Constantine
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Actually, what i meant is how to store it in database like using value stream or something like that, or it accurse automatically, and if it does, how to do the QueryAlertHistory in script inside a subscriber
thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
To your questions,
1. Alerts are stored automatically,
2. The right way to query alert history is on the Thing which fired the alert. In this case it is somewhat similar to querying value streams -- you do it in the entity context. In your subscription the thing name is in the "source" parameter, so you'd do something like this:
// Parameters depend on the type of alert you need, see Help for details
let allAlerts = Things[source].QueryAlertHistory({
oldestFirst: undefined /* BOOLEAN */,
maxItems: undefined /* NUMBER {"defaultValue":500} */,
endDate: undefined /* DATETIME */,
query: undefined /* QUERY */,
startDate: undefined /* DATETIME */
});
Having said that, there's usually a better solution than querying alerts history in an alert subscription, which can be very inefficient, especially if your alerts fire frequently. We might be able to suggest you something better if you describe your use case in more detail.
/ Constantine
