/gateway/disponibilityController ``` const kibana = require('../api/kibana') const data = [ { key: 'Ativacao Esim', parameters: [ { match: { message_message: 'esim' } }, { range: { "@timestamp": { gte: "2022-12-01T00:00:00", lte: "now" }, } }, ] } ] const dataSuccess = [ { key: 'Ativacao Esim', parameters: [ { match: { message_message: 'esim' } }, { match: { level: 'INFO' } }, { range: { "@timestamp": { gte: "2022-12-01T00:00:00", lte: "now" }, } }, ] } ] module.exports = { async getDisponibility(req, res) { const { page, limit } = req.body Promise.all(data.map(async ({ key, parameters }) => ({ key, ...await kibana.search(parameters, page, limit) }))) .then(resp => res.json(resp)) }, async getSuccess(req, res) { Promise.all(dataSuccess.map(async ({ key, parameters}) => ({ key, ...await kibana.searchSuccess(parameters) }))) .then(resp => {res.json(resp)}) } } ``` /api/kibana/index ``` const { Client } = require('@elastic/elasticsearch') const client = new Client({ node: 'http://10.129.200.27:9200' }) module.exports = { async search (parameters, page, limit) { try { const { body } = await client.search({ index: 'logstash-**', ...(page && { from: page }), ...(limit && {size: limit}), body: { query: { bool: { must: [ ...parameters ] } } }, }, { meta: true}) const { total: { value }, hits } = body.hits return { total: value, hits } } catch (err) { return { error: err.message } } }, async searchSuccess (parameters) { try { const { body } = await client.search({ index: 'logstash-**', body: { query: { bool: { must: [ ...parameters ] } } }, }, { meta: true}) const { total: { value }, hits } = body.hits return { success: value, hits } } catch (err) { return { error: err.message } } } } ``` /gateway/router ``` router.get('/disponibility/success', passport.isAuthenticated, disponibilityController.getSuccess) ```