Skip to content

RAD-5646-Monitor and Alert on Event Counts via Scheduled Task #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 25 additions & 38 deletions event-count-monitoring.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 =============================== ")
Expand All @@ -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 =============================== ")
Expand Down Expand Up @@ -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;
};
};