Skip to content

Commit

Permalink
Merge branch 'feature-google-analytics' of github.com:clcninja/uptime…
Browse files Browse the repository at this point in the history
…-kuma into feature-google-analytics
  • Loading branch information
c committed Jan 31, 2023
2 parents 4178c17 + 2239e70 commit 7209db5
Show file tree
Hide file tree
Showing 65 changed files with 996 additions and 440 deletions.
5 changes: 5 additions & 0 deletions db/patch-ping-packet-size.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- You should not modify if this have pushed to Github, unless it does serious wrong with the db.
BEGIN TRANSACTION;
ALTER TABLE monitor
ADD packet_size INTEGER DEFAULT 56 NOT NULL;
COMMIT;
2 changes: 1 addition & 1 deletion docker/alpine-base.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ FROM node:16-alpine3.12
WORKDIR /app

# Install apprise, iputils for non-root ping, setpriv
RUN apk add --no-cache iputils setpriv dumb-init python3 py3-cryptography py3-pip py3-six py3-yaml py3-click py3-markdown py3-requests py3-requests-oauthlib && \
RUN apk add --no-cache iputils setpriv dumb-init python3 py3-cryptography py3-pip py3-six py3-yaml py3-click py3-markdown py3-requests py3-requests-oauthlib git && \
pip3 --no-cache-dir install apprise==1.2.1 && \
rm -rf /root/.cache
2 changes: 1 addition & 1 deletion docker/builder-go.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Build in Golang
# Run npm run build-healthcheck-armv7 in the host first, another it will be super slow where it is building the armv7 healthcheck
############################################
FROM golang:1.19.4-buster
FROM golang:1.19-buster
WORKDIR /app
ARG TARGETPLATFORM
COPY ./extra/ ./extra/
Expand Down
2 changes: 1 addition & 1 deletion docker/debian-base.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ WORKDIR /app
# Stupid python3 and python3-pip actually install a lot of useless things into Debian, specify --no-install-recommends to skip them, make the base even smaller than alpine!
RUN apt update && \
apt --yes --no-install-recommends install python3 python3-pip python3-cryptography python3-six python3-yaml python3-click python3-markdown python3-requests python3-requests-oauthlib \
sqlite3 iputils-ping util-linux dumb-init && \
sqlite3 iputils-ping util-linux dumb-init git && \
pip3 --no-cache-dir install apprise==1.2.1 && \
rm -rf /var/lib/apt/lists/* && \
apt --yes autoremove
Expand Down
11 changes: 10 additions & 1 deletion extra/healthcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@ import (
"net/http"
"os"
"runtime"
"strings"
"time"
)

func main() {
isFreeBSD := runtime.GOOS == "freebsd"

// Is K8S + uptime-kuma as the container name
// See #2083
isK8s := strings.HasPrefix(os.Getenv("UPTIME_KUMA_PORT"), "tcp://")

// process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{
InsecureSkipVerify: true,
Expand Down Expand Up @@ -44,7 +49,11 @@ func main() {
hostname = "127.0.0.1"
}

port := os.Getenv("UPTIME_KUMA_PORT")
port := ""
// UPTIME_KUMA_PORT is override by K8S unexpectedly,
if !isK8s {
port = os.Getenv("UPTIME_KUMA_PORT")
}
if len(port) == 0 {
port = os.Getenv("PORT")
}
Expand Down
6 changes: 3 additions & 3 deletions extra/healthcheck.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ if (sslKey && sslCert) {

// If host is omitted, the server will accept connections on the unspecified IPv6 address (::) when IPv6 is available and the unspecified IPv4 address (0.0.0.0) otherwise.
// Dual-stack support for (::)
let hostname = process.env.UPTIME_KUMA_HOST;
let hostname = process.env.UPTIME_KUMA_SERVICE_HOST || process.env.UPTIME_KUMA_HOST || "::";

// Also read HOST if not *BSD, as HOST is a system environment variable in FreeBSD
if (!hostname && !FBSD) {
hostname = process.env.HOST;
}

const port = parseInt(process.env.UPTIME_KUMA_PORT || process.env.PORT || 3001);
const port = parseInt(process.env.UPTIME_KUMA_SERVICE_PORT || process.env.UPTIME_KUMA_PORT || process.env.PORT || 3001);

let options = {
host: hostname || "127.0.0.1",
host: hostname,
port: port,
timeout: 28 * 1000,
};
Expand Down
2 changes: 2 additions & 0 deletions server/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const badgeConstants = {
naColor: "#999",
defaultUpColor: "#66c20a",
defaultDownColor: "#c2290a",
defaultPendingColor: "#f8a306",
defaultMaintenanceColor: "#1747f5",
defaultPingColor: "blue", // as defined by badge-maker / shields.io
defaultStyle: "flat",
defaultPingValueSuffix: "ms",
Expand Down
9 changes: 9 additions & 0 deletions server/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const { setSetting, setting } = require("./util-server");
const { log, sleep } = require("../src/util");
const dayjs = require("dayjs");
const knex = require("knex");
const { PluginsManager } = require("./plugins-manager");

/**
* Database & App Data Folder
Expand Down Expand Up @@ -65,6 +66,7 @@ class Database {
"patch-grpc-monitor.sql": true,
"patch-add-radius-monitor.sql": true,
"patch-monitor-add-resend-interval.sql": true,
"patch-ping-packet-size.sql": true,
"patch-maintenance-table2.sql": true,
"patch-add-gamedig-monitor.sql": true,
"patch-add-google-analytics-status-page-tag.sql": true,
Expand All @@ -85,6 +87,13 @@ class Database {
static init(args) {
// Data Directory (must be end with "/")
Database.dataDir = process.env.DATA_DIR || args["data-dir"] || "./data/";

// Plugin feature is working only if the dataDir = "./data";
if (Database.dataDir !== "./data/") {
log.warn("PLUGIN", "Warning: In order to enable plugin feature, you need to use the default data directory: ./data/");
PluginsManager.disable = true;
}

Database.path = Database.dataDir + "kuma.db";
if (! fs.existsSync(Database.dataDir)) {
fs.mkdirSync(Database.dataDir, { recursive: true });
Expand Down
24 changes: 24 additions & 0 deletions server/git.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const childProcess = require("child_process");

class Git {

static clone(repoURL, cwd, targetDir = ".") {
let result = childProcess.spawnSync("git", [
"clone",
repoURL,
targetDir,
], {
cwd: cwd,
});

if (result.status !== 0) {
throw new Error(result.stderr.toString("utf-8"));
} else {
return result.stdout.toString("utf-8") + result.stderr.toString("utf-8");
}
}
}

module.exports = {
Git,
};
17 changes: 13 additions & 4 deletions server/model/monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class Monitor extends BeanModel {
expiryNotification: this.isEnabledExpiryNotification(),
ignoreTls: this.getIgnoreTls(),
upsideDown: this.isUpsideDown(),
packetSize: this.packetSize,
maxredirects: this.maxredirects,
accepted_statuscodes: this.getAcceptedStatuscodes(),
dns_resolve_type: this.dns_resolve_type,
Expand Down Expand Up @@ -375,7 +376,7 @@ class Monitor extends BeanModel {
bean.status = UP;

} else if (this.type === "ping") {
bean.ping = await ping(this.hostname);
bean.ping = await ping(this.hostname, this.packetSize);
bean.msg = "";
bean.status = UP;
} else if (this.type === "dns") {
Expand Down Expand Up @@ -485,7 +486,7 @@ class Monitor extends BeanModel {
bean.msg = res.data.response.servers[0].name;

try {
bean.ping = await ping(this.hostname);
bean.ping = await ping(this.hostname, this.packetSize);
} catch (_) { }
} else {
throw new Error("Server not found on Steam");
Expand Down Expand Up @@ -654,9 +655,17 @@ class Monitor extends BeanModel {
bean.msg = await redisPingAsync(this.databaseConnectionString);
bean.status = UP;
bean.ping = dayjs().valueOf() - startTime;

} else if (this.type in UptimeKumaServer.monitorTypeList) {
let startTime = dayjs().valueOf();
const monitorType = UptimeKumaServer.monitorTypeList[this.type];
await monitorType.check(this, bean);
if (!bean.ping) {
bean.ping = dayjs().valueOf() - startTime;
}

} else {
bean.msg = "Unknown Monitor Type";
bean.status = PENDING;
throw new Error("Unknown Monitor Type");
}

if (this.isUpsideDown()) {
Expand Down
19 changes: 19 additions & 0 deletions server/monitor-types/monitor-type.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class MonitorType {

name = undefined;

/**
*
* @param {Monitor} monitor
* @param {Heartbeat} heartbeat
* @returns {Promise<void>}
*/
async check(monitor, heartbeat) {
throw new Error("You need to override check()");
}

}

module.exports = {
MonitorType,
};
1 change: 0 additions & 1 deletion server/notification-providers/clicksendsms.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class ClickSendSMS extends NotificationProvider {
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
let okMsg = "Sent Successfully.";
try {
console.log({ notification });
let config = {
headers: {
"Content-Type": "application/json",
Expand Down
13 changes: 13 additions & 0 deletions server/plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Plugin {
async load() {

}

async unload() {

}
}

module.exports = {
Plugin,
};
Loading

0 comments on commit 7209db5

Please sign in to comment.