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