http://www.linux-centos.com/2012/07/12/centos%E4%B8%8Blogwatch%E7%9A%84%E9%85%8D%E7%BD%AE/html
1
|
vim
/
usr
/
share
/
logwatch
/
default
.
conf
/
logwatch
.
conf
|
主要修改两个选项linux
1
2
3
4
5
|
# 这里能够改成本身的EMAIL地址
MailTo
=
root
# 这里能够改成Med、High
Detail
=
Low
|
其余选项vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
# 当你收到邮件时, 显示是谁发给你的
MailFrom
=
Logwatch
# 处理何时的日志 , 可选项 All , Yesterday , Today , 即全部, 昨天的 , 今天的
Range
=
All
# 日志详细度, 可选项 Low , Med , High , 或是 0-10数字
Detail
=
High
# 可选项, Yes 会被打印到系统标准输出, 而且不会以邮件的形式发送到 MailTo 设定的邮箱里 , No 选项则会发到邮箱中
Print
=
No
# 监控全部服务 all
Server
=
All
# 不监控的服务前面加 “-” , 如 -httpd , 即不监控 httpd 服务 , 能够写多条
Service
=
“
-
httpd”
Service
=
“
-
sshd”
|
发送HTML格式的邮件centos
1
2
|
vi
/
usr
/
share
/
logwatch
/
scripts
/
logwatch
.
pl
$
Config
{
'output'
}
=
"html"
;
|
Logwatch 使用app
a. 配置好之后 , 使用以下命令测试ssh
1
|
/
usr
/
bin
/
perl
/
usr
/
share
/
logwatch
/
scripts
/
logwatch
.
pl
|
你会发现没有 httpd , sshd 服务的日志报告 ,
去掉 Service = “-sshd” 配置 , 再执行上面命令 , 就能够看到 sshd 服务的 report 了
b. Logwatch 并非以系统服务形式来跑的 , 而是靠在命令行上敲的 , 因此能够使用 crontab 来定时执行
在配置好 Logwatch 后 , 会生成一个软链 /etc/cron.daily/0logwatch , 对应文件为 /usr/share/logwatch/scripts/logwatch.pl
你能够删除这个软链 , 并重写 crontab :ide
1
|
*
00
*
*
*
/
usr
/
bin
/
perl
/
usr
/
share
/
logwatch
/
scripts
/
logwatch
.
pl
>
/
dev
/
null
2
>
&
1
|
Logwatch 命令行使用测试
Logwatch 也能够在命令行上使用, 以下例子:
logwatch –detail High –Service All –range All –print # 显示全部日志, –detail , –Service, –range 开关能够在 logwatch.conf 中 找到
logwatch –service cron –detail High # 查看 sshd 日志spa
如下是 logwatch 的参数解释:
–detail <level>: 报告的详细度,可选项: High, Med, Low , 数字 0-10
–logfile <name>: 指日志文件名
–service <name>: 服务名,有对应的解析脚本,能够在 /usr/share/logwatch/scripts/services 中找到
–print: 打印打标准输出
–mailto <addr>: 收件人地址
–archives: 使用压缩的文件, 轮转的文件, 例如 messages.一、messages.1.gz
–save <filename>: 保存到文件
–range <range>: 日期范围, Yesterday, Today, All
–debug <level>: 调试级别: High, Med, Low
–splithosts: 为每一个主机建立一份报告
–multiemail: 将报告发送给多个邮件地址命令行
故障排除
若是没有收到 Logwatch日志报告邮件 , 请检察本地 sendmail 服务是否正常
直接指定邮件发送
#logwatch –range today –print –mailto sina@sina.com 当天
/usr/share/logwatch/scripts/logwatch.pl –mailto sina@sina.com