Error displaying fleet agents -"Error fetching agents Cannot read properties of undefined (reading 'map')"

One fine morning, fleet section just decided not to show agents enrolled in a particular policy. I suspected two issues, @timestamp was not present in some of the fleet related indices, I added mapping for the same, second, agents were updating to version 8.9 which caused this. Error is coming from helpers.js file, line number 34. Second issue no clue how to solve. Error is as shown in figure -

Full Error in kibana log is

{"service":{"node":{"roles":["background_tasks","ui"]}},"ecs":{"version":"8.6.1"},"@timestamp":"2023-07-27T17:07:04.269+00:00","message":"Cannot read properties of undefined (reading 'map')","error":{"message":"Cannot read properties of undefined (reading 'map')","type":"TypeError","stack_trace":"TypeError: Cannot read properties of undefined (reading 'map')\n    at /usr/share/kibana/node_modules/@kbn/fleet-plugin/server/services/agents/helpers.js:34:28\n    at Array.map (<anonymous>)\n    at searchHitToAgent (/usr/share/kibana/node_modules/@kbn/fleet-plugin/server/services/agents/helpers.js:29:222)\n    at Array.map (<anonymous>)\n    at Object.getAgentsByKuery (/usr/share/kibana/node_modules/@kbn/fleet-plugin/server/services/agents/crud.js:244:30)\n    at runMicrotasks (<anonymous>)\n    at processTicksAndRejections (node:internal/process/task_queues:96:5)\n    at getAgentsHandler (/usr/share/kibana/node_modules/@kbn/fleet-plugin/server/routes/agent/handlers.js:156:22)\n    at Router.handle (/usr/share/kibana/node_modules/@kbn/core-http-router-server-internal/src/router.js:149:30)\n    at handler (/usr/share/kibana/node_modules/@kbn/core-http-router-server-internal/src/router.js:115:50)\n    at exports.Manager.execute (/usr/share/kibana/node_modules/@hapi/hapi/lib/toolkit.js:60:28)\n    at Object.internals.handler (/usr/share/kibana/node_modules/@hapi/hapi/lib/handler.js:46:20)\n    at exports.execute (/usr/share/kibana/node_modules/@hapi/hapi/lib/handler.js:31:20)\n    at Request._lifecycle (/usr/share/kibana/node_modules/@hapi/hapi/lib/request.js:371:32)\n    at Request._execute (/usr/share/kibana/node_modules/@hapi/hapi/lib/request.js:281:9)"},"log":{"level":"ERROR","logger":"plugins.fleet"},"process":{"pid":2786},"trace":{"id":"4de74d693be1afdba"},"transaction":{"id":"cf0bdbe"}}

Here is the mentioned lines from 34 to 41 of /usr/share/kibana/node_modules/@kbn/fleet-plugin/server/services/agents/helpers.js
file where the error originates -

 units: component.units.map(unit => ({  #line 34
      id: unit.id,
      type: unit.type,
      status: unit.status,
      message: unit.message,
      // key-value pairs
      payload: unit.payload
    }))

Please help.

Hi @M_S

Can I ask you which version of Kibana are you running? this should have been fixed in 8.9, if you are not in 8.9 upgrading should probably fix it.

1 Like

Precisely this was the issue. Kibana was still in version 8.8 whereas fleet was on latest upgrade.

Unfortunately you will have to upgrade Kibana and Elasticsearch to 8.9 to fix that Fleet server version should <= to Elasticsearch and kibana version. It's documented here Deploy on-premises and self-managed | Fleet and Elastic Agent Guide [8.9] | Elastic

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.