Skip to content

Commit

Permalink
updated diag package
Browse files Browse the repository at this point in the history
  • Loading branch information
adnanrahic committed May 11, 2020
1 parent ccec648 commit 9eecbf1
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 32 deletions.
32 changes: 0 additions & 32 deletions bin/spm-client-diagnostics.js

This file was deleted.

65 changes: 65 additions & 0 deletions bin/spm-nodejs-diagnostics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env node
/*
* @copyright Copyright (c) Sematext Group, Inc. - All Rights Reserved
*
* @licence SPM for Node.js is free-to-use, proprietary software.
* THIS IS PROPRIETARY SOURCE CODE OF Sematext Group, Inc. (Sematext)
* This source code may not be copied, reverse engineered, or altered for any purpose.
* This source code is to be used exclusively by users and customers of Sematext.
* Please see the full license (found in LICENSE in this distribution) for details on its license and the licenses of its dependencies.
*/
var fs = require('fs')
var AdmZip = require('adm-zip')
var zip = new AdmZip()
var config = require('spm-agent').Config
var util = require('util')
var os = require('os')
var path = require('path')

var systemInfo = {
operatingSystem: os.type() + ', ' + os.platform() + ', ' + os.release() + ', ' + os.arch(),
processVersions: process.versions,
processEnvironment: process.env
}

// load ENV like Logsene receivers from file containing
// env vars e.g. SPM_RECEIVER_URL, EVENTS_RECEIVER_URL, LOGSENE_RECEIVER_URL
// the file overwrites the actual environment
// and is used by Sematext Enterprise or multi-region setups to
// setup receiver URLs
function loadEnvFromFile (fileName) {
try {
var receivers = fs.readFileSync(fileName).toString()
if (receivers) {
var lines = receivers.split('\n')
}
systemInfo.receiverConfigFileUsed = fileName
systemInfo.receivers = receivers
console.log('Reading receivers.config: ' + fileName)
lines.forEach(function (line) {
var kv = line.split('=')
if (kv.length === 2 && kv[1].length > 0) {
process.env[kv[0].trim()] = kv[1].trim()
console.log(kv[0].trim() + ' = ' + kv[1].trim())
}
})
} catch (error) {}
}
var envFileName = '/etc/sematext/receivers.config'
/**
if (/win/.test(os.platform()) {
envFileName = process.env.ProgramData + '\\Sematext\\receivers.config'
}
**/
loadEnvFromFile(envFileName)

var cfgDumpFileName = path.join(os.tmpdir(), 'spm-nodejs-diagnostics.json')
fs.writeFileSync(cfgDumpFileName, util.inspect(config).toString() + '\nSystem-Info:\n' + util.inspect(systemInfo))
zip.addLocalFile(cfgDumpFileName)
zip.addLocalFolder(config.logger.dir)

var archFileName = path.join(os.tmpdir(), 'spm-nodejs-diagnostics.zip')
zip.writeZip(archFileName)
console.log('Sematext Agent Node.js diagnostics info is in: ' + archFileName)
console.log('Please e-mail the file to [email protected]')
fs.unlink(cfgDumpFileName, function () {})

0 comments on commit 9eecbf1

Please sign in to comment.