我的tripwire报告的理想解决scheme是:
如果发现违规,每日电子邮件只会生成
每个星期天,无论是否发现违规,都会通过电子邮件发送报告
我也对SF'ers的意见感兴趣。 也许这是违背tripwire的目的? 我可以看到有人提出这个观点。
我从很多主机获取大量tripwire报告的解决scheme是将它们全部发送到一个将它们堆叠在一个文件中的地址,然后在它们上面运行一个简单的工作,只报告主机名和违规计数,报告是否有任何非违规计数的主机。
首先,所有的主机将他们的报告发送到[email protected] 。 这很容易安排从每个crontab条目; 我这样做:
# check the tripwires [email protected] 3 1 * * * /usr/sbin/tripwire --check
其次,在邮件服务器上,我有一个别名条目,说:
# tripwire report autoprocessing tripwire: /var/tmp/tripwire
第三,我有一个每天早上运行的cron作业来处理这个文件的内容,另一个每天晚上运行一个作业去除它(所以我只查看最近的输出):
# report problems with nightly tripwire runs 2 7 * * * /usr/local/bin/tripwire-check 45 23 * * * rm -f /var/tmp/tripwire
这里是/ usr / local / bin / tripwire-check的内容; 这很简单:
#!/bin/tcsh grep "Total violation" /var/tmp/tripwire | grep -vw 0 > /dev/null || exit 0 egrep 'Host name|Total vio' /var/tmp/tripwire | mail -s "NIGHTLY TRIPWIRE VIOLATIONS `date +%Y%m%d`" [email protected]
第一个grep退出,没有任何邮件或输出IFO所有包含违规计数的行也包含数字0作为一个整体单词; 第二个,只有在第一行失败时才被调用,生成简明摘要电子邮件并发送给我。
最后,当出现错误报告时,这里是一个示例输出:
Subject: NIGHTLY TRIPWIRE VIOLATIONS 20050401 Date: Fri, 1 Apr 2005 07:02:00 +0100 To: [email protected] From: root <[email protected]> Host name: fw03b.company.com Total violations found: 0 Host name: je01b.company.com Total violations found: 0 Host name: ms01.company.com Total violations found: 1 Host name: fw05a.company.com Total violations found: 0 Host name: fw02b.company.com Total violations found: 0 Host name: fw01b.company.com Total violations found: 0 Host name: je02o.company.com Total violations found: 0 Host name: je01a.company.com Total violations found: 0 Host name: fw04a.company.com Total violations found: 0 Host name: fw04b.company.com Total violations found: 0 Host name: je02p.company.com Total violations found: 0 Host name: fw02a.company.com Total violations found: 0 Host name: fw03a.company.com Total violations found: 0 Host name: rp01a.company.com Total violations found: 0 Host name: rp01b.company.com Total violations found: 0 Host name: je03o.company.com Total violations found: 0 Host name: db03.company.com Total violations found: 0 Host name: lb02p.company.com Total violations found: 15 Host name: rp02o.company.com Total violations found: 23 Host name: as05.company.com Total violations found: 0 Host name: db02.company.com Total violations found: 0
希望这有一些用处。
Tripwire有一个选项可以禁止没有错误的报告(MAILNOVIOLATIONS),它可以在configuration文件中find…
您可以设置2个不同的twcfg文件,一个将MAILNOVIOLATIONS设置为TRUE,另一个将此选项设置为FALSE
MAILNOVIOLATIONS =true (or false)
然后你的cronjob可以使用-c标志运行tripwire来selecttwcfg文件
每日报告crontab:
30 12 * * 1,2,3,4,5,6 /usr/sbin/tripwire --check -c PATH_TO_DAILY_CFG_FILE | mail -s "Tripwire report for `uname -n`, errors found" [email protected]
周日报告crontab:
30 12 * * 0 /usr/sbin/tripwire --check -c PATH_TO_WEEKLY_CFG_FILE | mail -s "Weekly Tripwire report for `uname -n`" [email protected]
这样,你的日常cronjob将运行tripwire使用configuration文件,只有电子邮件报告,如果发现违规,你的每周cronjob会通过电子邮件发送报告,无论。
ps上面的crontab命令来自使用Debian的系统,您可能需要编辑Tripwire二进制文件的path。
我知道我已经selectMadHatter先生的提交作为答案,但经过一番思考,我想到了其他可能的工作。 有没有人看到为什么这不起作用?
tripwire_out=`/usr/sbin/tripwire --check`; test -z "`echo $tripwire_out | grep 'Total violations found: 0'`"&& echo $tripwire_out
我已经在shell中testing过了,它按预期工作。 但是,我还没有取代tripwire cron作业。
你们有什么感想?
另一个可能的简单的解决scheme,不完全是要求,但可能有用的人。
只需在邮件主题中发送“发现的总违规数”,我就会不断收到通知,但是我不需要打开它们,虽然我发现有一些违规行为正在发生。 这样我也确定tripwire保持正常工作:
tripwire --check > /tmp/twreport; mail -s "Tripwire report for `uname -n`: `grep 'Total violations found' /tmp/twreport`" [email protected] < /tmp/twreport; rm /tmp/twreport
一步步:
1.-我在文件“twreport”中保存tripwire报告
tripwire --check > /tmp/twreport;
2.-我做了一个grep在“发现总的违规行”的twreport文件。 我将其插入到邮件命令的主题中。 我在邮件正文中获得了twreport文本内容:
mail -s "Tripwire report for `uname -n`: `grep 'Total violations found' /tmp/twreport`" [email protected] < /tmp/twreport
3.-最后,我删除了twreport文件:
rm /tmp/twreport