mirror of
https://github.com/openmhz/trunk-server.git
synced 2026-11-09 15:27:30 -05:00
@@ -12,6 +12,9 @@ const mailjet = new Mailjet({
|
||||
apiSecret: process.env['MAILJET_SECRET']
|
||||
});
|
||||
|
||||
var systemList = [];
|
||||
var systemListTime = Date.now();
|
||||
|
||||
exports.contact_system = async function(req, res) {
|
||||
var system = await System.findOne({
|
||||
shortName: req.params.shortName.toLowerCase()
|
||||
@@ -97,25 +100,19 @@ exports.contact_system = async function(req, res) {
|
||||
|
||||
}
|
||||
|
||||
exports.get_systems = async function (req, res) {
|
||||
async function load_systems(systemClients) {
|
||||
let fromDate = new Date(Date.now() - 60 * 60 * 24 * 30 * 1000);
|
||||
//const results = await System.find({lastActive: {$gte: fromDate}}).populate('userId', "screenName").catch( err => {
|
||||
const results = await System.find({lastActive: {$gte: fromDate}}).populate('userId', "screenName").catch( err => {
|
||||
//const results = await System.find({active: true}).populate('userId', "screenName").catch( err => {
|
||||
const results = await System.find({active: true}).catch( err => {
|
||||
//const results = await System.find({active: true}).catch( err => { // super simple query
|
||||
console.error("Error - get_systems: " + err.message);
|
||||
res.status(500);
|
||||
res.json({
|
||||
success: false,
|
||||
message: err
|
||||
});
|
||||
return;
|
||||
});
|
||||
var systemList = [];
|
||||
systemList = [];
|
||||
for (var result in results) {
|
||||
|
||||
var clientCount = 0;
|
||||
if (req.systemClients.hasOwnProperty(results[result].shortName)) {
|
||||
clientCount = req.systemClients[results[result].shortName];
|
||||
if (systemClients.hasOwnProperty(results[result].shortName)) {
|
||||
clientCount = systemClients[results[result].shortName];
|
||||
}
|
||||
var system = {
|
||||
name: results[result].name,
|
||||
@@ -142,6 +139,16 @@ exports.get_systems = async function (req, res) {
|
||||
system.screenName = null;
|
||||
systemList.push(system);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
exports.get_systems = async function (req, res) {
|
||||
if ((systemList.length == 0) || (systemListTime < (Date.now() - 60 * 1000 * 15))) {
|
||||
await load_systems(req.systemClients);
|
||||
systemListTime = Date.now();
|
||||
}
|
||||
|
||||
res.contentType('json');
|
||||
res.send(JSON.stringify({
|
||||
success: true,
|
||||
|
||||
@@ -13,7 +13,7 @@ const { NodeHttpHandler } = require('@smithy/node-http-handler');
|
||||
const https = require('https');
|
||||
|
||||
const agent = new https.Agent({
|
||||
maxSockets: 150
|
||||
maxSockets: 250
|
||||
});
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ var s3_endpoint = process.env['S3_ENDPOINT'] != null ? process.env['S3_ENDPOINT'
|
||||
var s3_region = process.env['S3_REGION'] != null ? process.env['S3_REGION'] : 'us-west-1';
|
||||
var s3_bucket = process.env['S3_BUCKET'] != null ? process.env['S3_BUCKET'] : 'openmhz-west';
|
||||
var s3_profile = process.env['S3_PROFILE'] != null ? process.env['S3_PROFILE'] : 'wasabi-account';
|
||||
|
||||
var s3_public_url = process.env['S3_PUBLIC_URL'] != null ? process.env['S3_PUBLIC_URL'] : s3_endpoint + "/" + s3_bucket;
|
||||
|
||||
const client = new S3Client({
|
||||
requestHandler: new NodeHttpHandler({
|
||||
@@ -165,7 +165,7 @@ exports.upload = async function (req, res, next) {
|
||||
|
||||
var endpoint = s3_endpoint;
|
||||
var bucket = s3_bucket;
|
||||
var url = s3_endpoint + "/" + s3_bucket + "/" + object_key;
|
||||
var url = s3_public_url + "/" + object_key;
|
||||
|
||||
var call = new Call({
|
||||
shortName: shortName,
|
||||
|
||||
@@ -270,7 +270,7 @@ io.sockets.on('connection', function (client) {
|
||||
|
||||
if (typeof clients[client.id] === "undefined") {
|
||||
console.error("How can it be undefined here!!");
|
||||
console.error(clients[client.id]);
|
||||
console.error(client.id);
|
||||
return;
|
||||
}
|
||||
if (group) {
|
||||
|
||||
@@ -15,19 +15,20 @@ async function updateActiveSystems() {
|
||||
// go through all the systems
|
||||
// if you have received some calls during that last period, make the system active
|
||||
if ((callTotals[item.shortName] != undefined) && (callTotals[item.shortName][0] > 0)) {
|
||||
//item.active = true;
|
||||
item.active = true;
|
||||
item.callAvg = callTotals[item.shortName][0] / timePeriod;
|
||||
item.lastActive = new Date();
|
||||
} else {
|
||||
//item.active = false;
|
||||
item.active = false;
|
||||
item.callAvg = 0;
|
||||
}
|
||||
/*
|
||||
let fromDate = new Date(Date.now() - 60 * 60 * 24 * 30 * 1000);
|
||||
if ((item.lastActive != null) && (item.lastActive > fromDate)) {
|
||||
item.active = true;
|
||||
} else {
|
||||
item.active = false;
|
||||
}
|
||||
}*/
|
||||
await item.save();
|
||||
};
|
||||
}
|
||||
@@ -76,6 +77,7 @@ exports.addError = function (call) {
|
||||
|
||||
// Keeps track of the number of calls for each talkgroup for a system
|
||||
exports.addCall = function (call) {
|
||||
/*
|
||||
// if you haven't started keeping track of stats for the System yet
|
||||
if (talkgroupStats[call.shortName] === undefined) {
|
||||
talkgroupStats[call.shortName] = {};
|
||||
@@ -121,14 +123,14 @@ exports.addCall = function (call) {
|
||||
// add to the call count and total length, Call Average is calc by dividing the two...
|
||||
sysErrors[call.freq].totalLen += call.len;
|
||||
sysErrors[call.freq].errors += call.errorCount;
|
||||
sysErrors[call.freq].spikes += call.spikeCount;
|
||||
sysErrors[call.freq].spikes += call.spikeCount;*/
|
||||
}
|
||||
|
||||
|
||||
// This gets called when a Time Period is up
|
||||
exports.shiftStats = async function () {
|
||||
|
||||
|
||||
console.log("Started Shifting Stats at: " + new Date());
|
||||
// for all the systems in Error Stats
|
||||
for (var shortName in uploadErrors) {
|
||||
if (uploadErrors.hasOwnProperty(shortName)) {
|
||||
@@ -147,8 +149,8 @@ exports.shiftStats = async function () {
|
||||
uploadErrors[shortName][0] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
console.log("Finished Shifting Upload Errors at: " + new Date());
|
||||
/*
|
||||
// for each system in decodeErrorsFreq
|
||||
for (let shortName in decodeErrorsFreq) {
|
||||
|
||||
@@ -195,7 +197,7 @@ exports.shiftStats = async function () {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
console.log("Finished Shifting Decode Errors at: " + new Date());
|
||||
|
||||
// for each system in talkgroupStats
|
||||
for (let shortName in talkgroupStats) {
|
||||
@@ -265,7 +267,9 @@ exports.shiftStats = async function () {
|
||||
await SystemStat.updateOne(query, update, options);
|
||||
}
|
||||
}
|
||||
console.log("Finished Shifting Talkgroup Stats at: " + new Date());*/
|
||||
updateActiveSystems();
|
||||
console.log("Finished Updating Active Systems at: " + new Date());
|
||||
}
|
||||
exports.callTotals = function (shortName) {
|
||||
return callTotals[shortName];
|
||||
|
||||
@@ -77,6 +77,7 @@ services:
|
||||
- S3_BUCKET
|
||||
- S3_PROFILE
|
||||
- S3_REGION
|
||||
- S3_PUBLIC_URL
|
||||
- OTEL_SERVICE_NAME
|
||||
- HONEYCOMB_API_KEY
|
||||
volumes:
|
||||
|
||||
Reference in New Issue
Block a user