-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extracted the group monitor ot a different monitoring type
- Loading branch information
1 parent
36196f6
commit 3a89624
Showing
3 changed files
with
57 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
const { | ||
UP, | ||
PENDING, | ||
DOWN, | ||
} = require("../../src/util"); | ||
const { MonitorType } = require("./monitor-type"); | ||
const Monitor = require("../model/monitor"); | ||
|
||
class GroupMonitorType extends MonitorType { | ||
|
||
name = "dns"; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
async check(monitor, heartbeat, _server) { | ||
const children = await Monitor.getChildren(monitor.id); | ||
|
||
if (children.length > 0) { | ||
heartbeat.status = UP; | ||
heartbeat.msg = "All children up and running"; | ||
for (const child of children) { | ||
if (!child.active) { | ||
// Ignore inactive childs | ||
continue; | ||
} | ||
const lastBeat = await Monitor.getPreviousHeartbeat(child.id); | ||
|
||
// Only change state if the monitor is in worse conditions then the ones before | ||
// lastBeat.status could be null | ||
if (!lastBeat) { | ||
heartbeat.status = PENDING; | ||
} else if (heartbeat.status === UP && (lastBeat.status === PENDING || lastBeat.status === DOWN)) { | ||
heartbeat.status = lastBeat.status; | ||
} else if (heartbeat.status === PENDING && lastBeat.status === DOWN) { | ||
heartbeat.status = lastBeat.status; | ||
} | ||
} | ||
|
||
if (heartbeat.status !== UP) { | ||
heartbeat.msg = "Child inaccessible"; | ||
} | ||
} else { | ||
// Set status pending if group is empty | ||
heartbeat.status = PENDING; | ||
heartbeat.msg = "Group empty"; | ||
} | ||
} | ||
} | ||
|
||
module.exports = { | ||
GroupMonitorType, | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters