Skip to content

Commit

Permalink
fix(api-filters): Filter creation is now logged to graylog and authlo…
Browse files Browse the repository at this point in the history
…g ZMS-34 (#616)

* log filter creation to logs

* api.js, filterroutes, remove unnecessary loggelf param

* instead of dumping all filter data, create a human readable description of it using getFilterStrings

* separate getFilterStrings data into _filter_query and _filter_action fields, make them human-readable by joining
  • Loading branch information
NickOvt authored Feb 19, 2024
1 parent bf313cc commit 6f0e4b5
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions lib/api/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,35 @@ module.exports = (db, server, userHandler, settingsHandler) => {
}
}

const filterStrings = getFilterStrings(filterData);

// Log added filter to graylog
userHandler.loggelf({
short_message: '[FILTERS] Added new filter',
_user: user,
_mailbox: filterData.action.mailbox,
_filter_id: filterData._id.toString(),
_filter_query: filterStrings.query.map(item => item.filter(val => val).join(': ')).join(', '),
_filter_action: filterStrings.action.map(item => item.filter(val => val).join(': ')).join(', '),
_filter_name: filterData.name,
_filter_created: filterData.created,
_filter_disabled: filterData.disabled
});

// Log added filter to authlog as well
try {
await userHandler.logAuthEvent(user, {
action: 'filter added',
result: 'success',
filter: filterData._id,
protocol: 'API',
sess: values.sess,
ip: values.ip
});
} catch (err) {
log.error('API [Filter]', err);
}

return res.json({
success: r.acknowledged,
id: filterData._id.toString()
Expand Down

0 comments on commit 6f0e4b5

Please sign in to comment.