You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
2.9 KiB
66 lines
2.9 KiB
var path = require('path')
|
|
var fs = require('fs')
|
|
var skqlib = require('./skq_modules/skq-lib')
|
|
|
|
// GLOBAL CONFIG
|
|
process['CONFIG'] = JSON.parse(fs.readFileSync(path.join(__dirname, 'config','skqitam-server-config.json'), 'utf8'))
|
|
process['CONFIG']['GLOBAL']['RUN_DIR'] = __dirname
|
|
process['CONFIG']['LOCAL']= skqlib.it_am_init()
|
|
|
|
// console.log(JSON.stringify(process['CONFIG'], null, 2))
|
|
|
|
console.log('Data Dir: ' + path.join(__dirname, process['CONFIG']['GLOBAL']['ITAM_DATA_DIR']))
|
|
|
|
let hostdir_base = path.join(__dirname, process['CONFIG']['GLOBAL']['ITAM_DATA_DIR'], 'hosts')
|
|
let hostdirs = fs.readdirSync(hostdir_base)
|
|
|
|
// console.log(JSON.stringify(hostdirs, null, 2))
|
|
|
|
try {
|
|
fs.mkdirSync(path.join(__dirname, process['CONFIG']['GLOBAL']['ITAM_DATA_DIR'], 'reports'), { recursive: true })
|
|
} catch (e) {
|
|
console.log('ERROR: Could not mkdir: ' + path.join(__dirname, process['CONFIG']['GLOBAL']['ITAM_DATA_DIR'], 'reports'))
|
|
process.exit(1)
|
|
}
|
|
|
|
try {
|
|
fs.mkdirSync(path.join(__dirname, process['CONFIG']['GLOBAL']['ITAM_DATA_DIR'], 'proc'), { recursive: true })
|
|
} catch (e) {
|
|
console.log('ERROR: Could not mkdir: ' + path.join(__dirname, process['CONFIG']['GLOBAL']['ITAM_DATA_DIR'], 'indexed-data'))
|
|
process.exit(1)
|
|
}
|
|
|
|
let index_data_file = path.join(__dirname, process['CONFIG']['GLOBAL']['ITAM_DATA_DIR'], 'proc', 'index-data.json')
|
|
let index_data = {}
|
|
|
|
try {
|
|
index_data = JSON.parse(fs.readFileSync(index_data_file, 'utf8'))
|
|
} catch (e) {
|
|
// Do Nothing
|
|
}
|
|
|
|
|
|
for (hd in hostdirs) {
|
|
let data_files = fs.readdirSync(path.join(__dirname, process['CONFIG']['GLOBAL']['ITAM_DATA_DIR'], 'hosts', hostdirs[hd], 'raw'))
|
|
|
|
console.log ("LATEST DATA: " + path.join(__dirname, process['CONFIG']['GLOBAL']['ITAM_DATA_DIR'], 'hosts', hostdirs[hd], 'raw', data_files[0]))
|
|
|
|
let host_data = JSON.parse(fs.readFileSync(path.join(__dirname, process['CONFIG']['GLOBAL']['ITAM_DATA_DIR'], 'hosts', hostdirs[hd], 'raw', data_files[0]), 'utf8'))
|
|
|
|
// console.log(JSON.stringify(host_data, null, 2))
|
|
|
|
if (!index_data.hasOwnProperty(host_data['ITAM']['ID'])) {
|
|
index_data[ host_data['ITAM']['ID'] ] = {}
|
|
}
|
|
|
|
index_data[ host_data['ITAM']['ID'] ]['LATEST_DATA'] = host_data['ITAM']['STARTTIME']
|
|
index_data[ host_data['ITAM']['ID'] ]['HOSTNAME'] = host_data['ITAM']['HOSTNAME']
|
|
index_data[ host_data['ITAM']['ID'] ]['LOCAL_HOSTNAME'] = host_data['SOURCE']['NODEJS']['HOST']['HOSTNAME']
|
|
index_data[ host_data['ITAM']['ID'] ]['IP_ADDR'] = host_data['SOURCE']['NODEJS']['HOST']['IP_ADDR'][0]['address']
|
|
index_data[ host_data['ITAM']['ID'] ]['OS'] = host_data['SOURCE']['NODEJS']['OS']['DISTRO']
|
|
index_data[ host_data['ITAM']['ID'] ]['OS_VERSION'] = host_data['SOURCE']['NODEJS']['OS']['DISTRO_VERSION']
|
|
index_data[ host_data['ITAM']['ID'] ]['OS_INSTALL_DATE'] = host_data['SOURCE']['OS_INSTALL_ISO_DATE']
|
|
|
|
}
|
|
|
|
fs.writeFileSync(index_data_file, JSON.stringify(index_data, null, 2), 'utf8')
|