Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
process.on('unhandledRejection', (errorOrReason, currPromise) => {
const errStr = String(errorOrReason && errorOrReason.stack || JSON.stringify(errorOrReason));
const key = String(errorOrReason && errorOrReason.message);
const content = `<p><strong>${lang.__('mail.errorStack')}</strong></p><p></p><pre><code>${errStr}</code></pre><p></p>`;
// 恢复上下文
if (currPromise && currPromise.domain) {
currPromise.domain.run(function() {
logger.error(`unhandledRejection reason: ${errStr}`);
setImmediate(function() {
require('util/mail/mail.js').SendMail(key, 'js', 600, {
'title': key,
'runtimeType': 'unhandledRejection',
'content': content
});
});
});
} else {
logger.error(`unhandledRejection reason: ${errStr}`);
setImmediate(function() {}, function(err, data, errData) { // eslint-disable-line handle-callback-err
const key = `cpu80.v4:${serverInfo.intranetIp}`;
let content = `<strong>${lang.__('mail.singleCoreCpu')}${serverInfo.cpu},${lang.__('mail.CPUUsageRate')}:${cpuUsed},${lang.__('mail.UsageRateGreaterThan80%')},${lang.__('mail.fiveSecondsCpuProfiler')}</strong>`;
let str = '';
if (data) {
str = data;
str = str.replace(/');
content += `<p><strong>${lang.__('mail.processSnapshot')}:</strong></p><pre style="font-size:12px">${str}</pre>`;
}
// 获取本机信息,用来分组
require('api/cmdb').GetDeviceThisServer().done(function(data) {
data = data || {};
const business = data.business && data.business[0] || {};
const profCallback = (result) => {if (currMemory && currMemory.rss > config.memoryLimit) {
logger.error('worker${cpu} pid=${pid} memoryUsage ${memoryUsage}, hit memoryLimit: ${memoryLimit}, kill it', {
memoryUsage: currMemory.rss,
memoryLimit: config.memoryLimit,
pid: worker.process.pid,
cpu: cpuid
});
logger.error(worker.lastMessage);
mail.SendMail(key, 'js', 600, {
'to': config.mailTo,
'cc': config.mailCC,
'runtimeType': 'Memory',
'msgInfo': `${serverInfo.intranetIp} ${lang.__('mail.memoryExceedingTips')}`,
'title': `${serverInfo.intranetIp} ${lang.__('mail.memoryExceedingWaring')}`,
'content': `<p><strong>${serverInfo.intranetIp} ${lang.__('mail.memoryExceedingTips')}</strong></p>`
});
restartWorker(worker);
}
}
}
if (
true
&& (nowDate.getHours() % 8 === 0)
&& nowDate.getMinutes() === 1
&& nowDate.getSeconds() <= 10
) {
// 8小时一次
require('api/keyman/runtimeAdd.js').hello();const blackIPList = [];
let blackIPListText = '';
maxArr.forEach((max, i) => {
blackIPListText += `<pre>[${max.StdX10}%]${max.ip} [${i + 1}/${max.count}]</pre>`;
blackIPListText += formatCacheList(max.list);
blackIPList.push(max.ip);
});
const key = `v6.AVG_TSW_IP_STD_X10.${serverInfo.intranetIp}`;
let title = '';
if (config.CCIPLimitAutoBlock) {
title = `[${lang.__('mail.IPAggregationNotice')}][${cache.ipCacheLast.StdX10}%]${serverInfo.intranetIp}`;
blackIPList.forEach((ip) => {
logger.info(`addBlackList: ${ip}`);
this.addBlackList(ip);
});
} else {
title = `[${lang.__('mail.IPAggregationWarning')}][${cache.ipCacheLast.StdX10}%]${serverInfo.intranetIp}`;
}
mail.SendMail(key, 'TSW', 3600, {
'to': config.mailTo,
'cc': config.mailCC,
'title': title,
'content': `<p><strong>${lang.__('mail.viewDocsForIPAggregation')}: </strong> https://tswjs.org/doc/api/ipCCFinder </p>`
+ `<p><strong>${lang.__('mail.serverIP')}:</strong>${serverInfo.intranetIp}</p>`
+ `<p><strong>${lang.__('mail.maliciousIP')}:</strong></p>`
+ blackIPListTextlogger.info(`addBlackList: ${ip}`);
this.addBlackList(ip);
});
} else {
title = `[${lang.__('mail.IPAggregationWarning')}][${cache.ipCacheLast.StdX10}%]${serverInfo.intranetIp}`;
}
mail.SendMail(key, 'TSW', 3600, {
'to': config.mailTo,
'cc': config.mailCC,
'title': title,
'content': `<p><strong>${lang.__('mail.viewDocsForIPAggregation')}: </strong> https://tswjs.org/doc/api/ipCCFinder </p>`
+ `<p><strong>${lang.__('mail.serverIP')}:</strong>${serverInfo.intranetIp}</p>`
+ `<p><strong>${lang.__('mail.maliciousIP')}:</strong></p>`
+ blackIPListText
+ `<p><strong>${lang.__('mail.autoIntoBlackList')}:</strong>` + (config.CCIPLimitAutoBlock ? `${lang.__('mail.yes')}` : `${lang.__('mail.no')}`) + '</p>'
+ `<p><strong>${lang.__('mail.IPAggregationDegree')}:</strong>${cache.ipCacheLast.StdX10}%</p>`
+ `<p><strong>${lang.__('mail.warningThreshold')}:</strong>${CCIPLimit}</p>`
+ `<p><strong>${lang.__('mail.normalValue')}:</strong>5-50</p>`
+ `<p><strong>${lang.__('mail.testingTimeConsuming')}:</strong>${parseInt((cache.ipCacheLast.end - cache.ipCacheLast.start) / 1000, 10)}s</p>`
+ `<p><strong>${lang.__('mail.evidenceList')}:</strong></p>`
+ content
});
return true;
};
}
if (err.message.indexOf('ETIMEDOUT') > 0) {
return;
}
if (err.message.indexOf('timeout') > 0) {
return;
}
if (err.message.indexOf('hang up') > 0) {
return;
}
if (err.message.indexOf('error:140943FC') > 0) {
return;
}
const key = err.message;
const content = `<p><strong>${lang.__('mail.errorStack')}</strong></p><p></p><pre><code>${err.stack}</code></pre><p></p>`;
mail.SendMail(key, 'js', 600, {
'title': key,
'runtimeType': 'Error',
'msgInfo': err.stack || err.message,
'content': content
});
}
});this.addBlackList(ip);
});
} else {
title = `[${lang.__('mail.IPAggregationWarning')}][${cache.ipCacheLast.StdX10}%]${serverInfo.intranetIp}`;
}
mail.SendMail(key, 'TSW', 3600, {
'to': config.mailTo,
'cc': config.mailCC,
'title': title,
'content': `<p><strong>${lang.__('mail.viewDocsForIPAggregation')}: </strong> https://tswjs.org/doc/api/ipCCFinder </p>`
+ `<p><strong>${lang.__('mail.serverIP')}:</strong>${serverInfo.intranetIp}</p>`
+ `<p><strong>${lang.__('mail.maliciousIP')}:</strong></p>`
+ blackIPListText
+ `<p><strong>${lang.__('mail.autoIntoBlackList')}:</strong>` + (config.CCIPLimitAutoBlock ? `${lang.__('mail.yes')}` : `${lang.__('mail.no')}`) + '</p>'
+ `<p><strong>${lang.__('mail.IPAggregationDegree')}:</strong>${cache.ipCacheLast.StdX10}%</p>`
+ `<p><strong>${lang.__('mail.warningThreshold')}:</strong>${CCIPLimit}</p>`
+ `<p><strong>${lang.__('mail.normalValue')}:</strong>5-50</p>`
+ `<p><strong>${lang.__('mail.testingTimeConsuming')}:</strong>${parseInt((cache.ipCacheLast.end - cache.ipCacheLast.start) / 1000, 10)}s</p>`
+ `<p><strong>${lang.__('mail.evidenceList')}:</strong></p>`
+ content
});
return true;
};
const profCallback = (result) => {
mail.SendMail(key, 'js', 600, {
'to': config.mailTo,
'cc': config.mailCC,
'runtimeType': 'CPU',
'msgInfo': `${business.module}[CPU]${serverInfo.intranetIp}${lang.__('mail.singleCoreCpu')}${serverInfo.cpu},${lang.__('mail.CPUUsageRate')}:${cpuUsed},${lang.__('mail.UsageRateGreaterThan80%')}`,
'title': `${business.module}[CPU]${serverInfo.intranetIp}${lang.__('mail.singleCoreCpu')}${serverInfo.cpu},${lang.__('mail.CPUUsageRate')}:${cpuUsed},${lang.__('mail.UsageRateGreaterThan80%')}`,
'content': content,
'attachment': result ? {
fileType: true,
dispositionType: 'attachment',
fileName: 'cpu-profiler.cpuprofile',
content: result
} : ''
});
};