systemd-journal-annotations.c 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. #include "systemd-internals.h"
  3. const char *errno_map[] = {
  4. [1] = "1 (EPERM)", // "Operation not permitted",
  5. [2] = "2 (ENOENT)", // "No such file or directory",
  6. [3] = "3 (ESRCH)", // "No such process",
  7. [4] = "4 (EINTR)", // "Interrupted system call",
  8. [5] = "5 (EIO)", // "Input/output error",
  9. [6] = "6 (ENXIO)", // "No such device or address",
  10. [7] = "7 (E2BIG)", // "Argument list too long",
  11. [8] = "8 (ENOEXEC)", // "Exec format error",
  12. [9] = "9 (EBADF)", // "Bad file descriptor",
  13. [10] = "10 (ECHILD)", // "No child processes",
  14. [11] = "11 (EAGAIN)", // "Resource temporarily unavailable",
  15. [12] = "12 (ENOMEM)", // "Cannot allocate memory",
  16. [13] = "13 (EACCES)", // "Permission denied",
  17. [14] = "14 (EFAULT)", // "Bad address",
  18. [15] = "15 (ENOTBLK)", // "Block device required",
  19. [16] = "16 (EBUSY)", // "Device or resource busy",
  20. [17] = "17 (EEXIST)", // "File exists",
  21. [18] = "18 (EXDEV)", // "Invalid cross-device link",
  22. [19] = "19 (ENODEV)", // "No such device",
  23. [20] = "20 (ENOTDIR)", // "Not a directory",
  24. [21] = "21 (EISDIR)", // "Is a directory",
  25. [22] = "22 (EINVAL)", // "Invalid argument",
  26. [23] = "23 (ENFILE)", // "Too many open files in system",
  27. [24] = "24 (EMFILE)", // "Too many open files",
  28. [25] = "25 (ENOTTY)", // "Inappropriate ioctl for device",
  29. [26] = "26 (ETXTBSY)", // "Text file busy",
  30. [27] = "27 (EFBIG)", // "File too large",
  31. [28] = "28 (ENOSPC)", // "No space left on device",
  32. [29] = "29 (ESPIPE)", // "Illegal seek",
  33. [30] = "30 (EROFS)", // "Read-only file system",
  34. [31] = "31 (EMLINK)", // "Too many links",
  35. [32] = "32 (EPIPE)", // "Broken pipe",
  36. [33] = "33 (EDOM)", // "Numerical argument out of domain",
  37. [34] = "34 (ERANGE)", // "Numerical result out of range",
  38. [35] = "35 (EDEADLK)", // "Resource deadlock avoided",
  39. [36] = "36 (ENAMETOOLONG)", // "File name too long",
  40. [37] = "37 (ENOLCK)", // "No locks available",
  41. [38] = "38 (ENOSYS)", // "Function not implemented",
  42. [39] = "39 (ENOTEMPTY)", // "Directory not empty",
  43. [40] = "40 (ELOOP)", // "Too many levels of symbolic links",
  44. [42] = "42 (ENOMSG)", // "No message of desired type",
  45. [43] = "43 (EIDRM)", // "Identifier removed",
  46. [44] = "44 (ECHRNG)", // "Channel number out of range",
  47. [45] = "45 (EL2NSYNC)", // "Level 2 not synchronized",
  48. [46] = "46 (EL3HLT)", // "Level 3 halted",
  49. [47] = "47 (EL3RST)", // "Level 3 reset",
  50. [48] = "48 (ELNRNG)", // "Link number out of range",
  51. [49] = "49 (EUNATCH)", // "Protocol driver not attached",
  52. [50] = "50 (ENOCSI)", // "No CSI structure available",
  53. [51] = "51 (EL2HLT)", // "Level 2 halted",
  54. [52] = "52 (EBADE)", // "Invalid exchange",
  55. [53] = "53 (EBADR)", // "Invalid request descriptor",
  56. [54] = "54 (EXFULL)", // "Exchange full",
  57. [55] = "55 (ENOANO)", // "No anode",
  58. [56] = "56 (EBADRQC)", // "Invalid request code",
  59. [57] = "57 (EBADSLT)", // "Invalid slot",
  60. [59] = "59 (EBFONT)", // "Bad font file format",
  61. [60] = "60 (ENOSTR)", // "Device not a stream",
  62. [61] = "61 (ENODATA)", // "No data available",
  63. [62] = "62 (ETIME)", // "Timer expired",
  64. [63] = "63 (ENOSR)", // "Out of streams resources",
  65. [64] = "64 (ENONET)", // "Machine is not on the network",
  66. [65] = "65 (ENOPKG)", // "Package not installed",
  67. [66] = "66 (EREMOTE)", // "Object is remote",
  68. [67] = "67 (ENOLINK)", // "Link has been severed",
  69. [68] = "68 (EADV)", // "Advertise error",
  70. [69] = "69 (ESRMNT)", // "Srmount error",
  71. [70] = "70 (ECOMM)", // "Communication error on send",
  72. [71] = "71 (EPROTO)", // "Protocol error",
  73. [72] = "72 (EMULTIHOP)", // "Multihop attempted",
  74. [73] = "73 (EDOTDOT)", // "RFS specific error",
  75. [74] = "74 (EBADMSG)", // "Bad message",
  76. [75] = "75 (EOVERFLOW)", // "Value too large for defined data type",
  77. [76] = "76 (ENOTUNIQ)", // "Name not unique on network",
  78. [77] = "77 (EBADFD)", // "File descriptor in bad state",
  79. [78] = "78 (EREMCHG)", // "Remote address changed",
  80. [79] = "79 (ELIBACC)", // "Can not access a needed shared library",
  81. [80] = "80 (ELIBBAD)", // "Accessing a corrupted shared library",
  82. [81] = "81 (ELIBSCN)", // ".lib section in a.out corrupted",
  83. [82] = "82 (ELIBMAX)", // "Attempting to link in too many shared libraries",
  84. [83] = "83 (ELIBEXEC)", // "Cannot exec a shared library directly",
  85. [84] = "84 (EILSEQ)", // "Invalid or incomplete multibyte or wide character",
  86. [85] = "85 (ERESTART)", // "Interrupted system call should be restarted",
  87. [86] = "86 (ESTRPIPE)", // "Streams pipe error",
  88. [87] = "87 (EUSERS)", // "Too many users",
  89. [88] = "88 (ENOTSOCK)", // "Socket operation on non-socket",
  90. [89] = "89 (EDESTADDRREQ)", // "Destination address required",
  91. [90] = "90 (EMSGSIZE)", // "Message too long",
  92. [91] = "91 (EPROTOTYPE)", // "Protocol wrong type for socket",
  93. [92] = "92 (ENOPROTOOPT)", // "Protocol not available",
  94. [93] = "93 (EPROTONOSUPPORT)", // "Protocol not supported",
  95. [94] = "94 (ESOCKTNOSUPPORT)", // "Socket type not supported",
  96. [95] = "95 (ENOTSUP)", // "Operation not supported",
  97. [96] = "96 (EPFNOSUPPORT)", // "Protocol family not supported",
  98. [97] = "97 (EAFNOSUPPORT)", // "Address family not supported by protocol",
  99. [98] = "98 (EADDRINUSE)", // "Address already in use",
  100. [99] = "99 (EADDRNOTAVAIL)", // "Cannot assign requested address",
  101. [100] = "100 (ENETDOWN)", // "Network is down",
  102. [101] = "101 (ENETUNREACH)", // "Network is unreachable",
  103. [102] = "102 (ENETRESET)", // "Network dropped connection on reset",
  104. [103] = "103 (ECONNABORTED)", // "Software caused connection abort",
  105. [104] = "104 (ECONNRESET)", // "Connection reset by peer",
  106. [105] = "105 (ENOBUFS)", // "No buffer space available",
  107. [106] = "106 (EISCONN)", // "Transport endpoint is already connected",
  108. [107] = "107 (ENOTCONN)", // "Transport endpoint is not connected",
  109. [108] = "108 (ESHUTDOWN)", // "Cannot send after transport endpoint shutdown",
  110. [109] = "109 (ETOOMANYREFS)", // "Too many references: cannot splice",
  111. [110] = "110 (ETIMEDOUT)", // "Connection timed out",
  112. [111] = "111 (ECONNREFUSED)", // "Connection refused",
  113. [112] = "112 (EHOSTDOWN)", // "Host is down",
  114. [113] = "113 (EHOSTUNREACH)", // "No route to host",
  115. [114] = "114 (EALREADY)", // "Operation already in progress",
  116. [115] = "115 (EINPROGRESS)", // "Operation now in progress",
  117. [116] = "116 (ESTALE)", // "Stale file handle",
  118. [117] = "117 (EUCLEAN)", // "Structure needs cleaning",
  119. [118] = "118 (ENOTNAM)", // "Not a XENIX named type file",
  120. [119] = "119 (ENAVAIL)", // "No XENIX semaphores available",
  121. [120] = "120 (EISNAM)", // "Is a named type file",
  122. [121] = "121 (EREMOTEIO)", // "Remote I/O error",
  123. [122] = "122 (EDQUOT)", // "Disk quota exceeded",
  124. [123] = "123 (ENOMEDIUM)", // "No medium found",
  125. [124] = "124 (EMEDIUMTYPE)", // "Wrong medium type",
  126. [125] = "125 (ECANCELED)", // "Operation canceled",
  127. [126] = "126 (ENOKEY)", // "Required key not available",
  128. [127] = "127 (EKEYEXPIRED)", // "Key has expired",
  129. [128] = "128 (EKEYREVOKED)", // "Key has been revoked",
  130. [129] = "129 (EKEYREJECTED)", // "Key was rejected by service",
  131. [130] = "130 (EOWNERDEAD)", // "Owner died",
  132. [131] = "131 (ENOTRECOVERABLE)", // "State not recoverable",
  133. [132] = "132 (ERFKILL)", // "Operation not possible due to RF-kill",
  134. [133] = "133 (EHWPOISON)", // "Memory page has hardware error",
  135. };
  136. const char *linux_capabilities[] = {
  137. [CAP_CHOWN] = "CHOWN",
  138. [CAP_DAC_OVERRIDE] = "DAC_OVERRIDE",
  139. [CAP_DAC_READ_SEARCH] = "DAC_READ_SEARCH",
  140. [CAP_FOWNER] = "FOWNER",
  141. [CAP_FSETID] = "FSETID",
  142. [CAP_KILL] = "KILL",
  143. [CAP_SETGID] = "SETGID",
  144. [CAP_SETUID] = "SETUID",
  145. [CAP_SETPCAP] = "SETPCAP",
  146. [CAP_LINUX_IMMUTABLE] = "LINUX_IMMUTABLE",
  147. [CAP_NET_BIND_SERVICE] = "NET_BIND_SERVICE",
  148. [CAP_NET_BROADCAST] = "NET_BROADCAST",
  149. [CAP_NET_ADMIN] = "NET_ADMIN",
  150. [CAP_NET_RAW] = "NET_RAW",
  151. [CAP_IPC_LOCK] = "IPC_LOCK",
  152. [CAP_IPC_OWNER] = "IPC_OWNER",
  153. [CAP_SYS_MODULE] = "SYS_MODULE",
  154. [CAP_SYS_RAWIO] = "SYS_RAWIO",
  155. [CAP_SYS_CHROOT] = "SYS_CHROOT",
  156. [CAP_SYS_PTRACE] = "SYS_PTRACE",
  157. [CAP_SYS_PACCT] = "SYS_PACCT",
  158. [CAP_SYS_ADMIN] = "SYS_ADMIN",
  159. [CAP_SYS_BOOT] = "SYS_BOOT",
  160. [CAP_SYS_NICE] = "SYS_NICE",
  161. [CAP_SYS_RESOURCE] = "SYS_RESOURCE",
  162. [CAP_SYS_TIME] = "SYS_TIME",
  163. [CAP_SYS_TTY_CONFIG] = "SYS_TTY_CONFIG",
  164. [CAP_MKNOD] = "MKNOD",
  165. [CAP_LEASE] = "LEASE",
  166. [CAP_AUDIT_WRITE] = "AUDIT_WRITE",
  167. [CAP_AUDIT_CONTROL] = "AUDIT_CONTROL",
  168. [CAP_SETFCAP] = "SETFCAP",
  169. [CAP_MAC_OVERRIDE] = "MAC_OVERRIDE",
  170. [CAP_MAC_ADMIN] = "MAC_ADMIN",
  171. [CAP_SYSLOG] = "SYSLOG",
  172. [CAP_WAKE_ALARM] = "WAKE_ALARM",
  173. [CAP_BLOCK_SUSPEND] = "BLOCK_SUSPEND",
  174. [37 /*CAP_AUDIT_READ*/] = "AUDIT_READ",
  175. [38 /*CAP_PERFMON*/] = "PERFMON",
  176. [39 /*CAP_BPF*/] = "BPF",
  177. [40 /* CAP_CHECKPOINT_RESTORE */] = "CHECKPOINT_RESTORE",
  178. };
  179. static const char *syslog_facility_to_name(int facility) {
  180. switch (facility) {
  181. case LOG_FAC(LOG_KERN): return "kern";
  182. case LOG_FAC(LOG_USER): return "user";
  183. case LOG_FAC(LOG_MAIL): return "mail";
  184. case LOG_FAC(LOG_DAEMON): return "daemon";
  185. case LOG_FAC(LOG_AUTH): return "auth";
  186. case LOG_FAC(LOG_SYSLOG): return "syslog";
  187. case LOG_FAC(LOG_LPR): return "lpr";
  188. case LOG_FAC(LOG_NEWS): return "news";
  189. case LOG_FAC(LOG_UUCP): return "uucp";
  190. case LOG_FAC(LOG_CRON): return "cron";
  191. case LOG_FAC(LOG_AUTHPRIV): return "authpriv";
  192. case LOG_FAC(LOG_FTP): return "ftp";
  193. case LOG_FAC(LOG_LOCAL0): return "local0";
  194. case LOG_FAC(LOG_LOCAL1): return "local1";
  195. case LOG_FAC(LOG_LOCAL2): return "local2";
  196. case LOG_FAC(LOG_LOCAL3): return "local3";
  197. case LOG_FAC(LOG_LOCAL4): return "local4";
  198. case LOG_FAC(LOG_LOCAL5): return "local5";
  199. case LOG_FAC(LOG_LOCAL6): return "local6";
  200. case LOG_FAC(LOG_LOCAL7): return "local7";
  201. default: return NULL;
  202. }
  203. }
  204. static const char *syslog_priority_to_name(int priority) {
  205. switch (priority) {
  206. case LOG_ALERT: return "alert";
  207. case LOG_CRIT: return "critical";
  208. case LOG_DEBUG: return "debug";
  209. case LOG_EMERG: return "panic";
  210. case LOG_ERR: return "error";
  211. case LOG_INFO: return "info";
  212. case LOG_NOTICE: return "notice";
  213. case LOG_WARNING: return "warning";
  214. default: return NULL;
  215. }
  216. }
  217. FACET_ROW_SEVERITY syslog_priority_to_facet_severity(FACETS *facets __maybe_unused, FACET_ROW *row, void *data __maybe_unused) {
  218. // same to
  219. // https://github.com/systemd/systemd/blob/aab9e4b2b86905a15944a1ac81e471b5b7075932/src/basic/terminal-util.c#L1501
  220. // function get_log_colors()
  221. FACET_ROW_KEY_VALUE *priority_rkv = dictionary_get(row->dict, "PRIORITY");
  222. if(!priority_rkv || priority_rkv->empty)
  223. return FACET_ROW_SEVERITY_NORMAL;
  224. int priority = str2i(buffer_tostring(priority_rkv->wb));
  225. if(priority <= LOG_ERR)
  226. return FACET_ROW_SEVERITY_CRITICAL;
  227. else if (priority <= LOG_WARNING)
  228. return FACET_ROW_SEVERITY_WARNING;
  229. else if(priority <= LOG_NOTICE)
  230. return FACET_ROW_SEVERITY_NOTICE;
  231. else if(priority >= LOG_DEBUG)
  232. return FACET_ROW_SEVERITY_DEBUG;
  233. return FACET_ROW_SEVERITY_NORMAL;
  234. }
  235. static char *uid_to_username(uid_t uid, char *buffer, size_t buffer_size) {
  236. static __thread char tmp[1024 + 1];
  237. struct passwd pw, *result = NULL;
  238. if (getpwuid_r(uid, &pw, tmp, sizeof(tmp), &result) != 0 || !result || !pw.pw_name || !(*pw.pw_name))
  239. snprintfz(buffer, buffer_size - 1, "%u", uid);
  240. else
  241. snprintfz(buffer, buffer_size - 1, "%u (%s)", uid, pw.pw_name);
  242. return buffer;
  243. }
  244. static char *gid_to_groupname(gid_t gid, char* buffer, size_t buffer_size) {
  245. static __thread char tmp[1024];
  246. struct group grp, *result = NULL;
  247. if (getgrgid_r(gid, &grp, tmp, sizeof(tmp), &result) != 0 || !result || !grp.gr_name || !(*grp.gr_name))
  248. snprintfz(buffer, buffer_size - 1, "%u", gid);
  249. else
  250. snprintfz(buffer, buffer_size - 1, "%u (%s)", gid, grp.gr_name);
  251. return buffer;
  252. }
  253. void netdata_systemd_journal_transform_syslog_facility(FACETS *facets __maybe_unused, BUFFER *wb, FACETS_TRANSFORMATION_SCOPE scope __maybe_unused, void *data __maybe_unused) {
  254. const char *v = buffer_tostring(wb);
  255. if(*v && isdigit(*v)) {
  256. int facility = str2i(buffer_tostring(wb));
  257. const char *name = syslog_facility_to_name(facility);
  258. if (name) {
  259. buffer_flush(wb);
  260. buffer_strcat(wb, name);
  261. }
  262. }
  263. }
  264. void netdata_systemd_journal_transform_priority(FACETS *facets __maybe_unused, BUFFER *wb, FACETS_TRANSFORMATION_SCOPE scope __maybe_unused, void *data __maybe_unused) {
  265. if(scope == FACETS_TRANSFORM_FACET_SORT)
  266. return;
  267. const char *v = buffer_tostring(wb);
  268. if(*v && isdigit(*v)) {
  269. int priority = str2i(buffer_tostring(wb));
  270. const char *name = syslog_priority_to_name(priority);
  271. if (name) {
  272. buffer_flush(wb);
  273. buffer_strcat(wb, name);
  274. }
  275. }
  276. }
  277. void netdata_systemd_journal_transform_errno(FACETS *facets __maybe_unused, BUFFER *wb, FACETS_TRANSFORMATION_SCOPE scope __maybe_unused, void *data __maybe_unused) {
  278. if(scope == FACETS_TRANSFORM_FACET_SORT)
  279. return;
  280. const char *v = buffer_tostring(wb);
  281. if(*v && isdigit(*v)) {
  282. unsigned err_no = str2u(buffer_tostring(wb));
  283. if(err_no > 0 && err_no < sizeof(errno_map) / sizeof(*errno_map)) {
  284. const char *name = errno_map[err_no];
  285. if(name) {
  286. buffer_flush(wb);
  287. buffer_strcat(wb, name);
  288. }
  289. }
  290. }
  291. }
  292. // ----------------------------------------------------------------------------
  293. // UID and GID transformation
  294. #define UID_GID_HASHTABLE_SIZE 10000
  295. struct word_t2str_hashtable_entry {
  296. struct word_t2str_hashtable_entry *next;
  297. Word_t hash;
  298. size_t len;
  299. char str[];
  300. };
  301. struct word_t2str_hashtable {
  302. SPINLOCK spinlock;
  303. size_t size;
  304. struct word_t2str_hashtable_entry *hashtable[UID_GID_HASHTABLE_SIZE];
  305. };
  306. struct word_t2str_hashtable uid_hashtable = {
  307. .size = UID_GID_HASHTABLE_SIZE,
  308. };
  309. struct word_t2str_hashtable gid_hashtable = {
  310. .size = UID_GID_HASHTABLE_SIZE,
  311. };
  312. struct word_t2str_hashtable_entry **word_t2str_hashtable_slot(struct word_t2str_hashtable *ht, Word_t hash) {
  313. size_t slot = hash % ht->size;
  314. struct word_t2str_hashtable_entry **e = &ht->hashtable[slot];
  315. while(*e && (*e)->hash != hash)
  316. e = &((*e)->next);
  317. return e;
  318. }
  319. const char *uid_to_username_cached(uid_t uid, size_t *length) {
  320. spinlock_lock(&uid_hashtable.spinlock);
  321. struct word_t2str_hashtable_entry **e = word_t2str_hashtable_slot(&uid_hashtable, uid);
  322. if(!(*e)) {
  323. static __thread char buf[1024];
  324. const char *name = uid_to_username(uid, buf, sizeof(buf));
  325. size_t size = strlen(name) + 1;
  326. *e = callocz(1, sizeof(struct word_t2str_hashtable_entry) + size);
  327. (*e)->len = size - 1;
  328. (*e)->hash = uid;
  329. memcpy((*e)->str, name, size);
  330. }
  331. spinlock_unlock(&uid_hashtable.spinlock);
  332. *length = (*e)->len;
  333. return (*e)->str;
  334. }
  335. const char *gid_to_groupname_cached(gid_t gid, size_t *length) {
  336. spinlock_lock(&gid_hashtable.spinlock);
  337. struct word_t2str_hashtable_entry **e = word_t2str_hashtable_slot(&gid_hashtable, gid);
  338. if(!(*e)) {
  339. static __thread char buf[1024];
  340. const char *name = gid_to_groupname(gid, buf, sizeof(buf));
  341. size_t size = strlen(name) + 1;
  342. *e = callocz(1, sizeof(struct word_t2str_hashtable_entry) + size);
  343. (*e)->len = size - 1;
  344. (*e)->hash = gid;
  345. memcpy((*e)->str, name, size);
  346. }
  347. spinlock_unlock(&gid_hashtable.spinlock);
  348. *length = (*e)->len;
  349. return (*e)->str;
  350. }
  351. DICTIONARY *boot_ids_to_first_ut = NULL;
  352. void netdata_systemd_journal_transform_boot_id(FACETS *facets __maybe_unused, BUFFER *wb, FACETS_TRANSFORMATION_SCOPE scope __maybe_unused, void *data __maybe_unused) {
  353. const char *boot_id = buffer_tostring(wb);
  354. if(*boot_id && isxdigit(*boot_id)) {
  355. usec_t ut = UINT64_MAX;
  356. usec_t *p_ut = dictionary_get(boot_ids_to_first_ut, boot_id);
  357. if(!p_ut) {
  358. #ifndef HAVE_SD_JOURNAL_RESTART_FIELDS
  359. struct journal_file *jf;
  360. dfe_start_read(journal_files_registry, jf) {
  361. const char *files[2] = {
  362. [0] = jf_dfe.name,
  363. [1] = NULL,
  364. };
  365. sd_journal *j = NULL;
  366. int r = sd_journal_open_files(&j, files, ND_SD_JOURNAL_OPEN_FLAGS);
  367. if(r < 0 || !j) {
  368. internal_error(true, "JOURNAL: while looking for the first timestamp of boot_id '%s', "
  369. "sd_journal_open_files('%s') returned %d",
  370. boot_id, jf_dfe.name, r);
  371. continue;
  372. }
  373. ut = journal_file_update_annotation_boot_id(j, jf, boot_id);
  374. sd_journal_close(j);
  375. }
  376. dfe_done(jf);
  377. #endif
  378. }
  379. else
  380. ut = *p_ut;
  381. if(ut && ut != UINT64_MAX) {
  382. char buffer[RFC3339_MAX_LENGTH];
  383. rfc3339_datetime_ut(buffer, sizeof(buffer), ut, 0, true);
  384. switch(scope) {
  385. default:
  386. case FACETS_TRANSFORM_DATA:
  387. case FACETS_TRANSFORM_VALUE:
  388. buffer_sprintf(wb, " (%s) ", buffer);
  389. break;
  390. case FACETS_TRANSFORM_FACET:
  391. case FACETS_TRANSFORM_FACET_SORT:
  392. case FACETS_TRANSFORM_HISTOGRAM:
  393. buffer_flush(wb);
  394. buffer_sprintf(wb, "%s", buffer);
  395. break;
  396. }
  397. }
  398. }
  399. }
  400. void netdata_systemd_journal_transform_uid(FACETS *facets __maybe_unused, BUFFER *wb, FACETS_TRANSFORMATION_SCOPE scope __maybe_unused, void *data __maybe_unused) {
  401. if(scope == FACETS_TRANSFORM_FACET_SORT)
  402. return;
  403. const char *v = buffer_tostring(wb);
  404. if(*v && isdigit(*v)) {
  405. uid_t uid = str2i(buffer_tostring(wb));
  406. size_t len;
  407. const char *name = uid_to_username_cached(uid, &len);
  408. buffer_contents_replace(wb, name, len);
  409. }
  410. }
  411. void netdata_systemd_journal_transform_gid(FACETS *facets __maybe_unused, BUFFER *wb, FACETS_TRANSFORMATION_SCOPE scope __maybe_unused, void *data __maybe_unused) {
  412. if(scope == FACETS_TRANSFORM_FACET_SORT)
  413. return;
  414. const char *v = buffer_tostring(wb);
  415. if(*v && isdigit(*v)) {
  416. gid_t gid = str2i(buffer_tostring(wb));
  417. size_t len;
  418. const char *name = gid_to_groupname_cached(gid, &len);
  419. buffer_contents_replace(wb, name, len);
  420. }
  421. }
  422. void netdata_systemd_journal_transform_cap_effective(FACETS *facets __maybe_unused, BUFFER *wb, FACETS_TRANSFORMATION_SCOPE scope __maybe_unused, void *data __maybe_unused) {
  423. if(scope == FACETS_TRANSFORM_FACET_SORT)
  424. return;
  425. const char *v = buffer_tostring(wb);
  426. if(*v && isdigit(*v)) {
  427. uint64_t cap = strtoul(buffer_tostring(wb), NULL, 16);
  428. if(cap) {
  429. buffer_fast_strcat(wb, " (", 2);
  430. for (size_t i = 0, added = 0; i < sizeof(linux_capabilities) / sizeof(linux_capabilities[0]); i++) {
  431. if (linux_capabilities[i] && (cap & (1ULL << i))) {
  432. if (added)
  433. buffer_fast_strcat(wb, " | ", 3);
  434. buffer_strcat(wb, linux_capabilities[i]);
  435. added++;
  436. }
  437. }
  438. buffer_fast_strcat(wb, ")", 1);
  439. }
  440. }
  441. }
  442. void netdata_systemd_journal_transform_timestamp_usec(FACETS *facets __maybe_unused, BUFFER *wb, FACETS_TRANSFORMATION_SCOPE scope __maybe_unused, void *data __maybe_unused) {
  443. if(scope == FACETS_TRANSFORM_FACET_SORT)
  444. return;
  445. const char *v = buffer_tostring(wb);
  446. if(*v && isdigit(*v)) {
  447. uint64_t ut = str2ull(buffer_tostring(wb), NULL);
  448. if(ut) {
  449. char buffer[RFC3339_MAX_LENGTH];
  450. rfc3339_datetime_ut(buffer, sizeof(buffer), ut, 6, true);
  451. buffer_sprintf(wb, " (%s)", buffer);
  452. }
  453. }
  454. }
  455. // ----------------------------------------------------------------------------
  456. void netdata_systemd_journal_dynamic_row_id(FACETS *facets __maybe_unused, BUFFER *json_array, FACET_ROW_KEY_VALUE *rkv, FACET_ROW *row, void *data __maybe_unused) {
  457. FACET_ROW_KEY_VALUE *pid_rkv = dictionary_get(row->dict, "_PID");
  458. const char *pid = pid_rkv ? buffer_tostring(pid_rkv->wb) : FACET_VALUE_UNSET;
  459. const char *identifier = NULL;
  460. FACET_ROW_KEY_VALUE *container_name_rkv = dictionary_get(row->dict, "CONTAINER_NAME");
  461. if(container_name_rkv && !container_name_rkv->empty)
  462. identifier = buffer_tostring(container_name_rkv->wb);
  463. if(!identifier) {
  464. FACET_ROW_KEY_VALUE *syslog_identifier_rkv = dictionary_get(row->dict, "SYSLOG_IDENTIFIER");
  465. if(syslog_identifier_rkv && !syslog_identifier_rkv->empty)
  466. identifier = buffer_tostring(syslog_identifier_rkv->wb);
  467. if(!identifier) {
  468. FACET_ROW_KEY_VALUE *comm_rkv = dictionary_get(row->dict, "_COMM");
  469. if(comm_rkv && !comm_rkv->empty)
  470. identifier = buffer_tostring(comm_rkv->wb);
  471. }
  472. }
  473. buffer_flush(rkv->wb);
  474. if(!identifier || !*identifier)
  475. buffer_strcat(rkv->wb, FACET_VALUE_UNSET);
  476. else if(!pid || !*pid)
  477. buffer_sprintf(rkv->wb, "%s", identifier);
  478. else
  479. buffer_sprintf(rkv->wb, "%s[%s]", identifier, pid);
  480. buffer_json_add_array_item_string(json_array, buffer_tostring(rkv->wb));
  481. }
  482. // ----------------------------------------------------------------------------
  483. struct message_id_info {
  484. const char *msg;
  485. };
  486. static DICTIONARY *known_journal_messages_ids = NULL;
  487. void netdata_systemd_journal_message_ids_init(void) {
  488. known_journal_messages_ids = dictionary_create(DICT_OPTION_DONT_OVERWRITE_VALUE);
  489. struct message_id_info i = { 0 };
  490. i.msg = "Journal start"; dictionary_set(known_journal_messages_ids, "f77379a8490b408bbe5f6940505a777b", &i, sizeof(i));
  491. i.msg = "Journal stop"; dictionary_set(known_journal_messages_ids, "d93fb3c9c24d451a97cea615ce59c00b", &i, sizeof(i));
  492. i.msg = "Journal dropped"; dictionary_set(known_journal_messages_ids, "a596d6fe7bfa4994828e72309e95d61e", &i, sizeof(i));
  493. i.msg = "Journal missed"; dictionary_set(known_journal_messages_ids, "e9bf28e6e834481bb6f48f548ad13606", &i, sizeof(i));
  494. i.msg = "Journal usage"; dictionary_set(known_journal_messages_ids, "ec387f577b844b8fa948f33cad9a75e6", &i, sizeof(i));
  495. i.msg = "Coredump"; dictionary_set(known_journal_messages_ids, "fc2e22bc6ee647b6b90729ab34a250b1", &i, sizeof(i));
  496. i.msg = "Truncated core"; dictionary_set(known_journal_messages_ids, "5aadd8e954dc4b1a8c954d63fd9e1137", &i, sizeof(i));
  497. i.msg = "Backtrace"; dictionary_set(known_journal_messages_ids, "1f4e0a44a88649939aaea34fc6da8c95", &i, sizeof(i));
  498. i.msg = "Session start"; dictionary_set(known_journal_messages_ids, "8d45620c1a4348dbb17410da57c60c66", &i, sizeof(i));
  499. i.msg = "Session stop"; dictionary_set(known_journal_messages_ids, "3354939424b4456d9802ca8333ed424a", &i, sizeof(i));
  500. i.msg = "Seat start"; dictionary_set(known_journal_messages_ids, "fcbefc5da23d428093f97c82a9290f7b", &i, sizeof(i));
  501. i.msg = "Seat stop"; dictionary_set(known_journal_messages_ids, "e7852bfe46784ed0accde04bc864c2d5", &i, sizeof(i));
  502. i.msg = "Machine start"; dictionary_set(known_journal_messages_ids, "24d8d4452573402496068381a6312df2", &i, sizeof(i));
  503. i.msg = "Machine stop"; dictionary_set(known_journal_messages_ids, "58432bd3bace477cb514b56381b8a758", &i, sizeof(i));
  504. i.msg = "Time change"; dictionary_set(known_journal_messages_ids, "c7a787079b354eaaa9e77b371893cd27", &i, sizeof(i));
  505. i.msg = "Timezone change"; dictionary_set(known_journal_messages_ids, "45f82f4aef7a4bbf942ce861d1f20990", &i, sizeof(i));
  506. i.msg = "Tainted"; dictionary_set(known_journal_messages_ids, "50876a9db00f4c40bde1a2ad381c3a1b", &i, sizeof(i));
  507. i.msg = "Startup finished"; dictionary_set(known_journal_messages_ids, "b07a249cd024414a82dd00cd181378ff", &i, sizeof(i));
  508. i.msg = "User startup finished"; dictionary_set(known_journal_messages_ids, "eed00a68ffd84e31882105fd973abdd1", &i, sizeof(i));
  509. i.msg = "Sleep start"; dictionary_set(known_journal_messages_ids, "6bbd95ee977941e497c48be27c254128", &i, sizeof(i));
  510. i.msg = "Sleep stop"; dictionary_set(known_journal_messages_ids, "8811e6df2a8e40f58a94cea26f8ebf14", &i, sizeof(i));
  511. i.msg = "Shutdown"; dictionary_set(known_journal_messages_ids, "98268866d1d54a499c4e98921d93bc40", &i, sizeof(i));
  512. i.msg = "Factory reset"; dictionary_set(known_journal_messages_ids, "c14aaf76ec284a5fa1f105f88dfb061c", &i, sizeof(i));
  513. i.msg = "Crash exit"; dictionary_set(known_journal_messages_ids, "d9ec5e95e4b646aaaea2fd05214edbda", &i, sizeof(i));
  514. i.msg = "Crash failed"; dictionary_set(known_journal_messages_ids, "3ed0163e868a4417ab8b9e210407a96c", &i, sizeof(i));
  515. i.msg = "Crash freeze"; dictionary_set(known_journal_messages_ids, "645c735537634ae0a32b15a7c6cba7d4", &i, sizeof(i));
  516. i.msg = "Crash no coredump"; dictionary_set(known_journal_messages_ids, "5addb3a06a734d3396b794bf98fb2d01", &i, sizeof(i));
  517. i.msg = "Crash no fork"; dictionary_set(known_journal_messages_ids, "5c9e98de4ab94c6a9d04d0ad793bd903", &i, sizeof(i));
  518. i.msg = "Crash unknown signal"; dictionary_set(known_journal_messages_ids, "5e6f1f5e4db64a0eaee3368249d20b94", &i, sizeof(i));
  519. i.msg = "Crash systemd signal"; dictionary_set(known_journal_messages_ids, "83f84b35ee264f74a3896a9717af34cb", &i, sizeof(i));
  520. i.msg = "Crash process signal"; dictionary_set(known_journal_messages_ids, "3a73a98baf5b4b199929e3226c0be783", &i, sizeof(i));
  521. i.msg = "Crash waitpid failed"; dictionary_set(known_journal_messages_ids, "2ed18d4f78ca47f0a9bc25271c26adb4", &i, sizeof(i));
  522. i.msg = "Crash coredump failed"; dictionary_set(known_journal_messages_ids, "56b1cd96f24246c5b607666fda952356", &i, sizeof(i));
  523. i.msg = "Crash coredump pid"; dictionary_set(known_journal_messages_ids, "4ac7566d4d7548f4981f629a28f0f829", &i, sizeof(i));
  524. i.msg = "Crash shell fork failed"; dictionary_set(known_journal_messages_ids, "38e8b1e039ad469291b18b44c553a5b7", &i, sizeof(i));
  525. i.msg = "Crash execle failed"; dictionary_set(known_journal_messages_ids, "872729b47dbe473eb768ccecd477beda", &i, sizeof(i));
  526. i.msg = "Selinux failed"; dictionary_set(known_journal_messages_ids, "658a67adc1c940b3b3316e7e8628834a", &i, sizeof(i));
  527. i.msg = "Battery low warning"; dictionary_set(known_journal_messages_ids, "e6f456bd92004d9580160b2207555186", &i, sizeof(i));
  528. i.msg = "Battery low poweroff"; dictionary_set(known_journal_messages_ids, "267437d33fdd41099ad76221cc24a335", &i, sizeof(i));
  529. i.msg = "Core mainloop failed"; dictionary_set(known_journal_messages_ids, "79e05b67bc4545d1922fe47107ee60c5", &i, sizeof(i));
  530. i.msg = "Core no xdgdir path"; dictionary_set(known_journal_messages_ids, "dbb136b10ef4457ba47a795d62f108c9", &i, sizeof(i));
  531. i.msg = "Core capability bounding user"; dictionary_set(known_journal_messages_ids, "ed158c2df8884fa584eead2d902c1032", &i, sizeof(i));
  532. i.msg = "Core capability bounding"; dictionary_set(known_journal_messages_ids, "42695b500df048298bee37159caa9f2e", &i, sizeof(i));
  533. i.msg = "Core disable privileges"; dictionary_set(known_journal_messages_ids, "bfc2430724ab44499735b4f94cca9295", &i, sizeof(i));
  534. i.msg = "Core start target failed"; dictionary_set(known_journal_messages_ids, "59288af523be43a28d494e41e26e4510", &i, sizeof(i));
  535. i.msg = "Core isolate target failed"; dictionary_set(known_journal_messages_ids, "689b4fcc97b4486ea5da92db69c9e314", &i, sizeof(i));
  536. i.msg = "Core fd set failed"; dictionary_set(known_journal_messages_ids, "5ed836f1766f4a8a9fc5da45aae23b29", &i, sizeof(i));
  537. i.msg = "Core pid1 environment"; dictionary_set(known_journal_messages_ids, "6a40fbfbd2ba4b8db02fb40c9cd090d7", &i, sizeof(i));
  538. i.msg = "Core manager allocate"; dictionary_set(known_journal_messages_ids, "0e54470984ac419689743d957a119e2e", &i, sizeof(i));
  539. i.msg = "Smack failed write"; dictionary_set(known_journal_messages_ids, "d67fa9f847aa4b048a2ae33535331adb", &i, sizeof(i));
  540. i.msg = "Shutdown error"; dictionary_set(known_journal_messages_ids, "af55a6f75b544431b72649f36ff6d62c", &i, sizeof(i));
  541. i.msg = "Valgrind helper fork"; dictionary_set(known_journal_messages_ids, "d18e0339efb24a068d9c1060221048c2", &i, sizeof(i));
  542. i.msg = "Unit starting"; dictionary_set(known_journal_messages_ids, "7d4958e842da4a758f6c1cdc7b36dcc5", &i, sizeof(i));
  543. i.msg = "Unit started"; dictionary_set(known_journal_messages_ids, "39f53479d3a045ac8e11786248231fbf", &i, sizeof(i));
  544. i.msg = "Unit failed"; dictionary_set(known_journal_messages_ids, "be02cf6855d2428ba40df7e9d022f03d", &i, sizeof(i));
  545. i.msg = "Unit stopping"; dictionary_set(known_journal_messages_ids, "de5b426a63be47a7b6ac3eaac82e2f6f", &i, sizeof(i));
  546. i.msg = "Unit stopped"; dictionary_set(known_journal_messages_ids, "9d1aaa27d60140bd96365438aad20286", &i, sizeof(i));
  547. i.msg = "Unit reloading"; dictionary_set(known_journal_messages_ids, "d34d037fff1847e6ae669a370e694725", &i, sizeof(i));
  548. i.msg = "Unit reloaded"; dictionary_set(known_journal_messages_ids, "7b05ebc668384222baa8881179cfda54", &i, sizeof(i));
  549. i.msg = "Unit restart scheduled"; dictionary_set(known_journal_messages_ids, "5eb03494b6584870a536b337290809b3", &i, sizeof(i));
  550. i.msg = "Unit resources"; dictionary_set(known_journal_messages_ids, "ae8f7b866b0347b9af31fe1c80b127c0", &i, sizeof(i));
  551. i.msg = "Unit success"; dictionary_set(known_journal_messages_ids, "7ad2d189f7e94e70a38c781354912448", &i, sizeof(i));
  552. i.msg = "Unit skipped"; dictionary_set(known_journal_messages_ids, "0e4284a0caca4bfc81c0bb6786972673", &i, sizeof(i));
  553. i.msg = "Unit failure result"; dictionary_set(known_journal_messages_ids, "d9b373ed55a64feb8242e02dbe79a49c", &i, sizeof(i));
  554. i.msg = "Spawn failed"; dictionary_set(known_journal_messages_ids, "641257651c1b4ec9a8624d7a40a9e1e7", &i, sizeof(i));
  555. i.msg = "Unit process exit"; dictionary_set(known_journal_messages_ids, "98e322203f7a4ed290d09fe03c09fe15", &i, sizeof(i));
  556. i.msg = "Forward syslog missed"; dictionary_set(known_journal_messages_ids, "0027229ca0644181a76c4e92458afa2e", &i, sizeof(i));
  557. i.msg = "Overmounting"; dictionary_set(known_journal_messages_ids, "1dee0369c7fc4736b7099b38ecb46ee7", &i, sizeof(i));
  558. i.msg = "Unit oomd kill"; dictionary_set(known_journal_messages_ids, "d989611b15e44c9dbf31e3c81256e4ed", &i, sizeof(i));
  559. i.msg = "Unit out of memory"; dictionary_set(known_journal_messages_ids, "fe6faa94e7774663a0da52717891d8ef", &i, sizeof(i));
  560. i.msg = "Lid opened"; dictionary_set(known_journal_messages_ids, "b72ea4a2881545a0b50e200e55b9b06f", &i, sizeof(i));
  561. i.msg = "Lid closed"; dictionary_set(known_journal_messages_ids, "b72ea4a2881545a0b50e200e55b9b070", &i, sizeof(i));
  562. i.msg = "System docked"; dictionary_set(known_journal_messages_ids, "f5f416b862074b28927a48c3ba7d51ff", &i, sizeof(i));
  563. i.msg = "System undocked"; dictionary_set(known_journal_messages_ids, "51e171bd585248568110144c517cca53", &i, sizeof(i));
  564. i.msg = "Power key"; dictionary_set(known_journal_messages_ids, "b72ea4a2881545a0b50e200e55b9b071", &i, sizeof(i));
  565. i.msg = "Power key long press"; dictionary_set(known_journal_messages_ids, "3e0117101eb243c1b9a50db3494ab10b", &i, sizeof(i));
  566. i.msg = "Reboot key"; dictionary_set(known_journal_messages_ids, "9fa9d2c012134ec385451ffe316f97d0", &i, sizeof(i));
  567. i.msg = "Reboot key long press"; dictionary_set(known_journal_messages_ids, "f1c59a58c9d943668965c337caec5975", &i, sizeof(i));
  568. i.msg = "Suspend key"; dictionary_set(known_journal_messages_ids, "b72ea4a2881545a0b50e200e55b9b072", &i, sizeof(i));
  569. i.msg = "Suspend key long press"; dictionary_set(known_journal_messages_ids, "bfdaf6d312ab4007bc1fe40a15df78e8", &i, sizeof(i));
  570. i.msg = "Hibernate key"; dictionary_set(known_journal_messages_ids, "b72ea4a2881545a0b50e200e55b9b073", &i, sizeof(i));
  571. i.msg = "Hibernate key long press"; dictionary_set(known_journal_messages_ids, "167836df6f7f428e98147227b2dc8945", &i, sizeof(i));
  572. i.msg = "Invalid configuration"; dictionary_set(known_journal_messages_ids, "c772d24e9a884cbeb9ea12625c306c01", &i, sizeof(i));
  573. i.msg = "Dnssec failure"; dictionary_set(known_journal_messages_ids, "1675d7f172174098b1108bf8c7dc8f5d", &i, sizeof(i));
  574. i.msg = "Dnssec trust anchor revoked"; dictionary_set(known_journal_messages_ids, "4d4408cfd0d144859184d1e65d7c8a65", &i, sizeof(i));
  575. i.msg = "Dnssec downgrade"; dictionary_set(known_journal_messages_ids, "36db2dfa5a9045e1bd4af5f93e1cf057", &i, sizeof(i));
  576. i.msg = "Unsafe user name"; dictionary_set(known_journal_messages_ids, "b61fdac612e94b9182285b998843061f", &i, sizeof(i));
  577. i.msg = "Mount point path not suitable"; dictionary_set(known_journal_messages_ids, "1b3bb94037f04bbf81028e135a12d293", &i, sizeof(i));
  578. i.msg = "Device path not suitable"; dictionary_set(known_journal_messages_ids, "010190138f494e29a0ef6669749531aa", &i, sizeof(i));
  579. i.msg = "Nobody user unsuitable"; dictionary_set(known_journal_messages_ids, "b480325f9c394a7b802c231e51a2752c", &i, sizeof(i));
  580. i.msg = "Systemd udev settle deprecated"; dictionary_set(known_journal_messages_ids, "1c0454c1bd2241e0ac6fefb4bc631433", &i, sizeof(i));
  581. i.msg = "Time sync"; dictionary_set(known_journal_messages_ids, "7c8a41f37b764941a0e1780b1be2f037", &i, sizeof(i));
  582. i.msg = "Time bump"; dictionary_set(known_journal_messages_ids, "7db73c8af0d94eeb822ae04323fe6ab6", &i, sizeof(i));
  583. i.msg = "Shutdown scheduled"; dictionary_set(known_journal_messages_ids, "9e7066279dc8403da79ce4b1a69064b2", &i, sizeof(i));
  584. i.msg = "Shutdown canceled"; dictionary_set(known_journal_messages_ids, "249f6fb9e6e2428c96f3f0875681ffa3", &i, sizeof(i));
  585. i.msg = "TPM pcr extend"; dictionary_set(known_journal_messages_ids, "3f7d5ef3e54f4302b4f0b143bb270cab", &i, sizeof(i));
  586. i.msg = "Memory trim"; dictionary_set(known_journal_messages_ids, "f9b0be465ad540d0850ad32172d57c21", &i, sizeof(i));
  587. i.msg = "Sysv generator deprecated"; dictionary_set(known_journal_messages_ids, "a8fa8dacdb1d443e9503b8be367a6adb", &i, sizeof(i));
  588. // gnome
  589. // https://gitlab.gnome.org/GNOME/gnome-session/-/blob/main/gnome-session/gsm-manager.c
  590. i.msg = "Gnome SM startup succeeded"; dictionary_set(known_journal_messages_ids, "0ce153587afa4095832d233c17a88001", &i, sizeof(i));
  591. i.msg = "Gnome SM unrecoverable failure"; dictionary_set(known_journal_messages_ids, "10dd2dc188b54a5e98970f56499d1f73", &i, sizeof(i));
  592. // gnome-shell
  593. // https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/main/js/ui/main.js#L56
  594. i.msg = "Gnome shell started";dictionary_set(known_journal_messages_ids, "f3ea493c22934e26811cd62abe8e203a", &i, sizeof(i));
  595. // flathub
  596. // https://docs.flatpak.org/de/latest/flatpak-command-reference.html
  597. i.msg = "Flatpak cache"; dictionary_set(known_journal_messages_ids, "c7b39b1e006b464599465e105b361485", &i, sizeof(i));
  598. // ???
  599. i.msg = "Flathub pulls"; dictionary_set(known_journal_messages_ids, "75ba3deb0af041a9a46272ff85d9e73e", &i, sizeof(i));
  600. i.msg = "Flathub pull errors"; dictionary_set(known_journal_messages_ids, "f02bce89a54e4efab3a94a797d26204a", &i, sizeof(i));
  601. // ??
  602. i.msg = "Boltd starting"; dictionary_set(known_journal_messages_ids, "dd11929c788e48bdbb6276fb5f26b08a", &i, sizeof(i));
  603. // Netdata
  604. i.msg = "Netdata connection from child"; dictionary_set(known_journal_messages_ids, "ed4cdb8f1beb4ad3b57cb3cae2d162fa", &i, sizeof(i));
  605. i.msg = "Netdata connection to parent"; dictionary_set(known_journal_messages_ids, "6e2e3839067648968b646045dbf28d66", &i, sizeof(i));
  606. i.msg = "Netdata alert transition"; dictionary_set(known_journal_messages_ids, "9ce0cb58ab8b44df82c4bf1ad9ee22de", &i, sizeof(i));
  607. i.msg = "Netdata alert notification"; dictionary_set(known_journal_messages_ids, "6db0018e83e34320ae2a659d78019fb7", &i, sizeof(i));
  608. }
  609. void netdata_systemd_journal_transform_message_id(FACETS *facets __maybe_unused, BUFFER *wb, FACETS_TRANSFORMATION_SCOPE scope __maybe_unused, void *data __maybe_unused) {
  610. const char *message_id = buffer_tostring(wb);
  611. struct message_id_info *i = dictionary_get(known_journal_messages_ids, message_id);
  612. if(!i)
  613. return;
  614. switch(scope) {
  615. default:
  616. case FACETS_TRANSFORM_DATA:
  617. case FACETS_TRANSFORM_VALUE:
  618. buffer_sprintf(wb, " (%s)", i->msg);
  619. break;
  620. case FACETS_TRANSFORM_FACET:
  621. case FACETS_TRANSFORM_FACET_SORT:
  622. case FACETS_TRANSFORM_HISTOGRAM:
  623. buffer_flush(wb);
  624. buffer_strcat(wb, i->msg);
  625. break;
  626. }
  627. }
  628. // ----------------------------------------------------------------------------
  629. static void netdata_systemd_journal_rich_message(FACETS *facets __maybe_unused, BUFFER *json_array, FACET_ROW_KEY_VALUE *rkv, FACET_ROW *row __maybe_unused, void *data __maybe_unused) {
  630. buffer_json_add_array_item_object(json_array);
  631. buffer_json_member_add_string(json_array, "value", buffer_tostring(rkv->wb));
  632. buffer_json_object_close(json_array);
  633. }