summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 4207aaf)
raw | patch | inline | side by side (parent: 4207aaf)
author | Pavel Rochnyack <pavel2000@ngs.ru> | |
Tue, 10 Oct 2017 10:31:18 +0000 (17:31 +0700) | ||
committer | Pavel Rochnyack <pavel2000@ngs.ru> | |
Tue, 10 Oct 2017 10:31:18 +0000 (17:31 +0700) |
src/ipmi.c | patch | blob | history |
diff --git a/src/ipmi.c b/src/ipmi.c
index 2036d7d221d4db8c4eabaf5bf37c998a5624687e..2d859cb7808aa8c205aa95721ceb6de2efe5e295 100644 (file)
--- a/src/ipmi.c
+++ b/src/ipmi.c
}
} /* void c_ipmi_log */
+static notification_t c_ipmi_notification_init(c_ipmi_instance_t const *st,
+ int severity) {
+ notification_t n = {severity, cdtime(), "", "", "ipmi", "", "", "", NULL};
+
+ sstrncpy(n.host, (st->host != NULL) ? st->host : hostname_g, sizeof(n.host));
+ return n;
+} /* notification_t c_ipmi_notification_init */
+
/*
* Sensor handlers
*/
list_item->sensor_name, st->name);
if (st->notify_notpresent) {
- notification_t n = {
- NOTIF_WARNING, cdtime(), "", "", "ipmi", "", "", "", NULL};
+ notification_t n = c_ipmi_notification_init(st, NOTIF_WARNING);
- sstrncpy(n.host, (st->host != NULL) ? st->host : hostname_g,
- sizeof(n.host));
sstrncpy(n.type_instance, list_item->sensor_name,
sizeof(n.type_instance));
sstrncpy(n.type, list_item->sensor_type, sizeof(n.type));
list_item->sensor_name, st->name);
if (st->notify_notpresent) {
- notification_t n = {NOTIF_OKAY, cdtime(), "", "", "ipmi",
- "", "", "", NULL};
+ notification_t n = c_ipmi_notification_init(st, NOTIF_OKAY);
- sstrncpy(n.host, (st->host != NULL) ? st->host : hostname_g,
- sizeof(n.host));
sstrncpy(n.type_instance, list_item->sensor_name,
sizeof(n.type_instance));
sstrncpy(n.type, list_item->sensor_type, sizeof(n.type));
pthread_mutex_unlock(&st->sensor_list_lock);
if (st->notify_add && (st->init_in_progress == 0)) {
- notification_t n = {NOTIF_OKAY, cdtime(), "", "", "ipmi", "", "", "", NULL};
+ notification_t n = c_ipmi_notification_init(st, NOTIF_OKAY);
- sstrncpy(n.host, (st->host != NULL) ? st->host : hostname_g,
- sizeof(n.host));
sstrncpy(n.type_instance, list_item->sensor_name, sizeof(n.type_instance));
sstrncpy(n.type, list_item->sensor_type, sizeof(n.type));
snprintf(n.message, sizeof(n.message), "sensor %s added",
pthread_mutex_unlock(&st->sensor_list_lock);
if (st->notify_remove && st->active) {
- notification_t n = {NOTIF_WARNING, cdtime(), "", "", "ipmi", "", "", "",
- NULL};
+ notification_t n = c_ipmi_notification_init(st, NOTIF_WARNING);
- sstrncpy(n.host, (st->host != NULL) ? st->host : hostname_g,
- sizeof(n.host));
sstrncpy(n.type_instance, list_item->sensor_name, sizeof(n.type_instance));
sstrncpy(n.type, list_item->sensor_type, sizeof(n.type));
snprintf(n.message, sizeof(n.message), "sensor %s removed",
if (event == NULL)
return IPMI_EVENT_NOT_HANDLED;
+ notification_t n = c_ipmi_notification_init(st, NOTIF_OKAY);
/* offset is a table index and it's represented as enum of strings that are
organized in the way - high and low for each threshold severity level */
- notification_t n = {NOTIF_OKAY, cdtime(), "", "", "ipmi", "", "", "", NULL};
unsigned int offset = (2 * threshold) + high_low;
unsigned int event_type = ipmi_sensor_get_event_reading_type(sensor);
unsigned int sensor_type = ipmi_sensor_get_sensor_type(sensor);
DEBUG("Threshold event received for sensor %s", n.type_instance);
- sstrncpy(n.host, (st->host != NULL) ? st->host : hostname_g, sizeof(n.host));
sstrncpy(n.type, ipmi_sensor_get_sensor_type_string(sensor), sizeof(n.type));
n.severity = sensor_convert_threshold_severity(threshold);
n.time = NS_TO_CDTIME_T(ipmi_event_get_timestamp(event));
if (event == NULL)
return IPMI_EVENT_NOT_HANDLED;
- notification_t n = {NOTIF_OKAY, cdtime(), "", "", "ipmi", "", "", "", NULL};
+ notification_t n = c_ipmi_notification_init(st, NOTIF_OKAY);
unsigned int event_type = ipmi_sensor_get_event_reading_type(sensor);
unsigned int sensor_type = ipmi_sensor_get_sensor_type(sensor);
const char *event_state =
DEBUG("Discrete event received for sensor %s", n.type_instance);
- sstrncpy(n.host, (st->host != NULL) ? st->host : hostname_g, sizeof(n.host));
sstrncpy(n.type, ipmi_sensor_get_sensor_type_string(sensor), sizeof(n.type));
n.time = NS_TO_CDTIME_T(ipmi_event_get_timestamp(event));
if (!still_connected) {
if (st->notify_conn && st->connected && st->init_in_progress == 0) {
- notification_t n = {NOTIF_FAILURE, cdtime(), "", "", "ipmi", "", "", "",
- NULL};
+ notification_t n = c_ipmi_notification_init(st, NOTIF_FAILURE);
- sstrncpy(n.host, (st->host != NULL) ? st->host : hostname_g,
- sizeof(n.host));
sstrncpy(n.message, "IPMI connection lost", sizeof(n.plugin));
plugin_dispatch_notification(&n);
}
if (st->notify_conn && !st->connected && st->init_in_progress == 0) {
- notification_t n = {NOTIF_OKAY, cdtime(), "", "", "ipmi", "", "", "", NULL};
+ notification_t n = c_ipmi_notification_init(st, NOTIF_OKAY);
- sstrncpy(n.host, (st->host != NULL) ? st->host : hostname_g,
- sizeof(n.host));
sstrncpy(n.message, "IPMI connection restored", sizeof(n.plugin));
plugin_dispatch_notification(&n);