| 1 | #include <stdio.h> |
| 2 | #include <stdlib.h> |
| 3 | #include <inttypes.h> |
| 4 | #include <ctype.h> |
| 5 | #include <stdbool.h> |
| 6 | #include <string.h> |
| 7 | |
| 8 | // from winnt.h |
| 9 | #define EVENTLOG_SUCCESS 0x0000 |
| 10 | #define EVENTLOG_ERROR_TYPE 0x0001 |
| 11 | #define EVENTLOG_WARNING_TYPE 0x0002 |
| 12 | #define EVENTLOG_INFORMATION_TYPE 0x0004 |
| 13 | #define EVENTLOG_AUDIT_SUCCESS 0x0008 |
| 14 | #define EVENTLOG_AUDIT_FAILURE 0x0010 |
| 15 | |
| 16 | // the severities we define in .mc file |
| 17 | #define STATUS_SEVERITY_INFORMATIONAL 0x1 |
| 18 | #define STATUS_SEVERITY_WARNING 0x2 |
| 19 | #define STATUS_SEVERITY_ERROR 0x3 |
| 20 | |
| 21 | #define FACILITY_APPLICATION 0x0fff |
| 22 | |
| 23 | #include "nd_log-common.h" |
| 24 | #include "nd_log-to-windows-common.h" |
| 25 | |
| 26 | const char *get_msg_symbol(MESSAGE_ID msg) { |
| 27 | switch(msg) { |
| 28 | case MSGID_MESSAGE_ONLY: |
| 29 | return "MESSAGE_ONLY"; |
| 30 | |
| 31 | case MSGID_MESSAGE_ERRNO: |
| 32 | return "MESSAGE_ERRNO"; |
| 33 | |
| 34 | case MSGID_REQUEST_ONLY: |
| 35 | return "REQUEST_ONLY"; |
| 36 | |
| 37 | case MSGID_ACCESS_MESSAGE: |
| 38 | return "ACCESS_MESSAGE"; |
| 39 | |
| 40 | case MSGID_ACCESS_MESSAGE_REQUEST: |
| 41 | return "ACCESS_MESSAGE_REQUEST"; |
| 42 | |
| 43 | case MSGID_ACCESS_MESSAGE_USER: |
| 44 | return "ACCESS_MESSAGE_USER"; |
| 45 | |
| 46 | case MSGID_ACCESS: |
| 47 | return "ACCESS"; |
| 48 | |
| 49 | case MSGID_ACCESS_USER: |
| 50 | return "ACCESS_USER"; |
| 51 | |
| 52 | case MSGID_ACCESS_FORWARDER: |
| 53 | return "ACCESS_FORWARDER"; |
| 54 | |
| 55 | case MSGID_ACCESS_FORWARDER_USER: |
| 56 | return "ACCESS_FORWARDER_USER"; |
| 57 | |
| 58 | case MSGID_ALERT_TRANSITION: |
| 59 | return "ALERT_TRANSITION"; |
| 60 | |
| 61 | default: |
| 62 | fprintf(stderr, "\n\nInvalid message id %d!\n\n\n", msg); |
| 63 | exit(1); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | const char *get_msg_format(MESSAGE_ID msg) { |
| 68 | switch(msg) { |
| 69 | case MSGID_MESSAGE_ONLY: |
| 70 | return "%2(%12): %64\r\n"; |
| 71 | |
| 72 | case MSGID_MESSAGE_ERRNO: |
| 73 | return "%2(%12): %64%n\r\n" |
| 74 | "%n\r\n" |
| 75 | " Unix Errno : %5%n\r\n" |
| 76 | " Windows Error: %6%n\r\n" |
| 77 | ; |
| 78 | |
| 79 | case MSGID_REQUEST_ONLY: |
| 80 | return "%2(%12): %63\r\n"; |
| 81 | |
| 82 | case MSGID_ACCESS_MESSAGE: |
| 83 | return "%64\r\n"; |
| 84 | |
| 85 | case MSGID_ACCESS_MESSAGE_REQUEST: |
| 86 | return "%64%n\r\n" |
| 87 | "%n\r\n" |
| 88 | " Request: %63%n\r\n" |
| 89 | ; |
| 90 | |
| 91 | case MSGID_ACCESS_MESSAGE_USER: |
| 92 | return "%64%n\r\n" |
| 93 | "%n\r\n" |
| 94 | " User: %21, role: %22, permissions: %23%n\r\n" |
| 95 | ; |
| 96 | |
| 97 | case MSGID_ACCESS: |
| 98 | return "%33 %63%n\r\n" |
| 99 | "%n\r\n" |
| 100 | " Response Code : %34%n\r\n" |
| 101 | " Transaction ID: %36%n\r\n" |
| 102 | " Source IP : %24%n\r\n" |
| 103 | ; |
| 104 | |
| 105 | case MSGID_ACCESS_USER: |
| 106 | return "%33 %63%n\r\n" |
| 107 | "%n\r\n" |
| 108 | " Response Code : %34%n\r\n" |
| 109 | " Transaction ID: %36%n\r\n" |
| 110 | " Source IP : %24%n\r\n" |
| 111 | " User : %21, role: %22, permissions: %23%n\r\n" |
| 112 | ; |
| 113 | |
| 114 | case MSGID_ACCESS_FORWARDER: |
| 115 | return "%33 %63%n\r\n" |
| 116 | "%n\r\n" |
| 117 | " Response Code : %34%n\r\n" |
| 118 | " Transaction ID: %36%n\r\n" |
| 119 | " Source IP : %24, For %27%n\r\n" |
| 120 | ; |
| 121 | |
| 122 | case MSGID_ACCESS_FORWARDER_USER: |
| 123 | return "%33 %63%n\r\n" |
| 124 | "%n\r\n" |
| 125 | " Response Code : %34%n\r\n" |
| 126 | " Transaction ID: %36%n\r\n" |
| 127 | " Source IP : %24, For %27%n\r\n" |
| 128 | " User : %21, role: %22, permissions: %23%n\r\n" |
| 129 | ; |
| 130 | |
| 131 | case MSGID_ALERT_TRANSITION: |
| 132 | return "Alert '%47' of instance '%16' on node '%15' transitioned from %57 to %56\r\n"; |
| 133 | |
| 134 | default: |
| 135 | fprintf(stderr, "\n\nInvalid message id %d!\n\n\n", msg); |
| 136 | exit(1); |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | int main(int argc, const char **argv) { |
| 141 | (void)argc; (void)argv; |
| 142 | |
| 143 | const char *header = NULL, *footer = NULL, *s_header = NULL, *s_footer = NULL; |
| 144 | |
| 145 | bool manifest = false; |
| 146 | if(argc == 2 && strcmp(argv[1], "--manifest") == 0) { |
| 147 | manifest = true; |
| 148 | |
| 149 | header = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n" |
| 150 | "<!--\r\n" |
| 151 | "\r\n" |
| 152 | " THIS FILE IS AUTOMATICALLY GENERATED - DO NOT EDIT\r\n" |
| 153 | "\r\n" |
| 154 | " This XML file can be verified by running mc.exe (the MS tool) with this manifest as param.\r\n" |
| 155 | "\r\n" |
| 156 | " \"c:\\Program Files (x86)\\Windows Kits\\10\\bin\\10.0.26100.0\\x64\\mc.exe\" wevt_netdata_manifest.xml wevt_netdata.mc\r\n" |
| 157 | "\r\n" |
| 158 | " -->\r\n" |
| 159 | "<instrumentationManifest\r\n" |
| 160 | " xmlns=\"http://schemas.microsoft.com/win/2004/08/events\"\r\n" |
| 161 | " xmlns:win=\"http://manifests.microsoft.com/win/2004/08/windows/events\"\r\n" |
| 162 | " xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\r\n" |
| 163 | " <instrumentation>\r\n" |
| 164 | " <events>\r\n" |
| 165 | "\r\n" |
| 166 | " <provider name=\"" NETDATA_ETW_PROVIDER_NAME "\"\r\n" |
| 167 | " guid=\"" NETDATA_ETW_PROVIDER_GUID_STR "\"\r\n" |
| 168 | " symbol=\"NETDATA_ETW_PROVIDER_GUID\"\r\n" |
| 169 | " messageFileName=\"%SystemRoot%\\System32\\wevt_netdata.dll\"\r\n" |
| 170 | " resourceFileName=\"%SystemRoot%\\System32\\wevt_netdata.dll\"\r\n" |
| 171 | " message=\"$(string.ND_PROVIDER_NAME)\">\r\n" |
| 172 | "\r\n" |
| 173 | " <!-- Define the provider sub-channels -->\r\n" |
| 174 | " <channels>\r\n" |
| 175 | " <channel name=\"" NETDATA_ETW_CHANNEL_NAME "/" NETDATA_ETW_SUBCHANNEL_DAEMON "\"\r\n" |
| 176 | " symbol=\"CHANNEL_DAEMON\"\r\n" |
| 177 | " type=\"Operational\"\r\n" |
| 178 | " message=\"$(string.Channel.Daemon)\"\r\n" |
| 179 | " enabled=\"true\"\r\n" |
| 180 | " />\r\n" |
| 181 | "\r\n" |
| 182 | " <channel name=\"" NETDATA_ETW_CHANNEL_NAME "/" NETDATA_ETW_SUBCHANNEL_COLLECTORS "\"\r\n" |
| 183 | " symbol=\"CHANNEL_COLLECTORS\"\r\n" |
| 184 | " type=\"Operational\"\r\n" |
| 185 | " message=\"$(string.Channel.Collectors)\"\r\n" |
| 186 | " enabled=\"true\"\r\n" |
| 187 | " />\r\n" |
| 188 | "\r\n" |
| 189 | " <channel name=\"" NETDATA_ETW_CHANNEL_NAME "/" NETDATA_ETW_SUBCHANNEL_ACCESS "\"\r\n" |
| 190 | " symbol=\"CHANNEL_ACCESS\"\r\n" |
| 191 | " type=\"Operational\"\r\n" |
| 192 | " message=\"$(string.Channel.Access)\"\r\n" |
| 193 | " enabled=\"true\"\r\n" |
| 194 | " />\r\n" |
| 195 | "\r\n" |
| 196 | " <channel name=\"" NETDATA_ETW_CHANNEL_NAME "/" NETDATA_ETW_SUBCHANNEL_HEALTH "\"\r\n" |
| 197 | " symbol=\"CHANNEL_HEALTH\"\r\n" |
| 198 | " type=\"Operational\"\r\n" |
| 199 | " message=\"$(string.Channel.Health)\"\r\n" |
| 200 | " enabled=\"true\"\r\n" |
| 201 | " />\r\n" |
| 202 | "\r\n" |
| 203 | " <channel name=\"" NETDATA_ETW_CHANNEL_NAME "/" NETDATA_ETW_SUBCHANNEL_ACLK "\"\r\n" |
| 204 | " symbol=\"CHANNEL_ACLK\"\r\n" |
| 205 | " type=\"Operational\"\r\n" |
| 206 | " message=\"$(string.Channel.Aclk)\"\r\n" |
| 207 | " enabled=\"true\"\r\n" |
| 208 | " />\r\n" |
| 209 | " </channels>\r\n" |
| 210 | "\r\n" |
| 211 | " <levels>\r\n" |
| 212 | " </levels>\r\n" |
| 213 | "\r\n" |
| 214 | " <opcodes>\r\n" |
| 215 | " </opcodes>\r\n" |
| 216 | "\r\n" |
| 217 | " <tasks>\r\n" |
| 218 | " </tasks>\r\n" |
| 219 | "\r\n" |
| 220 | " <templates>\r\n" |
| 221 | " <template tid=\"AllFieldsTemplate\">\r\n" |
| 222 | " <!-- 0 (NDF_STOP) should not be here %1 is Timestamp, %64 is the Message -->\r\n" |
| 223 | " <data name=\"Timestamp\" inType=\"win:UnicodeString\"/> <!-- 1 (NDF_TIMESTAMP_REALTIME_USEC) -->\r\n" |
| 224 | " <data name=\"Program\" inType=\"win:UnicodeString\"/> <!-- 2 (NDF_SYSLOG_IDENTIFIER) -->\r\n" |
| 225 | " <data name=\"NetdataLogSource\" inType=\"win:UnicodeString\"/> <!-- 3 (NDF_LOG_SOURCE) -->\r\n" |
| 226 | " <data name=\"Level\" inType=\"win:UnicodeString\"/> <!-- 4 (NDF_PRIORITY) -->\r\n" |
| 227 | " <data name=\"UnixErrno\" inType=\"win:UnicodeString\"/> <!-- 5 (NDF_ERRNO) -->\r\n" |
| 228 | " <data name=\"WindowsLastError\" inType=\"win:UnicodeString\"/> <!-- 6 (NDF_WINERROR) -->\r\n" |
| 229 | " <data name=\"InvocationID\" inType=\"win:UnicodeString\"/> <!-- 7 (NDF_INVOCATION_ID) -->\r\n" |
| 230 | " <data name=\"CodeLine\" inType=\"win:UnicodeString\"/> <!-- 8 (NDF_LINE) -->\r\n" |
| 231 | " <data name=\"CodeFile\" inType=\"win:UnicodeString\"/> <!-- 9 (NDF_FILE) -->\r\n" |
| 232 | " <data name=\"CodeFunction\" inType=\"win:UnicodeString\"/> <!-- 10 (NDF_FUNC) -->\r\n" |
| 233 | " <data name=\"ThreadID\" inType=\"win:UnicodeString\"/> <!-- 11 (NDF_TID) -->\r\n" |
| 234 | " <data name=\"ThreadName\" inType=\"win:UnicodeString\"/> <!-- 12 (NDF_THREAD_TAG) -->\r\n" |
| 235 | " <data name=\"MessageID\" inType=\"win:UnicodeString\"/> <!-- 13 (NDF_MESSAGE_ID) -->\r\n" |
| 236 | " <data name=\"Module\" inType=\"win:UnicodeString\"/> <!-- 14 (NDF_MODULE) -->\r\n" |
| 237 | " <data name=\"Node\" inType=\"win:UnicodeString\"/> <!-- 15 (NDF_NIDL_NODE) -->\r\n" |
| 238 | " <data name=\"Instance\" inType=\"win:UnicodeString\"/> <!-- 16 (NDF_NIDL_INSTANCE) -->\r\n" |
| 239 | " <data name=\"Context\" inType=\"win:UnicodeString\"/> <!-- 17 (NDF_NIDL_CONTEXT) -->\r\n" |
| 240 | " <data name=\"Dimension\" inType=\"win:UnicodeString\"/> <!-- 18 (NDF_NIDL_DIMENSION) -->\r\n" |
| 241 | " <data name=\"SourceTransport\" inType=\"win:UnicodeString\"/> <!-- 19 (NDF_SRC_TRANSPORT) -->\r\n" |
| 242 | " <data name=\"AccountID\" inType=\"win:UnicodeString\"/> <!-- 20 (NDF_ACCOUNT_ID) -->\r\n" |
| 243 | " <data name=\"UserName\" inType=\"win:UnicodeString\"/> <!-- 21 (NDF_USER_NAME) -->\r\n" |
| 244 | " <data name=\"UserRole\" inType=\"win:UnicodeString\"/> <!-- 22 (NDF_USER_ROLE) -->\r\n" |
| 245 | " <data name=\"UserPermissions\" inType=\"win:UnicodeString\"/> <!-- 23 (NDF_USER_ACCESS) -->\r\n" |
| 246 | " <data name=\"SourceIP\" inType=\"win:UnicodeString\"/> <!-- 24 (NDF_SRC_IP) -->\r\n" |
| 247 | " <data name=\"SourceForwardedHost\" inType=\"win:UnicodeString\"/> <!-- 25 (NDF_SRC_PORT) -->\r\n" |
| 248 | " <data name=\"SourceForwardedFor\" inType=\"win:UnicodeString\"/> <!-- 26 (NDF_SRC_FORWARDED_HOST) -->\r\n" |
| 249 | " <data name=\"SourcePort\" inType=\"win:UnicodeString\"/> <!-- 27 (NDF_SRC_FORWARDED_FOR) -->\r\n" |
| 250 | " <data name=\"SourceCapabilities\" inType=\"win:UnicodeString\"/> <!-- 28 (NDF_SRC_CAPABILITIES) -->\r\n" |
| 251 | " <data name=\"DestinationTransport\" inType=\"win:UnicodeString\"/> <!-- 29 (NDF_DST_TRANSPORT) -->\r\n" |
| 252 | " <data name=\"DestinationIP\" inType=\"win:UnicodeString\"/> <!-- 30 (NDF_DST_IP) -->\r\n" |
| 253 | " <data name=\"DestinationPort\" inType=\"win:UnicodeString\"/> <!-- 31 (NDF_DST_PORT) -->\r\n" |
| 254 | " <data name=\"DestinationCapabilities\" inType=\"win:UnicodeString\"/> <!-- 32 (NDF_DST_CAPABILITIES) -->\r\n" |
| 255 | " <data name=\"RequestMethod\" inType=\"win:UnicodeString\"/> <!-- 33 (NDF_REQUEST_METHOD) -->\r\n" |
| 256 | " <data name=\"ResponseCode\" inType=\"win:UnicodeString\"/> <!-- 34 (NDF_RESPONSE_CODE) -->\r\n" |
| 257 | " <data name=\"ConnectionID\" inType=\"win:UnicodeString\"/> <!-- 35 (NDF_CONNECTION_ID) -->\r\n" |
| 258 | " <data name=\"TransactionID\" inType=\"win:UnicodeString\"/> <!-- 36 (NDF_TRANSACTION_ID) -->\r\n" |
| 259 | " <data name=\"ResponseSentBytes\" inType=\"win:UnicodeString\"/> <!-- 37 (NDF_RESPONSE_SENT_BYTES) -->\r\n" |
| 260 | " <data name=\"ResponseSizeBytes\" inType=\"win:UnicodeString\"/> <!-- 38 (NDF_RESPONSE_SIZE_BYTES) -->\r\n" |
| 261 | " <data name=\"ResponsePreparationTimeUsec\" inType=\"win:UnicodeString\"/> <!-- 39 (NDF_RESPONSE_PREPARATION_TIME_USEC) -->\r\n" |
| 262 | " <data name=\"ResponseSentTimeUsec\" inType=\"win:UnicodeString\"/> <!-- 40 (NDF_RESPONSE_SENT_TIME_USEC) -->\r\n" |
| 263 | " <data name=\"ResponseTotalTimeUsec\" inType=\"win:UnicodeString\"/> <!-- 41 (NDF_RESPONSE_TOTAL_TIME_USEC) -->\r\n" |
| 264 | " <data name=\"AlertID\" inType=\"win:UnicodeString\"/> <!-- 42 (NDF_ALERT_ID) -->\r\n" |
| 265 | " <data name=\"AlertUniqueID\" inType=\"win:UnicodeString\"/> <!-- 43 (NDF_ALERT_UNIQUE_ID) -->\r\n" |
| 266 | " <data name=\"AlertTransitionID\" inType=\"win:UnicodeString\"/> <!-- 44 (NDF_ALERT_TRANSITION_ID) -->\r\n" |
| 267 | " <data name=\"AlertEventID\" inType=\"win:UnicodeString\"/> <!-- 45 (NDF_ALERT_EVENT_ID) -->\r\n" |
| 268 | " <data name=\"AlertConfig\" inType=\"win:UnicodeString\"/> <!-- 46 (NDF_ALERT_CONFIG_HASH) -->\r\n" |
| 269 | " <data name=\"AlertName\" inType=\"win:UnicodeString\"/> <!-- 47 (NDF_ALERT_NAME) -->\r\n" |
| 270 | " <data name=\"AlertClass\" inType=\"win:UnicodeString\"/> <!-- 48 (NDF_ALERT_CLASS) -->\r\n" |
| 271 | " <data name=\"AlertComponent\" inType=\"win:UnicodeString\"/> <!-- 49 (NDF_ALERT_COMPONENT) -->\r\n" |
| 272 | " <data name=\"AlertType\" inType=\"win:UnicodeString\"/> <!-- 50 (NDF_ALERT_TYPE) -->\r\n" |
| 273 | " <data name=\"AlertExec\" inType=\"win:UnicodeString\"/> <!-- 51 (NDF_ALERT_EXEC) -->\r\n" |
| 274 | " <data name=\"AlertRecipient\" inType=\"win:UnicodeString\"/> <!-- 52 (NDF_ALERT_RECIPIENT) -->\r\n" |
| 275 | " <data name=\"AlertDuration\" inType=\"win:UnicodeString\"/> <!-- 53 (NDF_ALERT_DURATION) -->\r\n" |
| 276 | " <data name=\"AlertValue\" inType=\"win:UnicodeString\"/> <!-- 54 (NDF_ALERT_VALUE) -->\r\n" |
| 277 | " <data name=\"AlertOldValue\" inType=\"win:UnicodeString\"/> <!-- 55 (NDF_ALERT_VALUE_OLD) -->\r\n" |
| 278 | " <data name=\"AlertStatus\" inType=\"win:UnicodeString\"/> <!-- 56 (NDF_ALERT_STATUS) -->\r\n" |
| 279 | " <data name=\"AlertOldStatus\" inType=\"win:UnicodeString\"/> <!-- 57 (NDF_ALERT_STATUS_OLD) -->\r\n" |
| 280 | " <data name=\"Source\" inType=\"win:UnicodeString\"/> <!-- 58 (NDF_ALERT_SOURCE) -->\r\n" |
| 281 | " <data name=\"AlertUnits\" inType=\"win:UnicodeString\"/> <!-- 59 (NDF_ALERT_UNITS) -->\r\n" |
| 282 | " <data name=\"AlertSummary\" inType=\"win:UnicodeString\"/> <!-- 60 (NDF_ALERT_SUMMARY) -->\r\n" |
| 283 | " <data name=\"AlertInfo\" inType=\"win:UnicodeString\"/> <!-- 61 (NDF_ALERT_INFO) -->\r\n" |
| 284 | " <data name=\"AlertNotificationTime\" inType=\"win:UnicodeString\"/> <!-- 62 (NDF_ALERT_NOTIFICATION_REALTIME_USEC) -->\r\n" |
| 285 | " <data name=\"Request\" inType=\"win:UnicodeString\"/> <!-- 63 (NDF_REQUEST) -->\r\n" |
| 286 | " <data name=\"Message\" inType=\"win:UnicodeString\"/> <!-- 64 (NDF_MESSAGE) -->\r\n" |
| 287 | " <data name=\"StackTrace\" inType=\"win:UnicodeString\"/> <!-- 65 (NDF_STACK_TRACE) -->\r\n" |
| 288 | " </template>\r\n" |
| 289 | " </templates>\r\n" |
| 290 | "\r\n" |
| 291 | " <events>\r\n" |
| 292 | ; |
| 293 | |
| 294 | footer = " </events>\r\n" |
| 295 | " </provider>\r\n" |
| 296 | " </events>\r\n" |
| 297 | " </instrumentation>\r\n" |
| 298 | ; |
| 299 | |
| 300 | s_header = " <localization>\r\n" |
| 301 | " <resources culture=\"en-US\">\r\n" |
| 302 | " <stringTable>\r\n" |
| 303 | " <string id=\"ND_PROVIDER_NAME\" value=\"" NETDATA_ETW_PROVIDER_NAME "\"/>\r\n" |
| 304 | "\r\n" |
| 305 | " <string id=\"Channel.Daemon\" value=\"Daemon\"/>\r\n" |
| 306 | " <string id=\"Channel.Collectors\" value=\"Collectors\"/>\r\n" |
| 307 | " <string id=\"Channel.Access\" value=\"Access\"/>\r\n" |
| 308 | " <string id=\"Channel.Health\" value=\"Health\"/>\r\n" |
| 309 | " <string id=\"Channel.Aclk\" value=\"Aclk\"/>\r\n" |
| 310 | "\r\n" |
| 311 | ; |
| 312 | |
| 313 | s_footer = " </stringTable>\r\n" |
| 314 | " </resources>\r\n" |
| 315 | " </localization>\r\n" |
| 316 | "</instrumentationManifest>\r\n" |
| 317 | ; |
| 318 | } |
| 319 | else { |
| 320 | header = ";// THIS FILE IS AUTOMATICALLY GENERATED - DO NOT EDIT\r\n" |
| 321 | "\r\n" |
| 322 | "MessageIdTypedef=DWORD\r\n" |
| 323 | "\r\n" |
| 324 | "SeverityNames=(\r\n" |
| 325 | " Informational=0x1:STATUS_SEVERITY_INFORMATIONAL\r\n" |
| 326 | " Warning=0x2:STATUS_SEVERITY_WARNING\r\n" |
| 327 | " Error=0x3:STATUS_SEVERITY_ERROR\r\n" |
| 328 | " )\r\n" |
| 329 | "\r\n" |
| 330 | "FacilityNames=(\r\n" |
| 331 | " " NETDATA_CHANNEL_NAME "=0x0FFF:FACILITY_NETDATA\r\n" |
| 332 | " )\r\n" |
| 333 | "\r\n" |
| 334 | "LanguageNames=(\r\n" |
| 335 | " English=0x409:MSG00409\r\n" |
| 336 | " )\r\n" |
| 337 | "\r\n" |
| 338 | ; |
| 339 | |
| 340 | footer = ""; |
| 341 | } |
| 342 | |
| 343 | bool done[UINT16_MAX] = { 0 }; |
| 344 | char symbol[1024]; |
| 345 | |
| 346 | printf("%s", header); |
| 347 | for(size_t src = 1; src < _NDLS_MAX ;src++) { |
| 348 | for(size_t pri = 0; pri < _NDLP_MAX ;pri++) { |
| 349 | uint8_t severity = get_severity_from_priority(pri); |
| 350 | |
| 351 | for(size_t msg = 1; msg < _MSGID_MAX ;msg++) { |
| 352 | |
| 353 | if(src >= 16) { |
| 354 | fprintf(stderr, "\n\nSource %zu is bigger than 4 bits!\n\n", src); |
| 355 | return 1; |
| 356 | } |
| 357 | |
| 358 | if(pri >= 16) { |
| 359 | fprintf(stderr, "\n\nPriority %zu is bigger than 4 bits!\n\n", pri); |
| 360 | return 1; |
| 361 | } |
| 362 | |
| 363 | if(msg >= 256) { |
| 364 | fprintf(stderr, "\n\nMessageID %zu is bigger than 8 bits!\n\n", msg); |
| 365 | return 1; |
| 366 | } |
| 367 | |
| 368 | uint16_t eventID = construct_event_code(src, pri, msg); |
| 369 | if((eventID & 0xFFFF) != eventID) { |
| 370 | fprintf(stderr, "\n\nEventID 0x%x is bigger than 16 bits!\n\n", eventID); |
| 371 | return 1; |
| 372 | } |
| 373 | |
| 374 | if(done[eventID]) continue; |
| 375 | done[eventID] = true; |
| 376 | |
| 377 | const char *level = get_level_from_priority_str(pri); |
| 378 | const char *pri_txt; |
| 379 | switch(pri) { |
| 380 | case NDLP_EMERG: |
| 381 | pri_txt = "EMERG"; |
| 382 | break; |
| 383 | |
| 384 | case NDLP_CRIT: |
| 385 | pri_txt = "CRIT"; |
| 386 | break; |
| 387 | |
| 388 | case NDLP_ALERT: |
| 389 | pri_txt = "ALERT"; |
| 390 | break; |
| 391 | |
| 392 | case NDLP_ERR: |
| 393 | pri_txt = "ERR"; |
| 394 | break; |
| 395 | |
| 396 | case NDLP_WARNING: |
| 397 | pri_txt = "WARN"; |
| 398 | break; |
| 399 | |
| 400 | case NDLP_INFO: |
| 401 | pri_txt = "INFO"; |
| 402 | break; |
| 403 | |
| 404 | case NDLP_NOTICE: |
| 405 | pri_txt = "NOTICE"; |
| 406 | break; |
| 407 | |
| 408 | case NDLP_DEBUG: |
| 409 | pri_txt = "DEBUG"; |
| 410 | break; |
| 411 | |
| 412 | default: |
| 413 | fprintf(stderr, "\n\nInvalid priority %zu!\n\n\n", pri); |
| 414 | return 1; |
| 415 | } |
| 416 | |
| 417 | const char *channel; |
| 418 | const char *src_txt; |
| 419 | switch(src) { |
| 420 | case NDLS_COLLECTORS: |
| 421 | src_txt = "COLLECTORS"; |
| 422 | channel = NETDATA_ETW_CHANNEL_NAME "/" NETDATA_ETW_SUBCHANNEL_COLLECTORS; |
| 423 | break; |
| 424 | |
| 425 | case NDLS_ACCESS: |
| 426 | src_txt = "ACCESS"; |
| 427 | channel = NETDATA_ETW_CHANNEL_NAME "/" NETDATA_ETW_SUBCHANNEL_ACCESS; |
| 428 | break; |
| 429 | |
| 430 | case NDLS_HEALTH: |
| 431 | src_txt = "HEALTH"; |
| 432 | channel = NETDATA_ETW_CHANNEL_NAME "/" NETDATA_ETW_SUBCHANNEL_HEALTH; |
| 433 | break; |
| 434 | |
| 435 | case NDLS_DEBUG: |
| 436 | src_txt = "DEBUG"; |
| 437 | channel = NETDATA_ETW_CHANNEL_NAME "/" NETDATA_ETW_SUBCHANNEL_DAEMON; |
| 438 | break; |
| 439 | |
| 440 | case NDLS_DAEMON: |
| 441 | src_txt = "DAEMON"; |
| 442 | channel = NETDATA_ETW_CHANNEL_NAME "/" NETDATA_ETW_SUBCHANNEL_DAEMON; |
| 443 | break; |
| 444 | |
| 445 | case NDLS_ACLK: |
| 446 | src_txt = "ACLK"; |
| 447 | channel = NETDATA_ETW_CHANNEL_NAME "/" NETDATA_ETW_SUBCHANNEL_ACLK; |
| 448 | break; |
| 449 | |
| 450 | default: |
| 451 | fprintf(stderr, "\n\nInvalid source %zu!\n\n\n", src); |
| 452 | return 1; |
| 453 | } |
| 454 | |
| 455 | const char *msg_txt = get_msg_symbol(msg); |
| 456 | const char *format = get_msg_format(msg); |
| 457 | |
| 458 | const char *severity_txt; |
| 459 | switch (severity) { |
| 460 | case STATUS_SEVERITY_INFORMATIONAL: |
| 461 | severity_txt = "Informational"; |
| 462 | break; |
| 463 | |
| 464 | case STATUS_SEVERITY_ERROR: |
| 465 | severity_txt = "Error"; |
| 466 | break; |
| 467 | |
| 468 | case STATUS_SEVERITY_WARNING: |
| 469 | severity_txt = "Warning"; |
| 470 | break; |
| 471 | |
| 472 | default: |
| 473 | fprintf(stderr, "\n\nInvalid severity id %u!\n\n\n", severity); |
| 474 | return 1; |
| 475 | } |
| 476 | |
| 477 | if(manifest) |
| 478 | snprintf(symbol, sizeof(symbol), "ED_%s_%s_%s", src_txt, pri_txt, msg_txt); |
| 479 | else |
| 480 | snprintf(symbol, sizeof(symbol), "MC_%s_%s_%s", src_txt, pri_txt, msg_txt); |
| 481 | |
| 482 | if(manifest) |
| 483 | printf(" <event symbol=\"%s\"\r\n" |
| 484 | " value=\"0x%x\"\r\n" |
| 485 | " message=\"$(string.msg.MAN_%s)\"\r\n" |
| 486 | " channel=\"%s\"\r\n" |
| 487 | " level=\"%s\"\r\n" |
| 488 | " task=\"win:None\"\r\n" |
| 489 | " opcode=\"win:Info\"\r\n" |
| 490 | " template=\"AllFieldsTemplate\"/>\r\n\r\n", |
| 491 | symbol, eventID, msg_txt, channel, level); |
| 492 | else |
| 493 | printf("MessageId=0x%x\r\n" |
| 494 | "Severity=%s\r\n" |
| 495 | "Facility=" NETDATA_CHANNEL_NAME "\r\n" |
| 496 | "SymbolicName=%s\r\n" |
| 497 | "Language=English\r\n" |
| 498 | "%s" |
| 499 | ".\r\n" |
| 500 | "\r\n", |
| 501 | eventID, severity_txt, symbol, format); |
| 502 | } |
| 503 | } |
| 504 | } |
| 505 | printf("%s", footer); |
| 506 | |
| 507 | if(s_header) { |
| 508 | printf("%s", s_header); |
| 509 | |
| 510 | for(size_t msg = 1; msg < _MSGID_MAX ;msg++) { |
| 511 | const char *msg_txt = get_msg_symbol(msg); |
| 512 | const char *format = get_msg_format(msg); |
| 513 | printf(" <string id=\"msg.MAN_%s\" value=\"%s\"/>\r\n", msg_txt, format); |
| 514 | } |
| 515 | |
| 516 | printf("%s", s_footer); |
| 517 | } |
| 518 | } |
| 519 |