update: #SERVER.IP#仅返回一个IP(优先返回ipv4地址)| 新增获取ipv4与ipv6地址的占位符
This commit is contained in:
		
							parent
							
								
									5bf29dabf5
								
							
						
					
					
						commit
						fc9a65d18c
					
				@ -159,11 +159,37 @@ func (ns *NotificationServerBundle) Send(message string) error {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// replaceParamInString 替换字符串中的占位符
 | 
					// replaceParamInString 替换字符串中的占位符
 | 
				
			||||||
func replaceParamsInString(s *Server, str string, message string, mod func(string) string) string {
 | 
					func replaceParamsInString(s *Server, str string, message string, mod func(string) string) string {
 | 
				
			||||||
 | 
						// IP处理
 | 
				
			||||||
 | 
						ipv4 := ""
 | 
				
			||||||
 | 
						ipv6 := ""
 | 
				
			||||||
 | 
						validIP := ""
 | 
				
			||||||
 | 
						if s != nil {
 | 
				
			||||||
 | 
							ipList := strings.Split(s.Host.IP, "/")
 | 
				
			||||||
 | 
							if len(ipList) > 1 {
 | 
				
			||||||
 | 
								// 双栈
 | 
				
			||||||
 | 
								ipv4 = ipList[0]
 | 
				
			||||||
 | 
								ipv6 = ipList[1]
 | 
				
			||||||
 | 
								validIP = ipv4
 | 
				
			||||||
 | 
							} else if len(ipList) == 1 {
 | 
				
			||||||
 | 
								// 仅ipv4|ipv6
 | 
				
			||||||
 | 
								if strings.Contains(ipList[0], ":") {
 | 
				
			||||||
 | 
									ipv6 = ipList[0]
 | 
				
			||||||
 | 
									validIP = ipv6
 | 
				
			||||||
 | 
								} else {
 | 
				
			||||||
 | 
									ipv4 = ipList[0]
 | 
				
			||||||
 | 
									validIP = ipv4
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if mod != nil {
 | 
						if mod != nil {
 | 
				
			||||||
		str = strings.ReplaceAll(str, "#NEZHA#", mod(message))
 | 
							str = strings.ReplaceAll(str, "#NEZHA#", mod(message))
 | 
				
			||||||
		if s != nil {
 | 
							if s != nil {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			str = strings.ReplaceAll(str, "#SERVER.NAME#", mod(s.Name))
 | 
								str = strings.ReplaceAll(str, "#SERVER.NAME#", mod(s.Name))
 | 
				
			||||||
			str = strings.ReplaceAll(str, "#SERVER.IP#", mod(s.Host.IP))
 | 
								str = strings.ReplaceAll(str, "#SERVER.IP#", mod(validIP))
 | 
				
			||||||
 | 
								str = strings.ReplaceAll(str, "#SERVER.IPV4#", mod(ipv4))
 | 
				
			||||||
 | 
								str = strings.ReplaceAll(str, "#SERVER.IPV6#", mod(ipv6))
 | 
				
			||||||
			str = strings.ReplaceAll(str, "#SERVER.CPU#", mod(fmt.Sprintf("%f", s.State.CPU)))
 | 
								str = strings.ReplaceAll(str, "#SERVER.CPU#", mod(fmt.Sprintf("%f", s.State.CPU)))
 | 
				
			||||||
			str = strings.ReplaceAll(str, "#SERVER.MEM#", mod(fmt.Sprintf("%d", s.State.MemUsed)))
 | 
								str = strings.ReplaceAll(str, "#SERVER.MEM#", mod(fmt.Sprintf("%d", s.State.MemUsed)))
 | 
				
			||||||
			str = strings.ReplaceAll(str, "#SERVER.SWAP#", mod(fmt.Sprintf("%d", s.State.SwapUsed)))
 | 
								str = strings.ReplaceAll(str, "#SERVER.SWAP#", mod(fmt.Sprintf("%d", s.State.SwapUsed)))
 | 
				
			||||||
@ -182,7 +208,9 @@ func replaceParamsInString(s *Server, str string, message string, mod func(strin
 | 
				
			|||||||
		str = strings.ReplaceAll(str, "#NEZHA#", message)
 | 
							str = strings.ReplaceAll(str, "#NEZHA#", message)
 | 
				
			||||||
		if s != nil {
 | 
							if s != nil {
 | 
				
			||||||
			str = strings.ReplaceAll(str, "#SERVER.NAME#", s.Name)
 | 
								str = strings.ReplaceAll(str, "#SERVER.NAME#", s.Name)
 | 
				
			||||||
			str = strings.ReplaceAll(str, "#SERVER.IP#", s.Host.IP)
 | 
								str = strings.ReplaceAll(str, "#SERVER.IP#", validIP)
 | 
				
			||||||
 | 
								str = strings.ReplaceAll(str, "#SERVER.IPV4#", ipv4)
 | 
				
			||||||
 | 
								str = strings.ReplaceAll(str, "#SERVER.IPV6#", ipv6)
 | 
				
			||||||
			str = strings.ReplaceAll(str, "#SERVER.CPU#", fmt.Sprintf("%f", s.State.CPU))
 | 
								str = strings.ReplaceAll(str, "#SERVER.CPU#", fmt.Sprintf("%f", s.State.CPU))
 | 
				
			||||||
			str = strings.ReplaceAll(str, "#SERVER.MEM#", fmt.Sprintf("%d", s.State.MemUsed))
 | 
								str = strings.ReplaceAll(str, "#SERVER.MEM#", fmt.Sprintf("%d", s.State.MemUsed))
 | 
				
			||||||
			str = strings.ReplaceAll(str, "#SERVER.SWAP#", fmt.Sprintf("%d", s.State.SwapUsed))
 | 
								str = strings.ReplaceAll(str, "#SERVER.SWAP#", fmt.Sprintf("%d", s.State.SwapUsed))
 | 
				
			||||||
 | 
				
			|||||||
@ -36,7 +36,7 @@
 | 
				
			|||||||
            </div>
 | 
					            </div>
 | 
				
			||||||
            <div class="secret field">
 | 
					            <div class="secret field">
 | 
				
			||||||
                <label>Body</label>
 | 
					                <label>Body</label>
 | 
				
			||||||
                <textarea name="RequestBody" placeholder='{
  "content":"#NEZHA#",
  "ServerName":"#SERVER.NAME#",
  "ServerIP":"#SERVER.IP#",
  "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"
  "UDP_CONN_COUNT":"#SERVER.UDPCONNCOUNT"
}'></textarea>
 | 
					                <textarea name="RequestBody" placeholder='{
  "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"
  "UDP_CONN_COUNT":"#SERVER.UDPCONNCOUNT"
}'></textarea>
 | 
				
			||||||
            </div>
 | 
					            </div>
 | 
				
			||||||
            <div class="field">
 | 
					            <div class="field">
 | 
				
			||||||
                <div class="ui nf-ssl checkbox">
 | 
					                <div class="ui nf-ssl checkbox">
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user