Metric Definition for priority being lowered
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2024 08:47 AM
Hello All,
I currently have a requirement to create a metric definition for incident priority that is lowered. I currently have the following code but it is not creating any metric definitions. Any help would be greatly appreciated!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2024 09:27 AM
@Patrick Cavanau Your image of code is not clear for me can't read anything, but you should be having similar logic:
// Ensure both current and previous priorities exist
if (!previous || !previous.priority || !current.priority) {
return false;
}
// Check if the priority was lowered
var currentPriority = parseInt(current.priority);
var previousPriority = parseInt(previous.priority);
if (currentPriority > previousPriority) {
gs.info("Metric captured: Priority lowered from " + previousPriority + " to " + currentPriority);
return true; // Metric will be recorded
}
return false;
Hope this will help you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2024 09:42 AM
thank you for this. Unfortunately, It will not allow me to use return in the code for metric definitions
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2024 09:58 AM
@Patrick Cavanau Please try below first in lower instance and this should work in metric definition:
// Ensure the Metric Instance is properly initialized
var mi = new MetricInstance(definition, current);
// Check if the metric instance exists and the priority has been lowered
if (!mi.metricExists()) {
// Capture the previous priority state for comparison
var prevPriority = current.priority.changes()[0]; // Get the previous priority value (if any)
// Check if the priority was lowered (we compare previous and current priority)
if (prevPriority && current.priority < prevPriority) { // Ensure priority is being lowered
gs.info("Priority lowered for Incident " + current.sys_id + " from " + prevPriority + " to " + current.priority);
// Start the duration when the priority is lowered
mi.startDuration();
}
}
// When the incident priority is updated, check if the metric instance exists and stop the duration
if (mi.metricExists() && current.priority != prevPriority) {
gs.info("Priority change detected for Incident " + current.sys_id + " from " + prevPriority + " to " + current.priority);
// End the duration for the priority change
mi.endDuration();
}