Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add xml support to HTTP monitors #2610

Merged
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
3a18801
Add Body Encoding field
Aug 11, 2022
2b9bf09
Add non-json support for http body
Aug 12, 2022
0d58526
Merge branch 'master' into feature/expand-http-payload-support
Aug 12, 2022
31cc328
fix lint
Aug 12, 2022
6ec6410
Merge branch 'master' into feature/expand-http-payload-support
Aug 20, 2022
fa1fc0f
Merge branch 'master' into feature/expand-http-payload-support
Sep 7, 2022
0814d64
Merge branch 'master' into feature/expand-http-payload-support
Sep 25, 2022
5809088
Don't override a user-defined content-type header
Sep 26, 2022
6537f4f
content-type change
Sep 26, 2022
f6919ae
remove TODO
Sep 26, 2022
3adc9e6
Add only xml support to http monitors
Genc Jan 14, 2023
be850dd
Merge remote-tracking branch 'remote/master' into feature/add-xml-sup…
Genc Jan 14, 2023
15c64d4
Fix lint
Genc Jan 14, 2023
9890a07
Fix lint
Genc Jan 14, 2023
cf21aa3
Fix lint
Genc Jan 14, 2023
86ba6f8
Merge remote-tracking branch 'remote/master' into feature/add-xml-sup…
Genc Jan 20, 2023
aef8507
reorder fix
Genc Jan 20, 2023
cd017fc
Merge remote-tracking branch 'remote/master' into feature/add-xml-sup…
Genc Jan 21, 2023
7866d1e
Merge remote-tracking branch 'remote/master' into feature/add-xml-sup…
Genc Jan 24, 2023
9329ec9
Merge remote-tracking branch 'remote/master' into feature/add-xml-sup…
Genc Jan 25, 2023
2673b50
Add "Body Encoding" to en.json
Genc Jan 25, 2023
35bd129
Merge remote-tracking branch 'remote/master' into feature/add-xml-sup…
Genc Jan 28, 2023
064bc00
Merge remote-tracking branch 'remote/master' into feature/add-xml-sup…
Genc Jan 30, 2023
7dacc6a
Merge remote-tracking branch 'remote/master' into feature/add-xml-sup…
Genc Jan 30, 2023
4287f7e
Merge remote-tracking branch 'remote/master' into feature/add-xml-sup…
Genc Feb 2, 2023
b2ddb5c
Dummy commit for build
Genc Feb 2, 2023
603b3a7
Dummy commit for build
Genc Feb 2, 2023
666838f
Merge remote-tracking branch 'remote/master' into feature/add-xml-sup…
Genc Feb 3, 2023
39c99b0
Merge remote-tracking branch 'remote/master' into feature/add-xml-sup…
Genc Feb 5, 2023
19c8538
Merge remote-tracking branch 'remote/master' into feature/add-xml-sup…
Genc Feb 11, 2023
c9b4a7f
Change column type
Genc Feb 17, 2023
9e3a77f
Customize body placeholder for body encoding
Genc Feb 18, 2023
3ab0fae
Add update query for old monitors and save new data correctly
Genc Feb 18, 2023
72106ba
Merge remote-tracking branch 'remote/master' into feature/add-xml-sup…
Genc Feb 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions db/patch-http-body-encoding.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- 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 TEXT;
louislam marked this conversation as resolved.
Show resolved Hide resolved

COMMIT;
1 change: 1 addition & 0 deletions server/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class Database {
"patch-maintenance-table2.sql": true,
"patch-add-gamedig-monitor.sql": true,
"patch-add-google-analytics-status-page-tag.sql": true,
"patch-http-body-encoding.sql": true
};

/**
Expand Down
17 changes: 15 additions & 2 deletions server/model/monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class Monitor extends BeanModel {
radiusCalledStationId: this.radiusCalledStationId,
radiusCallingStationId: this.radiusCallingStationId,
game: this.game,
httpBodyEncoding: this.httpBodyEncoding
};

if (includeSensitiveData) {
Expand Down Expand Up @@ -272,17 +273,29 @@ class Monitor extends BeanModel {

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
const options = {
url: this.url,
method: (this.method || "get").toLowerCase(),
...(this.body ? { data: JSON.parse(this.body) } : {}),
...(bodyValue ? { data: bodyValue } : {}),
timeout: this.interval * 1000 * 0.8,
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",
"User-Agent": "Uptime-Kuma/" + version,
...(this.headers ? JSON.parse(this.headers) : {}),
...(contentType ? { "Content-Type": contentType } : {}),
...(basicAuthHeader),
...(this.headers ? JSON.parse(this.headers) : {})
},
maxRedirects: this.maxredirects,
validateStatus: (status) => {
Expand Down
1 change: 1 addition & 0 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,7 @@ let needSetup = false;
bean.radiusCalledStationId = monitor.radiusCalledStationId;
bean.radiusCallingStationId = monitor.radiusCallingStationId;
bean.radiusSecret = monitor.radiusSecret;
bean.httpBodyEncoding = monitor.httpBodyEncoding;

bean.validate();

Expand Down
3 changes: 2 additions & 1 deletion src/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -695,5 +695,6 @@
"Google Analytics ID": "Google Analytics ID",
"Edit Tag": "Edit Tag",
"Server Address": "Server Address",
"Learn More": "Learn More"
"Learn More": "Learn More",
"Body Encoding": "Body Encoding"
}
16 changes: 13 additions & 3 deletions src/pages/EditMonitor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,15 @@
</select>
</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 -->
<div class="my-3">
<label for="body" class="form-label">{{ $t("Body") }}</label>
Expand Down Expand Up @@ -872,6 +881,7 @@ message HealthCheckResponse {
mqttTopic: "",
mqttSuccessMessage: "",
authMethod: null,
httpBodyEncoding: "json"
};

if (this.$root.proxyList && !this.monitor.proxyId) {
Expand Down Expand Up @@ -909,7 +919,7 @@ message HealthCheckResponse {
* @returns {boolean} Is the form input valid?
*/
isInputValid() {
if (this.monitor.body) {
if (this.monitor.body && (!this.monitor.httpBodyEncoding || this.monitor.httpBodyEncoding === "json")) {
try {
JSON.parse(this.monitor.body);
} catch (err) {
Expand Down Expand Up @@ -940,8 +950,8 @@ message HealthCheckResponse {
return;
}

// Beautify the JSON format
if (this.monitor.body) {
// Beautify the JSON format (only if httpBodyEncoding is not set or === json)
if (this.monitor.body && (!this.monitor.httpBodyEncoding || this.monitor.httpBodyEncoding === "json")) {
this.monitor.body = JSON.stringify(JSON.parse(this.monitor.body), null, 4);
}

Expand Down