@@ -38,6 +38,7 @@ static struct monitor {
unsigned int poll_timeout;
unsigned int event_flags;
struct log_ctx ctx;
+ const char *run;
} monitor;
struct monitor_dimm {
@@ -389,6 +390,8 @@ static int monitor_event(struct ndctl_ctx *ctx,
for (i = 0; i < nfds; i++) {
mdimm = events[i].data.ptr;
if (util_dimm_event_filter(mdimm, monitor.event_flags)) {
+ rc = system(monitor.run);
+ ...
rc = notify_dimm_event(mdimm);
if (rc) {
err(&monitor, "%s: notify dimm event failed\n",
@@ -546,6 +549,7 @@ static int parse_monitor_config(const struct config *configs,
set_monitor_conf(¶m.region, "region", value, seek);
set_monitor_conf(¶m.namespace, "namespace", value, seek);
set_monitor_conf(&monitor.dimm_event, "dimm-event", value, seek);
+ set_monitor_conf(&monitor.run, "run", value, seek);
if (!monitor.log)
set_monitor_conf(&monitor.log, "log", value, seek);
@@ -581,6 +585,8 @@ int cmd_monitor(int argc, const char **argv, struct ndctl_ctx *ctx)
"emit extra debug messages to log"),
OPT_UINTEGER('p', "poll", &monitor.poll_timeout,
"poll and report events/status every <n> seconds"),
+ OPT_STRING('\0', "run", &monitor.run, "bash script",
+ "run a script when the smart event is monitored"),
OPT_END(),
};
const char * const u[] = {
@@ -598,6 +604,7 @@ int cmd_monitor(int argc, const char **argv, struct ndctl_ctx *ctx)
CONF_STR("monitor:dimm", ¶m.dimm, NULL),
CONF_STR("monitor:namespace", ¶m.namespace, NULL),
CONF_STR("monitor:dimm-event", &monitor.dimm_event, NULL),
+ CONF_STR("monitor:run", &monitor.run, NULL),
CONF_END(),
};
const char *prefix = "./";
@@ -646,6 +653,9 @@ int cmd_monitor(int argc, const char **argv, struct ndctl_ctx *ctx)
}
}
+ if (monitor.run && (strncmp(monitor.run, "./", 2) != 0))
+ fix_filename(prefix, (const char **)&monitor.run);
+
if (monitor.daemon) {
if (!monitor.log || strncmp(monitor.log, "./", 2) == 0)
monitor.ctx.log_fn = log_syslog;