Skip to content

Commit ac5726c

Browse files
committed
change error handling for reading host-os-release file
1 parent 1e2ffe1 commit ac5726c

File tree

1 file changed

+37
-24
lines changed

1 file changed

+37
-24
lines changed

src/server/extension/monitoring-endpoint.js

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ if (process.argv.length >= 3) {
1414
let withDiskUsage = false;
1515
if (process.argv[3]) {
1616
test = process.argv[3];
17-
if(test == 'diskusage:true') {
17+
if (test == 'diskusage:true') {
1818
withDiskUsage = true;
1919
}
2020
}
@@ -235,7 +235,7 @@ process.stdin.on('end', () => {
235235
}
236236

237237
function getPoolStatsFromAPI() {
238-
if(!withDiskUsage) {
238+
if (!withDiskUsage) {
239239
return false;
240240
}
241241
return new Promise((resolve, reject) => {
@@ -260,7 +260,7 @@ process.stdin.on('end', () => {
260260
}
261261

262262
function getDiskUsageFromAPI() {
263-
if(!withDiskUsage) {
263+
if (!withDiskUsage) {
264264
return false;
265265
}
266266
return new Promise((resolve, reject) => {
@@ -443,12 +443,19 @@ process.stdin.on('end', () => {
443443
versionId: osInfo['VERSION_ID'],
444444
prettyName: osInfo['PRETTY_NAME'],
445445
codename: osInfo['VERSION_CODENAME'],
446+
error: null
446447
};
447448

448449
} catch (error) {
449-
throwError("Fehler beim Auslesen des Host OS:" + error, '');
450-
return null;
451-
}
450+
451+
return {
452+
id: null,
453+
versionId: null,
454+
prettyName: null,
455+
codename: null,
456+
error: error
457+
};
458+
}
452459
}
453460

454461
function getPostgresVersion(dsn) {
@@ -491,7 +498,7 @@ process.stdin.on('end', () => {
491498
let statusMessages = [];
492499

493500
let configinfo = infoData[6];
494-
501+
495502
//////////////////////////////////////////////////////////////
496503
// get postgres version, cannot be part of Promise.all(), because we need the DSN.
497504
// DSN is in the response from getConfigFromInspectAPI()
@@ -754,10 +761,10 @@ process.stdin.on('end', () => {
754761
// objecttypes stat
755762
result.statistics = {};
756763
result.statistics.objecttypes = {};
757-
if(infoData[10]) {
758-
if(infoData[10]['IndexedByTableNameRead']) {
759-
Object.keys(infoData[10]['IndexedByTableNameRead']).forEach(function(key) {
760-
if(infoData[10]['IndexedByTableNameRead'][key].Count) {
764+
if (infoData[10]) {
765+
if (infoData[10]['IndexedByTableNameRead']) {
766+
Object.keys(infoData[10]['IndexedByTableNameRead']).forEach(function (key) {
767+
if (infoData[10]['IndexedByTableNameRead'][key].Count) {
761768
result.statistics.objecttypes[key] = infoData[10]['IndexedByTableNameRead'][key].Count;
762769
}
763770
});
@@ -766,7 +773,7 @@ process.stdin.on('end', () => {
766773

767774

768775
// filestats
769-
if(withDiskUsage) {
776+
if (withDiskUsage) {
770777
result.file_stats = {};
771778
result.file_stats.count = 0;
772779
result.file_stats.size = 0;
@@ -780,19 +787,19 @@ process.stdin.on('end', () => {
780787
}
781788

782789
// from objecttype
783-
if(infoData[9].length > 0) {
790+
if (infoData[9].length > 0) {
784791
let otCount = 0;
785792
let otSize = 0;
786-
for(let i=0;i<infoData[9].length;i++){
787-
if(infoData[9][i].OtStats) {
788-
if(infoData[9][i].OtStats.files) {
789-
if(infoData[9][i].OtStats.files.size) {
793+
for (let i = 0; i < infoData[9].length; i++) {
794+
if (infoData[9][i].OtStats) {
795+
if (infoData[9][i].OtStats.files) {
796+
if (infoData[9][i].OtStats.files.size) {
790797
var size = infoData[9][i].OtStats.files.size;
791798
var count = infoData[9][i].OtStats.files.count;
792-
if(count) {
799+
if (count) {
793800
otCount += count;
794801
}
795-
if(size != 0) {
802+
if (size != 0) {
796803
otSize = otSize + size;
797804
}
798805
}
@@ -803,9 +810,9 @@ process.stdin.on('end', () => {
803810
result.file_stats.size += otSize;
804811
}
805812

806-
if(result.file_stats.count > 0) {
813+
if (result.file_stats.count > 0) {
807814
var sizeString = (result.file_stats.size / (1024 ** 3)).toFixed(2) + ' GB';
808-
if(sizeString == '0.00 GB') {
815+
if (sizeString == '0.00 GB') {
809816
sizeString = (result.file_stats.size / (1024 ** 2)).toFixed(2) + ' MB';
810817
}
811818
result.file_stats.size = sizeString;
@@ -913,8 +920,14 @@ process.stdin.on('end', () => {
913920
statusResults.loglevel = 'nothing';
914921
statusResults.janitor = 'nothing';
915922

923+
// check of host-os-release file was read properly
924+
if (result.host_data.error !== null) {
925+
increaseStatus('warning');
926+
statusMessages.push('Host os-release file: ' + result.host_data.error);
927+
}
928+
916929
// check backups
917-
if(result.sqlbackups !== true) {
930+
if (result.sqlbackups !== true) {
918931
increaseStatus('warning');
919932
statusMessages.push('last Backup not found');
920933
}
@@ -996,11 +1009,11 @@ process.stdin.on('end', () => {
9961009
const highStatus = openSearchWatermarkConfig.high.replace('%', '') * 1;
9971010
const floodStatus = openSearchWatermarkConfig.flood_stage.replace('%', '') * 1;
9981011

999-
if(usedDiskInPercent >= highStatus) {
1012+
if (usedDiskInPercent >= highStatus) {
10001013
openSearchWatermarkStatus = 'high';
10011014
statusMessages.push('openSearchWatermarkStatus: high');
10021015
}
1003-
if(usedDiskInPercent >= floodStatus) {
1016+
if (usedDiskInPercent >= floodStatus) {
10041017
openSearchWatermarkStatus = 'flood_stage';
10051018
statusMessages.push('openSearchWatermarkStatus: flood_stage');
10061019
}

0 commit comments

Comments
 (0)