Skip to content

Instantly share code, notes, and snippets.

@YuriFontella
Last active February 1, 2019 13:28
Show Gist options
  • Select an option

  • Save YuriFontella/96df760dc3f6a29d4c5132922807f67c to your computer and use it in GitHub Desktop.

Select an option

Save YuriFontella/96df760dc3f6a29d4c5132922807f67c to your computer and use it in GitHub Desktop.
let alarm = { hostname: 'arch', ip: '127.0.0.1', group: 'servers', item: 'cpu', trigger: 'low' }
let rule = await model.Rules.findOne({
include: [{ as: 'acls', model: model.Acls, attributes: ['hostname', 'ip', 'group', 'item', 'trigger', 'status', 'time_start', 'time_end'], where: { type: 'zabbix' } }],
attributes: ['uuid', 'status'],
where: { client: '5bbcab43c4ba0b3f9ba4eca6' },
order: [[{ as: 'acls', model: model.Acls }, 'sequence', 'DESC']]
})
let array = []
_.map(rule.acls, async (object, index) => {
let list = {}
let exclude = ['status', 'time_start', 'time_end']
_.map(object.dataValues, async (value, key) => {
if (value && !exclude.includes(key)) {
list[key] = object[key]
}
})
let result = _.find([alarm], list)
if (result) {
array.push(object.dataValues)
}
})
if (_.first(array)) {
let object = _.first(array)
console.log(object)
console.log('Temos regras')
} else {
console.log('Não temos regras')
}
res.end()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment