Split SMBIOS information into seperate collection.

This commit is contained in:
Ylian Saint-Hilaire 2019-02-25 11:13:13 -08:00
parent 0865403772
commit 5d1423cbaf
36 changed files with 41 additions and 11 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

1
bob1.json Normal file

File diff suppressed because one or more lines are too long

14
db.js
View File

@ -113,6 +113,8 @@ module.exports.CreateDB = function (parent) {
}
});
// Setup MongoDB smbios collection, no indexes needed
obj.smbiosfile = db.collection('smbios'); // Collection containing all smbios information
} else {
// Use NeDB (The default)
obj.databaseType = 1;
@ -162,6 +164,9 @@ module.exports.CreateDB = function (parent) {
obj.powerfile.persistence.setAutocompactionInterval(36000);
obj.powerfile.ensureIndex({ fieldName: 'nodeid' });
obj.powerfile.ensureIndex({ fieldName: 'time', expireAfterSeconds: 60 * 60 * 24 * 10 }); // Limit the power event log to 10 days (Seconds * Minutes * Hours * Days)
// Setup the SMBIOS collection
obj.smbiosfile = new Datastore({ filename: obj.parent.getConfigFilePath('meshcentral-smbios.db'), autoload: true });
}
obj.SetupDatabase = function (func) {
@ -193,10 +198,10 @@ module.exports.CreateDB = function (parent) {
// TODO: Remove all mesh links to invalid users
// TODO: Remove all meshes that dont have any links
// Remote all the events and power events from the main collection.
// They are all in two seperate collections now.
// Remove all events, power events and SMBIOS data from the main collection. They are all in seperate collections now.
obj.file.remove({ type: 'event' }, { multi: true });
obj.file.remove({ type: 'power' }, { multi: true });
obj.file.remove({ type: 'smbios' }, { multi: true });
// Remove all objects that have a "meshid" that no longer points to a valid mesh.
obj.GetAllType('mesh', function (err, docs) {
@ -294,6 +299,11 @@ module.exports.CreateDB = function (parent) {
obj.getPowerTimeline = function (nodeid, func) { if (obj.databaseType == 1) { obj.powerfile.find({ nodeid: { $in: ['*', nodeid] } }, { _id: 0, nodeid: 0, s: 0 }).sort({ time: 1 }).exec(func); } else { obj.powerfile.find({ nodeid: { $in: ['*', nodeid] } }, { _id: 0, nodeid: 0, s: 0 }).sort({ time: 1 }, func); } };
obj.removeAllPowerEvents = function (domain) { obj.powerfile.remove({ }, { multi: true }); };
// Database actions on the SMBIOS collection
obj.SetSMBIOS = function (smbios, func) { obj.smbiosfile.update({ _id: smbios._id }, smbios, { upsert: true }, func); };
obj.RemoveSMBIOS = function (id) { obj.smbiosfile.remove({ _id: id }); };
obj.GetSMBIOS = function (id, func) { obj.smbiosfile.find({ _id: id }, func); };
// Read a configuration file from the database
obj.getConfigFile = function (path, func) { obj.Get('cfile/' + path, func); }

View File

@ -73,7 +73,7 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
obj.db.Remove('if' + obj.dbNodeKey); // Remove interface information
obj.db.Remove('nt' + obj.dbNodeKey); // Remove notes
obj.db.Remove('lc' + obj.dbNodeKey); // Remove last connect time
obj.db.Remove('sm' + obj.dbNodeKey); // Remove SMBios data
obj.db.RemoveSMBIOS(obj.dbNodeKey); // Remove SMBios data
obj.db.RemoveNode(obj.dbNodeKey); // Remove all entries with node:id
// Event node deletion
@ -893,8 +893,8 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
}
case 'smbios':
{
// The RAW SMBios table of this computer
obj.db.Set({ _id: 'sm' + obj.dbNodeKey, type: 'smbios', domain: domain.id, time: Date.now(), smbios: command.value });
// Store the RAW SMBios table of this computer
obj.db.SetSMBIOS({ _id: obj.dbNodeKey, domain: domain.id, time: new Date(), value: JSON.stringify(command.value) });
// Event the node interface information change (This is a lot of traffic, probably don't need this).
//obj.parent.parent.DispatchEvent(['*', obj.meshid], obj, { action: 'smBiosChange', nodeid: obj.dbNodeKey, domain: domain.id, smbios: command.value, nolog: 1 });

View File

@ -362,7 +362,13 @@ function CreateMeshCentralServer(config, args) {
if ((json == null) || (typeof json.length != 'number') || (json.length < 1)) { console.log('Invalid JSON format: ' + obj.args.dbimport + '.'); }
for (i in json) { if ((json[i].type == "mesh") && (json[i].links != null)) { for (var j in json[i].links) { var esc = obj.common.escapeFieldName(j); if (esc !== j) { json[i].links[esc] = json[i].links[j]; delete json[i].links[j]; } } } } // Escape MongoDB invalid field chars
//for (i in json) { if ((json[i].type == "node") && (json[i].host != null)) { json[i].rname = json[i].host; delete json[i].host; } } // DEBUG: Change host to rname
obj.db.RemoveAll(function () { obj.db.InsertMany(json, function (err) { if (err != null) { console.log(err); } else { console.log('Imported ' + json.length + ' objects(s) from ' + obj.args.dbimport + '.'); } process.exit(); }); });
setTimeout(function () { // If the Mongo database is being created for the first time, there is a race condition here. This will get around it.
obj.db.RemoveAll(function () {
obj.db.InsertMany(json, function (err) {
if (err != null) { console.log(err); } else { console.log('Imported ' + json.length + ' objects(s) from ' + obj.args.dbimport + '.'); } process.exit();
});
});
}, 100);
return;
}
/*

View File

@ -1250,7 +1250,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
obj.db.Remove('if' + node._id); // Remove interface information
obj.db.Remove('nt' + node._id); // Remove notes
obj.db.Remove('lc' + node._id); // Remove last connect time
obj.db.Remove('sm' + node._id); // Remove SMBios data
obj.db.RemoveSMBIOS(node._id); // Remove SMBios data
obj.db.RemoveNode(node._id); // Remove all entries with node:id
// Event node deletion

View File

@ -1,6 +1,7 @@
{
"__comment__" : "This is a sample configuration file, edit a section and remove the _ in front of the name. Refer to the user's guide for details.",
"settings": {
"_Cert": "myserver.mydomain.com",
"_MongoDb": "mongodb://127.0.0.1:27017/meshcentral",
"_WANonly": true,
"_LANonly": true,
@ -8,7 +9,10 @@
"_SessionTime": 30,
"_SessionKey": "MyReallySecretPassword1",
"_DbEncryptKey": "MyReallySecretPassword2",
"_DbExpire": { "events": 1728000, "powerevents": 864000 },
"_DbExpire": {
"events": 1728000,
"powerevents": 864000
},
"_Port": 443,
"_RedirPort": 80,
"_AllowLoginToken": true,
@ -20,10 +24,18 @@
"_UserBlockedIP": "127.0.0.1,::1,192.168.0.100",
"_AgentAllowedIP": "192.168.0.100/24",
"_AgentBlockedIP": "127.0.0.1,::1",
"_LocalDiscovery": { "name": "Local server name", "info": "Information about this server" },
"_LocalDiscovery": {
"name": "Local server name",
"info": "Information about this server"
},
"_TlsOffload": true,
"_MpsTlsOffload": true,
"_WebRtConfig": { "iceServers": [ { "urls": "stun:stun.services.mozilla.com" }, { "urls": "stun:stun.l.google.com:19302" } ] }
"_WebRtConfig": {
"iceServers": [
{ "urls": "stun:stun.services.mozilla.com" },
{ "urls": "stun:stun.l.google.com:19302" }
]
}
},
"_domains": {
"": {

View File

@ -5726,7 +5726,8 @@
if (currentMesh == null) return;
QH('p20meshName', EscapeHtml(currentMesh.name));
var meshtype = 'Unknown #' + currentMesh.mtype;
var meshrights = currentMesh.links['user/' + domain + '/' + userinfo.name.toLowerCase()].rights;
var meshrights = 0;
try { meshrights = currentMesh.links['user/' + domain + '/' + userinfo.name.toLowerCase()].rights; } catch (ex) { }
if (currentMesh.mtype == 1) meshtype = 'Intel&reg; AMT only, no agent';
if (currentMesh.mtype == 2) meshtype = 'Managed using a software agent';