From 582a85099230105ec83645a62d153b7c377f6b29 Mon Sep 17 00:00:00 2001 From: Jose Cuadra Date: Thu, 3 Apr 2025 10:44:03 -0600 Subject: [PATCH] RAD-5646 Monitor and Alert on Event Counts via Scheduled Task --- event-count-monitoring.js | 63 ++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 38 deletions(-) diff --git a/event-count-monitoring.js b/event-count-monitoring.js index 1408f56..2d0b2d1 100644 --- a/event-count-monitoring.js +++ b/event-count-monitoring.js @@ -86,13 +86,8 @@ function checkEventCounts() { var dateArray = new Array(); dateArray.push(new Date(dateFromRecent)); dateArray.push(new Date()); - const newquery = services.eventInstanceService.countQuery(conditions, dateArray); - const tempTotal = newquery[0].getTotal(); - var sum=0; - tempTotal.keySet().forEach((item) => { - sum += tempTotal.get(item); - }); - EVENT_TYPES_SUM.push(sum); + const newquery = services.eventInstanceService.count(rql.toString()); + EVENT_TYPES_SUM.push(newquery); } console.log("=============================== NUMBER OF EVENTS FOR RECENT PERIOD =============================== ") @@ -116,17 +111,9 @@ function checkEventCounts() { rql = RQLUtils.addAndRestriction(rql, new ASTNode("lt", "activeTs", dateNow.valueOf())); var conditions = new ConditionSortLimit(null, null, null, null); conditions = eventInstanceService.rqlToCondition(rql, subSelectMap, null, null); - var dateArray = new Array(); - dateArray.push(new Date(dateFromRecentMultiplier)); - dateArray.push(new Date()); - const newquery = services.eventInstanceService.countQuery(conditions, dateArray); - const tempTotal = newquery[0].getTotal(); - - var sum=0; - tempTotal.keySet().forEach((item) => { - sum += tempTotal.get(item); - }); - EVENT_TYPES_RANGE_PERIOD_SUM.push(sum); + const newquery = services.eventInstanceService.count(rql.toString()); + + EVENT_TYPES_RANGE_PERIOD_SUM.push(newquery); } console.log("=============================== NUMBER OF TOTAL EVENTS BY TYPE =============================== ") @@ -227,26 +214,26 @@ function determineDataPointType(dataPoint) { }; function setDataPointValue(dataPoint, newValue) { - const pointType = determineDataPointType(dataPoint); + const pointType = determineDataPointType(dataPoint); switch (pointType) { - case "BINARY": - //console.log(pointType); - const newBinaryValue = new binaryValue(!!newValue); - dataPointService.setValue(dataPoint.getId(), newBinaryValue, null); - break; - case "MULTISTATE": - //console.log(pointType); - const newMultistateValue = new multistateValue(newValue); - dataPointService.setValue(dataPoint.getId(), newMultistateValue, null); - break; - case "NUMERIC": - //console.log(pointType); - const newNumericValue = new numericValue(newValue); - dataPointService.setValue(dataPoint.getId(), newNumericValue, null); - break; - default: - console.log("Unsupported data point type: " + pointType + " for XID " + dataPoint.getXid()); - log.error(`Unsupported data point type: ${pointType} for XID ${dataPoint.getXid()}`); + case "BINARY": + //console.log(pointType); + const newBinaryValue = new binaryValue(!!newValue); + dataPointService.setValue(dataPoint.getId(), newBinaryValue, null); + break; + case "MULTISTATE": + //console.log(pointType); + const newMultistateValue = new multistateValue(newValue); + dataPointService.setValue(dataPoint.getId(), newMultistateValue, null); + break; + case "NUMERIC": + //console.log(pointType); + const newNumericValue = new numericValue(newValue); + dataPointService.setValue(dataPoint.getId(), newNumericValue, null); + break; + default: + console.log("Unsupported data point type: " + pointType + " for XID " + dataPoint.getXid()); + log.error(`Unsupported data point type: ${pointType} for XID ${dataPoint.getXid()}`); } return; -}; +}; \ No newline at end of file