import{_ as o,o as s,c as e,R as n}from"./chunks/framework.1625126e.js";const F=JSON.parse('{"title":"","description":"","frontmatter":{},"headers":[],"relativePath":"en_US/guide/notifications.md","filePath":"en_US/guide/notifications.md","lastUpdated":1691117191000}'),t={name:"en_US/guide/notifications.md"},a=n(`
Nezha Monitoring supports monitoring of server load, CPU, memory, hard disk, data transfer, monthly data transfer, number of processes, number of connections, and sends alarm notifications when one of these items reaches a user-set limit.
#NEZHA#
is the panel message placeholder, the panel will automatically replace the placeholder with the actual message when it triggers the notification
The content of Body is in JSON
format:When the request type is FORM,the value is in the form of key:value
,value
can contain placeholders that will be automatically replaced when notified. When the request type is JSON It will only do string substitution and submit to the URL
directly.
Placeholders can also be placed inside the URL, and it will perform a simple string substitution when requested.
Refer to the example below, it is very flexible.
Bark Example
Name: Bark
URL: The first part is the key, followed by three matches/: key/: body or/: key/: title/: body or/: key/: category/: title/: body
Request method: GET
Request Type: Default
Body: null
Name: Bark
URL:/push
Request method: POST
Request type: FORM
Body: {"title": "#SERVER.NAME#","device_key":"xxxxxxxxx","body":"#NEZHA#","icon":" https://xxxxxxxx/nz.png "}
Telegram Example, contributed by @haitau
Email notification example - Outlook
{"Content-type":"application/json", "Authorization":"Bearer {Token}"}
{
"message": {
"subject": "Server Status Notification",
"body": {
"contentType": "Text",
"content": "#NEZHA#"
},
"toRecipients": [
{
"emailAddress": {
"address": "ADDRESS FOR RECEVING EMAILS"
}
}
]
}
}
Notes for this method: This method requires calling Microsoft Graph V1.0, you need to go to Microsoft Graph and create your own application, give Mail.Send
permission and get the Token, or you can go Microsoft Graph Explorer directly to give permission and get the Token, just replace the Token in the Header with the actual Token.
Wechat Work Group bot Example, contributed by @ChowRex
Support placeholders:
{
"content": "#NEZHA#",
"ServerName": "#SERVER.NAME#",
"ServerIP": "#SERVER.IP#",
"ServerIPV4": "#SERVER.IPV4#",
"ServerIPV6": "#SERVER.IPV6#",
"CPU": "#SERVER.CPU#",
"MEM": "#SERVER.MEM#",
"SWAP": "#SERVER.SWAP#",
"DISK": "#SERVER.DISK#",
"NetInSpeed": "#SERVER.NETINSPEED#",
"NetOutSpeed": "#SERVER.NETOUTSPEED#",
"TransferIn": "#SERVER.TRANSFERIN#",
"TranferOut": "#SERVER.TRANSFEROUT#",
"Load1": "#SERVER.LOAD1#",
"Load5": "#SERVER.LOAD5#",
"Load15": "#SERVER.LOAD15#",
"TCP_CONN_COUNT": "#SERVER.TCPCONNCOUNT", # Invalid
"UDP_CONN_COUNT": "#SERVER.UDPCONNCOUNT", # Invalid
}
Sorry, this document is NOT available in English.
Name:WechatWork Group bot notification
URL:https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=YOUR_BOT_KEY
Request method: POST
Request type: JSON
Body:
{
"msgtype": "markdown",
"markdown": {
"content": "# Nezha Notification\\n\\n\\"#NEZHA#\\"\\n\\n> ServerName: \\"#SERVER.NAME#\\"\\n> IP: \\"#SERVER.IP#\\"\\n> IPv4: \\"#SERVER.IPV4#\\"\\n> IPv6: \\"#SERVER.IPV6#\\"\\n> CPU: \\"#SERVER.CPU#\\"\\n> Memory: \\"#SERVER.MEM#\\"\\n> SWAP: \\"#SERVER.SWAP#\\"\\n> Storage: \\"#SERVER.DISK#\\"\\n> Real-time Upload: \\"#SERVER.NETINSPEED#\\"\\n> Real-time Download: \\"#SERVER.NETOUTSPEED#\\"\\n> Total Upload: \\"#SERVER.TRANSFERIN#\\"\\n> Total Download: \\"#SERVER.TRANSFEROUT#\\"\\n> 1m Load: \\"#SERVER.LOAD1#\\"\\n> 5m Load: \\"#SERVER.LOAD5#\\"\\n> 15m Load: \\"#SERVER.LOAD15#\\"\\n> TCP Connections: \\"#SERVER.TCPCONNCOUNT\\"\\n> UDP Connections: \\"#SERVER.UDPCONNCOUNT\\"\\n\\n"
}
}
Delete relevant content information as needed
cpu
、memory
、swap
、disk
net_in_speed
Inbound speed, net_out_speed
Outbound speed, net_all_speed
Inbound + Outbound speed, transfer_in
Inbound Transfer, transfer_out
Outbound Transfer, transfer_all
Total Transferoffline
Offline monitoringload1
、load5
、load15
Loadprocess_count
Number of processes Currently, counting the number of processes takes up too many resources and is not supported at the momenttcp_conn_count
、udp_conn_count
Number of connections[{"type":"offline","duration":10, "cover":0, "ignore":{"5": true}}]
0
Cover all, use ignore
to ignore specific servers1
Ignore all, use ignore
to monitoring specific servers[{"type":"offline","duration":10, "cover":0, "ignore":{"5": true}}]
cover
with server id and boolean, e.g.: {"1": true, "2":false}
Complete examples:
Add an offline notification
- Name: Offline notification
- Rules:
[{"Type":"offline","Duration":10}]
- Enable: √
Add an notification when the CPU exceeds 50% for 10s but the memory usage is below 20% for 20s
- Name: CPU and RAM
- Rules:
[{"Type":"cpu","Min":0,"Max":50,"Duration":10},{"Type":"memory","Min":20,"Max":0,"Duration":20}]
- Enable: √
Send specific server notifications to specific notification groups
Case:
You have four servers, 1, 2, 3, 4, and two different notification groups, A and B
1, 2 The two servers are down for 10 minutes and send a notification to Notification Group A
3, 4 These two servers are down for ten minutes and then send a notification to Notification Group BFirst you need to set up two notification groups, A and B, and then add two alarm rules:
Rule I:
- Name: 1, 2 Off-line, send notification to group A
- Rules:
[{"type":"offline","duration":600,"cover":1,"ignore":{"1":true,"2":true}}]
- Notification group: A
- Enable: √
Rule II:
- Name: 3, 4 Off-line, send notification to group B
- Rules:
[{"type":"offline","duration":600,"cover":1,"ignore":{"3":true,"4":true}}]
- Notification group: B
- Enable: √
Using these rules flexibly will help you to make full use of the notification function
Can be used as monthly transfer notificatin
type
transfer_in_cycle
Inbound transfer during the cycletransfer_out_cycle
Outbound transfer during the cycletransfer_all_cycle
The sum of inbound and outbound transfer during the cyclecycle_start
Start date of the statistical cycle (can be the start date of your server's billing cycle), the time format is RFC3339, for example, the format in Beijing time zone is 2022-01-11T08:00:00.00+08:00
cycle_interval
Interval time cycle (For example, if the cycle is in days and the value is 7, it means that the statistics are counted every 7 days)
cycle_unit
Statistics cycle unit, default hour
, optional (hour
, day
, week
, month
, year
)
min/max
, cover
, ignore
Please refer to the basic rules to configure
Example:
The servers with ID 3 and 4 (defined in the
ignore
) are counted on the 1st of each month, and a notification is triggered when the monthly outbound transfer reaches 1TB during the cycle.
[{"type":"transfer_out_cycle","max":1099511627776,"cycle_start":"2022-01-01T00:00:00+08:00","cycle_interval":1,"cycle_unit":"month","cover":1,"ignore":{"3":true,"4":true}}]
If you need to perform a task while sending a notification message, you can set those items
Tasks to be triggered in case of failure
The task to be executed when the notification status matches the change from "normal" to "failure", the task should be set in advance in the tasks pageTasks to be triggered after fault recovery
The task to be executed when the notification status matches the change from " failure " to " normal ", the task should be set in advance in the tasks page