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