Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[elastalert-server]TypeError: Cannot read property 'search' of undefined #274

Closed
S733 opened this issue Nov 24, 2020 · 7 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@S733
Copy link

S733 commented Nov 24, 2020

Hi,
I'm getting the following error after I upgraded from elastalert-server:20200831. Getting the same error in v20201101 and v20201109. The error is not coming if I downgrade to v20200831.

17:37:58.095Z  INFO elastalert-server: Routes:  Successfully handled GET request for '/'.
Error: unable to verify the first certificate
    at TLSSocket.onConnectSecure (node:_tls_wrap:1497:34)
    at TLSSocket.emit (node:events:327:20)
    at TLSSocket._finishInit (node:_tls_wrap:932:8)
    at TLSWrap.ssl.onhandshakedone (node:_tls_wrap:706:12) {
  code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE',
  config: {
    url: 'https://user:[email protected]:9200',
    method: 'get',
    headers: {
      Accept: 'application/json, text/plain, */*',
      'User-Agent': 'axios/0.21.0'
    },
    transformRequest: [ [Function: transformRequest] ],
    transformResponse: [ [Function: transformResponse] ],
    timeout: 0,
    adapter: [Function: httpAdapter],
    xsrfCookieName: 'XSRF-TOKEN',
    xsrfHeaderName: 'X-XSRF-TOKEN',
    maxContentLength: -1,
    maxBodyLength: -1,
    validateStatus: [Function: validateStatus],
    data: undefined
  },
  request: <ref *1> Writable {
    _writableState: WritableState {
      objectMode: false,
      highWaterMark: 16384,
      finalCalled: false,
      needDrain: false,
      ending: false,
      ended: false,
      finished: false,
      destroyed: false,
      decodeStrings: true,
      defaultEncoding: 'utf8',
      length: 0,
      writing: false,
      corked: 0,
      sync: true,
      bufferProcessing: false,
      onwrite: [Function: bound onwrite],
      writecb: null,
      writelen: 0,
      afterWriteTickInfo: null,
      buffered: [],
      bufferedIndex: 0,
      allBuffers: true,
      allNoop: true,
      pendingcb: 0,
      constructed: true,
      prefinished: false,
      errorEmitted: false,
      emitClose: true,
      autoDestroy: true,
      errored: null,
      closed: false,
      closeEmitted: false,
      [Symbol(kOnFinished)]: []
    },
    _events: [Object: null prototype] {
      response: [Function: handleResponse],
      error: [Function: handleRequestError]
    },
    _eventsCount: 2,
    _maxListeners: undefined,
    _options: {
      maxRedirects: 21,
      maxBodyLength: 10485760,
      protocol: 'https:',
      path: '/',
      method: 'GET',
      headers: [Object],
      agent: undefined,
      agents: [Object],
      auth: 'user:pass',
      hostname: '10.0.0.223',
      port: '9200',
      nativeProtocols: [Object],
      pathname: '/'
    },
    _ended: true,
    _ending: true,
    _redirectCount: 0,
    _redirects: [],
    _requestBodyLength: 0,
    _requestBodyBuffers: [],
    _onNativeResponse: [Function (anonymous)],
    _currentRequest: ClientRequest {
      _events: [Object: null prototype],
      _eventsCount: 7,
      _maxListeners: undefined,
      outputData: [],
      outputSize: 0,
      writable: true,
      destroyed: false,
      _last: true,
      chunkedEncoding: false,
      shouldKeepAlive: false,
      _defaultKeepAlive: true,
      useChunkedEncodingByDefault: false,
      sendDate: false,
      _removedConnection: false,
      _removedContLen: false,
      _removedTE: false,
      _contentLength: 0,
      _hasBody: true,
      _trailer: '',
      finished: true,
      _headerSent: true,
      _closed: false,
      socket: [TLSSocket],
      _header: 'GET / HTTP/1.1\r\n' +
        'Accept: application/json, text/plain, */*\r\n' +
        'User-Agent: axios/0.21.0\r\n' +
        'Host: 10.0.0.223:9200\r\n' +
        'Authorization: Basic YmVhdHN1cVFIb3A=\r\n' +
        'Connection: close\r\n' +
        '\r\n',
      _keepAliveTimeout: 0,
      _onPendingData: [Function: noopPendingOutput],
      agent: [Agent],
      socketPath: undefined,
      method: 'GET',
      maxHeaderSize: undefined,
      insecureHTTPParser: undefined,
      path: '/',
      _ended: false,
      res: null,
      aborted: false,
      timeoutCb: null,
      upgradeOrConnect: false,
      parser: null,
      maxHeadersCount: null,
      reusedSocket: false,
      host: '10.0.0.223',
      protocol: 'https:',
      _redirectable: [Circular *1],
      [Symbol(kCapture)]: false,
      [Symbol(kNeedDrain)]: false,
      [Symbol(corked)]: 0,
      [Symbol(kOutHeaders)]: [Object: null prototype]
    },
    _currentUrl: 'https://user:[email protected]:9200/',
    [Symbol(kCapture)]: false
  },
  response: undefined,
  isAxiosError: true,
  toJSON: [Function: toJSON]
}
Error: unable to verify the first certificate
    at TLSSocket.onConnectSecure (node:_tls_wrap:1497:34)
    at TLSSocket.emit (node:events:327:20)
    at TLSSocket._finishInit (node:_tls_wrap:932:8)
    at TLSWrap.ssl.onhandshakedone (node:_tls_wrap:706:12) {
  code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE',
  config: {
    url: 'https://user:[email protected]:9200',
    method: 'get',
    headers: {
      Accept: 'application/json, text/plain, */*',
      'User-Agent': 'axios/0.21.0'
    },
    transformRequest: [ [Function: transformRequest] ],
    transformResponse: [ [Function: transformResponse] ],
    timeout: 0,
    adapter: [Function: httpAdapter],
    xsrfCookieName: 'XSRF-TOKEN',
    xsrfHeaderName: 'X-XSRF-TOKEN',
    maxContentLength: -1,
    maxBodyLength: -1,
    validateStatus: [Function: validateStatus],
    data: undefined
  },
  request: <ref *1> Writable {
    _writableState: WritableState {
      objectMode: false,
      highWaterMark: 16384,
      finalCalled: false,
      needDrain: false,
      ending: false,
      ended: false,
      finished: false,
      destroyed: false,
      decodeStrings: true,
      defaultEncoding: 'utf8',
      length: 0,
      writing: false,
      corked: 0,
      sync: true,
      bufferProcessing: false,
      onwrite: [Function: bound onwrite],
      writecb: null,
      writelen: 0,
      afterWriteTickInfo: null,
      buffered: [],
      bufferedIndex: 0,
      allBuffers: true,
      allNoop: true,
      pendingcb: 0,
      constructed: true,
      prefinished: false,
      errorEmitted: false,
      emitClose: true,
      autoDestroy: true,
      errored: null,
      closed: false,
      closeEmitted: false,
      [Symbol(kOnFinished)]: []
    },
    _events: [Object: null prototype] {
      response: [Function: handleResponse],
      error: [Function: handleRequestError]
    },
    _eventsCount: 2,
    _maxListeners: undefined,
    _options: {
      maxRedirects: 21,
      maxBodyLength: 10485760,
      protocol: 'https:',
      path: '/',
      method: 'GET',
      headers: [Object],
      agent: undefined,
      agents: [Object],
      auth: 'user:pass',
      hostname: '10.0.0.223',
      port: '9200',
      nativeProtocols: [Object],
      pathname: '/'
    },
    _ended: true,
    _ending: true,
    _redirectCount: 0,
    _redirects: [],
    _requestBodyLength: 0,
    _requestBodyBuffers: [],
    _onNativeResponse: [Function (anonymous)],
    _currentRequest: ClientRequest {
      _events: [Object: null prototype],
      _eventsCount: 7,
      _maxListeners: undefined,
      outputData: [],
      outputSize: 0,
      writable: true,
      destroyed: false,
      _last: true,
      chunkedEncoding: false,
      shouldKeepAlive: false,
      _defaultKeepAlive: true,
      useChunkedEncodingByDefault: false,
      sendDate: false,
      _removedConnection: false,
      _removedContLen: false,
      _removedTE: false,
      _contentLength: 0,
      _hasBody: true,
      _trailer: '',
      finished: true,
      _headerSent: true,
      _closed: false,
      socket: [TLSSocket],
      _header: 'GET / HTTP/1.1\r\n' +
        'Accept: application/json, text/plain, */*\r\n' +
        'User-Agent: axios/0.21.0\r\n' +
        'Host: 10.0.0.223:9200\r\n' +
        'Authorization: Basic YmVhdHN1cVFIb3A=\r\n' +
        'Connection: close\r\n' +
        '\r\n',
      _keepAliveTimeout: 0,
      _onPendingData: [Function: noopPendingOutput],
      agent: [Agent],
      socketPath: undefined,
      method: 'GET',
      maxHeaderSize: undefined,
      insecureHTTPParser: undefined,
      path: '/',
      _ended: false,
      res: null,
      aborted: false,
      timeoutCb: null,
      upgradeOrConnect: false,
      parser: null,
      maxHeadersCount: null,
      reusedSocket: false,
      host: '10.0.0.223',
      protocol: 'https:',
      _redirectable: [Circular *1],
      [Symbol(kCapture)]: false,
      [Symbol(kNeedDrain)]: false,
      [Symbol(corked)]: 0,
      [Symbol(kOutHeaders)]: [Object: null prototype]
    },
    _currentUrl: 'https://user:[email protected]:9200/',
    [Symbol(kCapture)]: false
  },
  response: undefined,
  isAxiosError: true,
  toJSON: [Function: toJSON]
}
TypeError: Cannot read property 'search' of undefined
    at metadataElastalertHandler (/opt/elastalert-server/src/handlers/metadata/get.js:122:12)
    at processTicksAndRejections (node:internal/process/task_queues:93:5)



@nsano-rururu nsano-rururu added duplicate This issue or pull request already exists bug Something isn't working and removed duplicate This issue or pull request already exists labels Nov 24, 2020
@nsano-rururu
Copy link
Collaborator

nsano-rururu commented Nov 25, 2020

Please use the one that does not have any problem until the fixed version is released.
If you are not using an SSL certificate, you will not have any problems.
It is unconfirmed whether it is a problem that occurs only with SSL self-signed certificate

@nsano-rururu
Copy link
Collaborator

@nsano-rururu
Copy link
Collaborator

@S733

By the way, is the SSL certificate a self-signed certificate or a legitimate certificate? This is a confirmation for wanting to confirm in the same environment before and after the program modification.

@nsano-rururu
Copy link
Collaborator

nsano-rururu commented Nov 25, 2020

Scheduled to be fixed

src/common/elasticsearch_client.js

before

const result = await axios.get(`${scheme}://${auth}${config.get('es_host')}:${config.get('es_port')}`);

after

const agent  = {};

if (config.get('es_ssl')) {
  agent.rejectUnauthorized = false;

  if (config.get('es_ca_certs')) {
    agent.ca = fs.readFileSync(config.get('es_ca_certs'));
  }
  if (config.get('es_client_cert')) {
    agent.cert = fs.readFileSync(config.get('es_client_cert'));
  }
  if (config.get('es_client_key')) {
    agent.key = fs.readFileSync(config.get('es_client_key'));
  }
}

const https = require('https');
const httpsAgent = new https.Agent(agent);
const result = await axios.get(`${scheme}://${auth}${config.get('es_host')}:${config.get('es_port')}`, { httpsAgent });

@nsano-rururu nsano-rururu changed the title TypeError: Cannot read property 'search' of undefined [elastalert-server]TypeError: Cannot read property 'search' of undefined Nov 25, 2020
@S733
Copy link
Author

S733 commented Nov 25, 2020

@nsano-rururu thanks for the reply. I'm using a self signed ssl certificate. The issue started after I updated to the latest version, I have reverted to the old v20200831.

@nsano-rururu nsano-rururu self-assigned this Nov 26, 2020
@nsano-rururu
Copy link
Collaborator

@S733

The modified docker image has been uploaded. Please confirm.
https://hub.docker.com/r/praecoapp/elastalert-server

@S733
Copy link
Author

S733 commented Dec 8, 2020

@nsano-rururu thanks working fine after the update.

@S733 S733 closed this as completed Dec 8, 2020
Repository owner locked and limited conversation to collaborators Oct 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants