mirror of
https://codeberg.org/ashley/poke.git
synced 2024-11-13 00:58:08 +01:00
remove statuspage
This commit is contained in:
parent
05b8dfff18
commit
ec821bf343
1 changed files with 2 additions and 87 deletions
89
server.js
89
server.js
|
@ -61,93 +61,8 @@
|
||||||
);
|
);
|
||||||
|
|
||||||
const sha384 = modules.hash;
|
const sha384 = modules.hash;
|
||||||
|
|
||||||
var http = require("https");
|
|
||||||
var ping = require("ping");
|
|
||||||
|
|
||||||
if (process.env.STATUSPAGE_API) {
|
|
||||||
// The following 4 are the actual values that pertain to your account and this specific metric.
|
|
||||||
var apiKey = process.env.STATUSPAGE_API;
|
|
||||||
var pageId = process.env.STATUSPAGE_PAGEID;
|
|
||||||
var metricId = process.env.STATUSPAGE_METRICID
|
|
||||||
var apiBase = "https://api.statuspage.io/v1";
|
|
||||||
|
|
||||||
var url =
|
|
||||||
apiBase + "/pages/" + pageId + "/metrics/" + metricId + "/data.json";
|
|
||||||
var authHeader = { Authorization: "OAuth " + apiKey };
|
|
||||||
var options = { method: "POST", headers: authHeader };
|
|
||||||
|
|
||||||
// Need at least 1 data point for every 5 minutes.
|
|
||||||
// Submit random data for the whole day.
|
|
||||||
var totalPoints = (60 / 5) * 24;
|
|
||||||
var epochInSeconds = Math.floor(new Date() / 1000);
|
|
||||||
|
|
||||||
// This function gets called every second.
|
|
||||||
function submit(count) {
|
|
||||||
count = count + 1;
|
|
||||||
|
|
||||||
if (count > totalPoints) return;
|
|
||||||
|
|
||||||
var currentTimestamp = epochInSeconds - (count - 1) * 5 * 60;
|
|
||||||
|
|
||||||
// Measure server ping here
|
|
||||||
var host = "poketube.fun"; // Replace with the server you want to ping
|
|
||||||
|
|
||||||
ping.promise
|
|
||||||
.probe(host)
|
|
||||||
.then((result) => {
|
|
||||||
var ping = result.time !== "unknown" ? parseInt(result.time) : -1;
|
|
||||||
|
|
||||||
ping = Math.min(Math.max(ping, 20), 250);
|
|
||||||
|
|
||||||
var data = {
|
|
||||||
timestamp: currentTimestamp,
|
|
||||||
value: ping,
|
|
||||||
};
|
|
||||||
|
|
||||||
var request = http.request(url, options, function (res) {
|
|
||||||
if (res.statusMessage === "Unauthorized") {
|
|
||||||
const genericError =
|
|
||||||
"Error encountered. Please ensure that your page code and authorization key are correct.";
|
|
||||||
return console.error(genericError);
|
|
||||||
}
|
|
||||||
res.on("data", function () {
|
|
||||||
console.log("Submitted point " + count + " of " + totalPoints);
|
|
||||||
});
|
|
||||||
res.on("end", function () {
|
|
||||||
setTimeout(function () {
|
|
||||||
submit(count);
|
|
||||||
}, 1000);
|
|
||||||
});
|
|
||||||
res.on("error", (error) => {
|
|
||||||
console.error(`Error caught: ${error.message}`);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
request.end(JSON.stringify({ data: data }));
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
console.error("Ping failed:", error);
|
|
||||||
// Submit a default value if the ping fails
|
|
||||||
var data = {
|
|
||||||
timestamp: currentTimestamp,
|
|
||||||
value: -1, // Use -1 to indicate ping failure
|
|
||||||
};
|
|
||||||
|
|
||||||
var request = http.request(url, options, function (res) {
|
|
||||||
// Handle response
|
|
||||||
});
|
|
||||||
|
|
||||||
request.end(JSON.stringify({ data: data }));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Initial call to start submitting data immediately.
|
|
||||||
submit(0);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
var app = modules.express();
|
var app = modules.express();
|
||||||
initlog("Loaded express.js");
|
initlog("Loaded express.js");
|
||||||
app.engine("html", require("ejs").renderFile);
|
app.engine("html", require("ejs").renderFile);
|
||||||
|
|
Loading…
Reference in a new issue