diff options
Diffstat (limited to 'src/journald/instutil.c')
-rw-r--r-- | src/journald/instutil.c | 115 |
1 files changed, 82 insertions, 33 deletions
diff --git a/src/journald/instutil.c b/src/journald/instutil.c index b3987bc..0c716f8 100644 --- a/src/journald/instutil.c +++ b/src/journald/instutil.c @@ -92,6 +92,27 @@ static int dup_journal_data( return 0; } +static int get_journal_data_int( + sd_journal *j, + const char *key, + long int *out) +{ + int r; + gchar *d; + + *out = -1; + r = dup_journal_data(j, key, &d); + if (r >= 0 && d != NULL && strlen(d) > 0) { + char *conv_err = NULL; + long int i = strtol(d, &conv_err, 10); + if (conv_err == NULL || *conv_err == '\0') + *out = i; + g_free(d); + return 0; + } + return -1; +} + static int get_record_message(sd_journal *j, gboolean full_format, gchar **out) { int r; @@ -173,6 +194,7 @@ int create_LMI_JournalLogRecord(sd_journal *j, uint64_t usec; CMPIDateTime *date; gchar *d; + long int i; LMI_JournalLogRecord_Set_CreationClassName(rec, LMI_JournalLogRecord_ClassName); LMI_JournalLogRecord_Set_LogCreationClassName(rec, LMI_JournalMessageLog_ClassName); @@ -200,40 +222,67 @@ int create_LMI_JournalLogRecord(sd_journal *j, } /* Optional: PerceivedSeverity */ - r = dup_journal_data(j, "PRIORITY", &d); + if (get_journal_data_int(j, "PRIORITY", &i) >= 0) { + switch (i) { + case LOG_EMERG: + /* 7 - Fatal/NonRecoverable should be used to indicate an error occurred, + * but it's too late to take remedial action. */ + LMI_JournalLogRecord_Set_PerceivedSeverity_Fatal_NonRecoverable(rec); + break; + case LOG_ALERT: + case LOG_CRIT: + /* 6 - Critical should be used to indicate action is needed NOW and the scope + * is broad (perhaps an imminent outage to a critical resource will result). */ + LMI_JournalLogRecord_Set_PerceivedSeverity_Critical(rec); + break; + case LOG_ERR: + /* 4 - Minor should be used to indicate action is needed, but the situation + * is not serious at this time. */ + LMI_JournalLogRecord_Set_PerceivedSeverity_Minor(rec); + break; + case LOG_WARNING: + /* 3 - Degraded/Warning should be used when its appropriate to let the user + * decide if action is needed. */ + LMI_JournalLogRecord_Set_PerceivedSeverity_Degraded_Warning(rec); + break; + case LOG_NOTICE: + case LOG_INFO: + case LOG_DEBUG: + /* 2 - Information */ + LMI_JournalLogRecord_Set_PerceivedSeverity_Information(rec); + break; + } + if (i >= 0 && i <= LOG_DEBUG) + LMI_JournalLogRecord_Set_SyslogSeverity(rec, i); + } + + /* Optional: UID */ + if (get_journal_data_int(j, "_UID", &i) >= 0) + LMI_JournalLogRecord_Set_UserID(rec, i); + + /* Optional: GID */ + if (get_journal_data_int(j, "_GID", &i) >= 0) + LMI_JournalLogRecord_Set_GroupID(rec, i); + + /* Optional: PID */ + if (get_journal_data_int(j, "SYSLOG_PID", &i) >= 0 || get_journal_data_int(j, "_PID", &i) >= 0) + LMI_JournalLogRecord_Set_ProcessID(rec, i); + + /* Optional: Syslog facility */ + if (get_journal_data_int(j, "SYSLOG_FACILITY", &i) >= 0 && i < LOG_NFACILITIES) + LMI_JournalLogRecord_Set_SyslogFacility(rec, i); + + /* Optional: Syslog identifier */ + r = dup_journal_data(j, "SYSLOG_IDENTIFIER", &d); if (r >= 0 && d != NULL && strlen(d) > 0) { - char *conv_err = NULL; - long int i = strtol(d, &conv_err, 10); - if (conv_err == NULL || *conv_err == '\0') - switch (i) { - case LOG_EMERG: - /* 7 - Fatal/NonRecoverable should be used to indicate an error occurred, - * but it's too late to take remedial action. */ - LMI_JournalLogRecord_Set_PerceivedSeverity_Fatal_NonRecoverable(rec); - break; - case LOG_ALERT: - case LOG_CRIT: - /* 6 - Critical should be used to indicate action is needed NOW and the scope - * is broad (perhaps an imminent outage to a critical resource will result). */ - LMI_JournalLogRecord_Set_PerceivedSeverity_Critical(rec); - break; - case LOG_ERR: - /* 4 - Minor should be used to indicate action is needed, but the situation - * is not serious at this time. */ - LMI_JournalLogRecord_Set_PerceivedSeverity_Minor(rec); - break; - case LOG_WARNING: - /* 3 - Degraded/Warning should be used when its appropriate to let the user - * decide if action is needed. */ - LMI_JournalLogRecord_Set_PerceivedSeverity_Degraded_Warning(rec); - break; - case LOG_NOTICE: - case LOG_INFO: - case LOG_DEBUG: - /* 2 - Information */ - LMI_JournalLogRecord_Set_PerceivedSeverity_Information(rec); - break; - } + LMI_JournalLogRecord_Set_SyslogIdentifier(rec, d); + g_free(d); + } + + /* Optional: Systemd unit */ + r = dup_journal_data(j, "_SYSTEMD_UNIT", &d); + if (r >= 0 && d != NULL && strlen(d) > 0) { + LMI_JournalLogRecord_Set_SystemdUnit(rec, d); g_free(d); } |