Browse Source

feat(monitor-checks): add should and should not dropdown

bertyhell/feature/monitor-checks
Bert Verhelst 3 years ago
parent
commit
eb810ec7c7
  1. 67
      server/model/monitor.js
  2. 9
      server/validate-monitor-checks.js
  3. 182
      src/components/MonitorCheckEditor.vue
  4. 16
      src/languages/en.js
  5. 16
      src/languages/nl-NL.js
  6. 35
      src/util.js
  7. 22
      src/util.ts

67
server/model/monitor.js

@ -6,11 +6,25 @@ dayjs.extend(utc);
dayjs.extend(timezone);
const axios = require("axios");
const { Prometheus } = require("../prometheus");
const { debug, UP, DOWN, PENDING, flipStatus, TimeLogger, MONITOR_CHECK_SELECTOR_TYPES,
const {
debug,
UP,
DOWN,
PENDING,
flipStatus,
TimeLogger,
MONITOR_CHECK_HTTP_CODE_TYPES,
MONITOR_CHECK_SELECTOR_TYPES,
HTTP_STATUS_CODE_SHOULD_EQUAL,
RESPONSE_SHOULD_CONTAIN_TEXT
RESPONSE_SHOULD_CONTAIN_TEXT,
} = require("../../src/util");
const { tcping, ping, dnsResolve, checkCertificate, getTotalClientInRoom } = require("../util-server");
const {
tcping,
ping,
dnsResolve,
checkCertificate,
getTotalClientInRoom,
} = require("../util-server");
const { R } = require("redbean-node");
const { BeanModel } = require("redbean-node/dist/bean-model");
const { Notification } = require("../notification");
@ -111,7 +125,7 @@ class Monitor extends BeanModel {
// undefined if not https
let tlsInfo = undefined;
if (! previousBeat) {
if (!previousBeat) {
previousBeat = await R.findOne("heartbeat", " monitor_id = ? ORDER BY time DESC", [
this.id,
]);
@ -129,7 +143,7 @@ class Monitor extends BeanModel {
}
// Duration
if (! isFirstBeat) {
if (!isFirstBeat) {
bean.duration = dayjs(bean.time).diff(dayjs(previousBeat.time), "second");
} else {
bean.duration = 0;
@ -148,7 +162,7 @@ class Monitor extends BeanModel {
},
httpsAgent: new https.Agent({
maxCachedSessions: 0, // Use Custom agent to disable session reuse (https://github.com/nodejs/node/issues/3940)
rejectUnauthorized: ! this.getIgnoreTls(),
rejectUnauthorized: !this.getIgnoreTls(),
}),
maxRedirects: this.maxredirects,
validateStatus: undefined,
@ -216,7 +230,7 @@ class Monitor extends BeanModel {
if (this.dnsLastResult !== dnsMessage) {
R.exec("UPDATE `monitor` SET dns_last_result = ? WHERE id = ? ", [
dnsMessage,
this.id
this.id,
]);
}
@ -227,7 +241,7 @@ class Monitor extends BeanModel {
let heartbeatCount = await R.count("heartbeat", " monitor_id = ? AND time > ? ", [
this.id,
time
time,
]);
debug("heartbeatCount" + heartbeatCount + " " + time);
@ -341,7 +355,7 @@ class Monitor extends BeanModel {
previousBeat = bean;
if (! this.isStop) {
if (!this.isStop) {
this.heartbeatInterval = setTimeout(beat, beatInterval * 1000);
}
@ -418,9 +432,11 @@ class Monitor extends BeanModel {
let avgPing = parseInt(await R.getCell(`
SELECT AVG(ping)
FROM heartbeat
WHERE time > DATETIME('now', ? || ' hours')
AND ping IS NOT NULL
AND monitor_id = ? `, [
WHERE time
> DATETIME('now'
, ? || ' hours')
AND ping IS NOT NULL
AND monitor_id = ? `, [
-duration,
monitorID,
]));
@ -454,30 +470,31 @@ class Monitor extends BeanModel {
// e.g. If the last beat's duration is bigger that the 24hrs window, it will use the duration between the (beat time - window margin) (THEN case in SQL)
let result = await R.getRow(`
SELECT
-- SUM all duration, also trim off the beat out of time window
-- SUM all duration, also trim off the beat out of time window
SUM(
CASE
WHEN (JULIANDAY(\`time\`) - JULIANDAY(?)) * 86400 < duration
THEN (JULIANDAY(\`time\`) - JULIANDAY(?)) * 86400
THEN (JULIANDAY(\`time\`) - JULIANDAY(?)) * 86400
ELSE duration
END
) AS total_duration,
END
) AS total_duration,
-- SUM all uptime duration, also trim off the beat out of time window
-- SUM all uptime duration, also trim off the beat out of time window
SUM(
CASE
WHEN (status = 1)
THEN
THEN
CASE
WHEN (JULIANDAY(\`time\`) - JULIANDAY(?)) * 86400 < duration
THEN (JULIANDAY(\`time\`) - JULIANDAY(?)) * 86400
ELSE duration
END
END
END
) AS uptime_duration
) AS uptime_duration
FROM heartbeat
WHERE time > ?
AND monitor_id = ?
WHERE time
> ?
AND monitor_id = ?
`, [
startTime, startTime, startTime, startTime, startTime,
monitorID,
@ -497,7 +514,7 @@ class Monitor extends BeanModel {
} else {
// Handle new monitor with only one beat, because the beat's duration = 0
let status = parseInt(await R.getCell("SELECT `status` FROM heartbeat WHERE monitor_id = ?", [ monitorID ]));
let status = parseInt(await R.getCell("SELECT `status` FROM heartbeat WHERE monitor_id = ?", [monitorID]));
if (status === UP) {
uptime = 1;
@ -523,10 +540,10 @@ class Monitor extends BeanModel {
const checks = await R.getAll("SELECT mc.type, mc.value FROM monitor_checks mc WHERE mc.monitor_id = ?", [this.id]);
checks.forEach(check => {
if (MONITOR_CHECK_SELECTOR_TYPES.includes(check.type) && typeof check.value === "string" && check.value.startsWith("{")) {
if (MONITOR_CHECK_HTTP_CODE_TYPES.includes(check.type) && typeof check.value === "string" && check.value.startsWith("[")) {
check.value = JSON.parse(check.value);
}
if (check.type === "HTTP_STATUS_CODE_SHOULD_EQUAL" && typeof check.value === "string" && check.value.startsWith("[")) {
if (MONITOR_CHECK_SELECTOR_TYPES.includes(check.type) && typeof check.value === "string" && check.value.startsWith("{")) {
check.value = JSON.parse(check.value);
}
});

9
server/validate-monitor-checks.js

@ -16,6 +16,15 @@ function validateMonitorChecks(res, checks, bean) {
}
break;
case "HTTP_STATUS_CODE_SHOULD_NOT_EQUAL":
if (!checkStatusCode(res.status, check.value)) {
bean.msg += `, status does not match '${check.value}'`;
bean.status = UP;
} else {
throw new Error(bean.msg + ", but status code does match " + check.value);
}
break;
case "RESPONSE_SHOULD_CONTAIN_TEXT":
if (responseText.includes(check.value)) {
bean.msg += `, response contains '${check.value}'`;

182
src/components/MonitorCheckEditor.vue

@ -1,36 +1,32 @@
<template>
<div class="monitor-check mb-4">
<div>
<select id="type" :value="monitorCheck.type" :class="{'form-select': true, 'mb-1': !!monitorCheck.type}" @input="changeType($event.target.value)" required>
<option value="HTTP_STATUS_CODE_SHOULD_EQUAL">
{{ $t("MonitorCheckTypeHttpStatusCodeShouldEqual") }}
</option>
<option value="RESPONSE_SHOULD_CONTAIN_TEXT">
{{ $t("MonitorCheckTypeResponseShouldContainText") }}
</option>
<option value="RESPONSE_SHOULD_NOT_CONTAIN_TEXT">
{{ $t("MonitorCheckTypeResponseShouldNotContainText") }}
</option>
<option value="RESPONSE_SHOULD_MATCH_REGEX">
{{ $t("MonitorCheckTypeResponseShouldMatchRegex") }}
</option>
<option value="RESPONSE_SHOULD_NOT_MATCH_REGEX">
{{ $t("MonitorCheckTypeResponseShouldNotMatchRegex") }}
</option>
<option value="RESPONSE_SELECTOR_SHOULD_EQUAL">
{{ $t("MonitorCheckTypeResponseSelectorShouldEqual") }}
</option>
<option value="RESPONSE_SELECTOR_SHOULD_NOT_EQUAL">
{{ $t("MonitorCheckTypeResponseSelectorShouldNotEqual") }}
</option>
<option value="RESPONSE_SELECTOR_SHOULD_MATCH_REGEX">
{{ $t("MonitorCheckTypeResponseSelectorShouldMatchRegex") }}
</option>
<option value="RESPONSE_SELECTOR_SHOULD_NOT_MATCH_REGEX">
{{ $t("MonitorCheckTypeResponseSelectorShouldNotMatchRegex") }}
</option>
</select>
<div v-if="monitorCheck.type === 'HTTP_STATUS_CODE_SHOULD_EQUAL'">
<div class="side-by-side">
<select id="invert-check" :value="invertedTypeOption" :class="{'form-select': true, 'mb-1': !!monitorCheck.type, 'me-1': true}"
@input="changeTypeInversion($event.target.value)" required>
<option value="SHOULD">{{ $t("MonitorCheckTypeShould") }}</option>
<option value="SHOULD_NOT">{{ $t("MonitorCheckTypeShouldNot") }}</option>
</select>
<select id="type" :value="monitorType" :class="{'form-select': true, 'mb-1': !!monitorCheck.type}"
@input="changeType($event.target.value)" required>
<option value="HTTP_STATUS_CODE_SHOULD_EQUAL">
{{ $t("MonitorCheckTypeHttpStatusCodeShouldEqual") }}
</option>
<option value="RESPONSE_SHOULD_CONTAIN_TEXT">
{{ $t("MonitorCheckTypeResponseShouldContainText") }}
</option>
<option value="RESPONSE_SHOULD_MATCH_REGEX">
{{ $t("MonitorCheckTypeResponseShouldMatchRegex") }}
</option>
<option value="RESPONSE_SELECTOR_SHOULD_EQUAL">
{{ $t("MonitorCheckTypeResponseSelectorShouldEqual") }}
</option>
<option value="RESPONSE_SELECTOR_SHOULD_MATCH_REGEX">
{{ $t("MonitorCheckTypeResponseSelectorShouldMatchRegex") }}
</option>
</select>
</div>
<div v-if="monitorType === 'HTTP_STATUS_CODE_SHOULD_EQUAL'">
<VueMultiselect
id="acceptedStatusCodes"
:options="acceptedStatusCodeOptions"
@ -46,29 +42,30 @@
@update:model-value="changeValue"
></VueMultiselect>
</div>
<div v-if="monitorCheck.type === 'RESPONSE_SHOULD_CONTAIN_TEXT' || monitorCheck.type === 'RESPONSE_SHOULD_NOT_CONTAIN_TEXT'">
<input :value="monitorCheck.value" type="text" class="form-control" required :placeholder="$t('MonitorCheckValuePlaceholder')" @input="changeValue($event.target.value)">
<div v-if="monitorType === 'RESPONSE_SHOULD_CONTAIN_TEXT'">
<input :value="monitorCheck.value" type="text" class="form-control" required :placeholder="$t('MonitorCheckValuePlaceholder')"
@input="changeValue($event.target.value)">
</div>
<div v-if="monitorCheck.type === 'RESPONSE_SHOULD_MATCH_REGEX' || monitorCheck.type === 'RESPONSE_SHOULD_NOT_MATCH_REGEX'">
<div v-if="monitorType === 'RESPONSE_SHOULD_MATCH_REGEX'">
<input type="text" class="form-control" required :value="monitorCheck.value"
:placeholder="$t('Regexp, Example: [a-z0-9.]+@gmail\.com')" @input="changeValue($event.target.value)"
>
</div>
<div
v-if="monitorCheck.type === 'RESPONSE_SELECTOR_SHOULD_EQUAL' || monitorCheck.type === 'RESPONSE_SELECTOR_SHOULD_NOT_EQUAL'"
>
<input :value="monitorCheck?.value?.selectorPath || ''" type="text" class="form-control mb-1" required :placeholder="$t('Selector, Example: customer.address.street')"
<div v-if="monitorType === 'RESPONSE_SELECTOR_SHOULD_EQUAL'">
<input :value="monitorCheck?.value?.selectorPath || ''" type="text" class="form-control mb-1" required
:placeholder="$t('Selector, Example: customer.address.street')"
@input="changeSelectorPath($event.target.value)"
>
<input :value="monitorCheck?.value?.selectorValue || ''" type="text" class="form-control" required :placeholder="$t('Value, Example: First street')" @input="changeSelectorValue($event.target.value)">
<input :value="monitorCheck?.value?.selectorValue || ''" type="text" class="form-control" required
:placeholder="$t('Value, Example: First street')" @input="changeSelectorValue($event.target.value)">
</div>
<div
v-if="monitorCheck.type === 'RESPONSE_SELECTOR_SHOULD_MATCH_REGEX' || monitorCheck.type === 'RESPONSE_SELECTOR_SHOULD_NOT_MATCH_REGEX'"
>
<input :value="monitorCheck?.value?.selectorPath || ''" type="text" class="form-control mb-1" required :placeholder="$t('Selector, Example: customer.contactInfo.email')"
<div v-if="monitorType === 'RESPONSE_SELECTOR_SHOULD_MATCH_REGEX'">
<input :value="monitorCheck?.value?.selectorPath || ''" type="text" class="form-control mb-1" required
:placeholder="$t('Selector, Example: customer.contactInfo.email')"
@input="changeSelectorPath($event.target.value)"
>
<input :value="monitorCheck?.value?.selectorValue || ''" type="text" class="form-control" required :placeholder="$t('Regexp, Example: [a-z0-9.]+@gmail\.com')"
<input :value="monitorCheck?.value?.selectorValue || ''" type="text" class="form-control" required
:placeholder="$t('Regexp, Example: [a-z0-9.]+@gmail\.com')"
@input="changeSelectorValue($event.target.value)"
>
</div>
@ -81,7 +78,14 @@
<script>
import VueMultiselect from "vue-multiselect";
import { MONITOR_CHECK_SELECTOR_TYPES, MONITOR_CHECK_STRING_TYPES } from "../util.ts";
import {
MONITOR_CHECK_INVERTED_TYPES,
MONITOR_CHECK_SELECTOR_TYPES,
MONITOR_CHECK_STRING_TYPES,
MONITOR_CHECK_SHOULD,
MONITOR_CHECK_SHOULD_NOT,
MONITOR_CHECK_MAP_NORMAL_TO_INVERTED, MONITOR_CHECK_MAP_INVERTED_TO_NORMAL, MONITOR_CHECK_HTTP_CODE_TYPES,
} from "../util.ts";
export default {
components: {
@ -100,6 +104,10 @@ export default {
data() {
return {
acceptedStatusCodeOptions: [],
// Contains SHOULD or SHOULD_NOT
invertedTypeOption: MONITOR_CHECK_SHOULD,
// Always contains the normal type (never the NOT variant)
monitorType: undefined,
};
},
mounted() {
@ -116,13 +124,33 @@ export default {
}
this.acceptedStatusCodeOptions = acceptedStatusCodeOptions;
if (this.monitorCheck.type) {
this.invertedTypeOption = MONITOR_CHECK_INVERTED_TYPES.includes(this.monitorCheck.type) ? MONITOR_CHECK_SHOULD_NOT : MONITOR_CHECK_SHOULD;
this.monitorType = MONITOR_CHECK_MAP_INVERTED_TO_NORMAL[this.monitorCheck.type] || this.monitorCheck.type;
}
},
methods: {
deleteMonitorCheck() {
this.$emit("delete");
},
changeTypeInversion(inversionType) {
this.invertedTypeOption = inversionType;
this.emitType();
},
changeType(type) {
if (MONITOR_CHECK_STRING_TYPES.includes(type) && MONITOR_CHECK_STRING_TYPES.includes(this.monitorCheck.type) ||
this.monitorType = type;
this.emitType();
},
// Combine invertedTypeOption with monitorType to produce the combined this.monitorCheck.type
emitType() {
if (!this.monitorType) {
return;
}
const type = this.invertedTypeOption === MONITOR_CHECK_SHOULD ? this.monitorType : MONITOR_CHECK_MAP_NORMAL_TO_INVERTED[this.monitorType];
if (MONITOR_CHECK_HTTP_CODE_TYPES.includes(type) && MONITOR_CHECK_HTTP_CODE_TYPES.includes(this.monitorCheck.type) ||
MONITOR_CHECK_STRING_TYPES.includes(type) && MONITOR_CHECK_STRING_TYPES.includes(this.monitorCheck.type) ||
MONITOR_CHECK_SELECTOR_TYPES.includes(type) && MONITOR_CHECK_SELECTOR_TYPES.includes(this.monitorCheck.type)) {
// Check value stays same type (string => string or object => object)
this.$emit("change", {
@ -133,7 +161,7 @@ export default {
// Check value switches (string => object or object => string)
this.$emit("change", {
type,
value: undefined
value: undefined,
});
}
},
@ -166,29 +194,51 @@ export default {
</script>
<style lang="scss" scoped>
@import "../assets/vars.scss";
.monitor-check {
display: flex;
input,
select {
border-radius: 19px 0 0 19px;
}
button {
margin-left: 0.25rem;
padding-left: 15px;
padding-right: 15px;
border-radius: 0 19px 19px 0;
@import "../assets/vars.scss";
.monitor-check {
display: flex;
> div:first-child {
width: 100%;
}
.side-by-side {
display: flex;
> select:first-child {
width: 40%;
+ select {
border-radius: 0;
margin-left: -1px;
}
}
}
input,
select {
border-radius: 19px 0 0 19px;
&:focus {
z-index: 1;
}
}
button {
margin-left: 0.25rem;
padding-left: 15px;
padding-right: 15px;
border-radius: 0 19px 19px 0;
}
}
}
</style>
<style lang="scss">
.monitor-check {
.multiselect__tags {
border-radius: 19px 0 0 19px;
.monitor-check {
.multiselect__tags {
border-radius: 19px 0 0 19px;
}
}
}
</style>

16
src/languages/en.js

@ -194,15 +194,13 @@ export default {
"pushbullet": "Pushbullet",
"line": "Line Messenger",
"mattermost": "Mattermost",
MonitorCheckTypeHttpStatusCodeShouldEqual: "HTTP status code should equal",
MonitorCheckTypeResponseShouldContainText: "Response should contain text",
MonitorCheckTypeResponseShouldNotContainText: "Response should not contain text",
MonitorCheckTypeResponseShouldMatchRegex: "Response should match regex",
MonitorCheckTypeResponseShouldNotMatchRegex: "Response should not match regex",
MonitorCheckTypeResponseSelectorShouldEqual: "Response selector should equal",
MonitorCheckTypeResponseSelectorShouldNotEqual: "Response selector should not equal",
MonitorCheckTypeResponseSelectorShouldMatchRegex: "Response selector should match regex",
MonitorCheckTypeResponseSelectorShouldNotMatchRegex: "Response selector should not match regex",
MonitorCheckTypeShould: "Should",
MonitorCheckTypeShouldNot: "Should not",
MonitorCheckTypeHttpStatusCodeShouldEqual: "equal status code",
MonitorCheckTypeResponseShouldContainText: "contain",
MonitorCheckTypeResponseShouldMatchRegex: "match regex",
MonitorCheckTypeResponseSelectorShouldEqual: "equal (JSON selector)",
MonitorCheckTypeResponseSelectorShouldMatchRegex: "match regex (JSON selector)",
MonitorCheckValuePlaceholder: "Value",
MonitorCheckSelectorPathPlaceholder: "Selector, Example: customer.address.street",
MonitorCheckSelectorValuePlaceholder: "Value, Example: First street",

16
src/languages/nl-NL.js

@ -195,15 +195,13 @@ export default {
pushbullet: "Pushbullet",
line: "Line Messenger",
mattermost: "Mattermost",
MonitorCheckTypeHttpStatusCodeShouldEqual: "HTTP status code moet gelijk zijn aan",
MonitorCheckTypeResponseShouldContainText: "Response moet tekst bevatten",
MonitorCheckTypeResponseShouldNotContainText: "Response mag tekst niet bevatten",
MonitorCheckTypeResponseShouldMatchRegex: "Response moet overeenkomen met regex",
MonitorCheckTypeResponseShouldNotMatchRegex: "Response mag niet overeenkomen met regex",
MonitorCheckTypeResponseSelectorShouldEqual: "Response selectie moet gelijk zijn aan",
MonitorCheckTypeResponseSelectorShouldNotEqual: "Response selectie mag niet gelijk zijn aan",
MonitorCheckTypeResponseSelectorShouldMatchRegex: "Response selectie moet overeenkomen met regex",
MonitorCheckTypeResponseSelectorShouldNotMatchRegex: "Response selecte mag niet overeenkomen met regex",
MonitorCheckTypeShould: "Moet",
MonitorCheckTypeShouldNot: "Mag niet",
MonitorCheckTypeHttpStatusCodeShouldEqual: "gelijk aan status code",
MonitorCheckTypeResponseShouldContainText: "bevatten",
MonitorCheckTypeResponseShouldMatchRegex: "overeenkomen met regex",
MonitorCheckTypeResponseSelectorShouldEqual: "gelijk zijn (JSON selectie)",
MonitorCheckTypeResponseSelectorShouldMatchRegex: "overeenkomen met regex (JSON selectie)",
MonitorCheckValuePlaceholder: "Waarde",
MonitorCheckSelectorPathPlaceholder: "Selectie, Voorbeeld: klant.adres.straat",
MonitorCheckSelectorValuePlaceholder: "Waarde, Voorbeeld: Hogestraat",

35
src/util.js

@ -7,7 +7,7 @@
// Backend uses the compiled file util.js
// Frontend uses util.ts
Object.defineProperty(exports, "__esModule", { value: true });
exports.genSecret = exports.getRandomInt = exports.getRandomArbitrary = exports.TimeLogger = exports.polyfill = exports.debug = exports.ucfirst = exports.sleep = exports.flipStatus = exports.STATUS_PAGE_PARTIAL_DOWN = exports.STATUS_PAGE_ALL_UP = exports.STATUS_PAGE_ALL_DOWN = exports.PENDING = exports.UP = exports.DOWN = exports.appName = exports.isDev = void 0;
exports.genSecret = exports.getRandomInt = exports.getRandomArbitrary = exports.TimeLogger = exports.polyfill = exports.debug = exports.ucfirst = exports.sleep = exports.flipStatus = exports.MONITOR_CHECK_MAP_INVERTED_TO_NORMAL = exports.MONITOR_CHECK_MAP_NORMAL_TO_INVERTED = exports.MONITOR_CHECK_INVERTED_TYPES = exports.MONITOR_CHECK_SELECTOR_TYPES = exports.MONITOR_CHECK_STRING_TYPES = exports.MONITOR_CHECK_HTTP_CODE_TYPES = exports.RESPONSE_SELECTOR_SHOULD_NOT_MATCH_REGEX = exports.RESPONSE_SELECTOR_SHOULD_MATCH_REGEX = exports.RESPONSE_SELECTOR_SHOULD_NOT_EQUAL = exports.RESPONSE_SELECTOR_SHOULD_EQUAL = exports.RESPONSE_SHOULD_NOT_MATCH_REGEX = exports.RESPONSE_SHOULD_MATCH_REGEX = exports.RESPONSE_SHOULD_NOT_CONTAIN_TEXT = exports.RESPONSE_SHOULD_CONTAIN_TEXT = exports.HTTP_STATUS_CODE_SHOULD_NOT_EQUAL = exports.HTTP_STATUS_CODE_SHOULD_EQUAL = exports.MONITOR_CHECK_SHOULD_NOT = exports.MONITOR_CHECK_SHOULD = exports.STATUS_PAGE_PARTIAL_DOWN = exports.STATUS_PAGE_ALL_UP = exports.STATUS_PAGE_ALL_DOWN = exports.PENDING = exports.UP = exports.DOWN = exports.appName = exports.isDev = void 0;
const _dayjs = require("dayjs");
const dayjs = _dayjs;
exports.isDev = process.env.NODE_ENV === "development";
@ -18,8 +18,37 @@ exports.PENDING = 2;
exports.STATUS_PAGE_ALL_DOWN = 0;
exports.STATUS_PAGE_ALL_UP = 1;
exports.STATUS_PAGE_PARTIAL_DOWN = 2;
exports.MONITOR_CHECK_STRING_TYPES = ["HTTP_STATUS_CODE_SHOULD_EQUAL", "RESPONSE_SHOULD_CONTAIN_TEXT", "RESPONSE_SHOULD_NOT_CONTAIN_TEXT", "RESPONSE_SHOULD_MATCH_REGEX", "RESPONSE_SHOULD_NOT_MATCH_REGEX"];
exports.MONITOR_CHECK_SELECTOR_TYPES = ["RESPONSE_SELECTOR_SHOULD_EQUAL", "RESPONSE_SELECTOR_SHOULD_NOT_EQUAL", "RESPONSE_SELECTOR_SHOULD_MATCH_REGEX", "RESPONSE_SELECTOR_SHOULD_NOT_MATCH_REGEX"];
// Monitor check types
exports.MONITOR_CHECK_SHOULD = "SHOULD";
exports.MONITOR_CHECK_SHOULD_NOT = "SHOULD_NOT";
exports.HTTP_STATUS_CODE_SHOULD_EQUAL = "HTTP_STATUS_CODE_SHOULD_EQUAL";
exports.HTTP_STATUS_CODE_SHOULD_NOT_EQUAL = "HTTP_STATUS_CODE_SHOULD_NOT_EQUAL";
exports.RESPONSE_SHOULD_CONTAIN_TEXT = "RESPONSE_SHOULD_CONTAIN_TEXT";
exports.RESPONSE_SHOULD_NOT_CONTAIN_TEXT = "RESPONSE_SHOULD_NOT_CONTAIN_TEXT";
exports.RESPONSE_SHOULD_MATCH_REGEX = "RESPONSE_SHOULD_MATCH_REGEX";
exports.RESPONSE_SHOULD_NOT_MATCH_REGEX = "RESPONSE_SHOULD_NOT_MATCH_REGEX";
exports.RESPONSE_SELECTOR_SHOULD_EQUAL = "RESPONSE_SELECTOR_SHOULD_EQUAL";
exports.RESPONSE_SELECTOR_SHOULD_NOT_EQUAL = "RESPONSE_SELECTOR_SHOULD_NOT_EQUAL";
exports.RESPONSE_SELECTOR_SHOULD_MATCH_REGEX = "RESPONSE_SELECTOR_SHOULD_MATCH_REGEX";
exports.RESPONSE_SELECTOR_SHOULD_NOT_MATCH_REGEX = "RESPONSE_SELECTOR_SHOULD_NOT_MATCH_REGEX";
exports.MONITOR_CHECK_HTTP_CODE_TYPES = [exports.HTTP_STATUS_CODE_SHOULD_EQUAL, exports.HTTP_STATUS_CODE_SHOULD_NOT_EQUAL];
exports.MONITOR_CHECK_STRING_TYPES = [exports.RESPONSE_SHOULD_CONTAIN_TEXT, exports.RESPONSE_SHOULD_NOT_CONTAIN_TEXT, exports.RESPONSE_SHOULD_MATCH_REGEX, exports.RESPONSE_SHOULD_NOT_MATCH_REGEX];
exports.MONITOR_CHECK_SELECTOR_TYPES = [exports.RESPONSE_SELECTOR_SHOULD_EQUAL, exports.RESPONSE_SELECTOR_SHOULD_NOT_EQUAL, exports.RESPONSE_SELECTOR_SHOULD_MATCH_REGEX, exports.RESPONSE_SELECTOR_SHOULD_NOT_MATCH_REGEX];
exports.MONITOR_CHECK_INVERTED_TYPES = [exports.HTTP_STATUS_CODE_SHOULD_NOT_EQUAL, exports.RESPONSE_SHOULD_NOT_CONTAIN_TEXT, exports.RESPONSE_SHOULD_NOT_MATCH_REGEX, exports.RESPONSE_SELECTOR_SHOULD_NOT_EQUAL, exports.RESPONSE_SELECTOR_SHOULD_NOT_MATCH_REGEX];
exports.MONITOR_CHECK_MAP_NORMAL_TO_INVERTED = {
[exports.HTTP_STATUS_CODE_SHOULD_EQUAL]: exports.HTTP_STATUS_CODE_SHOULD_NOT_EQUAL,
[exports.RESPONSE_SHOULD_CONTAIN_TEXT]: exports.RESPONSE_SHOULD_NOT_CONTAIN_TEXT,
[exports.RESPONSE_SHOULD_MATCH_REGEX]: exports.RESPONSE_SHOULD_NOT_MATCH_REGEX,
[exports.RESPONSE_SELECTOR_SHOULD_EQUAL]: exports.RESPONSE_SELECTOR_SHOULD_NOT_EQUAL,
[exports.RESPONSE_SELECTOR_SHOULD_MATCH_REGEX]: exports.RESPONSE_SELECTOR_SHOULD_NOT_MATCH_REGEX,
};
exports.MONITOR_CHECK_MAP_INVERTED_TO_NORMAL = {
[exports.HTTP_STATUS_CODE_SHOULD_NOT_EQUAL]: exports.HTTP_STATUS_CODE_SHOULD_EQUAL,
[exports.RESPONSE_SHOULD_NOT_CONTAIN_TEXT]: exports.RESPONSE_SHOULD_CONTAIN_TEXT,
[exports.RESPONSE_SHOULD_NOT_MATCH_REGEX]: exports.RESPONSE_SHOULD_MATCH_REGEX,
[exports.RESPONSE_SELECTOR_SHOULD_NOT_EQUAL]: exports.RESPONSE_SELECTOR_SHOULD_EQUAL,
[exports.RESPONSE_SELECTOR_SHOULD_NOT_MATCH_REGEX]: exports.RESPONSE_SELECTOR_SHOULD_MATCH_REGEX,
};
function flipStatus(s) {
if (s === exports.UP) {
return exports.DOWN;

22
src/util.ts

@ -20,7 +20,11 @@ export const STATUS_PAGE_ALL_UP = 1;
export const STATUS_PAGE_PARTIAL_DOWN = 2;
// Monitor check types
export const MONITOR_CHECK_SHOULD = "SHOULD";
export const MONITOR_CHECK_SHOULD_NOT = "SHOULD_NOT";
export const HTTP_STATUS_CODE_SHOULD_EQUAL = "HTTP_STATUS_CODE_SHOULD_EQUAL";
export const HTTP_STATUS_CODE_SHOULD_NOT_EQUAL = "HTTP_STATUS_CODE_SHOULD_NOT_EQUAL";
export const RESPONSE_SHOULD_CONTAIN_TEXT = "RESPONSE_SHOULD_CONTAIN_TEXT";
export const RESPONSE_SHOULD_NOT_CONTAIN_TEXT = "RESPONSE_SHOULD_NOT_CONTAIN_TEXT";
export const RESPONSE_SHOULD_MATCH_REGEX = "RESPONSE_SHOULD_MATCH_REGEX";
@ -30,8 +34,26 @@ export const RESPONSE_SELECTOR_SHOULD_NOT_EQUAL = "RESPONSE_SELECTOR_SHOULD_NOT_
export const RESPONSE_SELECTOR_SHOULD_MATCH_REGEX = "RESPONSE_SELECTOR_SHOULD_MATCH_REGEX";
export const RESPONSE_SELECTOR_SHOULD_NOT_MATCH_REGEX = "RESPONSE_SELECTOR_SHOULD_NOT_MATCH_REGEX";
export const MONITOR_CHECK_HTTP_CODE_TYPES = [HTTP_STATUS_CODE_SHOULD_EQUAL, HTTP_STATUS_CODE_SHOULD_NOT_EQUAL];
export const MONITOR_CHECK_STRING_TYPES = [RESPONSE_SHOULD_CONTAIN_TEXT, RESPONSE_SHOULD_NOT_CONTAIN_TEXT, RESPONSE_SHOULD_MATCH_REGEX, RESPONSE_SHOULD_NOT_MATCH_REGEX];
export const MONITOR_CHECK_SELECTOR_TYPES = [RESPONSE_SELECTOR_SHOULD_EQUAL, RESPONSE_SELECTOR_SHOULD_NOT_EQUAL, RESPONSE_SELECTOR_SHOULD_MATCH_REGEX, RESPONSE_SELECTOR_SHOULD_NOT_MATCH_REGEX];
export const MONITOR_CHECK_INVERTED_TYPES = [HTTP_STATUS_CODE_SHOULD_NOT_EQUAL, RESPONSE_SHOULD_NOT_CONTAIN_TEXT, RESPONSE_SHOULD_NOT_MATCH_REGEX, RESPONSE_SELECTOR_SHOULD_NOT_EQUAL, RESPONSE_SELECTOR_SHOULD_NOT_MATCH_REGEX];
export const MONITOR_CHECK_MAP_NORMAL_TO_INVERTED = {
[HTTP_STATUS_CODE_SHOULD_EQUAL]: HTTP_STATUS_CODE_SHOULD_NOT_EQUAL,
[RESPONSE_SHOULD_CONTAIN_TEXT]: RESPONSE_SHOULD_NOT_CONTAIN_TEXT,
[RESPONSE_SHOULD_MATCH_REGEX]: RESPONSE_SHOULD_NOT_MATCH_REGEX,
[RESPONSE_SELECTOR_SHOULD_EQUAL]: RESPONSE_SELECTOR_SHOULD_NOT_EQUAL,
[RESPONSE_SELECTOR_SHOULD_MATCH_REGEX]: RESPONSE_SELECTOR_SHOULD_NOT_MATCH_REGEX,
};
export const MONITOR_CHECK_MAP_INVERTED_TO_NORMAL = {
[HTTP_STATUS_CODE_SHOULD_NOT_EQUAL]: HTTP_STATUS_CODE_SHOULD_EQUAL,
[RESPONSE_SHOULD_NOT_CONTAIN_TEXT]: RESPONSE_SHOULD_CONTAIN_TEXT,
[RESPONSE_SHOULD_NOT_MATCH_REGEX]: RESPONSE_SHOULD_MATCH_REGEX,
[RESPONSE_SELECTOR_SHOULD_NOT_EQUAL]: RESPONSE_SELECTOR_SHOULD_EQUAL,
[RESPONSE_SELECTOR_SHOULD_NOT_MATCH_REGEX]: RESPONSE_SELECTOR_SHOULD_MATCH_REGEX,
};
export function flipStatus(s: number) {
if (s === UP) {

Loading…
Cancel
Save