mirror of
https://github.com/nodemailer/wildduck.git
synced 2024-12-26 01:40:48 +08:00
fix(api-quota): Quota reset now also logs storage diff. Log now includes zero valued fields ZMS-128 (#640)
* Log storage diff for quota usage recalculation API endpoint. Also logs 0 * include _set as required key as well
This commit is contained in:
parent
9f704f7c5d
commit
64c6b5e63c
2 changed files with 16 additions and 11 deletions
7
api.js
7
api.js
|
@ -467,7 +467,7 @@ module.exports = done => {
|
|||
emit: (key, message) => log.info('Gelf', JSON.stringify(message))
|
||||
};
|
||||
|
||||
loggelf = message => {
|
||||
loggelf = (message, requiredKeys = []) => {
|
||||
if (typeof message === 'string') {
|
||||
message = {
|
||||
short_message: message
|
||||
|
@ -484,7 +484,8 @@ module.exports = done => {
|
|||
message.timestamp = Date.now() / 1000;
|
||||
message._component = component;
|
||||
Object.keys(message).forEach(key => {
|
||||
if (!message[key]) {
|
||||
if (!message[key] && !requiredKeys.includes(key)) {
|
||||
// remove the key if it empty/falsy/undefined/null and it is not required to stay
|
||||
delete message[key];
|
||||
}
|
||||
});
|
||||
|
@ -538,7 +539,7 @@ module.exports = done => {
|
|||
|
||||
settingsHandler = new SettingsHandler({ db: db.database });
|
||||
|
||||
server.loggelf = message => loggelf(message);
|
||||
server.loggelf = (message, requiredKeys = []) => loggelf(message, requiredKeys);
|
||||
|
||||
server.lock = new Lock({
|
||||
redis: db.redis,
|
||||
|
|
|
@ -1705,14 +1705,18 @@ module.exports = (db, server, userHandler, settingsHandler) => {
|
|||
});
|
||||
}
|
||||
|
||||
server.loggelf({
|
||||
short_message: '[QUOTA] reset',
|
||||
_mail_action: 'quota',
|
||||
_user: userData._id,
|
||||
_set: Number(storageUsed) || 0,
|
||||
_previous_storage_used: Number(updateResponse.value.storageUsed) || 0,
|
||||
_storage_used: Number(storageUsed) || 0
|
||||
});
|
||||
server.loggelf(
|
||||
{
|
||||
short_message: '[QUOTA] reset',
|
||||
_mail_action: 'quota',
|
||||
_user: userData._id,
|
||||
_set: Number(storageUsed) || 0,
|
||||
_previous_storage_used: Number(updateResponse.value.storageUsed) || 0,
|
||||
_storage_used: Number(storageUsed) || 0,
|
||||
_storage_diff: Math.abs((Number(updateResponse.value.storageUsed) || 0) - (Number(storageUsed) || 0))
|
||||
},
|
||||
['_previous_storage_used', '_storage_used', '_storage_diff', '_set']
|
||||
);
|
||||
|
||||
return res.json({
|
||||
success: true,
|
||||
|
|
Loading…
Reference in a new issue