Skip to content

Commit

Permalink
Merge pull request #98 from rajnandan1/release/0.0.15
Browse files Browse the repository at this point in the history
Release/0.0.15
  • Loading branch information
rajnandan1 authored Aug 11, 2024
2 parents 3264e86 + 6ebaec5 commit 3941cc4
Show file tree
Hide file tree
Showing 29 changed files with 144 additions and 55 deletions.
2 changes: 2 additions & 0 deletions config/site.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,5 @@ i18n:
hi: "हिन्दी"
zh-CN: "中文"
ja: "日本語"
vi: "Tiếng Việt"
theme: dark
2 changes: 1 addition & 1 deletion locales/hi.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"today": "आज",
"uptime": "अपटाइम"
},
"numbers": ["", "", "", "", "", "", "", "", "", ""],
"numbers": ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"],
"root": {
"active_incidents": "सक्रिय घटनाएं",
"availability_per_component": "प्रति कॉम्पोनेन्ट उपलब्धता",
Expand Down
57 changes: 57 additions & 0 deletions locales/vi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"root": {
"ongoing_incidents": "Sự Cố Đang Xảy Ra",
"availability_per_component": "Độ Sẵn Sàng Của Từng Thành Phần",
"other_monitors": "Các Giám Sát Khác",
"no_monitors": "Không tìm thấy giám sát nào",
"read_doc_monitor": "Đọc tài liệu để thêm giám sát đầu tiên của bạn",
"here": "tại đây",
"category": "Danh Mục",
"incident": "Sự Cố",
"incidents": "Các Sự Cố",
"no_recent_incident": "Không có sự cố gần đây",
"recent_incidents": "Các Sự Cố Gần Đây",
"active_incidents": "Các Sự Cố Đang Hoạt Động",
"no_active_incident": "Không Có Sự Cố Đang Hoạt Động",
"last_x_hours": "Trong %hours giờ qua"
},
"statuses": {
"UP": "HOẠT ĐỘNG",
"DOWN": "NGỪNG HOẠT ĐỘNG",
"DEGRADED": "SUY GIẢM"
},
"incident": {
"identified": "Đã Xác Định",
"resolved": "Đã Giải Quyết",
"maintenance": "Bảo Trì"
},
"monitor": {
"share": "Chia Sẻ",
"badge": "Huy Hiệu",
"embed": "Nhúng",
"mode": "Chế Độ",
"status": "Trạng Thái",
"copied": "Đã Sao Chép",
"uptime": "Thời Gian Hoạt Động",
"theme": "Chủ Đề",
"theme_light": "Sáng",
"theme_dark": "Tối",
"today": "Hôm Nay",
"90_day": "90 Ngày",
"share_desc": "Chia sẻ giám sát này bằng một liên kết với người khác",
"badge_desc": "Nhận huy hiệu SVG cho giám sát này",
"embed_desc": "Nhúng giám sát này bằng <script> hoặc <iframe> vào ứng dụng của bạn.",
"cp_link": "Sao Chép Liên Kết",
"cpd_link": "Liên Kết Đã Được Sao Chép",
"cp_code": "Sao Chép Mã",
"cpd_code": "Mã Đã Được Sao Chép",
"status_x_minute": "%status trong %minute phút",
"status_x_minutes": "%status trong %minutes phút",
"status_x_hour_y_minute": "%status trong %hours giờ và %minutes phút",
"status_no_data": "Không Có Dữ Liệu",
"status_ok": "Trạng Thái OK",
"am": "sáng",
"pm": "chiều"
},
"numbers": ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
}
22 changes: 18 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kener",
"version": "0.0.14",
"version": "0.0.15",
"private": false,
"license": "MIT",
"description": "Kener: An open-source Node.js status page application for real-time service monitoring, incident management, and customizable reporting. Simplify service outage tracking, enhance incident communication, and ensure a seamless user experience.",
Expand Down Expand Up @@ -61,6 +61,7 @@
"bits-ui": "^0.9.9",
"clsx": "^2.0.0",
"croner": "^7.0.5",
"dotenv": "^16.4.5",
"express": "^4.18.2",
"fs-extra": "^11.1.1",
"js-yaml": "^4.1.0",
Expand Down
3 changes: 2 additions & 1 deletion scripts/check.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { FOLDER, FOLDER_MONITOR, FOLDER_SITE, ENV } from "./constants.js";
import { IsStringURLSafe } from "./tool.js";

import dotenv from "dotenv";
dotenv.config();
import fs from "fs-extra";
let STATUS_OK = false;
if (!!process.env.PUBLIC_KENER_FOLDER) {
Expand Down
2 changes: 2 additions & 0 deletions scripts/constants.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Define your constants
import dotenv from "dotenv";
dotenv.config();
const FOLDER = process.env.PUBLIC_KENER_FOLDER;
const ENV = process.env.NODE_ENV;
const MONITOR = "./config/monitors.yaml";
Expand Down
10 changes: 5 additions & 5 deletions scripts/cron-minute.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
import { GetIncidents, GetEndTimeFromBody, GetStartTimeFromBody, CloseIssue } from "./github.js";
import Randomstring from "randomstring";
import Queue from "queue";
import dotenv from "dotenv";
dotenv.config();

const Kener_folder = process.env.PUBLIC_KENER_FOLDER;
const apiQueue = new Queue({
Expand Down Expand Up @@ -103,17 +105,15 @@ function replaceAllOccurrences(originalString, searchString, replacement) {
return replacedString;
}
const pingCall = async (hostsV4, hostsV6) => {

let alive = true;
let latencyTotal = 0;
let countHosts = hostsV4.length + hostsV6.length;


for (let i = 0; i < hostsV4.length; i++) {
const host = hostsV4[i].trim();
try {
let res = await ping.promise.probe(host);
alive = alive && res.alive;
alive = alive && res.alive;
latencyTotal += res.time;
} catch (error) {
alive = alive && false;
Expand All @@ -140,7 +140,7 @@ const pingCall = async (hostsV4, hostsV6) => {
latency: parseInt(latencyTotal / countHosts),
type: "realtime"
};
}
};
const apiCall = async (envSecrets, url, method, headers, body, timeout, monitorEval) => {
let axiosHeaders = {};
axiosHeaders["User-Agent"] = "Kener/0.0.1";
Expand Down Expand Up @@ -345,7 +345,7 @@ const Minuter = async (envSecrets, monitor, githubConfig) => {
let pingResponse = await pingCall(monitor.ping.hostsV4, monitor.ping.hostsV6);
pingData[startOfMinute] = pingResponse;
}

webhookData = await getWebhookData(monitor);
manualData = await manualIncident(monitor, githubConfig);
//merge noData, apiData, webhookData, dayData
Expand Down
4 changes: 4 additions & 0 deletions scripts/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
import axios from "axios";
import { GetMinuteStartNowTimestampUTC } from "./tool.js";
import { marked } from "marked";
import { fileURLToPath } from "url";
import { dirname } from "path";
import dotenv from "dotenv";
dotenv.config();
const GH_TOKEN = process.env.GH_TOKEN;
const GhnotconfireguredMsg =
"owner or repo or GH_TOKEN is undefined. Read the docs to configure github: https://kener.ing/docs#h2github-setup";
Expand Down
2 changes: 2 additions & 0 deletions scripts/sitemap.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// create sitemap.xml
import fs from "fs-extra";
let siteMap = "";
import dotenv from "dotenv";
dotenv.config();
const site = JSON.parse(fs.readFileSync(process.env.PUBLIC_KENER_FOLDER + "/site.json", "utf8"));
const monitors = JSON.parse(
fs.readFileSync(process.env.PUBLIC_KENER_FOLDER + "/monitors.json", "utf8")
Expand Down
4 changes: 2 additions & 2 deletions scripts/startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ if it does, it will read the file and parse it into a json array of objects
each objects will have a name, url, method: required
name of each of these objects need to be unique
*/
import * as dotenv from "dotenv";
import fs from "fs-extra";
import yaml from "js-yaml";
import { Cron } from "croner";
Expand Down Expand Up @@ -105,7 +106,7 @@ const Startup = async () => {
) {
monitors[i].includeDegradedInDowntime = false;
}
if(hasPing) {
if (hasPing) {
let hostsV4 = monitor.ping.hostsV4;
let hostsV6 = monitor.ping.hostsV6;
let hasV4 = false;
Expand Down Expand Up @@ -134,7 +135,6 @@ const Startup = async () => {
process.exit(1);
}
monitors[i].hasPing = true;

}
if (hasAPI) {
let url = monitor.api.url;
Expand Down
7 changes: 4 additions & 3 deletions scripts/tool.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @ts-nocheck
import { MONITOR, SITE } from "./constants.js";

import dotenv from "dotenv";
dotenv.config();
const IsValidURL = function (url) {
return /^(http|https):\/\/[^ "]+$/.test(url);
};
Expand Down Expand Up @@ -142,7 +143,7 @@ const BeginningOfDay = (options = {}) => {
);
return dt.getTime() / 1000;
};
const ValidateIpAddress = function(input) {
const ValidateIpAddress = function (input) {
// Check if input is a valid IPv4 address
const ipv4Regex = /^(\d{1,3}\.){3}\d{1,3}$/;
if (ipv4Regex.test(input)) {
Expand All @@ -163,7 +164,7 @@ const ValidateIpAddress = function(input) {

// If none of the above conditions match, the input is invalid
return "Invalid";
}
};
export {
IsValidURL,
IsValidHTTPMethod,
Expand Down
2 changes: 1 addition & 1 deletion src/app.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!doctype html>
<html lang="en" class="dark dark:bg-background">
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
Expand Down
12 changes: 6 additions & 6 deletions src/lib/server/webhook.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-nocheck
import fs from "fs-extra";
import { env } from "$env/dynamic/public";
import { PUBLIC_KENER_FOLDER } from "$env/static/public";
import { ParseUptime } from "$lib/helpers.js";
import {
GetMinuteStartNowTimestampUTC,
Expand All @@ -17,7 +17,7 @@ const GetAllTags = function () {
let tags = [];
let monitors = [];
try {
monitors = JSON.parse(fs.readFileSync(env.PUBLIC_KENER_FOLDER + "/monitors.json", "utf8"));
monitors = JSON.parse(fs.readFileSync(PUBLIC_KENER_FOLDER + "/monitors.json", "utf8"));
tags = monitors.map((monitor) => monitor.tag);
} catch (err) {
return [];
Expand All @@ -28,7 +28,7 @@ const CheckIfValidTag = function (tag) {
let tags = [];
let monitors = [];
try {
monitors = JSON.parse(fs.readFileSync(env.PUBLIC_KENER_FOLDER + "/monitors.json", "utf8"));
monitors = JSON.parse(fs.readFileSync(PUBLIC_KENER_FOLDER + "/monitors.json", "utf8"));
tags = monitors.map((monitor) => monitor.tag);
if (tags.indexOf(tag) == -1) {
throw new Error("not a valid tag");
Expand Down Expand Up @@ -112,7 +112,7 @@ const store = function (data) {
}

//get the monitor object matching the tag
let monitors = JSON.parse(fs.readFileSync(env.PUBLIC_KENER_FOLDER + "/monitors.json", "utf8"));
let monitors = JSON.parse(fs.readFileSync(PUBLIC_KENER_FOLDER + "/monitors.json", "utf8"));
const monitor = monitors.find((monitor) => monitor.tag === tag);

//read the monitor.path0Day file
Expand All @@ -126,7 +126,7 @@ const store = function (data) {

//write the monitor.path0Day file
fs.writeFileSync(
env.PUBLIC_KENER_FOLDER + `/${monitor.folderName}.webhook.${Randomstring.generate()}.json`,
PUBLIC_KENER_FOLDER + `/${monitor.folderName}.webhook.${Randomstring.generate()}.json`,
JSON.stringify(day0, null, 2)
);

Expand Down Expand Up @@ -259,7 +259,7 @@ const GetMonitorStatusByTag = function (tag) {
uptime: null,
lastUpdatedAt: null
};
let monitors = JSON.parse(fs.readFileSync(env.PUBLIC_KENER_FOLDER + "/monitors.json", "utf8"));
let monitors = JSON.parse(fs.readFileSync(PUBLIC_KENER_FOLDER + "/monitors.json", "utf8"));
const { path0Day } = monitors.find((monitor) => monitor.tag === tag);
const dayData = JSON.parse(fs.readFileSync(path0Day, "utf8"));
const lastUpdatedAt = Object.keys(dayData)[Object.keys(dayData).length - 1];
Expand Down
4 changes: 2 additions & 2 deletions src/routes/+layout.server.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import fs from "fs-extra";
import { env } from "$env/dynamic/public";
import { PUBLIC_KENER_FOLDER } from "$env/static/public";
import i18n from "$lib/i18n/server";

export async function load({ params, route, url, cookies, request }) {
let site = JSON.parse(fs.readFileSync(env.PUBLIC_KENER_FOLDER + "/site.json", "utf8"));
let site = JSON.parse(fs.readFileSync(PUBLIC_KENER_FOLDER + "/site.json", "utf8"));
const headers = request.headers;
const userAgent = headers.get("user-agent");
let localTz = "GMT";
Expand Down
5 changes: 5 additions & 0 deletions src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
{#each Object.entries(data.site.metaTags) as [key, value]}
<meta name={key} content={value} />
{/each}
{#if !!data.site.theme && data.site.theme === "dark"}
<script>
document.documentElement.classList.add("dark");
</script>
{/if}
</svelte:head>

<slot />
Expand Down
4 changes: 2 additions & 2 deletions src/routes/+page.server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import {
FilterAndInsertMonitorInIncident
} from "../../scripts/github.js";
import { FetchData } from "$lib/server/page";
import { env } from "$env/dynamic/public";
import { PUBLIC_KENER_FOLDER } from "$env/static/public";
import fs from "fs-extra";

export async function load({ parent }) {
let monitors = JSON.parse(fs.readFileSync(env.PUBLIC_KENER_FOLDER + "/monitors.json", "utf8"));
let monitors = JSON.parse(fs.readFileSync(PUBLIC_KENER_FOLDER + "/monitors.json", "utf8"));
const parentData = await parent();
const siteData = parentData.site;
const github = siteData.github;
Expand Down
6 changes: 3 additions & 3 deletions src/routes/api/incident/+server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { json } from "@sveltejs/kit";
import { ParseIncidentPayload, auth, GHIssueToKenerIncident } from "$lib/server/webhook";
import { CreateIssue, SearchIssue } from "../../../../scripts/github";
import { env } from "$env/dynamic/public";
import { PUBLIC_KENER_FOLDER } from "$env/static/public";
import fs from "fs-extra";

export async function POST({ request }) {
Expand All @@ -27,7 +27,7 @@ export async function POST({ request }) {
}
);
}
let site = JSON.parse(fs.readFileSync(env.PUBLIC_KENER_FOLDER + "/site.json", "utf8"));
let site = JSON.parse(fs.readFileSync(PUBLIC_KENER_FOLDER + "/site.json", "utf8"));
let github = site.github;
let resp = await CreateIssue(github, title, body, githubLabels);
if (resp === null) {
Expand Down Expand Up @@ -74,7 +74,7 @@ export async function GET({ request, url }) {
}
);
}
let site = JSON.parse(fs.readFileSync(env.PUBLIC_KENER_FOLDER + "/site.json", "utf8"));
let site = JSON.parse(fs.readFileSync(PUBLIC_KENER_FOLDER + "/site.json", "utf8"));
let github = site.github;
const repo = `${github.owner}/${github.repo}`;
const is = "issue";
Expand Down
Loading

0 comments on commit 3941cc4

Please sign in to comment.