|
|
@ -61,7 +61,7 @@ let mem_bytes = os.totalmem() |
|
|
|
let mem_mb = Math.round(mem_bytes/(1024*1024)) |
|
|
|
console.log (" RAM: " + mem_mb + ' MB') |
|
|
|
// console.log (" NET: " + JSON.stringify(os.networkInterfaces(), null, 2))
|
|
|
|
console.log (" BASE_URL: " + process['CONFIG']['GLOBAL']['SERVER_BASE_URL']) |
|
|
|
console.log (" ITAM SRV: " + process['CONFIG']['GLOBAL']['SERVER_BASE_URL']) |
|
|
|
console.log ("") |
|
|
|
// console.log (" Script: " + process.argv)
|
|
|
|
console.log ("Collecting Data: This may take serveral minutes .....") |
|
|
@ -229,75 +229,68 @@ function rpm_list_to_json(rpm_list) { |
|
|
|
} |
|
|
|
|
|
|
|
function dpkg_list_to_json(dpkg_list) { |
|
|
|
let json_obj = [] |
|
|
|
let json_obj = {} |
|
|
|
let lines = dpkg_list.split(/\n/) |
|
|
|
let dpkg_list_regx = RegExp(/(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S.*)/) |
|
|
|
let pkg_info_regx = RegExp(/^(.*):\s+(.*)/) |
|
|
|
let apt_history_regx = RegExp(/^(.*):\s+(.*)/) |
|
|
|
// let pkg_name_regx = RegExp(/^(.*):(.*)/)
|
|
|
|
|
|
|
|
process.stdout.write('Processing Apt Pkgs: [0/' + lines.length + '] 0 % ') |
|
|
|
|
|
|
|
// Extract Apt Log - /var/log/apt/history.log.*.gz
|
|
|
|
let cmc_extract_apt_history = 'zcat /var/log/apt/history.log.*.gz > /var/tmp/apt-history.log' |
|
|
|
let cmc_append_apt_history = 'cat /var/log/apt/history.log >> /var/tmp/apt-history.log' |
|
|
|
try { |
|
|
|
childProcess.execSync(cmc_extract_apt_history, { encoding: 'utf8' }) |
|
|
|
try { |
|
|
|
childProcess.execSync(cmc_append_apt_history, { encoding: 'utf8' }) |
|
|
|
} catch (err) { |
|
|
|
console.log('ERROR: Failed to Extract Apt Log History ' + err) |
|
|
|
process.exit(1) |
|
|
|
} |
|
|
|
} catch (err) { |
|
|
|
console.log('ERROR: Failed to Extract Apt Log History ' + err) |
|
|
|
process.exit(1) |
|
|
|
let apt_history = apt_history_to_json() |
|
|
|
for (pkg_name in apt_history) { |
|
|
|
json_obj[pkg_name] = {} |
|
|
|
json_obj[pkg_name]['DPKG_LIST'] = {} |
|
|
|
json_obj[pkg_name]['APT_HISTORY'] = apt_history[pkg_name] |
|
|
|
json_obj[pkg_name]['APT_CACHE'] = {} |
|
|
|
} |
|
|
|
|
|
|
|
// Collect Package Meta Data
|
|
|
|
for (l in lines) { |
|
|
|
if ( (l % 10) == 0 ) { |
|
|
|
process.stdout.clearLine(); |
|
|
|
process.stdout.cursorTo(0); |
|
|
|
process.stdout.write('Processing Apt Pkgs: [' + l + '/' + lines.length + '] ' + Math.round(100 * l / Number(lines.length)) + ' % ') |
|
|
|
} |
|
|
|
|
|
|
|
if (mch = lines[l].match(dpkg_list_regx)) { |
|
|
|
if (mch[1] != "||/") { |
|
|
|
let pkg_name_split = String(mch[2]).split(':') |
|
|
|
let pkg_name = pkg_name_split[0] |
|
|
|
// console.log (JSON.stringify(pkg_name_split))
|
|
|
|
let pkg = {} |
|
|
|
pkg['SW_STATUS'] = mch[1] |
|
|
|
pkg['SW_NAME'] = mch[2] |
|
|
|
pkg['SW_VERSION'] = mch[3] |
|
|
|
pkg['SW_ARCH'] = mch[4] |
|
|
|
pkg['SW_DESCRIPTION'] = mch[5] |
|
|
|
pkg['STATUS'] = mch[1] |
|
|
|
pkg['NAME'] = mch[2] |
|
|
|
pkg['VERSION'] = mch[3] |
|
|
|
pkg['ARCH'] = mch[4] |
|
|
|
pkg['DESCRIPTION'] = mch[5] |
|
|
|
// console.log (pkg['SW_NAME'])
|
|
|
|
// console.log(pkg_name)
|
|
|
|
|
|
|
|
let cmd_pkg_info = 'apt-cache show ' + pkg['SW_NAME'] |
|
|
|
let pkg_info = childProcess.execSync(cmd_pkg_info, { encoding: 'utf8' }) |
|
|
|
let pkg_info_lines = pkg_info.split(/\n/) |
|
|
|
pkg['APT_CACHE'] = {} |
|
|
|
for (pl in pkg_info_lines) { |
|
|
|
if ( (l % 10) == 0 ) { |
|
|
|
process.stdout.clearLine(); |
|
|
|
process.stdout.cursorTo(0); |
|
|
|
process.stdout.write('Processing Apt Pkgs: [' + l + '/' + lines.length + '] ' + Math.round(100 * l / Number(lines.length)) + ' % ') |
|
|
|
} |
|
|
|
if (! json_obj.hasOwnProperty(pkg_name)) { |
|
|
|
json_obj[pkg_name] = {} |
|
|
|
json_obj[pkg_name]['DPKG_LIST'] = {} |
|
|
|
json_obj[pkg_name]['APT_HISTORY'] = {} |
|
|
|
json_obj[pkg_name]['APT_CACHE'] = {} |
|
|
|
} |
|
|
|
|
|
|
|
if (pmch = pkg_info_lines[pl].match(pkg_info_regx)) { |
|
|
|
pkg['APT_CACHE'][ pmch[1] ] = pmch[2] |
|
|
|
} |
|
|
|
json_obj[pkg_name]['DPKG_LIST'] = pkg |
|
|
|
|
|
|
|
pkg['APT_HISTORY'] = {} |
|
|
|
let cmd_apt_history = "/bin/egrep -B 2 '^Install\:.*" + pkg['SW_NAME'] + "' /var/tmp/apt-history.log" |
|
|
|
let cmd_pkg_info = 'apt-cache show ' + pkg['NAME'] |
|
|
|
try { |
|
|
|
let pkg_info_lines = String(childProcess.execSync(cmd_pkg_info, { encoding: 'utf8' })).split(/\n/) |
|
|
|
|
|
|
|
try { |
|
|
|
let apt_history = childProcess.execSync(cmd_apt_history, { encoding: 'utf8' }) |
|
|
|
let apt_history_lines = apt_history.split(/\n/) |
|
|
|
for (ah in apt_history_lines) { |
|
|
|
if (amch = apt_history_lines[ah].match(apt_history_regx)) { |
|
|
|
pkg['APT_HISTORY'][ amch[1] ] = amch[2] |
|
|
|
} |
|
|
|
// pkg['APT_CACHE'] = {}
|
|
|
|
for (pl in pkg_info_lines) { |
|
|
|
if (pmch = pkg_info_lines[pl].match(pkg_info_regx)) { |
|
|
|
json_obj[pkg_name]['APT_CACHE'][ pmch[1] ] = pmch[2] |
|
|
|
} |
|
|
|
} catch (err) { |
|
|
|
// pkg['APT_HISTORY'] = "WARNING: Apt History Missing Info: " + pkg['SW_NAME']
|
|
|
|
pkg['APT_HISTORY'] = "MISSING" |
|
|
|
} |
|
|
|
} catch (err) { |
|
|
|
console.log ('WARNING: Failed to run: ' + cmd_pkg_info + "\n" + err) |
|
|
|
} |
|
|
|
|
|
|
|
json_obj.push(pkg) |
|
|
|
// json_obj.push(pkg)
|
|
|
|
} |
|
|
|
} |
|
|
|
// console.log(JSON.stringify(pkg, null, 2))
|
|
|
@ -309,6 +302,199 @@ function dpkg_list_to_json(dpkg_list) { |
|
|
|
// return {}
|
|
|
|
} |
|
|
|
|
|
|
|
function apt_history_to_json() { |
|
|
|
let apt_history_obj = {} |
|
|
|
let pkg_list = {} |
|
|
|
let apt_history_regx = RegExp(/^(.*):\s+(.*)/) |
|
|
|
|
|
|
|
// Extract Apt Log - /var/log/apt/history.log.*.gz
|
|
|
|
let cmc_extract_apt_history = 'zcat /var/log/apt/history.log.*.gz > /var/tmp/apt-history.log' |
|
|
|
let cmc_append_apt_history = 'cat /var/log/apt/history.log >> /var/tmp/apt-history.log' |
|
|
|
try { |
|
|
|
childProcess.execSync(cmc_extract_apt_history, { encoding: 'utf8' }) |
|
|
|
try { |
|
|
|
childProcess.execSync(cmc_append_apt_history, { encoding: 'utf8' }) |
|
|
|
|
|
|
|
let apt_history_log = fs.readFileSync(path.join('/var', 'tmp', 'apt-history.log'), 'utf8').split(/\n/) |
|
|
|
for (ahl=0; ahl<apt_history_log.length; ahl++) { |
|
|
|
// console.log ('DEBUG: ' + ahl + ' ' + apt_history_log[ahl])
|
|
|
|
// console.log ('DEBUG: ' + apt_history_log.length)
|
|
|
|
if (ahmch = apt_history_log[ahl].match(apt_history_regx)) { |
|
|
|
// console.log ('DEBUG: ' + ahl + ' ' + apt_history_log[ahl])
|
|
|
|
if (ahmch[1] == 'Start-Date' ) { |
|
|
|
let apt_history_event = {} |
|
|
|
// console.log ('DEBUG: ' + ahl + ' ' + apt_history_log[ahl])
|
|
|
|
while ( (ahmch[1] != 'End-Date') && (ahl < apt_history_log.length)) { |
|
|
|
if (ahmch = apt_history_log[ahl++].match(apt_history_regx)) { |
|
|
|
// console.log ('DEBUG: ' + ahl++ + ' ' + ahmch[1] + ' ' + ahmch[2])
|
|
|
|
apt_history_event[ ahmch[1] ] = ahmch[2] |
|
|
|
} else { |
|
|
|
ahmch = ['NULL'] |
|
|
|
} |
|
|
|
} |
|
|
|
// console.log(JSON.stringify(apt_history_event, null, 2))
|
|
|
|
|
|
|
|
for (k in Object.keys(apt_history_event)) { |
|
|
|
// console.log (Object.keys(apt_history_event)[k])
|
|
|
|
switch (Object.keys(apt_history_event)[k]) { |
|
|
|
case 'Start-Date': |
|
|
|
// Do Nothing
|
|
|
|
break; |
|
|
|
case 'End-Date': |
|
|
|
// Do Nothing
|
|
|
|
break; |
|
|
|
case 'Commandline': |
|
|
|
// Do Nothing
|
|
|
|
break; |
|
|
|
case 'Requested-By': |
|
|
|
// Do Nothing
|
|
|
|
break; |
|
|
|
case 'Install': |
|
|
|
pkg_list = apt_history_event[ Object.keys(apt_history_event)[k] ].split('), ') |
|
|
|
// console.log(JSON.stringify(pkg_list, null, 2))
|
|
|
|
for (pkl in pkg_list) { |
|
|
|
// console.log ('DEBUG: ' + pkg_list[pkl])
|
|
|
|
if (pkg_meta1 = String(pkg_list[pkl].replace(/\)$/, '')).split(' (')) { |
|
|
|
// console.log('META1' + JSON.stringify(pkg_meta1, null, 2))
|
|
|
|
if (pkg_meta2 = String(pkg_meta1[0]).split(':')) { // Pkg Name : Arch
|
|
|
|
// console.log('META2' + JSON.stringify(pkg_meta2, null, 2))
|
|
|
|
if (! apt_history_obj.hasOwnProperty(pkg_meta2[0])) { apt_history_obj[ pkg_meta2[0] ] = {} } |
|
|
|
apt_history_obj[ pkg_meta2[0] ][apt_history_event['Start-Date']] = {} |
|
|
|
apt_history_obj[ pkg_meta2[0] ][apt_history_event['Start-Date']]['EVENT'] = Object.keys(apt_history_event)[k] |
|
|
|
apt_history_obj[ pkg_meta2[0] ][apt_history_event['Start-Date']]['ARCH'] = pkg_meta2[1] |
|
|
|
|
|
|
|
if (pkg_meta3 = String(pkg_meta1[1]).split(', ')) { // Version, Status
|
|
|
|
// console.log('META3' + JSON.stringify(pkg_meta3, null, 2))
|
|
|
|
apt_history_obj[ pkg_meta2[0] ][apt_history_event['Start-Date']]['VERSION'] = pkg_meta3[0] |
|
|
|
|
|
|
|
} else { |
|
|
|
console.log("WARNING: META3 MisMatch") |
|
|
|
} |
|
|
|
} else { |
|
|
|
console.log("WARNING: META2 MisMatch") |
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
console.log("WARNING: META1 MisMatch") |
|
|
|
} |
|
|
|
// if (pkmch = pkg_list[p].match())
|
|
|
|
} |
|
|
|
break; |
|
|
|
case 'Remove': |
|
|
|
pkg_list = apt_history_event[ Object.keys(apt_history_event)[k] ].split('), ') |
|
|
|
// console.log(JSON.stringify(pkg_list, null, 2))
|
|
|
|
for (pkl in pkg_list) { |
|
|
|
// console.log ('DEBUG: ' + pkg_list[pkl])
|
|
|
|
if (pkg_meta1 = String(pkg_list[pkl].replace(/\)$/, '')).split(' (')) { |
|
|
|
// console.log('META1' + JSON.stringify(pkg_meta1, null, 2))
|
|
|
|
if (pkg_meta2 = String(pkg_meta1[0]).split(':')) { // Pkg Name : Arch
|
|
|
|
// console.log('META2' + JSON.stringify(pkg_meta2, null, 2))
|
|
|
|
if (! apt_history_obj.hasOwnProperty(pkg_meta2[0])) { apt_history_obj[ pkg_meta2[0] ] = {} } |
|
|
|
apt_history_obj[ pkg_meta2[0] ][apt_history_event['Start-Date']] = {} |
|
|
|
apt_history_obj[ pkg_meta2[0] ][apt_history_event['Start-Date']]['EVENT'] = Object.keys(apt_history_event)[k] |
|
|
|
apt_history_obj[ pkg_meta2[0] ][apt_history_event['Start-Date']]['ARCH'] = pkg_meta2[1] |
|
|
|
|
|
|
|
if (pkg_meta3 = String(pkg_meta1[1]).split(', ')) { // Version, Status
|
|
|
|
// console.log('META3' + JSON.stringify(pkg_meta3, null, 2))
|
|
|
|
apt_history_obj[ pkg_meta2[0] ][apt_history_event['Start-Date']]['VERSION'] = pkg_meta3[0] |
|
|
|
|
|
|
|
} else { |
|
|
|
console.log("WARNING: META3 MisMatch") |
|
|
|
} |
|
|
|
} else { |
|
|
|
console.log("WARNING: META2 MisMatch") |
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
console.log("WARNING: META1 MisMatch") |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
case 'Upgrade': |
|
|
|
pkg_list = apt_history_event[ Object.keys(apt_history_event)[k] ].split('), ') |
|
|
|
// console.log(JSON.stringify(pkg_list, null, 2))
|
|
|
|
for (pkl in pkg_list) { |
|
|
|
// console.log ('DEBUG: ' + pkg_list[pkl])
|
|
|
|
if (pkg_meta1 = String(pkg_list[pkl].replace(/\)$/, '')).split(' (')) { |
|
|
|
// console.log('META1' + JSON.stringify(pkg_meta1, null, 2))
|
|
|
|
if (pkg_meta2 = String(pkg_meta1[0]).split(':')) { // Pkg Name : Arch
|
|
|
|
// console.log('META2' + JSON.stringify(pkg_meta2, null, 2))
|
|
|
|
if (! apt_history_obj.hasOwnProperty(pkg_meta2[0])) { apt_history_obj[ pkg_meta2[0] ] = {} } |
|
|
|
apt_history_obj[ pkg_meta2[0] ][apt_history_event['Start-Date']] = {} |
|
|
|
apt_history_obj[ pkg_meta2[0] ][apt_history_event['Start-Date']]['EVENT'] = Object.keys(apt_history_event)[k] |
|
|
|
apt_history_obj[ pkg_meta2[0] ][apt_history_event['Start-Date']]['ARCH'] = pkg_meta2[1] |
|
|
|
|
|
|
|
if (pkg_meta3 = String(pkg_meta1[1]).split(', ')) { // Version, Status
|
|
|
|
// console.log('META3' + JSON.stringify(pkg_meta3, null, 2))
|
|
|
|
apt_history_obj[ pkg_meta2[0] ][apt_history_event['Start-Date']]['VERSION'] = pkg_meta3[0] |
|
|
|
|
|
|
|
} else { |
|
|
|
console.log("WARNING: META3 MisMatch") |
|
|
|
} |
|
|
|
} else { |
|
|
|
console.log("WARNING: META2 MisMatch") |
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
console.log("WARNING: META1 MisMatch") |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
case 'Reinstall': |
|
|
|
pkg_list = apt_history_event[ Object.keys(apt_history_event)[k] ].split('), ') |
|
|
|
// console.log(JSON.stringify(pkg_list, null, 2))
|
|
|
|
for (pkl in pkg_list) { |
|
|
|
// console.log ('DEBUG: ' + pkg_list[pkl])
|
|
|
|
if (pkg_meta1 = String(pkg_list[pkl].replace(/\)$/, '')).split(' (')) { |
|
|
|
// console.log('META1' + JSON.stringify(pkg_meta1, null, 2))
|
|
|
|
if (pkg_meta2 = String(pkg_meta1[0]).split(':')) { // Pkg Name : Arch
|
|
|
|
// console.log('META2' + JSON.stringify(pkg_meta2, null, 2))
|
|
|
|
if (! apt_history_obj.hasOwnProperty(pkg_meta2[0])) { apt_history_obj[ pkg_meta2[0] ] = {} } |
|
|
|
apt_history_obj[ pkg_meta2[0] ][apt_history_event['Start-Date']] = {} |
|
|
|
apt_history_obj[ pkg_meta2[0] ][apt_history_event['Start-Date']]['EVENT'] = Object.keys(apt_history_event)[k] |
|
|
|
apt_history_obj[ pkg_meta2[0] ][apt_history_event['Start-Date']]['ARCH'] = pkg_meta2[1] |
|
|
|
|
|
|
|
if (pkg_meta3 = String(pkg_meta1[1]).split(', ')) { // Version, Status
|
|
|
|
// console.log('META3' + JSON.stringify(pkg_meta3, null, 2))
|
|
|
|
apt_history_obj[ pkg_meta2[0] ][apt_history_event['Start-Date']]['VERSION'] = pkg_meta3[0] |
|
|
|
|
|
|
|
} else { |
|
|
|
console.log("WARNING: META3 MisMatch") |
|
|
|
} |
|
|
|
} else { |
|
|
|
console.log("WARNING: META2 MisMatch") |
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
console.log("WARNING: META1 MisMatch") |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
case 'Error': |
|
|
|
// Do Nothing
|
|
|
|
break; |
|
|
|
default: |
|
|
|
console.log('WARNING: Unknown apt-history Event: ' + Object.keys(apt_history_event)[k]) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} catch (err) { |
|
|
|
console.log('ERROR: Failed to Extract Apt Log History ' + err) |
|
|
|
process.exit(1) |
|
|
|
} |
|
|
|
} catch (err) { |
|
|
|
console.log('ERROR: Failed to Extract Apt Log History ' + err) |
|
|
|
process.exit(1) |
|
|
|
} |
|
|
|
|
|
|
|
// console.log (JSON.stringify(apt_history_obj, null, 2))
|
|
|
|
return apt_history_obj |
|
|
|
} |
|
|
|
|
|
|
|
function iatm_upload_data(data) { |
|
|
|
// console.log (JSON.stringify(data, null, 2))
|
|
|
|
|
|
|
|