Please note that B<debug> is only available if collectd has been compiled with
debugging support.
+=item B<NotifyLevel> B<WARNING>|B<FAILURE>
+
+Controls which notifications should be sent to syslog. The default behaviour is
+not to send any. If either of C<WARNING> or C<FAILURE> is used, C<OKAY> notifications
+will also be sent to syslog.
+Notifications will be sent using severities based on their own levels. B<OKAY>
+and B<WARNING> will be sent using syslog B<WARNING> severity, whereas B<FAILURE>
+will yield a B<ERROR> syslog entry.
+
=back
=head2 Plugin C<table>
Please note that these placeholders are B<case sensitive>!
-=item B<Severity> B<"FATAL">|B<"WARNING">|B<"OKAY">
+=item B<Severity> B<"FAILURE">|B<"WARNING">|B<"OKAY">
Sets the severity of the message. If omitted, the severity B<"WARNING"> is
used.
static int logfile_config (const char *key, const char *value)
{
if (0 == strcasecmp (key, "LogLevel")) {
- if ((0 == strcasecmp (value, "emerg"))
- || (0 == strcasecmp (value, "alert"))
- || (0 == strcasecmp (value, "crit"))
- || (0 == strcasecmp (value, "err")))
- log_level = LOG_ERR;
- else if (0 == strcasecmp (value, "warning"))
- log_level = LOG_WARNING;
- else if (0 == strcasecmp (value, "notice"))
- log_level = LOG_NOTICE;
- else if (0 == strcasecmp (value, "info"))
- log_level = LOG_INFO;
-#if COLLECT_DEBUG
- else if (0 == strcasecmp (value, "debug"))
- log_level = LOG_DEBUG;
-#endif /* COLLECT_DEBUG */
- else
- return 1;
+ log_level = parse_log_severity(value);
+ if (log_level == -1) return 1; /* to keep previous behaviour */
}
else if (0 == strcasecmp (key, "File")) {
sfree (log_file);
}
} /* void plugin_log */
+int parse_log_severity (const char *severity)
+{
+ int log_level = -1;
+
+ if ((0 == strcasecmp (severity, "emerg"))
+ || (0 == strcasecmp (severity, "alert"))
+ || (0 == strcasecmp (severity, "crit"))
+ || (0 == strcasecmp (severity, "err")))
+ log_level = LOG_ERR;
+ else if (0 == strcasecmp (severity, "warning"))
+ log_level = LOG_WARNING;
+ else if (0 == strcasecmp (severity, "notice"))
+ log_level = LOG_NOTICE;
+ else if (0 == strcasecmp (severity, "info"))
+ log_level = LOG_INFO;
+#if COLLECT_DEBUG
+ else if (0 == strcasecmp (severity, "debug"))
+ log_level = LOG_DEBUG;
+#endif /* COLLECT_DEBUG */
+
+ return (log_level);
+} /* int parse_log_severity */
+
+int parse_notif_severity (const char *severity)
+{
+ int notif_severity = -1;
+
+ if (strcasecmp (severity, "FAILURE"))
+ notif_severity = NOTIF_FAILURE;
+ else if (strcmp (severity, "OKAY"))
+ notif_severity = NOTIF_OKAY;
+ else if ((strcmp (severity, "WARNING"))
+ || (strcmp (severity, "WARN")))
+ notif_severity = NOTIF_WARNING;
+
+ return (notif_severity);
+} /* int parse_notif_severity */
+
const data_set_t *plugin_get_ds (const char *name)
{
data_set_t *ds;
#else
static int log_level = LOG_INFO;
#endif /* COLLECT_DEBUG */
+static int notif_severity = -1;
static const char *config_keys[] =
{
- "LogLevel"
+ "LogLevel",
+ "NotifyLevel",
};
static int config_keys_num = STATIC_ARRAY_SIZE(config_keys);
{
if (strcasecmp (key, "LogLevel") == 0)
{
- if ((strcasecmp (value, "emerg") == 0)
- || (strcasecmp (value, "alert") == 0)
- || (strcasecmp (value, "crit") == 0)
- || (strcasecmp (value, "err") == 0))
- log_level = LOG_ERR;
- else if (strcasecmp (value, "warning") == 0)
- log_level = LOG_WARNING;
- else if (strcasecmp (value, "notice") == 0)
- log_level = LOG_NOTICE;
- else if (strcasecmp (value, "info") == 0)
- log_level = LOG_INFO;
-#if COLLECT_DEBUG
- else if (strcasecmp (value, "debug") == 0)
- log_level = LOG_DEBUG;
-#endif
- else
- return (1);
+ log_level = parse_log_severity (value);
+ if (log_level == -1) return (1);
+ }
+ else if (strcasecmp (key, "NotifyLevel") == 0)
+ {
+ notif_severity = parse_notif_severity(key);
}
- else
- return (-1);
return (0);
} /* int sl_config */
return (0);
}
+static int sl_notification (const notification_t *n,
+ user_data_t __attribute__((unused)) *user_data)
+{
+ char buf[1024] = "";
+ char *buf_ptr = buf;
+ int buf_len = sizeof (buf);
+ int status;
+ int severity;
+
+ /* do nothing if parsing of NotifSeverity failed */
+ if (notif_severity == -1)
+ return 0;
+ /* do nothing if NotifSeverity is higer than notification
+ * note that OKAY notifs will always be displayed */
+ if ((notif_severity == NOTIF_FAILURE) && (n -> severity == NOTIF_WARNING))
+ return 0;
+
+ status = ssnprintf (buf_ptr, buf_len, "Notification: severity = %s",
+ (n->severity == NOTIF_FAILURE) ? "FAILURE"
+ : ((n->severity == NOTIF_WARNING) ? "WARNING"
+ : ((n->severity == NOTIF_OKAY) ? "OKAY" : "UNKNOWN")));
+ if (status > 0)
+ {
+ buf_ptr += status;
+ buf_len -= status;
+ }
+
+#define APPEND(bufptr, buflen, key, value) \
+ if ((buflen > 0) && (strlen (value) > 0)) { \
+ int status = ssnprintf (bufptr, buflen, ", %s = %s", key, value); \
+ if (status > 0) { \
+ bufptr += status; \
+ buflen -= status; \
+ } \
+ }
+ APPEND (buf_ptr, buf_len, "host", n->host);
+ APPEND (buf_ptr, buf_len, "plugin", n->plugin);
+ APPEND (buf_ptr, buf_len, "plugin_instance", n->plugin_instance);
+ APPEND (buf_ptr, buf_len, "type", n->type);
+ APPEND (buf_ptr, buf_len, "type_instance", n->type_instance);
+ APPEND (buf_ptr, buf_len, "message", n->message);
+
+ buf[sizeof (buf) - 1] = '\0';
+
+ switch (n->severity)
+ {
+ case NOTIF_FAILURE:
+ severity = LOG_ERR;
+ break;
+ case NOTIF_WARNING:
+ severity = LOG_WARNING;
+ break;
+ case NOTIF_OKAY:
+ severity = LOG_WARNING;
+ break;
+ default: severity = LOG_INFO;
+ }
+ sl_log (severity, buf, NULL);
+
+ return (0);
+} /* int sl_notification */
+
void module_register (void)
{
openlog ("collectd", LOG_CONS | LOG_PID, LOG_DAEMON);
plugin_register_config ("syslog", sl_config, config_keys, config_keys_num);
plugin_register_log ("syslog", sl_log, /* user_data = */ NULL);
+ plugin_register_notification ("syslog", sl_notification, NULL);
plugin_register_shutdown ("syslog", sl_shutdown);
} /* void module_register(void) */