* collectd - src/mcelog.c
* MIT License
*
- * Copyright(c) 2016 Intel Corporation. All rights reserved.
+ * Copyright(c) 2016-2017 Intel Corporation. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
pthread_t tid; /* poll thread id */
llist_t *dimms_list; /* DIMMs list */
/* lock for dimms cache */
+ _Bool persist;
pthread_mutex_t dimms_lock;
} mcelog_config_t;
static int socket_receive(socket_adapter_t *self, FILE **p_file);
static mcelog_config_t g_mcelog_config = {
- .logfile = "/var/log/mcelog",
+ .logfile = "/var/log/mcelog", .persist = 0,
};
static socket_adapter_t socket_adapter = {
sfree(e->key);
sfree(e->value);
}
-
-}
-
-static llentry_t *mcelog_get_dimm(const char *name, llist_t *dimms_list) {
- if (dimms_list == NULL)
- return NULL;
-
- llentry_t *le = llist_search(g_mcelog_config.dimms_list, name);
- if (le != NULL)
- return le;
-
- return NULL;
}
/* Create or get dimm by dimm name/location */
} else
sstrncpy(dimm_name, rec->location, sizeof(dimm_name));
- llentry_t *dimm_le = mcelog_get_dimm(dimm_name, dimms_list);
+ llentry_t *dimm_le = llist_search(g_mcelog_config.dimms_list, dimm_name);
if (dimm_le == NULL) {
mcelog_memory_rec_t *dimm_mr = calloc(1, sizeof(*dimm_mr));
pthread_mutex_lock(&g_mcelog_config.dimms_lock);
memcpy(dimm->value, rec, sizeof(mcelog_memory_rec_t));
pthread_mutex_unlock(&g_mcelog_config.dimms_lock);
-
}
static int mcelog_config(oconfig_item_t *ci) {
+ int use_logfile = 0, use_memory = 0;
for (int i = 0; i < ci->children_num; i++) {
oconfig_item_t *child = ci->children + i;
- if (strcasecmp("McelogClientSocket", child->key) == 0) {
- if (cf_util_get_string_buffer(child, socket_adapter.unix_sock.sun_path,
- sizeof(socket_adapter.unix_sock.sun_path)) <
- 0) {
- ERROR(MCELOG_PLUGIN ": Invalid configuration option: \"%s\".",
+ if (strcasecmp("McelogLogfile", child->key) == 0) {
+ use_logfile = 1;
+ if (use_memory) {
+ ERROR(MCELOG_PLUGIN ": Invalid configuration option: \"%s\", Memory "
+ "option is already configured.",
child->key);
return (-1);
}
- } else if (strcasecmp("McelogLogfile", child->key) == 0) {
if (cf_util_get_string_buffer(child, g_mcelog_config.logfile,
sizeof(g_mcelog_config.logfile)) < 0) {
ERROR(MCELOG_PLUGIN ": Invalid configuration option: \"%s\".",
child->key);
return (-1);
}
+ memset(socket_adapter.unix_sock.sun_path, 0,
+ sizeof(socket_adapter.unix_sock.sun_path));
+ } else if (strcasecmp("Memory", child->key) == 0) {
+ if (use_logfile) {
+ ERROR(MCELOG_PLUGIN ": Invalid configuration option: \"%s\", Logfile "
+ "option is already configured.",
+ child->key);
+ return (-1);
+ }
+ use_memory = 1;
+ oconfig_item_t *mem_child = child->children;
+ for (int j = 0; j < child->children_num; j++) {
+ mem_child += j;
+ if (strcasecmp("McelogClientSocket", mem_child->key) == 0) {
+ if (cf_util_get_string_buffer(
+ mem_child, socket_adapter.unix_sock.sun_path,
+ sizeof(socket_adapter.unix_sock.sun_path)) < 0) {
+ ERROR(MCELOG_PLUGIN ": Invalid configuration option: \"%s\".",
+ mem_child->key);
+ return (-1);
+ }
+ } else if (strcasecmp("PersistentNotification", mem_child->key) == 0) {
+ if (cf_util_get_boolean(mem_child, &g_mcelog_config.persist) < 0) {
+ ERROR(MCELOG_PLUGIN ": Invalid configuration option: \"%s\".",
+ mem_child->key);
+ return (-1);
+ }
+ } else {
+ ERROR(MCELOG_PLUGIN ": Invalid Memory configuration option: \"%s\".",
+ mem_child->key);
+ return (-1);
+ }
+ }
+ memset(g_mcelog_config.logfile, 0, sizeof(g_mcelog_config.logfile));
} else {
ERROR(MCELOG_PLUGIN ": Invalid configuration option: \"%s\".",
child->key);
llentry_t *dimm = mcelog_dimm(mr, g_mcelog_config.dimms_list);
if (dimm == NULL) {
- ERROR(MCELOG_PLUGIN ": Error adding/getting dimm memory item to/from cache");
- return -1;
+ ERROR(MCELOG_PLUGIN
+ ": Error adding/getting dimm memory item to/from cache");
+ return (-1);
}
-
mcelog_memory_rec_t *mr_old = dimm->value;
+ if (!g_mcelog_config.persist) {
- if (mr_old->corrected_err_total != mr->corrected_err_total ||
- mr_old->corrected_err_timed != mr->corrected_err_timed)
- dispatch_corrected_notifs = 1;
+ if (mr_old->corrected_err_total != mr->corrected_err_total ||
+ mr_old->corrected_err_timed != mr->corrected_err_timed)
+ dispatch_corrected_notifs = 1;
- if (mr_old->uncorrected_err_total != mr->uncorrected_err_total ||
- mr_old->uncorrected_err_timed != mr->uncorrected_err_timed)
- dispatch_uncorrected_notifs = 1;
+ if (mr_old->uncorrected_err_total != mr->uncorrected_err_total ||
+ mr_old->uncorrected_err_timed != mr->uncorrected_err_timed)
+ dispatch_uncorrected_notifs = 1;
- if (!dispatch_corrected_notifs && !dispatch_uncorrected_notifs) {
- DEBUG("%s: No new notifications to dispatch", MCELOG_PLUGIN);
- return (0);
+ if (!dispatch_corrected_notifs && !dispatch_uncorrected_notifs) {
+ DEBUG("%s: No new notifications to dispatch", MCELOG_PLUGIN);
+ return (0);
+ }
+ } else {
+ dispatch_corrected_notifs = 1;
+ dispatch_uncorrected_notifs = 1;
}
sstrncpy(n.host, hostname_g, sizeof(n.host));
llentry_t *dimm = mcelog_dimm(mr, g_mcelog_config.dimms_list);
if (dimm == NULL) {
- ERROR(MCELOG_PLUGIN ": Error adding/getting dimm memory item to/from cache");
- return -1;
+ ERROR(MCELOG_PLUGIN
+ ": Error adding/getting dimm memory item to/from cache");
+ return (-1);
}
value_list_t vl = {
}
static int mcelog_init(void) {
+ if (g_mcelog_config.logfile != NULL &&
+ socket_adapter.unix_sock.sun_path != NULL) {
+ INFO(MCELOG_PLUGIN
+ ": No configuration selected defaulting to memory errors.");
+ memset(g_mcelog_config.logfile, 0, sizeof(g_mcelog_config.logfile));
+ }
g_mcelog_config.dimms_list = llist_create();
int err = pthread_mutex_init(&g_mcelog_config.dimms_lock, NULL);
if (err < 0) {
return (-1);
}
- if (plugin_thread_create(&g_mcelog_config.tid, NULL, poll_worker, NULL,
- NULL) != 0) {
- ERROR(MCELOG_PLUGIN ": Error creating poll thread.");
- return (-1);
+ if (socket_adapter.unix_sock.sun_path != NULL) {
+ if (plugin_thread_create(&g_mcelog_config.tid, NULL, poll_worker, NULL,
+ NULL) != 0) {
+ ERROR(MCELOG_PLUGIN ": Error creating poll thread.");
+ return (-1);
+ }
}
return (0);
}