X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fsmart.c;h=33b9751c2c72cff88fcce6500c4c6794d9c31afe;hb=9a68f99cfe1d2f3013534b3018068f808a6823c4;hp=6c01e677d94b8ac4647b99ab95263a5648f0525f;hpb=5e77bd677c549c4c1f81b8b8f7d78b8fd193749a;p=collectd.git diff --git a/src/smart.c b/src/smart.c index 6c01e677..33b9751c 100644 --- a/src/smart.c +++ b/src/smart.c @@ -35,12 +35,16 @@ static const char *config_keys[] = { "Disk", - "IgnoreSelected" + "IgnoreSelected", + "IgnoreSleepMode", + "UseSerial" }; static int config_keys_num = STATIC_ARRAY_SIZE (config_keys); static ignorelist_t *ignorelist = NULL; +static int ignore_sleep_mode = 0; +static int use_serial = 0; static int smart_config (const char *key, const char *value) { @@ -60,6 +64,16 @@ static int smart_config (const char *key, const char *value) invert = 0; ignorelist_set_invert (ignorelist, invert); } + else if (strcasecmp ("IgnoreSleepMode", key) == 0) + { + if (IS_TRUE (value)) + ignore_sleep_mode = 1; + } + else if (strcasecmp ("UseSerial", key) == 0) + { + if (IS_TRUE (value)) + use_serial = 1; + } else { return (-1); @@ -68,7 +82,8 @@ static int smart_config (const char *key, const char *value) return (0); } /* int smart_config */ -static void smart_submit (const char *dev, char *type, char *type_inst, double value) +static void smart_submit (const char *dev, const char *type, + const char *type_inst, double value) { value_t values[1]; value_list_t vl = VALUE_LIST_INIT; @@ -108,9 +123,28 @@ static void smart_handle_disk_attribute(SkDisk *d, const SkSmartAttributeParsedD sstrncpy (vl.type_instance, a->name, sizeof (vl.type_instance)); plugin_dispatch_values (&vl); + + if (a->threshold_valid && a->current_value <= a->threshold) + { + notification_t notif = { NOTIF_WARNING, + cdtime (), + "", + "", + "smart", "", + "smart_attribute", + "", + NULL }; + sstrncpy (notif.host, hostname_g, sizeof (notif.host)); + sstrncpy (notif.plugin_instance, dev, sizeof (notif.plugin_instance)); + sstrncpy (notif.type_instance, a->name, sizeof (notif.type_instance)); + ssnprintf (notif.message, sizeof (notif.message), + "attribute %s is below allowed threshold (%d < %d)", + a->name, a->current_value, a->threshold); + plugin_dispatch_notification (¬if); + } } -static void smart_handle_disk (const char *dev) +static void smart_handle_disk (const char *dev, const char *serial) { SkDisk *d = NULL; SkBool awake = FALSE; @@ -119,9 +153,16 @@ static void smart_handle_disk (const char *dev) const SkSmartParsedData *spd; uint64_t poweron, powercycles, badsectors, temperature; - shortname = strrchr(dev, '/'); - if (!shortname) return; - shortname++; + if (use_serial && serial) + { + shortname = serial; + } + else + { + shortname = strrchr(dev, '/'); + if (!shortname) return; + shortname++; + } if (ignorelist_match (ignorelist, shortname) != 0) { DEBUG ("smart plugin: ignoring %s.", dev); return; @@ -145,10 +186,13 @@ static void smart_handle_disk (const char *dev) DEBUG ("smart plugin: disk %s has no SMART support.", dev); goto end; } - if (sk_disk_check_sleep_mode (d, &awake) < 0 || !awake) + if (!ignore_sleep_mode) { - DEBUG ("smart plugin: disk %s is sleeping.", dev); - goto end; + if (sk_disk_check_sleep_mode (d, &awake) < 0 || !awake) + { + DEBUG ("smart plugin: disk %s is sleeping.", dev); + goto end; + } } if (sk_disk_smart_read_data (d) < 0) { @@ -227,13 +271,15 @@ static int smart_read (void) devices = udev_enumerate_get_list_entry (enumerate); udev_list_entry_foreach (dev_list_entry, devices) { - const char *path, *devpath; + const char *path, *devpath, *serial; path = udev_list_entry_get_name (dev_list_entry); dev = udev_device_new_from_syspath (handle_udev, path); devpath = udev_device_get_devnode (dev); + serial = udev_device_get_property_value (dev, "ID_SERIAL"); /* Query status with libatasmart */ - smart_handle_disk (devpath); + smart_handle_disk (devpath, serial); + udev_device_unref (dev); } udev_enumerate_unref (enumerate);