jetcheck 1.1.3 → 1.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/config-simple.js CHANGED
@@ -35,7 +35,7 @@ module.exports = {
35
35
  init: "DEGRADED",
36
36
 
37
37
  // test every 15 seconds
38
- interval: 15,
38
+ interval: 5,
39
39
 
40
40
  // checker tasks
41
41
  tasks: [
@@ -54,17 +54,17 @@ module.exports = {
54
54
  content: {
55
55
  from: "alert@tc.be-ys.io",
56
56
  to: "m.vergoz@protonmail.com",
57
- subject: "[FAILED] Dev test",
58
- text: `Hi, the 'Dev test' fails at ${new Date().toLocaleString()}`
57
+ // subject: "[FAILED] Dev test",
58
+ // text: `Hi, the 'Dev test' fails at ${new Date().toLocaleString()}`
59
59
  }
60
60
  },
61
61
 
62
- {
63
- type: "ovh.dns.zone.unset",
64
- account: OVH_BeysIO,
65
- zone: "be-ys.io",
66
- config: OVH_BeysIO_DNS
67
- },
62
+ // {
63
+ // type: "ovh.dns.zone.unset",
64
+ // account: OVH_BeysIO,
65
+ // zone: "be-ys.io",
66
+ // config: OVH_BeysIO_DNS
67
+ // },
68
68
 
69
69
  { type: "cmd", cmd: `logger "TEST: Disconnected from HTTP"` }
70
70
  ],
@@ -77,17 +77,17 @@ module.exports = {
77
77
  content: {
78
78
  from: "alert@tc.be-ys.io",
79
79
  to: "m.vergoz@protonmail.com",
80
- subject: "[RESOLVED] Dev test",
81
- text: `Hi, the 'Dev test' has been resolved at ${new Date().toLocaleString()}`
80
+ // subject: "[RESOLVED] Dev test",
81
+ // text: `Hi, the 'Dev test' has been resolved at ${new Date().toLocaleString()}`
82
82
  }
83
83
  },
84
84
 
85
- {
86
- type: "ovh.dns.zone.set",
87
- account: OVH_BeysIO,
88
- zone: "be-ys.io",
89
- config: OVH_BeysIO_DNS
90
- },
85
+ // {
86
+ // type: "ovh.dns.zone.set",
87
+ // account: OVH_BeysIO,
88
+ // zone: "be-ys.io",
89
+ // config: OVH_BeysIO_DNS
90
+ // },
91
91
 
92
92
  { type: "cmd", cmd: `logger "TEST: Connected from HTTP"` },
93
93
  ],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jetcheck",
3
- "version": "1.1.3",
3
+ "version": "1.1.5",
4
4
  "description": "Javascript based Network & System checker",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -16,6 +16,7 @@
16
16
  "axios": "^1.7.9",
17
17
  "body-parser": "^1.20.3",
18
18
  "ejs": "^3.1.10",
19
+ "elapsed": "^0.0.7",
19
20
  "express": "^4.21.2",
20
21
  "mkdirp": "^3.0.1",
21
22
  "nodemailer": "^6.9.16",
@@ -1,7 +1,7 @@
1
1
  const NodeMailer = require("nodemailer")
2
+ const Elapsed = require("elapsed")
2
3
 
3
4
  async function sender(options) {
4
- console.log(options)
5
5
  const ret = {}
6
6
  try {
7
7
  const transporter = NodeMailer.createTransport(options.transporter);
@@ -21,7 +21,55 @@ module.exports = async function (kernel) {
21
21
  return (`email(${options.content?.to})`)
22
22
  },
23
23
  trigger: async function (task, state) {
24
- await sender(task)
24
+ const options = { ...task }
25
+
26
+ if (!task.content)
27
+ task.content = {}
28
+
29
+ options.content = { ...task.content }
30
+
31
+ // manage auto subject
32
+ if (!task.content.subject) {
33
+ if (state.mode === "DEGRADED")
34
+ options.content.subject = `[RESOLVED] - ${state.name}`
35
+ else if (state.mode === "WORKING")
36
+ options.content.subject = `[FAILED] - ${state.name}`
37
+ }
38
+ else if (typeof task.subject === 'function')
39
+ options.content.subject = task.subject(options, state)
40
+
41
+ // manage email content
42
+ if (!task.content.text) {
43
+ const deadTime = state.hasOwnProperty("deadTime") ? state.deadTime : new Date
44
+ if (state.mode === "DEGRADED")
45
+ options.content.text = [
46
+ `Hi,`,
47
+ '',
48
+ `The test '${state.name}' has been resolved at ${new Date().toLocaleString()}`,
49
+ `\t- Detection time: ${deadTime.toLocaleString()}`,
50
+ `\t- Outage elapsed: ${(new Elapsed(deadTime)).optimal}`,
51
+ ].join("\n")
52
+ else if (state.mode === "WORKING")
53
+ options.content.text = [
54
+ `Hi,`,
55
+ '',
56
+ `The test '${state.name}' fails at ${new Date().toLocaleString()}`,
57
+ ].join("\n")
58
+ }
59
+ else if (typeof task.text === 'function')
60
+ options.content.text = task.text(options, state)
61
+
62
+ if(!options.content.text)
63
+ options.content.text = ""
64
+
65
+ options.content.text = [
66
+ options.content.text,
67
+ "",
68
+ "--",
69
+ `Jetcheck v${kernel.version}`
70
+ ].join("\n")
71
+
72
+ await sender(options)
25
73
  }
26
74
  }
27
75
  console.log("Loading Email plugin")
package/services/tests.js CHANGED
@@ -90,12 +90,13 @@ module.exports = async function (kernel) {
90
90
  async function pop() {
91
91
  const task = state.current.pop()
92
92
  if (!task) {
93
- if(state.succeed.length === 0 && state.failed.length === 0) {
93
+ if (state.succeed.length === 0 && state.failed.length === 0) {
94
94
  // do nothing
95
95
  }
96
96
  else if (state.succeed.length === 0) {
97
97
  if (state.mode === "WORKING") {
98
98
  console.log(`System "${testName}" is degraded`)
99
+ state.deadTime = new Date
99
100
  if (test.failed) {
100
101
  for (var item of test.failed) {
101
102
  const module = kernel.tests.plugins[item.type]
@@ -109,6 +110,7 @@ module.exports = async function (kernel) {
109
110
  else {
110
111
  if (state.mode === "DEGRADED") {
111
112
  console.log(`System ${testName} is restored`)
113
+
112
114
  if (test.succeed) {
113
115
  for (var item of test.succeed) {
114
116
  const module = kernel.tests.plugins[item.type]
@@ -116,6 +118,7 @@ module.exports = async function (kernel) {
116
118
  await module.trigger(item, state)
117
119
  }
118
120
  }
121
+ delete state.deadTime
119
122
  }
120
123
  state.mode = "WORKING"
121
124
  }
@@ -137,7 +140,7 @@ module.exports = async function (kernel) {
137
140
  state.succeed.push(task)
138
141
  else
139
142
  state.failed.push({ ...task, error })
140
- } catch(e) {
143
+ } catch (e) {
141
144
  console.log(`Test "${testName}" failed: ${e.message}`)
142
145
  }
143
146