-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogs.ts
90 lines (89 loc) · 2.53 KB
/
logs.ts
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
import fs from "fs";
import es from "event-stream";
import { writetoxls } from "./duration";
import { arch } from "os";
const json: string[] = [];
[
"SMS_SPLIT.Logaa",
"SMS_SPLIT.Logab",
"SMS_SPLIT.Logac",
"SMS_SPLIT.Logad",
"SMS_SPLIT.Logae",
"SMS_SPLIT.Logaf",
"SMS_SPLIT.Logag",
"SMS_SPLIT.Logah",
"SMTP.Log",
].forEach((partName) => {
console.log("********* running for ", partName);
let lineNr = 1;
let count = 0;
fs.createReadStream(`./inputFiles/logs/${partName}`, "utf8")
.pipe(es.split("\r\n"))
.pipe(
es.mapSync((line: string) => {
switch (lineNr % 3) {
case 1:
json[count++] = line;
break;
case 2:
json[count - 1] += ` ` + line;
break;
case 0:
break;
}
lineNr++;
})
)
.on("end", function () {
const data = json
.filter(
(x) =>
!x.includes("Permission denied") &&
!x.includes("Could not") &&
!x.includes("Resend") &&
!x.includes("SendSMTPDispatch") &&
!x.includes("error") &&
!x.includes("Error") &&
!x.includes("Routine") &&
!x.includes("f_bSendSMSMsg") &&
!x.includes("resend") &&
x !== ""
)
.map((entry) => {
console.log(entry);
const [date, rest] = entry.split(/\s\s\s\s\s/);
const [time, remainging] = rest.split(" ");
const [ticket, remaining2] = remainging
.split("Successfully dispatched Ticket ")[1]
.split(" for");
const [objectn, remaining3] = remaining2
.split("Object ")[1]
.split(" to");
const [name, remaining4] = remaining3.split("Contact ")[1].split(":");
if (remaining4 === undefined)
console.log(
rest,
"\n",
remainging,
"\n",
remaining2,
"\n",
remaining3,
"\n",
remaining4
);
const contact = remaining4.split(" ")[1];
const mobile = contact.split("@")[0];
return {
Date: date,
Time: time,
Ticket: ticket,
TerminalID: objectn,
ContactName: name,
contactNO: mobile,
remark: `Successfully dispatched Ticket ${ticket} for Object ${objectn} to Contact ${name}: ${mobile}`,
};
});
writetoxls(data, `logs_${partName}`);
});
});