-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathoJob_nAttrMon.yaml
227 lines (193 loc) · 9.34 KB
/
oJob_nAttrMon.yaml
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# nAttrMon ojob functionality
# Copyright 2023 Nuno Aguiar
# oJob_nAttrMon.yaml __NAM_DEBUG=1 __NAM_NEED_CH_PERSISTENCE=
#ojob:
# daemon: true
#todo:
#- nAttrMon Prepare shutdown
#- nAttrMon Init
#- Add plugs
#- nAttrMon Start
#- nAttrMon Stop
jobs:
# -------------------------------
- name: nAttrMon Prepare shutdown
type: shutdown
exec: |
try { ow.ch.utils.closeBuffer() } catch(e) {}
$ch()
.list()
.filter(r => r.startsWith("nattrmon::"))
.forEach(r => {
global.nattrmon.debug("Waiting for " + r + "...");
$ch(r).waitForJobs();
})
global.nattrmon.stop();
$ch("nattrmon::trigger").destroy()
log("nAttrMon stopped.");
//print(new Date() + " | Stopping.");
# -----------------------
- name: nAttrMon Shutdown
exec: |
try { ow.ch.utils.closeBuffer() } catch(e) {}
$ch()
.list()
.filter(r => r.startsWith("nattrmon::"))
.forEach(r => {
global.nattrmon.debug("Waiting for " + r + "...");
$ch(r).waitForJobs();
})
global.nattrmon.stop()
$ch("nattrmon::trigger").destroy()
log("nAttrMon stopped.")
# -------------------------
- name: nAttrMon Run Single
from:
- nAttrMon Start
exec: |
$ch("nattrmon::trigger").waitForJobs();
if ($ch().list().indexOf("nattrmon::cvals::__bufferTransit") >= 0) ow.ch.utils.flushBuffer("nattrmon::cvals::__bufferTransit");
if ($ch().list().indexOf("nattrmon::lvals::__bufferTransit") >= 0) ow.ch.utils.flushBuffer("nattrmon::lvals::__bufferTransit");
if ($ch().list().indexOf("nattrmon::warnings::__bufferTransit") >= 0) ow.ch.utils.flushBuffer("nattrmon::warnings::__bufferTransit");
["nattrmon::trigger", "nattrmon::plugs", "nattrmon::lvals", "nattrmon::cvals", "nattrmon::warnings", "nattrmon::wnotf", "nattrmon::lvals::buffer", "nattrmon::cvals::buffer", "nattrmon::warnings::buffer", "nattrmon::attributes", "nattrmon::warnings", "nattrmon::ps"]
.forEach(r => {
if ($ch().list().indexOf(r) >= 0) {
global.nattrmon.debug("Waiting for " + r + "...");
$ch(r).waitForJobs();
sleep(100, true);
}
});
if (isString(args.onStop)) args.onStop = [ args.onStop ];
if (isArray(args.onStop)) args.onStop.forEach(j => {
args = $job(j, args);
});
global.nattrmon.debug("Stopping...");
global.nattrmon.stop();
//exit(0);
//log("nAttrMon stopped.");
//print(new Date() + " | Stopping.");
# -------------------
- name: nAttrMon Stop
exec: |
$ch()
.list()
.filter(r => r.startsWith("nattrmon::"))
.forEach(r => {
global.nattrmon.debug("Waiting for " + r + "...");
$ch(r).waitForJobs();
});
global.nattrmon.debug("Stopping...");
exit(0);
# ----------------------------
- name : nAttrMon Add Plugs
typeArgs:
single: true
exec : |
var fnJob = j => {
if (isMap(j) && isDef(j.execJob) && isUnDef(j.exec) && isUnDef(j.execFrom)) {
j.exec = "var r = $job('" + j.execJob + "', args);\n";
j.exec += "if (isMap(r)) {\n";
j.exec += " if (isDef(r.set)) {\n";
j.exec += " r = r.set;\n";
j.exec += " } else {\n";
j.exec += " delete r.objId; delete r.__id; delete r.execid;\n";
j.exec += " };\n";
j.exec += "} return r;\n";
}
return j;
};
if (isDef(args.output)) {
args.output = fnJob(args.output);
var r = global.nattrmon.loadObject(args.output, "output");
global.nattrmon.addOutput(r, r.exec);
}
if (isDef(args.input)) {
args.input = fnJob(args.input);
if (isUnDef(args.input.timeInterval) && isUnDef(args.input.chSubscribe) && isUnDef(args.input.cron)) {
args.input.chSubscribe = "nattrmon::trigger";
}
var r = global.nattrmon.loadObject(args.input, "input");
global.nattrmon.addInput(r, r.exec);
}
if (isDef(args.validation)) {
args.validation = fnJob(args.validation);
var r = global.nattrmon.loadObject(args.validation, "validation");
global.nattrmon.addValidation(r, r.exec);
}
# --------------------
- name: nAttrMon Start
deps: nAttrMon Init
exec: |
global.nattrmon.debug("nAttrMon exec input plugs");
global.nattrmon.execPlugs(global.nattrmon.PLUGINPUTS);
global.nattrmon.debug("nAttrMon exec output plugs");
global.nattrmon.execPlugs(global.nattrmon.PLUGOUTPUTS);
global.nattrmon.debug("nAttrMon exec validation plugs");
global.nattrmon.execPlugs(global.nattrmon.PLUGVALIDATIONS);
global.nattrmon.debug("nAttrMon restoring snapshot");
log("nAttrMon started (main=" + global.NATTRMON_HOME + "; home=" + global.NATTRMON_SUBHOME + ").");
if (isString(args.onStart)) args.onStart = [ args.onStart ];
if (isArray(args.onStart)) args.onStart.forEach(j => {
args = $job(j, args);
});
$ch("nattrmon::trigger").set(1, 1);
# -------------------
- name: nAttrMon Init
exec: |
global.NATTRMON_HOME = args.NATTRMON_HOME || getEnv("NATTRMON_HOME");
if (isUnDef(global.NATTRMON_HOME)) global.NATTRMON_HOME = getOPackPath("nAttrMon") || ".";
global.NATTRMON_SUBHOME = args.NATTRMON_DIR || getEnv("NATTRMON_DIR");
if (isUnDef(global.NATTRMON_SUBHOME)) global.NATTRMON_SUBHOME = args.withHome || global.NATTRMON_HOME;
loadLib(global.NATTRMON_HOME + "/lib/nmain.js");
if (isDef(args.__NAM_LOGHK_HOWLONGAGOINMINUTE)) global.__NAM_LOGHK_HOWLONGAGOINMINUTE = Number(args.__NAM_LOGHK_HOWLONGAGOINMINUTE);
if (isDef(args.__NAM_LOGAUDIT)) global.__NAM_LOGAUDIT = Boolean(args.__NAM_LOGAUDIT);
if (isDef(args.__NAM_LOGAUDIT_TEMPLATE)) global.__NAM_LOGAUDIT_TEMPLATE = String(args.__NAM_LOGAUDIT_TEMPLATE);
if (isDef(args.__NAM_JAVA_ARGS)) global.__NAM_JAVA_ARGS = String(args.__NAM_JAVA_ARGS).split(",");
if (isDef(args.__NAM_MAXPLUGEXECUTE_TIME)) global.__NAM_MAXPLUGEXECUTE_TIME = Number(args.__NAM_MAXPLUGEXECUTE_TIME);
if (isDef(args.__NAM_BUFFERCHANNELS)) global.__NAM_BUFFERCHANNELS = Boolean(args.__NAM_BUFFERCHANNELS);
if (isDef(args.__NAM_BUFFERBYNUMBER)) global.__NAM_BUFFERBYNUMBER = Number(args.__NAM_BUFFERBYNUMBER);
if (isDef(args.__NAM_BUFFERBYTIME)) global.__NAM_BUFFERBYTIME = Number(args.__NAM_BUFFERBYTIME);
if (isDef(args.__NAM_NUMBER_WORKERS)) __cpucores = Number(args.__NAM_NUMBER_WORKERS);
if (isDef(args.__NAM_COREOBJECTS)) global.__NAM_COREOBJECTS = String(args.__NAM_COREOBJECTS);
if (isDef(args.__NAM_COREOBJECTS_LAZYLOADING)) global.__NAM_COREOBJECTS_LAZYLOADING = Boolean(args.__NAM_COREOBJECTS_LAZYLOADING);
if (isDef(args.__NAM_DEBUG)) global.__NAM_DEBUG = Boolean(args.__NAM_DEBUG);
if (isDef(args.__NAM_NEED_CH_PERSISTENCE)) global.__NAM_NEED_CH_PERSISTENCE = Boolean(args.__NAM_NEED_CH_PERSISTENCE);
if (isDef(args.__NAM_LOGCONSOLE)) global.__NAM_LOGCONSOLE = Boolean(args.__NAM_LOGCONSOLE); else global.__NAM_LOGCONSOLE = false;
if (isDef(args.__NAM_LOG_ASYNC)) __logFormat.async = Boolean(args.__NAM_LOG_ASYNC); else global.__NAM_LOG_ASYNC = true;
if (isDef(args.__NAM_MAXPLUGEXECUTE_TIME)) global.__NAM_MAXPLUGEXECUTE_TIME = Number(args.__NAM_MAXPLUGEXECUTE_TIME);
if (isDef(args.__NAM_SLOWDOWN)) global.__NAM_SLOWDOWN = Boolean(args.__NAM_SLOWDOWN)
if (isDef(args.__NAM_SLOWDOWN_WARNS)) global.__NAM_SLOWDOWN_WARNS = Boolean(args.__NAM_SLOWDOWN_WARNS)
if (isDef(args.__NAM_SLOWDOWN_TIME)) global.__NAM_SLOWDOWN_TIME = Number(args.__NAM_SLOWDOWN_TIME)
if (isDef(args.__NAM_NOPLUGFILES)) global.__NAM_NOPLUGFILES = Boolean(args.__NAM_NOPLUGFILES)
if (isString(args.__NAM_LIBS)) global.__NAM_LIBS = String(args.__NAM_LIBS)
if (isString(args.__NAM_CHANNEL_CVALS)) global.__NAM_CHANNEL_CVALS = String(args.__NAM_CHANNEL_CVALS);
if (isString(args.__NAM_CHANNEL_LVALS)) global.__NAM_CHANNEL_LVALS = String(args.__NAM_CHANNEL_LVALS);
if (isString(args.__NAM_CHANNEL_WARNS)) global.__NAM_CHANNEL_WARNS = String(args.__NAM_CHANNEL_WARNS);
if (isString(args.__NAM_CHANNEL_WNOTS)) global.__NAM_CHANNEL_WNOTS = String(args.__NAM_CHANNEL_WNOTS)
if (isString(args.__NAM_CHANNEL_LOGS)) global.__NAM_CHANNEL_LOGS = String(args.__NAM_CHANNEL_LOGS)
if (isDef(args.__NAM_CLOSEDHK_HOWLONGAGOINMS)) global.__NAM_CLOSEDHK_HOWLONGAGOINMS = Number(args.__NAM_CLOSEDHK_HOWLONGAGOINMS)
if (isDef(args.__NAM_CLOSEDHK_ONSTARTUP)) global.__NAM_CLOSEDHK_ONSTARTUP = toBoolean(args.__NAM_CLOSEDHK_ONSTARTUP)
if (isDef(args.__NAM_SEC_REPO)) global.__NAM_SEC_REPO = String(global.__NAM_SEC_REPO)
if (isDef(args.__NAM_SEC_BUCKET)) global.__NAM_SEC_BUCKET = String(global.__NAM_SEC_BUCKET)
if (isDef(args.__NAM_SEC_BUCKET_PASS)) global.__NAM_SEC_BUCKET_PASS = String(global.__NAM_SEC_BUCKET_PASS)
if (isDef(args.__NAM_SEC_MAIN_PASS)) global.__NAM_SEC_MAIN_PASS = String(global.__NAM_SEC_MAIN_PASS)
if (isDef(args.__NAM_SEC_FILE)) global.__NAM_SEC_FILE = String(global.__NAM_SEC_FILE)
if (isUnDef(args.withDirectory)) {
global.nattrmon = new nAttrMon(global.NATTRMON_SUBHOME + "/config", global.__NAM_DEBUG);
} else {
global.nattrmon = new nAttrMon(args.withDirectory, global.__NAM_DEBUG);
}
global.nattrmon.debug("nAttrMon start load plugs");
global.nattrmon.loadPlugs();
$ch("nattrmon::trigger").create();
(function() {
print("Reapplying parameters:");
$from(Object.keys(args))
.starts("__NAM_")
.notStarts("__NAM_SEC")
.sort()
.select(r => {
print(r + ": " + global[r]);
});
print(repeat(80, "-"));
})();