-
Notifications
You must be signed in to change notification settings - Fork 1
/
oJobES.yaml
41 lines (37 loc) · 1.7 KB
/
oJobES.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
# Copyright 2023 Nuno Aguiar
jobs:
- name: Start Log to ES
help: >
Starts logging to ElasticSearch. Expects:
url (String) The ElasticSearch cluster URL
index (String) An ElasticSearch index name (it will be suffixed automatically with the current date)
format (String) The format of the date if different from day.
host (String) A LogStash like host to identify in each entry
user (String) A user name.
pass (String) A password (encrypted or not).
stamp (Map) A map to stamp on each elasticsearch entry for extra info.
exec: |
if (isUnDef(args.url)) throw "Please provide URL to ElasticSearch";
if (isUnDef(args.index)) throw "Please provide an ElasticSearch index name";
if (isUnDef(args.host)) throw "Please provide a LogStash-like host for ElasticSearch";
args.stamp = _$(args.stamp).isMap().default(void 0);
startLog();
if (isDef(args.pass) && isUnDef(args.password)) args.password = args.pass
$ch("__es").create(void 0, "elasticsearch", {
url : args.url,
idKey: "id",
index: ow.ch.utils.getElasticIndex(args.index, args.format),
user : args.user,
pass : args.password
});
global.__esSubs = ow.ch.utils.getLogStashSubscriber("__es", "stdin", args.host, (e) => {
sprintErr(e);
}, void 0, args.stamp);
$ch("__log").subscribe(global.__esSubs);
addOnOpenAFShutdown(() => ($ch().list().indexOf("__log") ? $ch("__log").waitForJobs(2500) : __))
- name: Stop ES logging
help: >
Stops logging to ElasticSearch.
exec: |
$ch("__log").unsubscribe(global.esSubs);
stopLog();