1. 前言

本人在【原创】终结选择困难,Xshell、MobaXterm、PuTTY、SecureCRT 多款 SSH 终端软件该怎么选 一文中提到 MobaXterm 中有默认就很好用的高亮/突出显示集功能(HighLight sets),演示如下:

img

img

可以看到,突出显示集功能对于查看日志,检索程序输出信息时,对 success/warn/error 等关键字会进行高亮显示,提高了我们的排查效率。

此功能在 MobaXterm 上默认开启,并且有好几套针对不同场景的突出显示方案。包括:

  • OK/warning/error 方案
  • Unix shell script 方案
  • Cisco 网络配置方案
  • Perl 语法方案
  • SQL 语法方案

大家可以根据自己的需要,针对不同的 session 采用不同的突出显示方案,如下图所示:

img

2. 设置 Xshell6 的突出显示集

Xshell6 相对于 Xshell5,也增加了突出显示集功能,但没有默认开启,也没有默认的方案。

由于 Xshell6 和 MobaXterm 均使用正则表达式来进行突出显示,因此可以通过使用 MobaXterm 的显示方案来加强 Xshell6 的突出显示功能。不了解正则的同学可以看这篇:【原创】正则表达式基础知识速学笔记

但直接复制过来是不能使用的。原 MobaXterm 的正则方案中,还匹配了各种欧洲语言,例如法语德语丹麦语挪威语等等,崦在我们这,只会遇到中文和英文。因此本人在 MobaXterm 的正则方案上修改了如下内容:

  • 删除非英文匹配规则。
  • 添加少量中文匹配规则。
  • 添加了 UP/DOWN 匹配规则。

2.1 添加自定义突出显示集

img

img

2.2 添加自定义正则表达式规则

一共有五个规则:

  • 正确规则:
1
[^A-Za-z_&-](accepted|allowed|enabled|connected|successfully|成功|正确|successful|succeeded|success)[^A-Za-z_-]|[=>"':.,;({\[][ ]*(true|yes|ok)[ ]*[]=>"':.,;)} ]
  • 错误规则:
1
[^A-Za-z_&-]((bad|wrong|incorrect|improper|invalid|unsupported|bad)( file| memory)? (descriptor|alloc(ation)?|addr(ess)?|owner(ship)?|arg(ument)?|param(eter)?|setting|length|filename)|not properly|improperly|(operation |connection |authentication |access |permission )?(denied|disallowed|not allowed|refused|problem|failed|failure|not permitted)|no [A-Za-z]+( [A-Za-z]+)? found|invalid|unsupported|not supported|seg(mentation )?fault|错误|corruption|corrupted|corrupt|overflow|underrun|not ok|unimplemented|unsuccessfull|not implemented|errors?|\(ee\)|\(ni\))[^A-Za-z_-]|[=>"':.,;({\[][ ]*(false|no|ko)[ ]*[]=>"':.,;)} ]
  • 警告规则:
1
[^A-Za-z_&-](\[\-w[A-Za-z-]+\]|caught signal [0-9]+|警告|cannot|(connection (to (remote host|[a-z0-9.]+) )?)?(closed|terminated|stopped|not responding)|exited|no more [A-Za-z] available|unexpected|(command |binary |file )?not found|(o)+ps|out of (space|memory)|low (memory|disk)|unknown|disabled|disconnected|deprecated|refused|disconnect(ion)?|attention|warnings?|exclamation|alerts?|\(ww\)|\(\?\?\)|could not|unable to)[^A-Za-z_-]
  • 主机规则:
1
[^0-9A-Za-z_&-](localhost|([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-4])\.[0-9]+\.[0-9]+\.[0-9]+|null|none)[^0-9A-Za-z_-]
  • 信息规则:
1
[^A-Za-z_&-](last (failed )?login:|launching|checking|loading|creating|building|important|booting|starting|notice|informational|informations?|info|信息|note|\(ii\)|\(\!\!\))[^A-Za-z_-]

添加五个规则的方法如下:

img

img

依次添加五个规则,然后点击”设置为当前组”:

img

3. Xshell6 突出显示集效果展示:

相对于 MobaXterm,多了中文展示:

img

其他地方与 MobaXterm 效果类似

4. 关于正则

CSDN搜集

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 信息规则--青色
[^A-Za-z_&-](last (failed )?login:|launching|checking|loading|creating|building|important|booting|starting|notice|informational|informations?|info|信息|note|\(ii\)|\(\!\!\))[^A-Za-z_-]

# IPv4--紫色
[^0-9A-Za-z_&-](localhost|([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-4])\.[0-9]+\.[0-9]+\.[0-9]+|null|none)[^0-9A-Za-z_-]

# 网址--浅蓝
\b(http(s)?://[A-Za-z0-9_.:/&?=%~#{}()@+-]+)\b

# 正确规则--绿色
[^A-Za-z_&-](accepted|allowed|enabled|connected|successfully|成功|正确|successful|succeeded|success)[^A-Za-z_-]|[ \=\>\'\"\.:\,\;\(\{\[\]*]*(true|yes|ok)[ \=\>\'\"\.:\,\;\)\}\]\*]*

# 告警规则--黄色
[^A-Za-z_&-](\[\-w[A-Za-z-]+\]|caught signal [0-9]+|警告|cannot|(connection (to (remote host|[a-z0-9.]+) )?)?(closed|terminated|stopped|not responding)|exited|no more [A-Za-z] available|unexpected|(command |binary |file )?not found|(o)+ps|out of (space|memory)|lowmemory|disk)|unknown|disabled|disconnected|deprecated|refused|disconnect(ion)?|attention|warnings?|exclamation|alerts?|\(ww\)|\(\?\?\)|could not|unable to)[^A-Za-z_-]

# 错误规则--红色
[^A-Za-z_&-]((bad|wrong|incorrect|improper|invalid|unsupported|bad)( file| memory)? (descriptor|alloc(ation)?|addr(ess)?|owner(ship)?|arg(ument)?|param(eter)?|setting|length|filename)|not properly|improperly|(operation |connection |authentication |access |permission )?(denied|disallowed|not allowed|refused|problem|failed|failure|not permitted)|no [A-Za-z]+( [A-Za-z]+)? found|invalid|unsupported|not supported|seg(mentation )?fault|错误|corruption|corrupted|corrupt|overflow|underrun|not ok|unimplemented|unsuccessfull|not implemented|errors?|\(ee\)|\(ni\))[^A-Za-z_-]|[ \=\>\'\"\.:\,\;\(\{\[\]*]*(false|no|ko)[ \=\>\'\"\.:\,\;\)\}\]\*]*

# IPv4 && 网址
[^0-9A-Za-z_&-](localhost|([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-4])\.[0-9]+\.[0-9]+\.[0-9]+|null|none|\bhttp(s)?://[A-Za-z0-9_.:/&?=%~#{}()@+-]+\b)[^0-9A-Za-z_-]

知乎搜集

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# info
(\binfo\b)

# debug
(\bdebug\b)

# warn, inactive, unknown
(\bwarn(ing)?\b)|(\binactive\b)|(\bunknown\b)

# error, fail, false, down
(\berror\b)|(\bfail(ed)?\b)|(\bfalse\b)|(\bdown\b)

# active, success, true, ok, up
(\bactive(d)?\b)|(\bsuccess(ful(ly)?)?\b)|(\btrue\b)|(\bok\b)|(\bup\b)

# start, begin, enable, create, open
(\bstart(ed|ing)?\b)|(\bbegin(ning)?\b)|(\benable(d)?\b)|(\bcreate(d)?\b)|(\bopen\b)

# stop, end, finish, disable, delete, close
(\bstop(ped)?\b)|(\bend\b)|(\bfinish(ed)?\b)|(\bdisable(d)?\b)|(\bdelete(d)?\b)|(\bclose(d)?\b)

# IPv4
(?=(\b|\D))(((\d{1,2})|(1\d{1,2})|(2[0-4]\d)|(25[0-5]))\.){3}((\d{1,2})|(1\d{1,2})|(2[0-4]\d)|(25[0-5]))(?=(\b|\D))\s*

# IPv6
[\[ ]?\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*\]?

个人整理

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# http
\b(http(s)?://[A-Za-z0-9_.:/&?=%~#{}()@+-]+)\b

# IPV4
[^0-9A-Za-z_&-](localhost|([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-4])\.[0-9]+\.[0-9]+\.[0-9]+|null|none)[^0-9A-Za-z_-]

# Message
[^A-Za-z_&-](last (failed )?login:|launching|checking|loading|creating|building|important|booting|starting|notice|informational|informations?|info|信息|note|\(ii\)|\(\!\!\))[^A-Za-z_-]

# OK
[^A-Za-z_&-](accepted|allowed|enabled|connected|successfully|成功|正确|successful|succeeded|success)[^A-Za-z_-]|[ \=\>\'\"\.:\,\;\(\{\[\]*]*(true|yes|ok)[ \=\>\'\"\.:\,\;\)\}\]\*]*

# Waring
[^A-Za-z_&-](\[\-w[A-Za-z-]+\]|caught signal [0-9]+|警告|cannot|(connection (to (remote host|[a-z0-9.]+) )?)?(closed|terminated|stopped|not responding)|exited|no more [A-Za-z] available|unexpected|(command |binary |file )?not found|(o)+ps|out of (space|memory)|lowmemory|disk)|unknown|disabled|disconnected|deprecated|refused|disconnect(ion)?|attention|warnings?|exclamation|alerts?|\(ww\)|\(\?\?\)|could not|unable to)[^A-Za-z_-]

# Error
[^A-Za-z_&-]((bad|wrong|incorrect|improper|invalid|unsupported|bad)( file| memory)? (descriptor|alloc(ation)?|addr(ess)?|owner(ship)?|arg(ument)?|param(eter)?|setting|length|filename)|not properly|improperly|(operation |connection |authentication |access |permission )?(denied|disallowed|not allowed|refused|problem|failed|failure|not permitted)|no [A-Za-z]+( [A-Za-z]+)? found|invalid|unsupported|not supported|seg(mentation )?fault|错误|corruption|corrupted|corrupt|overflow|underrun|not ok|unimplemented|unsuccessfull|not implemented|errors?|\(ee\)|\(ni\))[^A-Za-z_-]|[ \=\>\'\"\.:\,\;\(\{\[\]*]*(false|no|ko)[ \=\>\'\"\.:\,\;\)\}\]\*]*

OpenAI生成

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# HTTP
\b(http(s)?:\/\/[A-Za-z0-9_.:\/&?=%~#{}()@+-]+)\b

# IPV4
\b(localhost|((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))\b

# INFO
\b(last (failed )?login:|launching|checking|loading|creating|building|booting|starting|info|信息|note)\b

# OK
\b(accepted|allowed|enabled|connected|success|成功|正确)\b|(?<!\w)(true|yes|ok)(?!\w)

# Warning
\b(caught signal|警告|cannot|closed|terminated|disconnected|deprecated|refused|attention|warning|alert|unexpected|exclamation)\b


# Error
\b(bad|wrong|invalid|error|failed|problem|corrupted|corrupt|no|false|ko|not ok|unimplemented|not supported)\b