1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 | 1x 1x 1x 1x 1x 57x 57x 57x 57x 41x 34x 1x 33x 32x 1x 7x 7x 7x 7x 4x 3x 1x 2x 1x 1x 1x 3x 3x 3x 3x 3x 3x 3x 1x 3x 1x 41x 41x 16x 16x 32x 32x 6x 32x 32x 32x 32x 32x 32x 6x 26x 32x 3x 32x 3x 32x 4x 28x 32x 2x 1x 1x 32x 2x 1x 1x 32x 2x 1x 1x 32x 2x 1x 1x 32x 1x 32x 1x 32x 1x 32x 1x 7x 7x 5x 2x 1x 1x 1x 1x 7x 20x 20x 20x 20x 19x 19x 19x 19x 19x 19x 1x 7x 7x 7x 7x 6x 6x 2x 2x 2x 6x 6x 2x 6x 1x 1x 6x 3x 3x 1x 7x 7x 7x 7x 1x 1x 6x 1x 1x 1x 1x 5x 1x 1x 1x 1x 5x 5x 4x 4x 4x 1x 1x 1x 4x 3x 3x 3x 4x 3x 3x 3x 4x 4x 2x 4x 1x 1x 4x 2x 2x 36x 36x 1x 1x 35x 35x 20x 19x 1x 15x 7x 2x 5x 8x 7x 2x 5x 1x 1x 1x 10x 10x 10x 10x 10x 10x 1x 9x 10x 1x 9x 10x 2x 1x 1x 10x 1x 1x 1x 1x 1x 1x 1x 1x 9x 9x 9x 9x 9x 9x 9x 9x 10x 1x 10x 10x 10x 3x 3x 2x 2x 1x 1x 1x 1x 10x 3x 3x 2x 2x 1x 1x 1x 1x 10x 3x 3x 2x 2x 1x 1x 1x 1x 10x 3x 3x 2x 2x 1x 1x 1x 1x 10x 3x 3x 2x 2x 1x 1x 1x 1x 10x 3x 3x 2x 2x 1x 1x 1x 1x 10x 3x 3x 2x 2x 1x 1x 1x 1x 10x 3x 3x 2x 2x 1x 1x 1x 1x 10x 2x 8x 14x 14x 14x 14x 1x 1x 1x 1x 13x 13x 13x 13x 13x 13x 13x 13x 3x 3x 3x 1x 3x 2x 2x 1x 3x 13x 13x 13x 13x 13x 13x 13x 13x 13x 11x 11x 2x 11x 10x 9x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 1x 1x 1x 19x 19x 19x 19x 19x 18x 1x 19x 5x 14x 19x 13x 6x 19x 5x 14x 19x 2x 17x 19x 18x 1x 19x 4x 15x 19x 2x 17x 19x 2x 1x 1x 19x 2x 2x 2x 2x 2x 2x 2x 2x 17x 17x 17x 17x 17x 17x 17x 17x 19x 1x 10x 10x 10x 3x 3x 2x 2x 1x 1x 1x 1x 10x 3x 3x 2x 2x 1x 1x 1x 1x 10x 3x 3x 2x 2x 1x 1x 1x 1x 10x 3x 3x 2x 2x 1x 1x 1x 1x 10x 3x 3x 2x 2x 1x 1x 1x 1x 10x 3x 3x 2x 2x 1x 1x 1x 1x 10x 3x 3x 2x 2x 1x 1x 1x 1x 10x 3x 3x 2x 2x 1x 1x 1x 1x 10x 2x 8x 22x 22x 22x 22x 1x 1x 1x 1x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 5x 5x 5x 2x 5x 4x 4x 1x 5x 21x 21x 20x 20x 5x 5x 3x 1x 2x 2x 1x 1x 15x 13x 13x 1x 1x 1x 12x 2x 2x 1x 1x 1x 1x 20x 20x 21x 21x 21x 2x 2x 2x 2x 4x 4x 3x 3x 2x 21x 21x 21x 21x 21x 21x 21x 21x 21x 20x 1x 21x 21x 11x 11x 2x 11x 10x 9x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 1x 1x 1x 6x 6x 6x 6x 6x 6x 6x 6x 6x 2x 1x 1x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 93x 1x 3x 3x 3x 3x 1x 3x 2x 1x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 2x 1x 1x 5x 5x 5x 1x 5x 1x 5x 5x 5x 318x 4x 3x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 5x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 158x 1x 2x 2x 2x 2x 1x 2x 1x 1x 1x | /** Copyright (c) 2018 Craig Yamato */ /** * @fileoverview The SyslogPro class for sending syslog messages * @author Craig Yamato <craig@kentik.com> * @copyright (c) 2018 - Craig Yamato * @version 0.0.0 * @since 0.0.0 * @exports Syslog * @exports LEEF * @exports CEF * @module SyslogPro */ "use strict"; const moment = require('moment'); const os = require("os"); const dns = require('dns'); let dnsPromises = dns.promises; const fs = require("fs"); /** * Format the ANSI foreground color code from a RGB hex code or ANSI color code * @private * @param {string} hex - The color hex code in the form of #FFFFFF or Number of * the ANSI color code (30-37 Standard & 0-255 Extended) * @returns {Promise} - The formated ANSI color code * @throws {Error} - A Format Error */ function rgbToAnsi (hex, extendedColor) { return new Promise((resolve, reject) => { let colorCode = 0; // Var to hold color code // Break HEX Code up into RGB const hexParts = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); if (hexParts || typeof hex === 'number') { if (typeof hex === 'number') { if (extendedColor && hex < 256) { resolve(hex); } else if ((hex > 29 && hex < 38) || (hex > 89 && hex < 98)) { resolve(hex); } else { reject (new Error('FORMAT ERROR: Color code not in range')); } } else { const r = parseInt(hexParts[1], 16); const g = parseInt(hexParts[2], 16); const b = parseInt(hexParts[3], 16); if (extendedColor) { if (r === g && g === b) { // Gray Scale Color if (r < 8) { colorCode = 16; } else if (r > 248) { colorCode = 231; } else { colorCode = Math.round(((r - 8) / 247) * 24) + 232; } } else { colorCode = 16 + (36 * Math.round(r / 255 * 5)) + (6 * Math.round(g / 255 * 5)) + Math.round(b / 255 * 5); } } else { colorCode = 30; const red = r / 255; const green = g / 255; const blue = b / 255; let v = Math.max(red, green, blue) * 100; v = Math.round(v / 50); if (v === 1) { colorCode += ((Math.round(b / 255) << 2) | (Math.round(g / 255) << 1) | Math.round(r / 255)); } if (v === 2) { colorCode += 60; } } } resolve(colorCode); return; } else { reject(new Error('TYPE ERROR: Not in RGB color hex or color code')); return; } }); } /** * A class to work with syslog messages using UDP, TCP, or TLS transport. * There is suport for Syslog message formating RFC-3164, RFC-5424 including * Structured Data, IBM LEEF (Log Event Extended Format), and HP CEF (Common * Event Format). The meesaging is fully configurabule and Ansi foreground * colors can be added. Both ANSI 8 and ANSI 256 color are fully suported. * @requires moment * @version 0.0.0 * @since 0.0.0 */ class Syslog { /** * Construct a new Syslog object with user options * @public * @version 0.0.0 * @since 0.0.0 * @this Syslog * @param {object} [options] - Options object * >>>Transport Configuraton * @param {string} [options.target='127.0.0.1'] - The IP Address|FQDN of the * Syslog Server, this option if set will take prasdents over any target * set in a formating object * @param {string} [options.protocol='udp'] - L4 transport portocol * (udp|tcp|tls), this option if set will take prasdents over any transport * set in a formating object * @param {number} [options.port=514] - IP port, this option if set will take * prasdents over any IP Port set in a formating object * @param {number} [options.tcpTimeout=10000] - Ignored for all other * transports, this option if set will take prasdents over any timeout * set in a formating object * @param {string[]} [options.tlsServerCerts] - Array of authrized TLS server * certificates file locations, this option if set will take prasdents * over any certificates set in a formating object * @param {string} [options.tlsClientCert] - Client TLS certificate file * location that this client should use, this option if set will take * prasdents over any certificates set in a formating object * @param {string} [options.tlsClientKey] - Client TLS key file * location that this client should use, this option if set will take * prasdents over any certificates set in a formating object * >>>Syslog Format Settings * @param {string} [options.format='none'] - Valid syslog format options for * this module are 'none', 'rfc3164', 'rfc5424', 'leef', 'cef' * @param {RFC3164} [options.rfc5424] - {@link module:SyslogPro~RFC5424| * RFC5424 related settings} * @param {RFC5424} [options.rfc5424] - {@link module:SyslogPro~RFC5424| * RFC5424 related settings} * @param {LEEF} [options.leef] - {@link module:SyslogPro~LEEF|IBM LEEF * (Log Event Extended Format) object} * @param {CEF} [options.cef] - {@link module:SyslogPro~CEF|HP CEF * (Common Event Format) formating object} */ constructor (options) { this.constructor__ = true; if (!options) { options = {}; } // Basic transport setup /** @type {string} */ this.target = options.target || 'localhost'; /** @type {string} */ this.protocol = options.protocol || 'udp'; this.protocol = this.protocol.toLowerCase(); /** @type {number} */ this.port = options.port || 514; /** @type {number} */ this.tcpTimeout = options.tcpTimeout || 10000; if ((typeof options.tlsServerCerts === 'object' && Array.isArray(options.tlsServerCerts)) || typeof options.tlsServerCerts === 'string') { this.addTlsServerCerts(options.tlsServerCerts); } else { /** @type {string[]} */ this.tlsServerCerts = []; } if (options.tlsClientCert) { /** @type {string} */ this.tlsClientCert = options.tlsClientCert; } if (options.tlsClientKey) { /** @type {string} */ this.tlsClientKey = options.tlsClientKey; } // Syslog Format if (typeof options.format === 'string') { /** @type {string} */ this.format = options.format.toLowerCase(); } else { this.format = options.format || 'none'; } if (options.rfc3164) { if (options.rfc3164.constructor__) { /** @type {RFC3164} */ this.rfc3164 = options.rfc3164; } else { this.rfc3164 = new RFC3164(options); } } if (options.rfc5424) { if (options.rfc5424.constructor__) { /** @type {RFC5424} */ this.rfc5424 = options.rfc5424; } else { this.rfc5424 = new RFC5424(options); } } if (options.leef) { if (options.leef.constructor__) { /** @type {LEEF} */ this.leef = options.leef; } else { this.leef = new LEEF(options); } } if (options.cef) { if (options.cef.constructor__) { /** @type {CEF} */ this.cef = options.cef; } else { this.cef = new CEF(options); } } if (this.format === 'rfc3164' && !this.rfc3164) { this.rfc3164 = new RFC3164(); } if (this.format === 'rfc5424' && !this.rfc5424) { this.rfc5424 = new RFC5424(); } if (this.format === 'leef' && !this.leef) { this.leef = new LEEF(); } if (this.format === 'cef' && !this.cef) { this.cef = new CEF(); } } /** * Add a TLS server certificate which can be used to authentacat the server * this syslog client is connecting too. This function will valadate the * input as a file location straing and add it to an array of certificates * @private * @version 0.0.0 * @since 0.0.0 * @param {string|string[]} certs - File location of the certificate(s) * @returns {Promise} - True * @throws {Error} - A Type Error */ addTlsServerCerts (certs) { return new Promise((resolve, reject) => { if (typeof certs === 'object' && Array.isArray(certs)) { /** @private @type {string[]} */ this.tlsServerCerts = certs; } else if (typeof certs === 'string') { this.tlsServerCerts = [certs]; } else { let errMsg = 'TYPE ERROR: Server Cert file loctions shoudl be a string'; errMsg += ' or array of strings'; reject(new Error(errMsg)); } resolve(true); }); } /** * Send the Syslog message over UDP * @private * @param {string} msg - The formated Syslog Message * @returns {Promise} - The Syslog formated string sent * @throws {Error} - Network Error */ udpMessage (msg) { return new Promise((resolve, reject) => { const dgram = require('dgram');// Test for target DNS and Address Family (IPv4/6) by looking up the DNS const dnsOptions = { verbatim: true }; dnsPromises.lookup(this.target, dnsOptions) .then((result) => { const udpType = result.family === 4 ? 'udp4' : 'udp6'; let client = dgram.createSocket(udpType); // Turn msg in to a UTF8 buffer let msgBuffer = Buffer.from(msg, 'utf8'); client.send(msgBuffer, this.port, this.target, (error) => { client.close(); resolve(msg); }); }) .catch((error) => { reject(error); // Reject out of the sendMessage function promise }); }); } /** * Send the Syslog message over TCP * @private * @param {string} msg - The formated Syslog Message * @returns {Promise} - The Syslog formated string sent * @throws {Error} - Timeout error for TCP and TLS connections * @throws {Error} - Network Error */ tcpMessage (msg) { return new Promise((resolve, reject) => { const net = require('net'); const dnsOptions = { verbatim: true }; dnsPromises.lookup(this.target, dnsOptions) .then((result) => { const tcpOptions = { host: this.target, port: this.port, family: result.family }; const client = net.createConnection(tcpOptions, () => { // Turn msg in to a UTF8 buffer let msgBuffer = Buffer.from(msg, 'utf8'); client.write(msgBuffer, () => { client.end(); }); }); client.setTimeout(this.tcpTimeout); client.on('end', () => { resolve(msg); }); client.on('timeout', () => { client.end(); reject(new Error('TIMEOUT ERROR: Syslog server TCP timeout')); }); client.on('error', (error) => { client.destroy(); reject(error); }); }) .catch((error) => { reject(error); }); }); } /** * Send the Syslog message over TLS * @private * @param {string} msg - The formated Syslog Message * @returns {Promise} - The Syslog formated string sent * @throws {Error} - Timeout error for TCP and TLS connections * @throws {Error} - Network Error */ tlsMessage (msg) { return new Promise((resolve, reject) => { const tls = require('tls'); const tlsOptions = { host: this.target, port: this.port, }; // Load client cert and key if requested if (typeof this.tlsClientKey === 'string' && typeof this.tlsClientCert === 'string') { tlsOptions.key = fs.readFileSync(this.tlsClientKey); tlsOptions.cert = fs.readFileSync(this.tlsClientCert); } else if (typeof this.tlsClientKey !== 'string' && typeof this.tlsClientKey !== 'undefined') { let errMsg = 'TYPE ERROR: TLS Client Key is not a file'; errMsg += 'location string'; reject(new Error(errMsg)); return; } else if (typeof this.tlsClientCert !== 'string' && typeof this.tlsClientCert !== 'undefined') { let errMsg = 'TYPE ERROR: TLS Client Cert is not a file'; errMsg += 'location string'; reject(new Error(errMsg)); return; } // Load any server certs if provided let tlsCerts = this.tlsServerCerts.length; if (tlsCerts > 0) { let tlsOptionsCerts = []; for (let certIndex=0; certIndex<tlsCerts; certIndex++) { if (typeof this.tlsServerCerts[certIndex] !== 'string') { let errMsg = 'TYPE ERROR: TLS Server Cert is not a file'; errMsg += 'location string'; reject(new Error(errMsg)); } let cert = fs.readFileSync(this.tlsServerCerts[certIndex]); tlsOptionsCerts.push(cert); } tlsOptions.ca = tlsOptionsCerts; tlsOptions.rejectUnauthorized = true; } const client = tls.connect(tlsOptions, () => { // Turn msg in to a UTF8 buffer let msgBuffer = Buffer.from(msg, 'utf8'); client.write(msgBuffer, () => { client.end(); }); }); client.setTimeout(this.tcpTimeout); // client.on('data', (data) => {}); client.on('end', () => { resolve(msg); }); client.on('timeout', () => { client.end(); reject(new Error('TIMEOUT ERROR: Syslog server TLS timeout')); }); client.on('error', (error) => { client.destroy(); reject(error); }); }); } /** * Send the Syslog message to the selected target Syslog server using the * selected transport. * @private * @param {string} msg - The formated Syslog Message * @returns {Promise} - The Syslog formated string sent * @throws {Error} - Timeout error for TCP and TLS connections * @throws {Error} - Network Error */ send (msg) { return new Promise((resolve, reject) => { if (typeof msg !== 'string') { reject(new Error("TYPE ERROR: Syslog message must be a string")); return; } this.protocol = this.protocol.toLowerCase(); if (this.protocol === 'udp') { this.udpMessage(msg) .then((result) => { resolve(result); }) .catch((reson) => { reject(reson); }); } else if (this.protocol === 'tcp') { this.tcpMessage(msg) .then((result) => { resolve(result); }) .catch((reson) => { reject(reson); }); } else if (this.protocol === 'tls') { this.tlsMessage(msg) .then((result) => { resolve(result); }) .catch((reson) => { reject(reson); }); } else { let errorMsg = 'FORMAT ERROR: Protocol not reconized, should be '; errorMsg += 'udp|tcp|tls'; reject(new Error(errorMsg)); } }); } } /** * A class to work with RFC3164 formated syslog messages. * @requires moment * @version 0.0.0 * @since 0.0.0 */ class RFC3164 { /** * Construct a new RFC3164 formated Syslog object with user options * @public * @this RFC3164 * @param {object} [options] - Options object * @param {string} [options.applacationName='NodeJSLogger'] - Applacation * @param {string} [options.hostname=os.hostname] - The name of this server * @param {number} [options.facility=23] - Facility code to use sending this * message * @param {boolean} [options.color=false] - Apply color coding encoding tag * with syslog message text * @param {boolean} [options.extendedColor=false] - Use the extedned ANSI * color set encoding tag with syslog message text * @param {object} [options.colors] - User defended colors for * severites * @param {string} [options.colors.emergencyColor] - A RGB Hex coded color in the form * of #FFFFFF or as or the ANSI color code number (30-37 Standard & 0-255 * Extended) * @param {string} [options.colors.alertColor] - A RGB Hex coded color in the form * of #FFFFFF or as or the ANSI color code number (30-37 Standard & 0-255 * Extended) * @param {string} [options.colors.criticalColor] - A RGB Hex coded color in the form * of #FFFFFF or as or the ANSI color code number (30-37 Standard & 0-255 * Extended) * @param {string} [options.colors.errorColor] - A RGB Hex coded color in the form * of #FFFFFF or as or the ANSI color code number (30-37 Standard & 0-255 * Extended) * @param {string} [options.colors.warningColor] - A RGB Hex coded color in the form * of #FFFFFF or as or the ANSI color code number (30-37 Standard & 0-255 * Extended) * @param {string} [options.colors.noticeColor] - A RGB Hex coded color in the form * of #FFFFFF or as or the ANSI color code number (30-37 Standard & 0-255 * Extended) * @param {string} [options.colors.informationalColor] - A RGB Hex coded color in the form * of #FFFFFF or as or the ANSI color code number (30-37 Standard & 0-255 * Extended) * @param {string} [options.colors.debugColor] - A RGB Hex coded color in the form * of #FFFFFF or as or the ANSI color code number (30-37 Standard & 0-255 * Extended) * @param {Syslog} [options.server=false] - A {@link module:SyslogPro~Syslog| * Syslog server connection} that should be used to send messages directly * from this class. @see SyslogPro~Syslog */ constructor (options) { /** @private @type {boolean} */ this.constructor__ = true; options = options || {}; this.hostname = options.hostname || os.hostname(); this.applacationName = options.applacationName || ''; this.facility = options.facility || 23; if (options.color) { /** @type {boolean} */ this.color = true; } else { this.color = false; } if (options.extendedColor) { /** @type {boolean} */ this.extendedColor = true; } else { this.extendedColor = false; } if (options.server) { if (!options.server.constructor__) { /** @private @type {Syslog} */ this.server = new Syslog(options.server); } else { this.server = options.server; } } if (this.extendedColor) { /** @private @type {number} */ this.emergencyColor = 1; // Red foreground color /** @private @type {number} */ this.alertColor = 202; // Dark Orange foreground color /** @private @type {number} */ this.criticalColor = 208; // Orange foreground color /** @private @type {number} */ this.errorColor = 178; // Light Orange foreground color /** @private @type {number} */ this.warningColor = 226; // Yellow foreground color /** @private @type {number} */ this.noticeColor = 117; // Light Blue foreground color /** @private @type {number} */ this.informationalColor = 45; // Blue foreground color /** @private @type {number} */ this.debugColor = 27; // Dark Blue foreground color } else { this.emergencyColor = 31; // Red foreground color this.alertColor = 31; // Red foreground color this.criticalColor = 31; // Red foreground color this.errorColor = 33; // Yellow foreground color this.warningColor = 33; // Yellow foreground color this.noticeColor = 36; // Blue foreground color this.informationalColor = 36; // Blue foreground color this.debugColor = 34; // Dark Blue foreground color } if (typeof options.colors === 'object') { this.setColor(options.colors, this.extendedColor); } } /** * Sets the color to be used for messages at a set priority * @public * @param {string} [colors.emergencyColor] - A RGB Hex coded color in the form * of #FFFFFF or as or the ANSI color code number (30-37 Standard & 0-255 * Extended) * @param {string} [colors.alertColor] - A RGB Hex coded color in the form * of #FFFFFF or as or the ANSI color code number (30-37 Standard & 0-255 * Extended) * @param {string} [colors.criticalColor] - A RGB Hex coded color in the form * of #FFFFFF or as or the ANSI color code number (30-37 Standard & 0-255 * Extended) * @param {string} [colors.errorColor] - A RGB Hex coded color in the form * of #FFFFFF or as or the ANSI color code number (30-37 Standard & 0-255 * Extended) * @param {string} [colors.warningColor] - A RGB Hex coded color in the form * of #FFFFFF or as or the ANSI color code number (30-37 Standard & 0-255 * Extended) * @param {string} [colors.noticeColor] - A RGB Hex coded color in the form * of #FFFFFF or as or the ANSI color code number (30-37 Standard & 0-255 * Extended) * @param {string} [colors.informationalColor] - A RGB Hex coded color in the form * of #FFFFFF or as or the ANSI color code number (30-37 Standard & 0-255 * Extended) * @param {string} [colors.debugColor] - A RGB Hex coded color in the form * of #FFFFFF or as or the ANSI color code number (30-37 Standard & 0-255 * Extended) * @throws {Error} A standard error object */ setColor (colors, extendedColor) { return new Promise((resolve, reject) => { let colorPromises = []; if (colors.emergencyColor) { colorPromises.push( new Promise((resolve,reject) => { rgbToAnsi(colors.emergencyColor, this.extendedColor) .then((result) => { this.emergencyColor = result; resolve(true); }) .catch((reson) => { reson.message = 'TYPE ERROR: '; reson.message += 'emergencyColor'; reson.message += ' Not in RGB color hex or color code'; reject(reson); }); })); } if (colors.alertColor) { colorPromises.push( new Promise((resolve,reject) => { rgbToAnsi(colors.alertColor, this.extendedColor) .then((result) => { this.alertColor = result; resolve(true); }) .catch((reson) => { reson.message = 'TYPE ERROR: '; reson.message += 'alertColor'; reson.message += ' Not in RGB color hex or color code'; reject(reson); }); })); } if (colors.criticalColor) { colorPromises.push( new Promise((resolve,reject) => { rgbToAnsi(colors.criticalColor, this.extendedColor) .then((result) => { this.criticalColor = result; resolve(true); }) .catch((reson) => { reson.message = 'TYPE ERROR: '; reson.message += 'criticalColor'; reson.message += ' Not in RGB color hex or color code'; reject(reson); }); })); } if (colors.errorColor) { colorPromises.push( new Promise((resolve,reject) => { rgbToAnsi(colors.errorColor, this.extendedColor) .then((result) => { this.errorColor = result; resolve(true); }) .catch((reson) => { reson.message = 'TYPE ERROR: '; reson.message += 'errorColor'; reson.message += ' Not in RGB color hex or color code'; reject(reson); }); })); } if (colors.warningColor) { colorPromises.push( new Promise((resolve,reject) => { rgbToAnsi(colors.warningColor, this.extendedColor) .then((result) => { this.warningColor = result; resolve(true); }) .catch((reson) => { reson.message = 'TYPE ERROR: '; reson.message += 'warningColor'; reson.message += ' Not in RGB color hex or color code'; reject(reson); }); })); } if (colors.noticeColor) { colorPromises.push( new Promise((resolve,reject) => { rgbToAnsi(colors.noticeColor, this.extendedColor) .then((result) => { this.noticeColor = result; resolve(true); }) .catch((reson) => { reson.message = 'TYPE ERROR: '; reson.message += 'noticeColor'; reson.message += ' Not in RGB color hex or color code'; reject(reson); }); })); } if (colors.informationalColor) { colorPromises.push( new Promise((resolve,reject) => { rgbToAnsi(colors.informationalColor, this.extendedColor) .then((result) => { this.informationalColor = result; resolve(true); }) .catch((reson) => { reson.message = 'TYPE ERROR: '; reson.message += 'informationalColor'; reson.message += ' Not in RGB color hex or color code'; reject(reson); }); })); } if (colors.debugColor) { colorPromises.push( new Promise((resolve,reject) => { rgbToAnsi(colors.debugColor, this.extendedColor) .then((result) => { this.debugColor = result; resolve(true); }) .catch((reson) => { reson.message = 'TYPE ERROR: '; reson.message += 'debugColor'; reson.message += ' Not in RGB color hex or color code'; reject(reson); }); })); } Promise.all(colorPromises) .then((results) => { resolve(true); }) .catch((reson) => { reject(reson); }); }); } /** * Building a formated message. Returns a promise with a formated message * @public * @param {string} msg - The Syslog Message * @param {object} [options] - Options object * @param {number} [options.severity=7] - An array of structure * @param {number} [options.colorCode=36] - The ANSI color code to use if * message coloration is selected * @returns {Promise} A Syslog formated string acording to the selected RFC * @throws {Error} A standard error object */ buildMessage (msg, options) { return new Promise((resolve, reject) => { options = options || {}; let severity = typeof options.severity === 'number' ? options.severity : 6; if (typeof msg !== 'string' || options.msgSeverity > 7) { let errMsg = 'FORMAT ERROR: Syslog message must be a string'; errMsg += ' msgSeverity must be a number between 0 and 7'; reject(new Error(errMsg)); return; } let fmtMsg = ''; // Formated Syslog message string var const newLine = '\n'; const newLineRegEx = /(\r|\n|(\r\n))/; const escapeCode = '\u001B'; const resetColor = '\u001B[0m'; // The PRI is common to both RFC formats const pri = (this.facility * 8) + severity; // Remove any newline character msg = msg.replace(newLineRegEx, ''); // Add requested color if (this.color) { options.msgColor = options.msgColor || 36; let colorCode = '['; if (this.extendedColor) { colorCode += '38;5;'; // Extended 256 Colors ANSI Code } if (typeof options.msgColor === 'number') { colorCode += options.msgColor; colorCode += 'm'; // ANSI Color Closer } else { colorCode = '[39m'; // Use terminal's defualt color } msg = escapeCode + colorCode + msg + resetColor; } // RegEx to find a leading 0 in the day of a DateTime for RFC3164 // RFC3164 uses BSD timeformat const rfc3164DateRegEx = /((A|D|F|J|M|N|O|S)(a|c|e|p|o|u)(b|c|g|l|n|p|r|t|v|y)\s)0(\d\s\d\d:\d\d:\d\d)/; const timestamp = moment() .format('MMM DD hh:mm:ss') .replace(rfc3164DateRegEx, '$1 $5'); // Build message fmtMsg = '<' + pri + '>'; fmtMsg += timestamp; fmtMsg += ' ' + this.hostname; fmtMsg += ' ' + this.applacationName; fmtMsg += ' ' + msg; fmtMsg += newLine; resolve(fmtMsg); }); } /** * send a RFC5424 formated message. Returns a promise with the formated * message that was sent. If no server connection was defined when the * class was created a defualt Syslog connector will be used. * @see SyslogPro~Syslog * @public * @param {string} msg - The unformated Syslog message to send * @param {object} [options] - Options object * @param {number} [options.severity=7] - An array of structure * @param {number} [options.colorCode=36] - The ANSI color code to use if * @returns {Promise} A Syslog formated string acording to the selected RFC * @throws {Error} A standard error object */ send (msg, options) { return new Promise((resolve, reject) => { if (!this.server) { this.server = new Syslog(); } this.buildMessage(msg, options) .then((result) => { this.server.send(result) .then((sendResult) => { resolve(sendResult); }) .catch((error) => { reject(error); }); }) .catch((error) => { reject(error); }); }); } /** * Send a syslog message with a secerity level of 0 (Emergency) * @public * @param {string} msg - The emergancy message to send to the Syslog server * @returns {Promise} - The formated syslog message sent to the Syslog server * @throws {Error} - Any bubbled up error */ emergency (msg) { return this.send(msg, { severity: 0, colorCode: this.emergencyColor }); } /** * Send a syslog message with a secerity level of 0 (Emergency) * @public * @param {string} msg - The emergancy message to send to the Syslog server * @returns {Promise} - The formated syslog message sent to the Syslog server * @throws {Error} - Any bubbled up error */ emer (msg) { return this.emergency(msg); } /** * Send a syslog message with a secerity level of 1 (Alert) * @public * @param {string} msg - The alert message to send to the Syslog server * @returns {Promise} - The formated syslog message sent to the Syslog server * @throws {Error} - Any bubbled up error */ alert (msg) { return this.send(msg, { severity: 1, colorCode: this.alertColor }); } /** * Send a syslog message with a secerity level of 2 (Critical) * @public * @param {string} msg - The critical message to send to the Syslog server * @returns {Promise} - The formated syslog message sent to the Syslog server * @throws {Error} - Any bubbled up error */ critical (msg) { return this.send(msg, { severity: 2, colorCode: this.criticalColor }); } /** * Send a syslog message with a secerity level of 2 (Critical) * @public * @param {string} msg - The critical message to send to the Syslog server * @returns {Promise} - The formated syslog message sent to the Syslog server * @throws {Error} - Any bubbled up error */ crit (msg) { return this.critical(msg); } /** * Send a syslog message with a secerity level of 3 (Error) * @public * @param {string} msg - The error message to send to the Syslog server * @returns {Promise} - The formated syslog message sent to the Syslog server * @throws {Error} - Any bubbled up error */ error (msg) { return this.send(msg, { severity: 3, colorCode: this.errorColor }); } /** * Send a syslog message with a secerity level of 3 (Error) * @public * @param {string} msg - The error message to send to the Syslog server * @returns {Promise} - The formated syslog message sent to the Syslog server * @throws {Error} - Any bubbled up error */ err (msg) { return this.error(msg); } /** * Send a syslog message with a secerity level of 4 (Warning) * @public * @param {string} msg - The warning message to send to the Syslog server * @returns {Promise} - The formated syslog message sent to the Syslog server * @throws {Error} - Any bubbled up error */ warning (msg) { return this.send(msg, { severity: 4, colorCode: this.warningColor }); } /** * Send a syslog message with a secerity level of 4 (Warning) * @public * @param {string} msg - The warning message to send to the Syslog server * @returns {Promise} - The formated syslog message sent to the Syslog server * @throws {Error} - Any bubbled up error */ warn (msg) { return this.warning(msg); } /** * Send a syslog message with a secerity level of 5 (Notice) * @public * @param {string} msg - The notice message to send to the Syslog server * @returns {Promise} - The formated syslog message sent to the Syslog server * @throws {Error} - Any bubbled up error */ notice (msg) { return this.send(msg, { severity: 5, colorCode: this.noticeColor }); } /** * Send a syslog message with a secerity level of 5 (Notice) * @public * @param {string} msg - The notice message to send to the Syslog server * @returns {Promise} - The formated syslog message sent to the Syslog server * @throws {Error} - Any bubbled up error */ note (msg) { return this.notice(msg); } /** * Send a syslog message with a secerity level of 6 (Informational) * @public * @param {string} msg - The informational message to send to the Syslog server * @returns {Promise} - The formated syslog message sent to the Syslog server * @throws {Error} - Any bubbled up error */ informational (msg) { return this.send(msg, { severity: 6, colorCode: this.informationalColor }); } /** * Send a syslog message with a secerity level of 6 (Informational) * @public * @param {string} msg - The informational message to send to the Syslog server * @returns {Promise} - The formated syslog message sent to the Syslog server * @throws {Error} - Any bubbled up error */ info (msg) { return this.informational(msg); } /** * Send a syslog message with a secerity level of 6 (Informational) * @public * @param {string} msg - The informational message to send to the Syslog server * @returns {Promise} - The formated syslog message sent to the Syslog server * @throws {Error} - Any bubbled up error */ log (msg) { return this.informational(msg); } /** * Send a syslog message with a secerity level of 7 (Debug) * @public * @param {string} msg - The debug message to send to the Syslog server * @returns {Promise} - The formated syslog message sent to the Syslog server * @throws {Error} - Any bubbled up error */ debug (msg) { return this.send(msg, { severity: 7, colorCode: this.debugColor }); } } /** * A class to work with RFC5424 formated syslog messages. * @requires moment * @version 0.0.0 * @since 0.0.0 */ class RFC5424 { /** * Construct a new RFC5424 formated Syslog object with user options * @public * @this RFC5424 * @param {object} [options] - Options object * @param {string} [options.applacationName='NodeJSLogger'] - Applacation * @param {string} [options.hostname=os.hostname] - The name of this server * @param {boolean} [options.timestamp=false] - Included a Timestamp * @param {boolean} [options.timestampUTC=false] - RFC tandard is for * local time * @param {boolean} [options.timestampMS=false] - Timestamp with ms * resoltuion * @param {boolean} [options.timestampTZ=true] - Should the timestamp * included timezone * @param {boolean} [options.encludeStructuredData=false] - Included * any provided structured data * @param {boolean} [options.utf8BOM=true] - Included the UTF8 * @param {boolean} [options.color=false] - Included the UTF8 * @param {boolean} [options.extendedColor=false] - Included the UTF8 * encoding tag with syslog message text * @param {object} [options.colors] - User defended colors for * severites * @param {string} [options.colors.emergencyColor] - A RGB Hex coded color in the form * of #FFFFFF or as or the ANSI color code number (30-37 Standard & 0-255 * Extended) * @param {string} [options.colors.alertColor] - A RGB Hex coded color in the form * of #FFFFFF or as or the ANSI color code number (30-37 Standard & 0-255 * Extended) * @param {string} [options.colors.criticalColor] - A RGB Hex coded color in the form * of #FFFFFF or as or the ANSI color code number (30-37 Standard & 0-255 * Extended) * @param {string} [options.colors.errorColor] - A RGB Hex coded color in the form * of #FFFFFF or as or the ANSI color code number (30-37 Standard & 0-255 * Extended) * @param {string} [options.colors.warningColor] - A RGB Hex coded color in the form * of #FFFFFF or as or the ANSI color code number (30-37 Standard & 0-255 * Extended) * @param {string} [options.colors.noticeColor] - A RGB Hex coded color in the form * of #FFFFFF or as or the ANSI color code number (30-37 Standard & 0-255 * Extended) * @param {string} [options.colors.informationalColor] - A RGB Hex coded color in the form * of #FFFFFF or as or the ANSI color code number (30-37 Standard & 0-255 * Extended) * @param {string} [options.colors.debugColor] - A RGB Hex coded color in the form * of #FFFFFF or as or the ANSI color code number (30-37 Standard & 0-255 * Extended) * @param {Syslog} [options.server=false] - A {@link module:SyslogPro~Syslog| * Syslog server connection} that should be used to send messages directly * from this class. @see SyslogPro~Syslog */ constructor (options) { /** @private @type {boolean} */ this.constructor__ = true; options = options || {}; this.hostname = options.hostname || os.hostname(); this.applacationName = options.applacationName || ''; if (typeof options.timestamp === 'undefined' || options.timestamp) { /** @type {boolean} */ this.timestamp = true; } else { this.timestamp = false; } if (options.timestampUTC) { /** @type {boolean} */ this.timestampUTC = true; } else { this.timestampUTC = false; } if (typeof options.timestampTZ === 'undefined' || options.timestampTZ) { /** @type {boolean} */ this.timestampTZ = true; } else { this.timestampTZ = false; } if (options.timestampMS) { /** @type {boolean} */ this.timestampMS = true; } else { this.timestampMS = false; } if (options.encludeStructuredData) { /** @type {boolean} */ this.encludeStructuredData = true; } else { this.encludeStructuredData = false; } if (typeof options.utf8BOM === 'undefined' || options.utf8BOM) { /** @type {boolean} */ this.utf8BOM = true; } else { this.utf8BOM = false; } if (options.color) { /** @type {boolean} */ this.color = true; } else { this.color = false; } if (options.extendedColor) { /** @type {boolean} */ this.extendedColor = true; } else { this.extendedColor = false; } if (options.server) { if (!options.server.constructor__) { /** @private @type {Syslog} */ this.server = new Syslog(options.server); } else { this.server = options.server; } } if (this.extendedColor) { /** @private @type {number} */ this.emergencyColor = 1; // Red foreground color /** @private @type {number} */ this.alertColor = 202; // Dark Orange foreground color /** @private @type {number} */ this.criticalColor = 208; // Orange foreground color /** @private @type {number} */ this.errorColor = 178; // Light Orange foreground color /** @private @type {number} */ this.warningColor = 226; // Yellow foreground color /** @private @type {number} */ this.noticeColor = 117; // Light Blue foreground color /** @private @type {number} */ this.informationalColor = 45; // Blue foreground color /** @private @type {number} */ this.debugColor = 27; // Dark Blue foreground color } else { this.emergencyColor = 31; // Red foreground color this.alertColor = 31; // Red foreground color this.criticalColor = 31; // Red foreground color this.errorColor = 33; // Yellow foreground color this.warningColor = 33; // Yellow foreground color this.noticeColor = 36; // Blue foreground color this.informationalColor = 36; // Blue foreground color this.debugColor = 34; // Dark Blue foreground color } if (typeof options.colors === 'object') { this.setColor(options.colors, this.extendedColor); } } /** * Sets the color to be used for messages at a set priority * @public * @param {string} [colors.emergencyColor] - A RGB Hex coded color in the form * of #FFFFFF or as or the ANSI color code number (30-37 Standard & 0-255 * Extended) * @param {string} [colors.alertColor] - A RGB Hex coded color in the form * of #FFFFFF or as or the ANSI color code number (30-37 Standard & 0-255 * Extended) * @param {string} [colors.criticalColor] - A RGB Hex coded color in the form * of #FFFFFF or as or the ANSI color code number (30-37 Standard & 0-255 * Extended) * @param {string} [colors.errorColor] - A RGB Hex coded color in the form * of #FFFFFF or as or the ANSI color code number (30-37 Standard & 0-255 * Extended) * @param {string} [colors.warningColor] - A RGB Hex coded color in the form * of #FFFFFF or as or the ANSI color code number (30-37 Standard & 0-255 * Extended) * @param {string} [colors.noticeColor] - A RGB Hex coded color in the form * of #FFFFFF or as or the ANSI color code number (30-37 Standard & 0-255 * Extended) * @param {string} [colors.informationalColor] - A RGB Hex coded color in the form * of #FFFFFF or as or the ANSI color code number (30-37 Standard & 0-255 * Extended) * @param {string} [colors.debugColor] - A RGB Hex coded color in the form * of #FFFFFF or as or the ANSI color code number (30-37 Standard & 0-255 * Extended) * @throws {Error} A standard error object */ setColor (colors, extendedColor) { return new Promise((resolve, reject) => { let colorPromises = []; if (colors.emergencyColor) { colorPromises.push( new Promise((resolve,reject) => { rgbToAnsi(colors.emergencyColor, this.extendedColor) .then((result) => { this.emergencyColor = result; resolve(true); }) .catch((reson) => { reson.message = 'TYPE ERROR: '; reson.message += 'emergencyColor'; reson.message += ' Not in RGB color hex or color code'; reject(reson); }); })); } if (colors.alertColor) { colorPromises.push( new Promise((resolve,reject) => { rgbToAnsi(colors.alertColor, this.extendedColor) .then((result) => { this.alertColor = result; resolve(true); }) .catch((reson) => { reson.message = 'TYPE ERROR: '; reson.message += 'alertColor'; reson.message += ' Not in RGB color hex or color code'; reject(reson); }); })); } if (colors.criticalColor) { colorPromises.push( new Promise((resolve,reject) => { rgbToAnsi(colors.criticalColor, this.extendedColor) .then((result) => { this.criticalColor = result; resolve(true); }) .catch((reson) => { reson.message = 'TYPE ERROR: '; reson.message += 'criticalColor'; reson.message += ' Not in RGB color hex or color code'; reject(reson); }); })); } if (colors.errorColor) { colorPromises.push( new Promise((resolve,reject) => { rgbToAnsi(colors.errorColor, this.extendedColor) .then((result) => { this.errorColor = result; resolve(true); }) .catch((reson) => { reson.message = 'TYPE ERROR: '; reson.message += 'errorColor'; reson.message += ' Not in RGB color hex or color code'; reject(reson); }); })); } if (colors.warningColor) { colorPromises.push( new Promise((resolve,reject) => { rgbToAnsi(colors.warningColor, this.extendedColor) .then((result) => { this.warningColor = result; resolve(true); }) .catch((reson) => { reson.message = 'TYPE ERROR: '; reson.message += 'warningColor'; reson.message += ' Not in RGB color hex or color code'; reject(reson); }); })); } if (colors.noticeColor) { colorPromises.push( new Promise((resolve,reject) => { rgbToAnsi(colors.noticeColor, this.extendedColor) .then((result) => { this.noticeColor = result; resolve(true); }) .catch((reson) => { reson.message = 'TYPE ERROR: '; reson.message += 'noticeColor'; reson.message += ' Not in RGB color hex or color code'; reject(reson); }); })); } if (colors.informationalColor) { colorPromises.push( new Promise((resolve,reject) => { rgbToAnsi(colors.informationalColor, this.extendedColor) .then((result) => { this.informationalColor = result; resolve(true); }) .catch((reson) => { reson.message = 'TYPE ERROR: '; reson.message += 'informationalColor'; reson.message += ' Not in RGB color hex or color code'; reject(reson); }); })); } if (colors.debugColor) { colorPromises.push( new Promise((resolve,reject) => { rgbToAnsi(colors.debugColor, this.extendedColor) .then((result) => { this.debugColor = result; resolve(true); }) .catch((reson) => { reson.message = 'TYPE ERROR: '; reson.message += 'debugColor'; reson.message += ' Not in RGB color hex or color code'; reject(reson); }); })); } Promise.all(colorPromises) .then((results) => { resolve(true); }) .catch((reson) => { reject(reson); }); }); } /** * Building a formated message. Returns a promise with a formated message * @public * @param {string} msg - The Syslog Message * @param {object} [options] - Options object * @param {number} [options.severity=7] - An array of structure * @param {number} [options.facility=23] - Facility code to use sending this * message * @param {string} [options.pid='-'] - The process id of the service sending * this message * @param {string[]} [options.structuredData] - An array of structure * data strings conforming to the IETF/IANA defined SD-IDs or IANA * registred SMI Network Management Private Enterprise Code SD-ID * conforming to the format * [name@<private enterprise number> parameter=value] * @param {number} [options.colorCode=36] - The ANSI color code to use if * message coloration is selected * @returns {Promise} A Syslog formated string acording to the selected RFC * @throws {Error} A standard error object */ buildMessage (msg, options) { return new Promise((resolve, reject) => { options = options || {}; let severity = typeof options.severity === 'number' ? options.severity : 6; if (typeof msg !== 'string' || options.severity > 7) { let errMsg = 'FORMAT ERROR: Syslog message must be a string'; errMsg += ' msgSeverity must be a number between 0 and 7'; reject(new Error(errMsg)); return; } let facility = options.facility || 23; let pid = options.pid || '-'; let id = options.id || '-'; let msgStructuredData = options.msgStructuredData || []; let fmtMsg = ''; // Formated Syslog message string var const newLine = '\n'; const newLineRegEx = /(\r|\n|(\r\n))/; const escapeCode = '\u001B'; const resetColor = '\u001B[0m'; // The PRI is common to both RFC formats const pri = (facility * 8) + severity; // Remove any newline character msg = msg.replace(newLineRegEx, ''); // Add requested color if (this.color) { options.msgColor = options.msgColor || 36; let colorCode = '['; if (this.extendedColor) { colorCode += '38;5;'; // Extended 256 Colors ANSI Code } if (typeof options.msgColor === 'number') { colorCode += options.msgColor; colorCode += 'm'; // ANSI Color Closer } else { colorCode = '[39m'; // Use terminal's defualt color } msg = escapeCode + colorCode + msg + resetColor; } // RFC5424 timestamp formating let timestamp = '-'; if (this.timestamp) { let timeQuality = '[timeQuality'; if (this.timestampUTC) { timeQuality += ' tzKnown=1'; if (this.timestampMS) { if (this.timestampTZ) { timestamp = moment().utc().format('YYYY-MM-DDThh:mm:ss.SSSSSSZ'); } else { timestamp = moment().utc().format('YYYY-MM-DDThh:mm:ss.SSSSSS'); } } else { if (this.timestampTZ) { timestamp = moment().utc().format('YYYY-MM-DDThh:mm:ssZ'); } else { timestamp = moment().utc().format('YYYY-MM-DDThh:mm:ss'); } } } else { if (this.timestampTZ) { timeQuality += ' tzKnown=1'; if (this.timestampMS) { timeQuality += ' isSynced=1'; timeQuality += ' syncAccuracy=0'; timestamp = moment().format('YYYY-MM-DDThh:mm:ss.SSSSSSZ'); } else { timestamp = moment().format('YYYY-MM-DDThh:mm:ssZ'); } } else { timeQuality += ' tzKnown=0'; if (this.timestampMS) { timeQuality += ' isSynced=1'; timeQuality += ' syncAccuracy=0'; timestamp = moment().format('YYYY-MM-DDThh:mm:ss.SSSSSS'); } else { timestamp = moment().format('YYYY-MM-DDThh:mm:ss'); } } } timeQuality += ']'; msgStructuredData.push(timeQuality); } // Build Structured Data string let structuredData = '-'; const sdElementCount = msgStructuredData.length; if (this.encludeStructuredData && sdElementCount > 0) { let sdElementNames = []; let sdElements = []; const sdElementNameRegEx = /(\[)(\S*)(\s|\])/; // Loop to drop duplicates of the same SD Element name for (let elementIndex=0; elementIndex<sdElementCount; elementIndex++) { let elementName = msgStructuredData[elementIndex] .match(sdElementNameRegEx)[2]; if (!sdElementNames.includes(elementName)) { sdElementNames.push(elementName); sdElements.push(msgStructuredData[elementIndex]); } } structuredData = sdElements.join(''); } // Build the message fmtMsg = '<' + pri + '>'; fmtMsg += '1'; // Version number fmtMsg += ' ' + timestamp; fmtMsg += ' ' + this.hostname; fmtMsg += ' ' + this.applacationName; fmtMsg += ' ' + pid; fmtMsg += ' ' + id; fmtMsg += ' ' + structuredData; if (this.utf8BOM) { fmtMsg += ' BOM' + msg; } else { fmtMsg += ' ' + msg; } fmtMsg += newLine; resolve(fmtMsg); }); } /** * send a RFC5424 formated message. Returns a promise with the formated * message that was sent. If no server connection was defined when the * class was created a defualt Syslog connector will be used. * @see SyslogPro~Syslog * @public * @param {string} msg - The unformated Syslog message to send * @returns {Promise} A Syslog formated string acording to the selected RFC * @throws {Error} A standard error object */ send (msg, options) { return new Promise((resolve, reject) => { if (!this.server) { this.server = new Syslog(); } this.buildMessage(msg, options) .then((result) => { this.server.send(result) .then((sendResult) => { resolve(sendResult); }) .catch((error) => { reject(error); }); }) .catch((error) => { reject(error); }); }); } /** * Send a syslog message with a secerity level of 0 (Emergency) * @public * @param {string} msg - The emergancy message to send to the Syslog server * @returns {Promise} - The formated syslog message sent to the Syslog server * @throws {Error} - Any bubbled up error */ emergency (msg) { return this.send(msg, { severity: 0, colorCode: this.emergencyColor }); } /** * Send a syslog message with a secerity level of 0 (Emergency) * @public * @param {string} msg - The emergancy message to send to the Syslog server * @returns {Promise} - The formated syslog message sent to the Syslog server * @throws {Error} - Any bubbled up error */ emer (msg) { return this.emergency(msg); } /** * Send a syslog message with a secerity level of 1 (Alert) * @public * @param {string} msg - The alert message to send to the Syslog server * @returns {Promise} - The formated syslog message sent to the Syslog server * @throws {Error} - Any bubbled up error */ alert (msg) { return this.send(msg, { severity: 1, colorCode: this.alertColor }); } /** * Send a syslog message with a secerity level of 2 (Critical) * @public * @param {string} msg - The critical message to send to the Syslog server * @returns {Promise} - The formated syslog message sent to the Syslog server * @throws {Error} - Any bubbled up error */ critical (msg) { return this.send(msg, { severity: 2, colorCode: this.criticalColor }); } /** * Send a syslog message with a secerity level of 2 (Critical) * @public * @param {string} msg - The critical message to send to the Syslog server * @returns {Promise} - The formated syslog message sent to the Syslog server * @throws {Error} - Any bubbled up error */ crit (msg) { return this.critical(msg); } /** * Send a syslog message with a secerity level of 3 (Error) * @public * @param {string} msg - The error message to send to the Syslog server * @returns {Promise} - The formated syslog message sent to the Syslog server * @throws {Error} - Any bubbled up error */ error (msg) { return this.send(msg, { severity: 3, colorCode: this.errorColor }); } /** * Send a syslog message with a secerity level of 3 (Error) * @public * @param {string} msg - The error message to send to the Syslog server * @returns {Promise} - The formated syslog message sent to the Syslog server * @throws {Error} - Any bubbled up error */ err (msg) { return this.error(msg); } /** * Send a syslog message with a secerity level of 4 (Warning) * @public * @param {string} msg - The warning message to send to the Syslog server * @returns {Promise} - The formated syslog message sent to the Syslog server * @throws {Error} - Any bubbled up error */ warning (msg) { return this.send(msg, { severity: 4, colorCode: this.warningColor }); } /** * Send a syslog message with a secerity level of 4 (Warning) * @public * @param {string} msg - The warning message to send to the Syslog server * @returns {Promise} - The formated syslog message sent to the Syslog server * @throws {Error} - Any bubbled up error */ warn (msg) { return this.warning(msg); } /** * Send a syslog message with a secerity level of 5 (Notice) * @public * @param {string} msg - The notice message to send to the Syslog server * @returns {Promise} - The formated syslog message sent to the Syslog server * @throws {Error} - Any bubbled up error */ notice (msg) { return this.send(msg, { severity: 5, colorCode: this.noticeColor }); } /** * Send a syslog message with a secerity level of 5 (Notice) * @public * @param {string} msg - The notice message to send to the Syslog server * @returns {Promise} - The formated syslog message sent to the Syslog server * @throws {Error} - Any bubbled up error */ note (msg) { return this.notice(msg); } /** * Send a syslog message with a secerity level of 6 (Informational) * @public * @param {string} msg - The informational message to send to the Syslog server * @returns {Promise} - The formated syslog message sent to the Syslog server * @throws {Error} - Any bubbled up error */ informational (msg) { return this.send(msg, { severity: 6, colorCode: this.informationalColor }); } /** * Send a syslog message with a secerity level of 6 (Informational) * @public * @param {string} msg - The informational message to send to the Syslog server * @returns {Promise} - The formated syslog message sent to the Syslog server * @throws {Error} - Any bubbled up error */ info (msg) { return this.informational(msg); } /** * Send a syslog message with a secerity level of 6 (Informational) * @public * @param {string} msg - The informational message to send to the Syslog server * @returns {Promise} - The formated syslog message sent to the Syslog server * @throws {Error} - Any bubbled up error */ log (msg) { return this.informational(msg); } /** * Send a syslog message with a secerity level of 7 (Debug) * @public * @param {string} msg - The debug message to send to the Syslog server * @returns {Promise} - The formated syslog message sent to the Syslog server * @throws {Error} - Any bubbled up error */ debug (msg) { return this.send(msg, { severity: 7, colorCode: this.debugColor }); } } /** * A class to work with IBM LEEF (Log Event Extended Format) messages this form * of system messages are designed to work with security systems. Messages can * be saved to file (Saving to file if not part of this module but a LEEF * formated mesage produced by this module can be saved externaly to it) or * sent via Syslog. * @requires moment * @version 0.0.0 * @since 0.0.0 */ class LEEF { /** * Construct a new LEEF object with user options * @public * @param {object} [options] - Options object * @param {string} [options.vendor='unknown'] - The vendor of the system that * genrated the event being reported * @param {string} [options.product='unknown'] - The product name of the * system that genrated the event being reported * @param {string} [options.version='unknown'] - The version name of the * system that genrated the event being reported * @param {string} [options.eventId='unknown'] - The eventId of the * system that genrated the event being reported * @param {boolean} [options.syslogHeader='true'] - Should the LEEF message * include a Syslog header with Timestamp and source * @param {Syslog} [options.server=false] - A {@link module:SyslogPro~Syslog| * Syslog server connection} that should be used to send messages directly * from this class. @see SyslogPro~Syslog */ constructor (options) { /** @private @type {boolean} */ this.constructor__ = true; options = options || {}; /** @type {string} */ this.vendor = options.vendor || 'unknown'; /** @type {string} */ this.product = options.product || 'unknown'; /** @type {string} */ this.version = options.version || 'unknown'; /** @type {string} */ this.eventId = options.eventId || 'unknown'; /** @type {boolean} */ this.syslogHeader = typeof options.syslogHeader === 'boolean' ? options.syslogHeader : true; /** @type {object} */ this.attrabutes = options.attrabutes || { cat: null, devTime: null, devTimeFormat: null, proto: null, sev: null, src: null, dst: null, srcPort: null, dstPort: null, srcPreNAT: null, dstPreNAT: null, srcPostNAT: null, dstPostNAT: null, usrName: null, srcMAC: null, dstMAC: null, srcPreNATPort: null, dstPreNATPort: null, srcPostNATPort: null, dstPostNATPort: null, identSrc: null, identHostName: null, identNetBios: null, identGrpName: null, identMAC: null, vSrc: null, vSrcName: null, accountName: null, srcBytes: null, dstBytes: null, srcPackets: null, dstPackets: null, totalPackets: null, role: null, realm: null, policy: null, resource: null, url: null, groupID: null, domain: null, isLoginEvent: null, isLogoutEvent: null, identSecondlp: null, calLanguage: null, AttributeLimits: null, calCountryOrRegion: null, }; if (options.server) { if (options.server.constructor__) { /** @private @type {Syslog} */ this.server = options.server; } else { this.server = new Syslog(options.server); } } } /** *Build a formated message * @public * @return {Promise} - string with formated message */ buildMessage () { return new Promise((resolve, reject) => { let fmtMsg = 'LEEF:2.0'; fmtMsg += '|' + this.vendor; fmtMsg += '|' + this.product; fmtMsg += '|' + this.version; fmtMsg += '|' + this.eventId; fmtMsg += '|'; // Build LEEF Attrabuites const Tab = '\x09'; const leefAttribs = Object.entries(this.attrabutes); const leefAttribsLen = leefAttribs.length; for (let attrib = 0; attrib < leefAttribsLen; attrib++) { if (leefAttribs[attrib][1] !== null) { fmtMsg += leefAttribs[attrib][0] + '=' + leefAttribs[attrib][1] + Tab; } } resolve(fmtMsg); }); } /** * @public * @param {Syslog} [options=false] - A {@link module:SyslogPro~Syslog| * Syslog server connection} that should be used to send messages directly * from this class. @see SyslogPro~Syslog */ send (options) { return new Promise((resolve, reject) => { this.buildMessage() .then((result) => { if (!this.server) { this.server = new Syslog(options); } this.server.send(result) .then((sendResult) => { resolve(sendResult); }) .catch((reson) => { reject(reson); }); }); }); } } /** * A class to work with HP CEF (Common Event Format) messages. This form * of system messages are designed to work with security systems. Messages can * be saved to file (Saving to file if not part of this module but a CEF * formated mesage produced by this module can be saved externaly to it) or * sent via Syslog. * @requires moment * @version 0.0.0 * @since 0.0.0 */ class CEF { /** * Construct a new CEF object with user options * @public * @param {object} [options] - Options object * @param {string} [options.deviceVendor='unknown'] - The vendor of the system * that genrated the event being reported * @param {string} [options.deviceProduct='unknown'] - The product name of the * system that genrated the event being reported * @param {string} [options.deviceVersion='unknown'] - The version name of the * system that genrated the event being reported * @param {string} [options.deviceEventClassId='unknown'] - The eventId of the * system that genrated the event being reported * @param {string} [options.name='unknown'] - Name of the service genrating * the notice * @param {string} [options.severity='unknown'] - Severity of the notification * @param {string} [options.extensions={}] - Any CEF Key=Value extentions * @param {Syslog} [options.server=false] - A {@link module:SyslogPro~Syslog| * Syslog server connection} that should be used to send messages directly * from this class. @see SyslogPro~Syslog */ constructor (options) { /** @private @type {boolean} */ this.constructor__ = true; options = options || {}; /** @type {string} */ this.deviceVendor = options.deviceVendor || 'Unknown'; /** @type {string} */ this.deviceProduct = options.deviceProduct || 'Unknown'; /** @type {string} */ this.deviceVersion = options.deviceVersion || 'Unknown'; /** @type {string} */ this.deviceEventClassId = options.deviceEventClassId || 'Unknown'; /** @type {string} */ this.name = options.name || 'Unknown'; /** @type {string} */ this.severity = options.severity || 'Unknown'; /** @type {object} */ this.extensions = options.extensions || { 'deviceAction': null, 'applicationProtocol': null, 'deviceCustomIPv6Address1': null, 'deviceCustomIPv6 Address1Label': null, 'deviceCustomIPv6Address3': null, 'deviceCustomIPv6Address3 Label': null, 'deviceCustomIPv6 Address4': null, 'deviceCustomIPv6 Address4Label': null, 'deviceEventCategory': null, 'deviceCustomFloatingPoint1': null, 'deviceCustom FloatingPoint1Label': null, 'deviceCustomFloatingPoint2': null, 'deviceCustomFloatingPoint2 Label': null, 'deviceCustomFloatingPoint3': null, 'deviceCustom FloatingPoint3Label': null, 'deviceCustomFloatingPoint4': null, 'deviceCustom FloatingPoint4Label': null, 'deviceCustomNumber1': null, 'deviceCustomNumber1Label': null, 'DeviceCustomNumber2': null, 'deviceCustomNumber2Label': null, 'deviceCustomNumber3': null, 'deviceCustomNumber3Label': null, 'baseEventCount': null, 'deviceCustomString1': null, 'deviceCustomString1Label': null, 'deviceCustomString2': null, 'deviceCustomString2Label': null, 'deviceCustomString3': null, 'deviceCustomString3Label': null, 'deviceCustomString4': null, 'deviceCustomString4Label': null, 'deviceCustomString5': null, 'deviceCustomString5Label': null, 'deviceCustomString6': null, 'deviceCustomString6Label': null, 'destinationDnsDomain': null, 'destinationServiceName': null, 'destinationTranslated Address': null, 'destinationTranslatedPort': null, 'deviceCustomDate1': null, 'deviceCustomDate1Label': null, 'deviceCustomDate2': null, 'deviceCustomDate2Label': null, 'deviceDirection': null, 'deviceDnsDomain': null, 'deviceExternalId': null, 'deviceFacility': null, 'deviceInboundInterface': null, 'deviceNtDomain': null, 'deviceOutboundInterface': null, 'devicePayloadId': null, 'deviceProcessName': null, 'deviceTranslatedAddress': null, 'destinationHostName': null, 'destinationMacAddress': null, 'destinationNtDomain': null, 'destinationProcessId': null, 'destinationUserPrivileges': null, 'destinationProcessName': null, 'destinationPort': null, 'destinationAddress': null, 'deviceTimeZone': null, 'destinationUserId': null, 'destinationUserName': null, 'deviceAddress': null, 'deviceHostName': null, 'deviceMacAddress': null, 'deviceProcessId': null, 'endTime': null, 'externalId': null, 'fileCreateTime': null, 'fileHash': null, 'fileId': null, 'fileModificationTime': null, 'filePath': null, 'filePermission': null, 'fileType': null, 'flexDate1': null, 'flexDate1Label': null, 'flexString1': null, 'flexString1Label': null, 'flexString2': null, 'flexString2Label': null, 'filename': null, 'fileSize': null, 'bytesIn': null, 'message': null, 'oldFileCreateTime': null, 'oldFileHash': null, 'oldFileId': null, 'oldFileModificationTime': null, 'oldFileName': null, 'oldFilePath': null, 'oldFileSize': null, 'oldFileType': null, 'bytesOut': null, 'eventOutcome': null, 'transportProtocol': null, 'Reason': null, 'requestUrl': null, 'requestClientApplication': null, 'requestContext': null, 'requestCookies': null, 'requestMethod': null, 'deviceReceiptTime': null, 'sourceHostName': null, 'sourceMacAddress': null, 'sourceNtDomain': null, 'sourceDnsDomain': null, 'sourceServiceName': null, 'sourceTranslatedAddress': null, 'sourceTranslatedPort': null, 'sourceProcessId': null, 'sourceUserPrivileges': null, 'sourceProcessName': null, 'sourcePort': null, 'sourceAddress': null, 'startTime': null, 'sourceUserId': null, 'sourceUserName': null, 'type': null, 'agentDnsDomain': null, 'agentNtDomain': null, 'agentTranslatedAddress': null, 'agentTranslatedZone ExternalID': null, 'agentTranslatedZoneURI': null, 'agentZoneExternalID': null, 'agentZoneURI': null, 'agentAddress': null, 'agentHostName': null, 'agentId': null, 'agentMacAddress': null, 'agentReceiptTime': null, 'agentType': null, 'agentTimeZone': null, 'agentVersion': null, 'customerExternalID': null, 'customerURI': null, 'destinationTranslated ZoneExternalID': null, 'destinationTranslated ZoneURI': null, 'destinationZoneExternalID': null, 'destinationZoneURI': null, 'deviceTranslatedZone ExternalID': null, 'deviceTranslatedZoneURI': null, 'deviceZoneExternalID': null, 'deviceZoneURI': null, 'destinationGeoLatitude': null, 'destinationGeoLongitude': null, 'eventId': null, 'rawEvent': null, 'sourceGeoLatitude': null, 'sourceGeoLongitude': null, 'sourceTranslatedZone ExternalID': null, 'sourceTranslatedZoneURI': null, 'sourceZoneExternalID': null, 'sourceZoneURI': null, }; if (options.server) { if (options.server.constructor__) { /** @private @type {Syslog} */ this.server = options.server; } else { this.server = new Syslog(options.server); } } } /** * Validate this CEF object * @public * @return {Promise} - True if valadated * @throws {Error} - First element to fail valadation */ validate () { return new Promise ((resolve, reject) => { const Extensions = { 'deviceAction': {key: 'act', type:'String', len:63, discription: 'Action taken by the device.'}, 'applicationProtocol': {key: 'app', type:'String', len:31, discription: 'Application level protocol, example values are HTTP, HTTPS, SSHv2, Telnet, POP, IMPA, IMAPS, and so on.'}, 'deviceCustomIPv6Address1': {key: 'c6a1', type:'String', len:null, discription: 'One of four IPv6 address fields available to map fields that do not apply to any other in this dictionary. TIP: See the guidelines under “User-Defined Extensions” for tips on using these fields.'}, 'deviceCustomIPv6 Address1Label': {key: 'c6a1Label', type:'String', len:1023, discription: 'All custom fields have a corresponding label field. Each of these fields is a string and describes the purpose of the custom field.'}, 'deviceCustomIPv6Address3': {key: 'c6a3', type:'String', len:null, discription: 'One of four IPv6 address fields available to map fields that do not apply to any other in this dictionary. TIP: See the guidelines under “User-Defined Extensions” for tips on using these fields.'}, 'deviceCustomIPv6Address3 Label': {key: 'c6a3Label', type:'String', len:1023, discription: 'All custom fields have a corresponding label field. Each of these fields is a string and describes the purpose of the custom field.'}, 'deviceCustomIPv6 Address4': {key: 'c6a4', type:'String', len:null, discription: 'One of four IPv6 address fields available to map fields that do not apply to any other in this dictionary. TIP: See the guidelines under “User-Defined Extensions” for tips on using these fields.'}, 'deviceCustomIPv6 Address4Label': {key: 'C6a4Label', type:'String', len:1023, discription: 'All custom fields have a corresponding label field. Each of these fields is a string and describes the purpose of the custom field.'}, 'deviceEventCategory': {key: 'cat', type:'String', len:1023, discription: 'Represents the category assigned by the originating device. Devices often use their own categorization schema to classify event. Example: “/Monitor/Disk/Read”'}, 'deviceCustomFloatingPoint1': {key: 'cfp1', type:'Number', len:null, discription: 'One of four floating point fields available to map fields that do not apply to any other in this dictionary.'}, 'deviceCustom FloatingPoint1Label': {key: 'cfp1Label', type:'String', len:1023, discription: 'All custom fields have a corresponding label field. Each of these fields is a string and describes the purpose of the custom field.'}, 'deviceCustomFloatingPoint2': {key: 'cfp2', type:'Number', len:null, discription: 'One of four floating point fields available to map fields that do not apply to any other in this dictionary.'}, 'deviceCustomFloatingPoint2 Label': {key: 'cfp2Label', type:'String', len:1023, discription: 'All custom fields have a corresponding label field. Each of these fields is a string and describes the purpose of the custom field.'}, 'deviceCustomFloatingPoint3': {key: 'cfp3', type:'Number', len:null, discription: 'One of four floating point fields available to map fields that do not apply to any other in this dictionary.'}, 'deviceCustom FloatingPoint3Label': {key: 'cfp3Label', type:'String', len:1023, discription: 'All custom fields have a corresponding label field. Each of these fields is a string and describes the purpose of the custom field.'}, 'deviceCustomFloatingPoint4': {key: 'cfp4', type:'Number', len:null, discription: 'One of four floating point fields available to map fields that do not apply to any other in this dictionary.'}, 'deviceCustom FloatingPoint4Label': {key: 'cfp4Label', type:'String', len:1023, discription: 'All custom fields have a corresponding label field. Each of these fields is a string and describes the purpose of the custom field.'}, 'deviceCustomNumber1': {key: 'cn1', type:'Number', len:null, discription: 'One of three number fields available to map fields that do not apply to any other in this dictionary. Use sparingly and seek a more specific, dictionary supplied field when possible.'}, 'deviceCustomNumber1Label': {key: 'cn1Label', type:'String', len:1023, discription: 'All custom fields have a corresponding label field. Each of these fields is a string and describes the purpose of the custom field.'}, 'DeviceCustomNumber2': {key: 'cn2', type:'Number', len:null, discription: 'One of three number fields available to map fields that do not apply to any other in this dictionary. Use sparingly and seek a more specific, dictionary supplied field when possible.'}, 'deviceCustomNumber2Label': {key: 'cn2Label', type:'String', len:1023, discription: 'All custom fields have a corresponding label field. Each of these fields is a string and describes the purpose of the custom field.'}, 'deviceCustomNumber3': {key: 'cn3', type:'Number', len:null, discription: 'One of three number fields available to map fields that do not apply to any other in this dictionary. Use sparingly and seek a more specific, dictionary supplied field when possible.'}, 'deviceCustomNumber3Label': {key: 'cn3Label', type:'String', len:1023, discription: 'All custom fields have a corresponding label field. Each of these fields is a string and describes the purpose of the custom field.'}, 'baseEventCount': {key: 'cnt', type:'Number', len:null, discription: 'A count associated with this event. How many times was this same event observed? Count can be omitted if it is 1.'}, 'deviceCustomString1': {key: 'cs1', type:'String', len:4000, discription: 'One of six strings available to map fields that do not apply to any other in this dictionary. Use sparingly and seek a more specific, dictionary supplied field when possible. TIP: See the guidelines under “User-Defined Extensions” for tips on using these fields.'}, 'deviceCustomString1Label': {key: 'cs1Label', type:'String', len:1023, discription: 'All custom fields have a corresponding label field. Each of these fields is a string and describes the purpose of the custom field.'}, 'deviceCustomString2': {key: 'cs2', type:'String', len:4000, discription: 'One of six strings available to map fields that do not apply to any other in this dictionary. Use sparingly and seek a more specific, dictionary supplied field when possible. TIP: See the guidelines under “User-Defined Extensions” for tips on using these fields.'}, 'deviceCustomString2Label': {key: 'cs2Label', type:'String', len:1023, discription: 'All custom fields have a corresponding label field. Each of these fields is a string and describes the purpose of the custom field.'}, 'deviceCustomString3': {key: 'cs3', type:'String', len:4000, discription: 'One of six strings available to map fields that do not apply to any other in this dictionary. Use sparingly and seek a more specific, dictionary supplied field when possible. TIP: See the guidelines under “User-Defined Extensions” for tips on using these fields.'}, 'deviceCustomString3Label': {key: 'cs3Label', type:'String', len:1023, discription: 'All custom fields have a corresponding label field. Each of these fields is a string and describes the purpose of the custom field.'}, 'deviceCustomString4': {key: 'cs4', type:'String', len:4000, discription: 'One of six strings available to map fields that do not apply to any other in this dictionary. Use sparingly and seek a more specific, dictionary supplied field when possible. TIP: See the guidelines under “User-Defined Extensions” for tips on using these fields.'}, 'deviceCustomString4Label': {key: 'cs4Label', type:'String', len:1023, discription: 'All custom fields have a corresponding label field. Each of these fields is a string and describes the purpose of the custom field.'}, 'deviceCustomString5': {key: 'cs5', type:'String', len:4000, discription: 'One of six strings available to map fields that do not apply to any other in this dictionary. Use sparingly and seek a more specific, dictionary supplied field when possible. TIP: See the guidelines under “User-Defined Extensions” for tips on using these fields.'}, 'deviceCustomString5Label': {key: 'cs5Label', type:'String', len:1023, discription: 'All custom fields have a corresponding label field. Each of these fields is a string and describes the purpose of the custom field.'}, 'deviceCustomString6': {key: 'cs6', type:'String', len:4000, discription: 'One of six strings available to map fields that do not apply to any other in this dictionary. Use sparingly and seek a more specific, dictionary supplied field when possible. TIP: See the guidelines under “User-Defined Extensions” for tips on using these fields.'}, 'deviceCustomString6Label': {key: 'cs6Label', type:'String', len:1023, discription: 'All custom fields have a corresponding label field. Each of these fields is a string and describes the purpose of the custom field.'}, 'destinationDnsDomain': {key: 'destination DnsDomain', type:'String', len:255, discription: 'The DNS domain part of the complete fully qualified domain name (FQDN).'}, 'destinationServiceName': {key: 'destination ServiceName', type:'String', len:1023, discription: 'The service targeted by this event. Example: “sshd”'}, 'destinationTranslated Address': {key: 'Destination Translated Address', type:'String', len:null, discription: 'Identifies the translated destination that the event refers to in an IP network. The format is an IPv4 address. Example: “192.168.10.1”'}, 'destinationTranslatedPort': {key: 'Destination TranslatedPort', type:'Number', len:null, discription: 'Port after it was translated; for example, a firewall. Valid port numbers are 0 to 65535.'}, 'deviceCustomDate1': {key: 'deviceCustom Date1', type:'String', len:null, discription: 'One of two timestamp fields available to map fields that do not apply to any other in this dictionary. Use sparingly and seek a more specific, dictionary supplied field when possible. TIP: See the guidelines under “User-Defined Extensions” for tips on using these fields.'}, 'deviceCustomDate1Label': {key: 'deviceCustom Date1Label', type:'String', len:1023, discription: 'All custom fields have a corresponding label field. Each of these fields is a string and describes the purpose of the custom field.'}, 'deviceCustomDate2': {key: 'deviceCustom Date2', type:'String', len:null, discription: 'One of two timestamp fields available to map fields that do not apply to any other in this dictionary. Use sparingly and seek a more specific, dictionary supplied field when possible. TIP: See the guidelines under “User-Defined Extensions” for tips on using these fields.'}, 'deviceCustomDate2Label': {key: 'deviceCustom Date2Label', type:'String', len:1023, discription: 'All custom fields have a corresponding label field. Each of these fields is a string and describes the purpose of the custom field.'}, 'deviceDirection': {key: 'deviceDirection', type:'Number', len:null, discription: 'Any information about what direction the observed communication has taken. The following values are supported: “0” for inbound or “1” for outbound'}, 'deviceDnsDomain': {key: 'deviceDns Domain', type:'String', len:255, discription: 'The DNS domain part of the complete fully qualified domain name (FQDN).'}, 'deviceExternalId': {key: 'device ExternalId', type:'String', len:255, discription: 'A name that uniquely identifies the device generating this event.'}, 'deviceFacility': {key: 'deviceFacility', type:'String', len:1023, discription: 'The facility generating this event. For example, Syslog has an explicit facility associated with every event.'}, 'deviceInboundInterface': {key: 'deviceInbound Interface', type:'String', len:128, discription: 'Interface on which the packet or data entered the device.'}, 'deviceNtDomain': {key: 'deviceNt Domain', type:'String', len:255, discription: 'The Windows domain name of the device address.'}, 'deviceOutboundInterface': {key: 'Device Outbound Interface', type:'String', len:128, discription: 'Interface on which the packet or data left the device.'}, 'devicePayloadId': {key: 'Device PayloadId', type:'String', len:128, discription: 'Unique identifier for the payload associated with the event.'}, 'deviceProcessName': {key: 'deviceProcess Name', type:'String', len:1023, discription: 'Process name associated with the event. An example might be the process generating the syslog entry in UNIX.'}, 'deviceTranslatedAddress': {key: 'device Translated Address', type:'String', len:null, discription: 'Identifies the translated device address that the event refers to in an IP network. The format is an IPv4 address. Example: “192.168.10.1”'}, 'destinationHostName': {key: 'dhost', type:'String', len:1023, discription: 'Identifies the destination that an event refers to in an IP network. The format should be a fully qualified domain name (FQDN) associated with the destination node, when a node is available. Examples: “host.domain.com” or “host”.'}, 'destinationMacAddress': {key: 'dmac', type:'String', len:null, discription: 'Six colon-seperated hexadecimal numbers. Example: “00:0D:60:AF:1B:61”'}, 'destinationNtDomain': {key: 'dntdom', type:'String', len:255, discription: 'The Windows domain name of the destination address.'}, 'destinationProcessId': {key: 'dpid', type:'Number', len:null, discription: 'Provides the ID of the destination process associated with the event. For example, if an event contains process ID 105, “105” is the process ID.'}, 'destinationUserPrivileges': {key: 'dpriv', type:'String', len:1023, discription: 'The typical values are “Administrator”, “User”, and “Guest”. This identifies the destination user’s privileges. In UNIX, for example, activity executed on the root user would be identified with destinationUser Privileges of “Administrator”.'}, 'destinationProcessName': {key: 'dproc', type:'String', len:1023, discription: 'The name of the event’s destination process. Example: “telnetd” or “sshd”.'}, 'destinationPort': {key: 'dpt', type:'Number', len:null, discription: 'The valid port numbers are between 0 and 65535.'}, 'destinationAddress': {key: 'dst', type:'String', len:null, discription: 'Identifies the destination address that the event refers to in an IP network. The format is an IPv4 address. Example: “192.168.10.1”'}, 'deviceTimeZone': {key: 'dtz', type:'String', len:255, discription: 'The timezone for the device generating the event.'}, 'destinationUserId': {key: 'duid', type:'String', len:1023, discription: 'Identifies the destination user by ID. For example, in UNIX, the root user is generally associated with user ID 0.'}, 'destinationUserName': {key: 'duser', type:'String', len:1023, discription: 'Identifies the destination user by name. This is the user associated with the event’s destination. Email addresses are often mapped into the UserName fields. The recipient is a candidate to put into this field.'}, 'deviceAddress': {key: 'dvc', type:'String', len:null, discription: 'Identifies the device address that an event refers to in an IP network. The format is an IPv4 address. Example: “192.168.10.1”.'}, 'deviceHostName': {key: 'dvchost', type:'String', len:100, discription: 'The format should be a fully qualified domain name (FQDN) associated with the device node, when a node is available. Example: “host.domain.com” or “host”.'}, 'deviceMacAddress': {key: 'dvcmac', type:'String', len:null, discription: 'Six colon-separated hexadecimal numbers. Example: “00:0D:60:AF:1B:61”'}, 'deviceProcessId': {key: 'dvcpid', type:'Number', len:null, discription: 'Provides the ID of the process on the device generating the event.'}, 'endTime': {key: 'end', type:'String', len:null, discription: 'The time at which the activity related to the event ended. The format is MMM dd yyyy HH:mm:ss or milliseconds since epoch (Jan 1st1970). An example would be reporting the end of a session.'}, 'externalId': {key: 'externalId', type:'String', len:40, discription: 'The ID used by an originating device. They are usually increasing numbers, associated with events.'}, 'fileCreateTime': {key: 'fileCreateTime', type:'String', len:null, discription: 'Time when the file was created.'}, 'fileHash': {key: 'fileHash', type:'String', len:255, discription: 'Hash of a file.'}, 'fileId': {key: 'fileId', type:'String', len:1023, discription: 'An ID associated with a file could be the inode.'}, 'fileModificationTime': {key: 'fileModification Time', type:'String', len:null, discription: 'Time when the file was last modified.'}, 'filePath': {key: 'filePath', type:'String', len:1023, discription: 'Full path to the file, including file name itself. Example: C:\Program Files \WindowsNT\Accessories\ wordpad.exe or /usr/bin/zip'}, 'filePermission': {key: 'filePermission', type:'String', len:1023, discription: 'Permissions of the file.'}, 'fileType': {key: 'fileType', type:'String', len:1023, discription: 'Type of file (pipe, socket, etc.)'}, 'flexDate1': {key: 'flexDate1', type:'String', len:null, discription: 'A timestamp field available to map a timestamp that does not apply to any other defined timestamp field in this dictionary. Use all flex fields sparingly and seek a more specific, dictionary supplied field when possible. These fields are typically reserved for customer use and should not be set by vendors unless necessary.'}, 'flexDate1Label': {key: 'flexDate1Label', type:'String', len:128, discription: 'The label field is a string and describes the purpose of the flex field.'}, 'flexString1': {key: 'flexString1', type:'String', len:1023, discription: 'One of four floating point fields available to map fields that do not apply to any other in this dictionary. Use sparingly and seek a more specific, dictionary supplied field when possible. These fields are typically reserved for customer use and should not be set by vendors unless necessary.'}, 'flexString1Label': {key: 'flexString1 Label', type:'String', len:128, discription: 'The label field is a string and describes the purpose of the flex field.'}, 'flexString2': {key: 'flexString2', type:'String', len:1023, discription: 'One of four floating point fields available to map fields that do not apply to any other in this dictionary. Use sparingly and seek a more specific, dictionary supplied field when possible. These fields are typically reserved for customer use and should not be set by vendors unless necessary.'}, 'flexString2Label': {key: 'flex String2Label', type:'String', len:128, discription: 'The label field is a string and describes the purpose of the flex field.'}, 'filename': {key: 'fname', type:'String', len:1023, discription: 'Name of the file only (without its path).'}, 'fileSize': {key: 'fsize', type:'Number', len:null, discription: 'Size of the file.'}, 'bytesIn': {key: 'in', type:'Number', len:null, discription: 'Number of bytes transferred inbound, relative to the source to destination relationship, meaning that data was flowing from source to destination.'}, 'message': {key: 'msg', type:'String', len:1023, discription: 'An arbitrary message giving more details about the event. Multi-line entries can be produced by using \n as the new line separator.'}, 'oldFileCreateTime': {key: 'oldFileCreate Time', type:'String', len:null, discription: 'Time when old file was created.'}, 'oldFileHash': {key: 'oldFileHash', type:'String', len:255, discription: 'Hash of the old file.'}, 'oldFileId': {key: 'oldFileId', type:'String', len:1023, discription: 'An ID associated with the old file could be the inode.'}, 'oldFileModificationTime': {key: 'oldFile Modification Time', type:'String', len:null, discription: 'Time when old file was last modified.'}, 'oldFileName': {key: 'oldFileName', type:'String', len:1023, discription: 'Name of the old file.'}, 'oldFilePath': {key: 'oldFilePath', type:'String', len:1023, discription: 'Full path to the old fiWindowsNT\Accessories le, including the file name itself. Examples: c:\Program Files\wordpad.exe or /usr/bin/zip'}, 'oldFileSize': {key: 'oldFileSize', type:'Number', len:null, discription: 'Size of the old file.'}, 'oldFileType': {key: 'oldFileType', type:'String', len:1023, discription: 'Type of the old file (pipe, socket, etc.)'}, 'bytesOut': {key: 'out', type:'Number', len:null, discription: 'Number of bytes transferred outbound relative to the source to destination relationship. For example, the byte number of data flowing from the destination to the source.'}, 'eventOutcome': {key: 'outcome', type:'String', len:63, discription: 'Displays the outcome, usually as ‘success’ or ‘failure’.'}, 'transportProtocol': {key: 'proto', type:'String', len:31, discription: 'Identifies the Layer-4 protocol used. The possible values are protocols such as TCP or UDP.'}, 'Reason': {key: 'reason', type:'String', len:1023, discription: 'The reason an audit event was generated. For example “badd password” or “unknown user”. This could also be an error or return code. Example: “0x1234”'}, 'requestUrl': {key: 'request', type:'String', len:1023, discription: 'In the case of an HTTP request, this field contains the URL accessed. The URL should contain the protocol as well. Example: “http://www/secure.com”'}, 'requestClientApplication': {key: 'requestClient Application', type:'String', len:1023, discription: 'The User-Agent associated with the request.'}, 'requestContext': {key: 'requestContext', type:'String', len:2048, discription: 'Description of the content from which the request originated (for example, HTTP Referrer)'}, 'requestCookies': {key: 'requestCookies', type:'String', len:1023, discription: 'Cookies associated with the request.'}, 'requestMethod': {key: 'requestMethod', type:'String', len:1023, discription: 'The method used to access a URL. Possible values: “POST”, “GET”, etc.'}, 'deviceReceiptTime': {key: 'rt', type:'String', len:null, discription: 'The time at which the event related to the activity was received. The format is MMM dd yyyy HH:mm:ss or milliseconds since epoch (Jan 1st 1970)'}, 'sourceHostName': {key: 'shost', type:'String', len:1023, discription: 'Identifies the source that an event refers to in an IP network. The format should be a fully qualified domain name (DQDN) associated with the source node, when a mode is available. Examples: “host” or “host.domain.com”.'}, 'sourceMacAddress': {key: 'smac', type:'String', len:null, discription: 'Six colon-separated hexadecimal numbers. Example: “00:0D:60:AF:1B:61”'}, 'sourceNtDomain': {key: 'sntdom', type:'String', len:255, discription: 'The Windows domain name for the source address.'}, 'sourceDnsDomain': {key: 'sourceDns Domain', type:'String', len:255, discription: 'The DNS domain part of the complete fully qualified domain name (FQDN).'}, 'sourceServiceName': {key: 'source ServiceName', type:'String', len:1023, discription: 'The service that is responsible for generating this event.'}, 'sourceTranslatedAddress': {key: 'source Translated Address', type:'String', len:null, discription: 'Identifies the translated source that the event refers to in an IP network. The format is an IPv4 address. Example: “192.168.10.1”.'}, 'sourceTranslatedPort': {key: 'source TranslatedPort', type:'Number', len:null, discription: 'A port number after being translated by, for example, a firewall. Valid port numbers are 0 to 65535.'}, 'sourceProcessId': {key: 'spid', type:'Number', len:null, discription: 'The ID of the source process associated with the event.'}, 'sourceUserPrivileges': {key: 'spriv', type:'String', len:1023, discription: 'The typical values are “Administrator”, “User”, and “Guest”. It identifies the source user’s privileges. In UNIX, for example, activity executed by the root user would be identified with “Administrator”.'}, 'sourceProcessName': {key: 'sproc', type:'String', len:1023, discription: 'The name of the event’s source process.'}, 'sourcePort': {key: 'spt', type:'Number', len:null, discription: 'The valid port numbers are 0 to 65535.'}, 'sourceAddress': {key: 'src', type:'String', len:null, discription: 'Identifies the source that an event refers to in an IP network. The format is an IPv4 address. Example: “192.168.10.1”.'}, 'startTime': {key: 'start', type:'String', len:null, discription: 'The time when the activity the event referred to started. The format is MMM dd yyyy HH:mm:ss or milliseconds since epoch (Jan 1st 1970)'}, 'sourceUserId': {key: 'suid', type:'String', len:1023, discription: 'Identifies the source user by ID. This is the user associated with the source of the event. For example, in UNIX, the root user is generally associated with user ID 0.'}, 'sourceUserName': {key: 'suser', type:'String', len:1023, discription: 'Identifies the source user by name. Email addresses are also mapped into the UserName fields. The sender is a candidate to put into this field.'}, 'type': {key: 'type', type:'Number', len:null, discription: '0 means base event, 1 means aggregated, 2 means correlation, and 3 means action. This field can be omitted for base events (type 0).'}, 'agentDnsDomain': {key: 'agentDns Domain', type:'String', len:255, discription: 'The DNS domain name of the ArcSight connector that processed the event.'}, 'agentNtDomain': {key: 'agentNtDomain', type:'String', len:255, discription: ''}, 'agentTranslatedAddress': {key: 'agentTranslated Address', type:'String', len:null, discription: ''}, 'agentTranslatedZone ExternalID': {key: 'agentTranslated ZoneExternalID', type:'String', len:200, discription: ''}, 'agentTranslatedZoneURI': {key: 'agentTranslated Zone URI', type:'String', len:2048, discription: ''}, 'agentZoneExternalID': {key: 'agentZone ExternalID', type:'String', len:200, discription: ''}, 'agentZoneURI': {key: 'agentZoneURI', type:'String', len:2048, discription: ''}, 'agentAddress': {key: 'agt', type:'String', len:null, discription: 'The IP address of the ArcSight connector that processed the event.'}, 'agentHostName': {key: 'ahost', type:'String', len:1023, discription: 'The hostname of the ArcSight connector that processed the event.'}, 'agentId': {key: 'aid', type:'String', len:40, discription: 'The agent ID of the ArcSight connector that processed the event.'}, 'agentMacAddress': {key: 'amac', type:'String', len:null, discription: 'The MAC address of the ArcSight connector that processed the event.'}, 'agentReceiptTime': {key: 'art', type:'String', len:null, discription: 'The time at which information about the event was received by the ArcSight connector.'}, 'agentType': {key: 'at', type:'String', len:63, discription: 'The agent type of the ArcSight connector that processed the event'}, 'agentTimeZone': {key: 'atz', type:'String', len:255, discription: 'The agent time zone of the ArcSight connector that processed the event.'}, 'agentVersion': {key: 'av', type:'String', len:31, discription: 'The version of the ArcSight connector that processed the event.'}, 'customerExternalID': {key: 'customer ExternalID', type:'String', len:200, discription: ''}, 'customerURI': {key: 'customerURI', type:'String', len:2048, discription: ''}, 'destinationTranslated ZoneExternalID': {key: 'destination TranslatedZone ExternalID', type:'String', len:200, discription: ''}, 'destinationTranslated ZoneURI': {key: 'destination Translated ZoneURI', type:'String', len:2048, discription: 'The URI for the Translated Zone that the destination asset has been assigned to in ArcSight.'}, 'destinationZoneExternalID': {key: 'destinationZone ExternalID', type:'String', len:200, discription: ''}, 'destinationZoneURI': {key: 'destinationZone URI', type:'String', len:2048, discription: 'The URI for the Zone that the destination asset has been assigned to in ArcSight.'}, 'deviceTranslatedZone ExternalID': {key: 'device TranslatedZone ExternalID', type:'String', len:200, discription: ''}, 'deviceTranslatedZoneURI': {key: 'device TranslatedZone URI', type:'String', len:2048, discription: 'The URI for the Translated Zone that the device asset has been assigned to in ArcSight.'}, 'deviceZoneExternalID': {key: 'deviceZone ExternalID', type:'String', len:200, discription: ''}, 'deviceZoneURI': {key: 'deviceZoneURI', type:'String', len:2048, discription: 'Thee URI for the Zone that the device asset has been assigned to in ArcSight.'}, 'destinationGeoLatitude': {key: 'dlat', type:'Number', len:null, discription: 'The latitudinal value from which the destination’s IP address belongs.'}, 'destinationGeoLongitude': {key: 'dlong', type:'Number', len:null, discription: 'The longitudinal value from which the destination’s IP address belongs.'}, 'eventId': {key: 'eventId', type:'Number', len:null, discription: 'This is a unique ID that ArcSight assigns to each event.'}, 'rawEvent': {key: 'rawEvent', type:'String', len:4000, discription: ''}, 'sourceGeoLatitude': {key: 'slat', type:'Number', len:null, discription: ''}, 'sourceGeoLongitude': {key: 'slong', type:'Number', len:null, discription: ''}, 'sourceTranslatedZone ExternalID': {key: 'source TranslatedZone ExternalID', type:'String', len:200, discription: ''}, 'sourceTranslatedZoneURI': {key: 'source TranslatedZone URI', type:'String', len:2048, discription: 'The URI for the Translated Zone that the destination asset has been assigned to in ArcSight.'}, 'sourceZoneExternalID': {key: 'sourceZone ExternalID', type:'String', len:200, discription: ''}, 'sourceZoneURI': {key: 'sourceZoneURI', type:'String', len:2048, discription: 'The URI for the Zone that the source asset has been assigned to in ArcSight.'}, }; if (typeof this.deviceVendor !== 'string' || typeof this.deviceProduct !== 'string' || typeof this.deviceVersion !== 'string' ) { reject(new Error('TYPE ERROR: CEF Device Info must be a string')); } if (this.severity && ( ( typeof this.severity === 'string' && ( this.severity !== 'Unknown' && this.severity !== 'Low' && this.severity !== 'Medium' && this.severity !== 'High' && this.severity !== 'Very-High' ) ) || ( typeof this.severity === 'number' && ( this.severity < 0 || this.severity > 10 ) ) ) ) { reject(new Error('TYPE ERROR: CEF Severity not set correctly')); } const cefExts = Object.entries(this.extensions); const cefExtsLen = cefExts.length; for (let ext = 0; ext < cefExtsLen; ext++) { if (cefExts[ext][1] !== null) { if(Extensions[cefExts[ext][0]]) { if (typeof cefExts[ext][1] === Extensions[cefExts[ext][0]] .type .toLowerCase()) { if (Extensions[cefExts[ext][0]].len > 0 && typeof cefExts[ext][1] === 'string' && cefExts[ext][1].length > Extensions[cefExts[ext][0]].len){ let errMsg = 'FORMAT ERROR:'; errMsg += ' CEF Extention Key'; errMsg += ' ' + cefExts[ext][0]; errMsg += ' value length is to long;'; errMsg += ' max length is'; errMsg += ' ' + Extensions[cefExts[ext][0]].len; reject(new Error(errMsg)); } } else { let errMsg = 'TYPE ERROR:'; errMsg += ' CEF Key'; errMsg += ' ' + cefExts[ext][0]; errMsg += ' value type was expected to be'; errMsg += ' ' + Extensions[cefExts[ext][0]].type.toLowerCase(); reject(new Error(errMsg)); } } } } resolve(true); }); } /** * Build a CEF formated string * @public * @return {Promise} - String with formated message */ buildMessage () { return new Promise((resolve, reject) => { let fmtMsg = 'CEF:0'; fmtMsg += '|' + this.deviceVendor; fmtMsg += '|' + this.deviceProduct; fmtMsg += '|' + this.deviceVersion; fmtMsg += '|' + this.deviceEventClassId; fmtMsg += '|' + this.name; fmtMsg += '|' + this.severity; fmtMsg += '|'; const cefExts = Object.entries(this.extensions); const cefExtsLen = cefExts.length; for (let ext = 0; ext < cefExtsLen; ext++) { if (cefExts[ext][1] !== null) { fmtMsg += cefExts[ext][0] + '=' + cefExts[ext][1] + ' '; } } resolve(fmtMsg); }); } /** * @public * @param {Syslog} [options=false] - A {@link module:SyslogPro~Syslog| * Syslog server connection} that should be used to send messages directly * from this class. @see SyslogPro~Syslog */ send (options) { return new Promise((resolve, reject) => { this.buildMessage() .then((result) => { if (!this.server) { this.server = new Syslog(options); } this.server.send(result) .then((sendResult) => { resolve(sendResult); }) .catch((reson) => { reject(reson); }); }); }); } } module.exports = { RgbToAnsi: rgbToAnsi, RFC3164: RFC3164, RFC5424:RFC5424, LEEF: LEEF, CEF: CEF, Syslog: Syslog }; |