smartd 仅在属性更改时发送电子邮件

smartd 仅在属性更改时发送电子邮件

我设置 smartd 来向我发送邮件报告,以防我的磁盘出现故障。不幸的是,我每天都会收到具有相同(不变)值的相同属性的垃圾邮件:

The following warning/error was logged by the smartd daemon:

Device: /dev/sdb [SAT], 1 Offline uncorrectable sectors

Device info:
ST32000542AS, S/N:XXXXX, WWN:5-XXXXXX-XXXXXXXX, FW:XXXX, 2.00 TB

我完全意识到具有不可纠正扇区的磁盘所隐含的危险。(此磁盘用于 RAID10 配置)

我只是不想每天收到相同的电子邮件,我只想在值发生变化/增加时收到一封电子邮件。

这是我的当前配置/etc/smartd.conf

DEVICESCAN -d removable -n standby -t -m root -M exec /usr/share/smartmontools/smartd-runner

为了实现 smartd 的预期行为,我必须改变什么?

答案1

启用状态持久性时的默认行为(我认为这是 Debian 中的默认行为)是在记录关键事件时每天发送一封电子邮件(或者更确切地说,当记录关键事件时,如果在至少一天,发送电子邮件)。您可以使用以下选项更改此行为-M;添加

-M once

到您的smartd.conf,并且关键事件只会生成一封电子邮件,不会重复。

(该-M once选项是该选项的补充-M exec。)

/var/lib/smartmontools要检查状态持久性是否确实启用,请检查;的内容您应该会看到最近更新的所有驱动器的状态文件。

答案2

您正在使用-M exec和 ,smartd-runner这显然是 Debian 的特色。

Package Maintainers and system administrators can put scripts to be run
when smartd detects an error into /etc/smartmontools/run.d. These
scripts will be run by smartd-runner using run-parts(8). The script will
receive the filename of the file containing the errormessage as first
parameter. See /etc/smartmontools/run.d/10mail for an example.

该运行程序的主要目的似乎是使发送邮件成为可选的(取决于是否首先安装了邮件程序),并且单独地,它似乎在桌面上触发弹出通知(如果安装了桌面通知程序)。

所以我想你可以修改 10mail 脚本来过滤掉重复的邮件。

另一种方法是使用该--savestates选项运行 smartd,然后-M once在 smartd.conf 中使用 - smartd.conf 手册页对此进行了更详细的描述,总结一下:

          once - send only one warning email for each type of disk problem

          daily - send additional warning reminder emails, once  per  day,

          diminishing - send additional warning reminder emails,  after  a
          one-day  interval,  then  a  two-day  interval,  then a four-day

          test - send a single test email immediately upon smartd startup.

          exec PATH - run the executable PATH instead of the default  mail

如果这不起作用,您要么必须忍受它,要么编写自己的邮件处理程序执行逻辑来进行相应的过滤。


我完全意识到具有不可纠正扇区的磁盘所隐含的危险。 (此磁盘用于 RAID10 配置)

我仍然建议立即更换此类驱动器。 RAID 在冗余方面做出的任何承诺只有在每个驱动器都处于 100% 工作状态时才有效。

更换驱动器后,您可以在删除的驱动器上进行完整的写入测试,而不会有数据丢失的风险 - 并且根据驱动器在此测试中的表现,您可以做出是否继续使用该驱动器的更明智的决定(最好在 raid 之外)或不。

在对驱动器进行测试之前,您不知道驱动器到底损坏了多少 - 而且您的 smartd.conf 看起来不像您正在运行定期自检,因此错误可能会在很长一段时间内未被检测到。这就是 RAID 在重建过程中死亡的原因。

答案3

这是一个旧线程,但我将发布我在 smartd 手册中找到的内容:

-U ID[+]

          [ATA only] Report if the number of offline uncorrectable sectors
          is  non-zero. Here ID is the id number of the Attribute whose
          raw value  is  the  Offline  Uncorrectable  Sector  count.   The
          allowed  range  of  ID  is 0 to 255 inclusive.  To turn off this
          reporting, use ID = 0.  If the -U ID option is not  given,  then
          it  defaults to -U 198 (since Attribute 198 is generally used to
          monitor offline uncorrectable sectors).  If  the  name  of  this
          Attribute  is  changed  by  a  '-v  198,FORMAT,NAME' (except '-v
          198,FORMAT,Offline_Scan_UNC_SectCt'), directive, the default  is
          changed to -U 0.

          If  '+'  is specified, a report is only printed if the number of
          sectors has increased since the last check cycle. **Some disks  do
          not  reset this attribute when a bad sector is reallocated.**  See
          also '-v 198,increasing' below.

因此添加选项 -U 198+ 应该完全符合您的要求。

相关内容