我使用winston elasticsearch将日志推送到一个elasticsearch集群中。
我已经为我的节点应用程序生成了自签名证书,下面是它的代码。
import * as winston from 'winston';
import * as fs from 'fs';
import { ElasticsearchTransport} from 'winston-elasticsearch';
const esTransportOpts = {
level: 'info',
index: 'someIndex',
ssl: {
ca: [fs.readFileSync('./src/utils/server.cert'), fs.readFileSync('./src/utils/server.key')],
// This ensures that certificates that are not signed by the 'ca' above get rejected
rejectUnauthorized: false
},
clientOpts: {
node: process.env.ELASTICSEARCH_URLS,// TODO: Make Variable.
// ssl: 'true'
}
};
const esTransport = new ElasticsearchTransport(esTransportOpts);
const logger = winston.createLogger({
transports: [
esTransport
]
});
// Compulsory error handling
logger.on('error', (error) => {
console.error('Error caught', error);
});
esTransport.on('warning', (error) => {
console.error('Error caught', error);
});
export default logger;
不幸的是,控制台在尝试推送日志时出现以下错误:
kyc-79945845d6-8mqfl: Error caught ResponseError: security_exception
kyc-79945845d6-8mqfl: at IncomingMessage.<anonymous> (/package/node_modules/@elastic/elasticsearch/lib/Transport.js:257:25)
kyc-79945845d6-8mqfl: at IncomingMessage.emit (events.js:323:22)
kyc-79945845d6-8mqfl: at IncomingMessage.EventEmitter.emit (domain.js:482:12)
kyc-79945845d6-8mqfl: at endReadableNT (_stream_readable.js:1204:12)
kyc-79945845d6-8mqfl: at processTicksAndRejections (internal/process/task_queues.js:84:21) {
kyc-79945845d6-8mqfl: name: 'ResponseError',
kyc-79945845d6-8mqfl: meta: {
kyc-79945845d6-8mqfl: body: { error: [Object], status: 401 },
kyc-79945845d6-8mqfl: statusCode: 401,
kyc-79945845d6-8mqfl: headers: {
kyc-79945845d6-8mqfl: 'www-authenticate': 'Bearer realm="security", ApiKey, Basic realm="security" charset="UTF-8"',
kyc-79945845d6-8mqfl: 'content-type': 'application/json; charset=UTF-8',
kyc-79945845d6-8mqfl: 'content-length': '549'
kyc-79945845d6-8mqfl: },
kyc-79945845d6-8mqfl: meta: {
kyc-79945845d6-8mqfl: context: null,
kyc-79945845d6-8mqfl: request: [Object],
kyc-79945845d6-8mqfl: name: 'elasticsearch-js',
kyc-79945845d6-8mqfl: connection: [Object],
kyc-79945845d6-8mqfl: attempts: 0,
kyc-79945845d6-8mqfl: aborted: false
kyc-79945845d6-8mqfl: }
kyc-79945845d6-8mqfl: }
kyc-79945845d6-8mqfl: }
我将感谢任何关于如何解决这个问题的观点。
暂无答案!
目前还没有任何答案,快来回答吧!