-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathdatabase.js
More file actions
67 lines (58 loc) · 2.08 KB
/
Copy pathdatabase.js
File metadata and controls
67 lines (58 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import path from 'path';
import { JSONFile, Low } from 'lowdb';
import env from './env.js';
const filePath = path.join(env.DATA_PATH, 'hothost.json');
const adapter = new JSONFile(filePath);
const db = new Low(adapter);
const _read = db.read.bind(db);
db.read = async function () {
await _read();
if (!db.data) {
db.data = {};
}
db.data.users ||= [];
db.data.monitoringData ||= [];
db.data.httpMonitoringData ||= [];
db.data.settings ||= {
RAM_THRESHOLD: 90,
RAM_STABILIZATION_LEVEL: 3,
DISK_THRESHOLD: 90,
DISK_STABILIZATION_LEVEL: 1,
HOST_IS_DOWN_CONFIRMATIONS: 1,
HTTP_ISSUE_CONFIRMATION: 1,
DAYS_FOR_SSL_EXPIRED: 14,
HOURS_FOR_NEXT_ALERT: 12,
};
db.data.pluginSettings ||= [];
db.data.hostGroups ||= [];
db.data.groupPluginSettings ||= [];
// Migrate legacy slackSettings/slackWebhook from group objects to groupPluginSettings
let migrated = false;
for (const group of db.data.hostGroups) {
if (group.slackSettings || group.slackWebhook) {
const alreadyMigrated = db.data.groupPluginSettings.some(
(s) => s.groupId === group.id && s.pluginId === 'slack-notifications'
);
if (!alreadyMigrated) {
const entry = {
groupId: group.id,
pluginId: 'slack-notifications',
params: group.slackSettings?.params || (group.slackWebhook ? { webhook: group.slackWebhook } : {}),
};
// Only set enabledEvents if explicitly configured; omit the property to inherit global settings
if (group.slackSettings?.enabledEvents) {
entry.enabledEvents = group.slackSettings.enabledEvents;
}
db.data.groupPluginSettings.push(entry);
}
delete group.slackSettings;
delete group.slackWebhook;
delete group.channelName;
migrated = true;
}
}
if (migrated) {
await db.write();
}
};
export default db;