8000 Faxm0dem/syslog notif by faxm0dem · Pull Request #3 · collectd/collectd · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Faxm0dem/syslog notif #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions src/collectd.conf.pod
Original file line number Diff line number Diff line change
Expand Up @@ -2786,7 +2786,18 @@ operating systems.
=item B<MaxPacketSize> I<1024-65535>

Set the maximum size for datagrams received over the network. Packets larger
than this will be truncated. Defaults to 1452E<nbsp>bytes.
than this will be truncated. Defaults to 1452E<nbsp>bytes, which is the maximum
payload size that can be transmitted in one Ethernet frame using IPv6E<nbsp>/
UDP.

On the server side, this limit should be set to the largest value used on
I<any> client. Likewise, the value on the client must not be larger than the
value on the server, or data will be lost.

B<Compatibility:> Versions prior to I<versionE<nbsp>4.8> used a fixed sized
buffer of 1024E<nbsp>bytes. Versions I<4.8>, I<4.9> and I<4.10> used a default
value of 1024E<nbsp>bytes to avoid problems when sending data to an older
server.

=item B<Forward> I<true|false>

Expand Down Expand Up @@ -4206,6 +4217,15 @@ syslog-daemon.
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>
Expand Down Expand Up @@ -5445,7 +5465,7 @@ convert counter values to rates.

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.
Expand Down
19 changes: 2 additions & 17 deletions src/logfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,8 @@ static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
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);
Expand Down
1 change: 1 addition & 0 deletions src/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ typedef struct receive_list_entry_s receive_list_entry_t;
* Private variables
*/
static int network_config_ttl = 0;
/* Ethernet - (IPv6 + UDP) = 1500 - (40 + 8) = 1452 */
static size_t network_config_packet_size = 1452;
static int network_config_forward = 0;
static int network_config_stats = 0;
Expand Down
38 changes: 38 additions & 0 deletions src/plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -1706,6 +1706,44 @@ void plugin_log (int level, const char *format, ...)
}
} /* 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;
Expand Down
2 changes: 2 additions & 0 deletions src/plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,8 @@ int plugin_dispatch_notification (const notification_t *notif);

void plugin_log (int level, const char *format, ...)
__attribute__ ((format(printf,2,3)));
int parse_log_severity (const char *severity);
int parse_notif_severity (const char *severity);

#define ERROR(...) plugin_log (LOG_ERR, __VA_ARGS__)
#define WARNING(...) plugin_log (LOG_WARNING, __VA_ARGS__)
Expand Down
92 changes: 72 additions & 20 deletions src/syslog.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,37 +33,26 @@ static int log_level = LOG_DEBUG;
#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);

static int sl_config (const char *key, const char *value)
{
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 */
Expand All @@ -84,11 +73,74 @@ static int sl_shutdown (void)
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) */
0