forked from ZhangMingZhao1/StreamerHelper
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
155 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
global.config = require('../templates/info.json') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { LogLevel } from "@/type/config"; | ||
import { mail } from "@/push/mail"; | ||
import { wechat } from "@/push/wechat"; | ||
|
||
type AllowTypes = keyof typeof global.config.StreamerHelper.push | ||
export type PushFunc = (level: LogLevel, ...args: string[]) => void | ||
|
||
const pushConfig = global.config.StreamerHelper.push | ||
const enables = Object.keys(pushConfig).filter(elem => pushConfig[elem as AllowTypes].enable) as Array<AllowTypes> | ||
const pushFuncMap = new Map<AllowTypes, PushFunc>( | ||
[ | ||
["mail", mail], | ||
["wechat", wechat] | ||
] | ||
) | ||
|
||
export const pushMsg = async (level: LogLevel, ...args: string[]) => { | ||
|
||
for (const enable of enables) { | ||
const pushFunc = pushFuncMap.get(enable) | ||
|
||
if (pushFunc) { | ||
pushFunc(level, ...args) | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import * as dayjs from "dayjs" | ||
const nodemailer = require("nodemailer") | ||
|
||
import { PushFunc } from "@/push"; | ||
import { LogLevel } from "@/type/config"; | ||
|
||
export const mail: PushFunc = async (level: LogLevel, ...args: string[]) => { | ||
|
||
const mailConfig = global.config.StreamerHelper.push.mail | ||
|
||
const transporter = nodemailer.createTransport({ | ||
host: mailConfig.host, | ||
port: mailConfig.port, | ||
secure: mailConfig.secure, | ||
auth: { | ||
user: mailConfig.from, | ||
pass: mailConfig.pwd, | ||
}, | ||
}); | ||
|
||
const msg = args.join(";") | ||
const html = `<p>告警信息: ${msg}</p> <p>级别: ${level}</p> <p>时间: ${dayjs().format()}</p> | ||
` | ||
|
||
transporter.sendMail({ | ||
from: mailConfig.from, | ||
to: mailConfig.to, | ||
subject: `StreamerHelper 发生 ${level} 级别告警`, | ||
html, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import * as dayjs from "dayjs" | ||
|
||
import { $axios } from "@/http" | ||
import { LogLevel } from "@/type/config" | ||
|
||
export const wechat = async (level: LogLevel, ...args: string[]) => { | ||
|
||
const msg = args.join(";") | ||
const desp = `告警信息: ${msg}\n \n级别: ${level}\n \n时间: ${dayjs().format()}` | ||
|
||
const params = { | ||
text: decodeURIComponent(`StreamerHelper 发生 ${level} 级别告警`), | ||
desp: decodeURIComponent(desp) | ||
} | ||
|
||
$axios.request({ | ||
url: `https://sctapi.ftqq.com/${global.config.StreamerHelper.push.wechat.sendKey}.send`, | ||
method: "post", | ||
params | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters