mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-12-18 04:04:41 -05:00
Merge pull request #2610 from bayramberkay/feature/add-xml-support-to-http-monitors
Add xml support to HTTP monitors
This commit is contained in:
commit
cecb0b6425
12
db/patch-http-body-encoding.sql
Normal file
12
db/patch-http-body-encoding.sql
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
-- You should not modify if this have pushed to Github, unless it does serious wrong with the db.
|
||||||
|
BEGIN TRANSACTION;
|
||||||
|
|
||||||
|
ALTER TABLE monitor ADD http_body_encoding VARCHAR(25);
|
||||||
|
|
||||||
|
COMMIT;
|
||||||
|
|
||||||
|
BEGIN TRANSACTION;
|
||||||
|
|
||||||
|
UPDATE monitor SET http_body_encoding = 'json' WHERE (type = 'http' or type = 'keyword') AND http_body_encoding IS NULL;
|
||||||
|
|
||||||
|
COMMIT;
|
@ -70,6 +70,7 @@ class Database {
|
|||||||
"patch-maintenance-table2.sql": true,
|
"patch-maintenance-table2.sql": true,
|
||||||
"patch-add-gamedig-monitor.sql": true,
|
"patch-add-gamedig-monitor.sql": true,
|
||||||
"patch-add-google-analytics-status-page-tag.sql": true,
|
"patch-add-google-analytics-status-page-tag.sql": true,
|
||||||
|
"patch-http-body-encoding.sql": true
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -111,6 +111,7 @@ class Monitor extends BeanModel {
|
|||||||
radiusCalledStationId: this.radiusCalledStationId,
|
radiusCalledStationId: this.radiusCalledStationId,
|
||||||
radiusCallingStationId: this.radiusCallingStationId,
|
radiusCallingStationId: this.radiusCallingStationId,
|
||||||
game: this.game,
|
game: this.game,
|
||||||
|
httpBodyEncoding: this.httpBodyEncoding
|
||||||
};
|
};
|
||||||
|
|
||||||
if (includeSensitiveData) {
|
if (includeSensitiveData) {
|
||||||
@ -272,17 +273,29 @@ class Monitor extends BeanModel {
|
|||||||
|
|
||||||
log.debug("monitor", `[${this.name}] Prepare Options for axios`);
|
log.debug("monitor", `[${this.name}] Prepare Options for axios`);
|
||||||
|
|
||||||
|
let contentType = null;
|
||||||
|
let bodyValue = null;
|
||||||
|
|
||||||
|
if (this.body && !this.httpBodyEncoding || this.httpBodyEncoding === "json") {
|
||||||
|
bodyValue = JSON.parse(this.body);
|
||||||
|
contentType = "application/json";
|
||||||
|
} else if (this.body && (this.httpBodyEncoding === "xml")) {
|
||||||
|
bodyValue = this.body;
|
||||||
|
contentType = "text/xml; charset=utf-8";
|
||||||
|
}
|
||||||
|
|
||||||
// Axios Options
|
// Axios Options
|
||||||
const options = {
|
const options = {
|
||||||
url: this.url,
|
url: this.url,
|
||||||
method: (this.method || "get").toLowerCase(),
|
method: (this.method || "get").toLowerCase(),
|
||||||
...(this.body ? { data: JSON.parse(this.body) } : {}),
|
...(bodyValue ? { data: bodyValue } : {}),
|
||||||
timeout: this.interval * 1000 * 0.8,
|
timeout: this.interval * 1000 * 0.8,
|
||||||
headers: {
|
headers: {
|
||||||
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
|
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
|
||||||
"User-Agent": "Uptime-Kuma/" + version,
|
"User-Agent": "Uptime-Kuma/" + version,
|
||||||
...(this.headers ? JSON.parse(this.headers) : {}),
|
...(contentType ? { "Content-Type": contentType } : {}),
|
||||||
...(basicAuthHeader),
|
...(basicAuthHeader),
|
||||||
|
...(this.headers ? JSON.parse(this.headers) : {})
|
||||||
},
|
},
|
||||||
maxRedirects: this.maxredirects,
|
maxRedirects: this.maxredirects,
|
||||||
validateStatus: (status) => {
|
validateStatus: (status) => {
|
||||||
|
@ -726,6 +726,7 @@ let needSetup = false;
|
|||||||
bean.radiusCalledStationId = monitor.radiusCalledStationId;
|
bean.radiusCalledStationId = monitor.radiusCalledStationId;
|
||||||
bean.radiusCallingStationId = monitor.radiusCallingStationId;
|
bean.radiusCallingStationId = monitor.radiusCallingStationId;
|
||||||
bean.radiusSecret = monitor.radiusSecret;
|
bean.radiusSecret = monitor.radiusSecret;
|
||||||
|
bean.httpBodyEncoding = monitor.httpBodyEncoding;
|
||||||
|
|
||||||
bean.validate();
|
bean.validate();
|
||||||
|
|
||||||
|
@ -671,5 +671,6 @@
|
|||||||
"Google Analytics ID": "Google Analytics ID",
|
"Google Analytics ID": "Google Analytics ID",
|
||||||
"Edit Tag": "Edit Tag",
|
"Edit Tag": "Edit Tag",
|
||||||
"Server Address": "Server Address",
|
"Server Address": "Server Address",
|
||||||
"Learn More": "Learn More"
|
"Learn More": "Learn More",
|
||||||
|
"Body Encoding": "Body Encoding"
|
||||||
}
|
}
|
||||||
|
@ -503,6 +503,15 @@
|
|||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Encoding -->
|
||||||
|
<div class="my-3">
|
||||||
|
<label for="httpBodyEncoding" class="form-label">{{ $t("Body Encoding") }}</label>
|
||||||
|
<select id="httpBodyEncoding" v-model="monitor.httpBodyEncoding" class="form-select">
|
||||||
|
<option value="json">JSON</option>
|
||||||
|
<option value="xml">XML</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- Body -->
|
<!-- Body -->
|
||||||
<div class="my-3">
|
<div class="my-3">
|
||||||
<label for="body" class="form-label">{{ $t("Body") }}</label>
|
<label for="body" class="form-label">{{ $t("Body") }}</label>
|
||||||
@ -723,6 +732,15 @@ message HealthCheckResponse {
|
|||||||
` ]);
|
` ]);
|
||||||
},
|
},
|
||||||
bodyPlaceholder() {
|
bodyPlaceholder() {
|
||||||
|
if (this.monitor && this.monitor.httpBodyEncoding && this.monitor.httpBodyEncoding === "xml") {
|
||||||
|
return this.$t("Example:", [ `
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
|
||||||
|
<soap:Body>
|
||||||
|
<Uptime>Kuma</Uptime>
|
||||||
|
</soap:Body>
|
||||||
|
</soap:Envelope>` ]);
|
||||||
|
}
|
||||||
return this.$t("Example:", [ `
|
return this.$t("Example:", [ `
|
||||||
{
|
{
|
||||||
"key": "value"
|
"key": "value"
|
||||||
@ -872,6 +890,7 @@ message HealthCheckResponse {
|
|||||||
mqttTopic: "",
|
mqttTopic: "",
|
||||||
mqttSuccessMessage: "",
|
mqttSuccessMessage: "",
|
||||||
authMethod: null,
|
authMethod: null,
|
||||||
|
httpBodyEncoding: "json"
|
||||||
};
|
};
|
||||||
|
|
||||||
if (this.$root.proxyList && !this.monitor.proxyId) {
|
if (this.$root.proxyList && !this.monitor.proxyId) {
|
||||||
@ -909,7 +928,7 @@ message HealthCheckResponse {
|
|||||||
* @returns {boolean} Is the form input valid?
|
* @returns {boolean} Is the form input valid?
|
||||||
*/
|
*/
|
||||||
isInputValid() {
|
isInputValid() {
|
||||||
if (this.monitor.body) {
|
if (this.monitor.body && (!this.monitor.httpBodyEncoding || this.monitor.httpBodyEncoding === "json")) {
|
||||||
try {
|
try {
|
||||||
JSON.parse(this.monitor.body);
|
JSON.parse(this.monitor.body);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@ -933,6 +952,7 @@ message HealthCheckResponse {
|
|||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
async submit() {
|
async submit() {
|
||||||
|
|
||||||
this.processing = true;
|
this.processing = true;
|
||||||
|
|
||||||
if (!this.isInputValid()) {
|
if (!this.isInputValid()) {
|
||||||
@ -940,11 +960,15 @@ message HealthCheckResponse {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Beautify the JSON format
|
// Beautify the JSON format (only if httpBodyEncoding is not set or === json)
|
||||||
if (this.monitor.body) {
|
if (this.monitor.body && (!this.monitor.httpBodyEncoding || this.monitor.httpBodyEncoding === "json")) {
|
||||||
this.monitor.body = JSON.stringify(JSON.parse(this.monitor.body), null, 4);
|
this.monitor.body = JSON.stringify(JSON.parse(this.monitor.body), null, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.monitor.type && this.monitor.type !== "http" && this.monitor.type !== "keyword") {
|
||||||
|
this.monitor.httpBodyEncoding = null;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.monitor.headers) {
|
if (this.monitor.headers) {
|
||||||
this.monitor.headers = JSON.stringify(JSON.parse(this.monitor.headers), null, 4);
|
this.monitor.headers = JSON.stringify(JSON.parse(this.monitor.headers), null, 4);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user