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 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353
|
# SPDX-FileCopyrightText: 2024 Greenbone AG
#
# SPDX-License-Identifier: GPL-3.0-or-later
"""
Greenbone Management Protocol (GMP) version 22.4
"""
from typing import Iterable, Mapping, Optional, Sequence, Union
from gvm.utils import SupportsStr, to_dotted_types_dict
from .._protocol import GvmProtocol, T
from .requests.v224 import (
Aggregates,
AggregateStatistic,
AlertCondition,
AlertEvent,
AlertMethod,
Alerts,
AliveTest,
Audits,
Authentication,
CertBundAdvisories,
Cpes,
CredentialFormat,
Credentials,
CredentialType,
Cves,
DfnCertAdvisories,
EntityID,
EntityType,
Feed,
FeedType,
Filters,
FilterType,
Groups,
Help,
HelpFormat,
Hosts,
HostsOrdering,
InfoType,
Notes,
Nvts,
OperatingSystems,
Overrides,
Permissions,
PermissionSubjectType,
Policies,
PortLists,
PortRangeType,
ReportFormats,
ReportFormatType,
Reports,
Results,
Roles,
ScanConfigs,
Scanners,
ScannerType,
Schedules,
SecInfo,
Severity,
SnmpAuthAlgorithm,
SnmpPrivacyAlgorithm,
SortOrder,
SystemReports,
Tags,
Targets,
Tasks,
Tickets,
TicketStatus,
TLSCertificates,
TrashCan,
UserAuthType,
Users,
UserSettings,
Version,
Vulnerabilities,
)
_TYPE_FIELDS = [
AggregateStatistic,
AlertCondition,
AlertEvent,
AlertMethod,
AliveTest,
CredentialFormat,
CredentialType,
EntityType,
FeedType,
FilterType,
HostsOrdering,
InfoType,
HelpFormat,
PortRangeType,
PermissionSubjectType,
ReportFormatType,
ScannerType,
SnmpAuthAlgorithm,
SnmpPrivacyAlgorithm,
SortOrder,
TicketStatus,
UserAuthType,
]
class GMPv224(GvmProtocol[T]):
"""
A class implementing the Greenbone Management Protocol (GMP) version 22.4
Example:
.. code-block:: python
from gvm.protocols.gmp import GMPv224 as GMP
with GMP(connection) as gmp:
resp = gmp.get_tasks()
"""
_authenticated = False
def __init__(self, *args, **kwargs):
"""
Create a new GMP protocol instance.
Args:
connection: Connection to use to talk with the remote daemon. See
:mod:`gvm.connections` for possible connection types.
transform: Optional transform `callable <https://docs.python.org/3/library/functions.html#callable>`_
to convert response data.
After each request the callable gets passed the plain response data
which can be used to check the data and/or conversion into different
representations like a xml dom.
See :mod:`gvm.transforms` for existing transforms.
"""
super().__init__(*args, **kwargs)
self.types = to_dotted_types_dict(_TYPE_FIELDS)
@staticmethod
def get_protocol_version() -> tuple[int, int]:
"""
Return the supported GMP version as major, minor version tuple
"""
return (22, 4)
def is_authenticated(self) -> bool:
"""Checks if the user is authenticated
If the user is authenticated privileged GMP commands like get_tasks
may be send to gvmd.
Returns:
bool: True if an authenticated connection to gvmd has been
established.
"""
return self._authenticated
def authenticate(self, username: str, password: str) -> T:
"""Authenticate to gvmd.
The generated authenticate command will be send to server.
Afterwards the response is read, transformed and returned.
Args:
username: Username
password: Password
"""
response = self._send_request(
Authentication.authenticate(username=username, password=password)
)
if response.is_success:
self._authenticated = True
return self._transform(response)
def describe_auth(self) -> T:
"""Describe authentication methods
Returns a list of all used authentication methods if such a list is
available.
"""
return self._send_request_and_transform_response(
Authentication.describe_auth()
)
def modify_auth(
self, group_name: str, auth_conf_settings: dict[str, str]
) -> T:
"""Modifies an existing auth.
Args:
group_name: Name of the group to be modified.
auth_conf_settings: The new auth config.
"""
return self._send_request_and_transform_response(
Authentication.modify_auth(group_name, auth_conf_settings)
)
def get_version(self) -> T:
"""Get the Greenbone Vulnerability Management Protocol (GMP) version
used by the remote gvmd.
"""
return self._send_request_and_transform_response(Version.get_version())
def clone_port_list(self, port_list_id: EntityID) -> T:
"""Clone an existing port list
Args:
port_list_id: UUID of an existing port list to clone from
"""
return self._send_request_and_transform_response(
PortLists.clone_port_list(port_list_id)
)
def create_port_list(
self, name: str, port_range: str, *, comment: Optional[str] = None
) -> T:
"""Create a new port list
Args:
name: Name of the new port list
port_range: Port list ranges e.g. `"T: 1-1234"` for tcp port
1 - 1234
comment: Comment for the port list
"""
return self._send_request_and_transform_response(
PortLists.create_port_list(name, port_range, comment=comment)
)
def create_port_range(
self,
port_list_id: EntityID,
start: int,
end: int,
port_range_type: Union[str, PortRangeType],
*,
comment: Optional[str] = None,
) -> T:
"""Create new port range
Args:
port_list_id: UUID of the port list to which to add the range
start: The first port in the range
end: The last port in the range
port_range_type: The type of the ports: TCP, UDP, ...
comment: Comment for the port range
"""
return self._send_request_and_transform_response(
PortLists.create_port_range(
port_list_id, start, end, port_range_type, comment=comment
)
)
def delete_port_list(
self, port_list_id: EntityID, *, ultimate: bool = False
) -> T:
"""Delete an existing port list
Args:
port_list_id: UUID of the port list to be deleted.
ultimate: Whether to remove entirely, or to the trashcan.
"""
return self._send_request_and_transform_response(
PortLists.delete_port_list(port_list_id, ultimate=ultimate)
)
def delete_port_range(self, port_range_id: EntityID) -> T:
"""Delete an existing port range
Args:
port_range_id: UUID of the port range to be deleted.
"""
return self._send_request_and_transform_response(
PortLists.delete_port_range(port_range_id)
)
def get_port_lists(
self,
*,
filter_string: Optional[str] = None,
filter_id: Optional[EntityID] = None,
details: Optional[bool] = None,
targets: Optional[bool] = None,
trash: Optional[bool] = None,
) -> T:
"""Request a list of port lists
Args:
filter_string: Filter term to use for the query
filter_id: UUID of an existing filter to use for the query
details: Whether to include full port list details
targets: Whether to include targets using this port list
trash: Whether to get port lists in the trashcan instead
"""
return self._send_request_and_transform_response(
PortLists.get_port_lists(
filter_string=filter_string,
filter_id=filter_id,
details=details,
targets=targets,
trash=trash,
)
)
def get_port_list(self, port_list_id: EntityID) -> T:
"""Request a single port list
Args:
port_list_id: UUID of an existing port list
"""
return self._send_request_and_transform_response(
PortLists.get_port_list(port_list_id)
)
def modify_port_list(
self,
port_list_id: EntityID,
*,
comment: Optional[str] = None,
name: Optional[str] = None,
) -> T:
"""Modify an existing port list.
Args:
port_list_id: UUID of port list to modify.
name: Name of port list.
comment: Comment on port list.
"""
return self._send_request_and_transform_response(
PortLists.modify_port_list(port_list_id, comment=comment, name=name)
)
def get_aggregates(
self,
resource_type: Union[EntityType, str],
*,
filter_string: Optional[str] = None,
filter_id: Optional[EntityID] = None,
sort_criteria: Optional[
Iterable[dict[str, Union[str, SortOrder, AggregateStatistic]]]
] = None,
data_columns: Optional[Iterable[str]] = None,
group_column: Optional[str] = None,
subgroup_column: Optional[str] = None,
text_columns: Optional[Iterable[str]] = None,
first_group: Optional[int] = None,
max_groups: Optional[int] = None,
mode: Optional[int] = None,
**kwargs,
) -> T:
"""Request aggregated information on a resource / entity type
Additional arguments can be set via the kwargs parameter for backward
compatibility with older versions of python-gvm, but are not validated.
Args:
resource_type: The entity type to gather data from
filter_string: Filter term to use for the query
filter_id: UUID of an existing filter to use for the query
sort_criteria: List of sort criteria (dicts that can contain
a field, stat and order)
data_columns: List of fields to aggregate data from
group_column: The field to group the entities by
subgroup_column: The field to further group the entities
inside groups by
text_columns: List of simple text columns which no statistics
are calculated for
first_group: The index of the first aggregate group to return
max_groups: The maximum number of aggregate groups to return,
-1 for all
mode: Special mode for aggregation
"""
return self._send_request_and_transform_response(
Aggregates.get_aggregates(
resource_type,
filter_string=filter_string,
filter_id=filter_id,
sort_criteria=sort_criteria,
data_columns=data_columns,
group_column=group_column,
subgroup_column=subgroup_column,
text_columns=text_columns,
first_group=first_group,
max_groups=max_groups,
mode=mode,
**kwargs,
)
)
def get_feeds(self) -> T:
"""Request the list of feeds"""
return self._send_request_and_transform_response(Feed.get_feeds())
def get_feed(self, feed_type: Union[FeedType, str]) -> T:
"""Request a single feed
Args:
feed_type: Type of single feed to get: NVT, CERT or SCAP
"""
return self._send_request_and_transform_response(
Feed.get_feed(feed_type)
)
def help(
self,
*,
help_format: Optional[Union[HelpFormat, str]] = None,
brief: Optional[bool] = None,
) -> T:
"""Get the help text
Args:
help_format: Format of of the help:
"html", "rnc", "text" or "xml
brief: If True help is brief
"""
return self._send_request_and_transform_response(
Help.help(help_format=help_format, brief=brief)
)
def get_system_reports(
self,
*,
name: Optional[str] = None,
duration: Optional[int] = None,
start_time: Optional[str] = None,
end_time: Optional[str] = None,
brief: Optional[bool] = None,
slave_id: Optional[EntityID] = None,
) -> T:
"""Request a list of system reports
Args:
name: A string describing the required system report
duration: The number of seconds into the past that the system report
should include
start_time: The start of the time interval the system report should
include in ISO time format
end_time: The end of the time interval the system report should
include in ISO time format
brief: Whether to include the actual system reports
slave_id: UUID of GMP scanner from which to get the system reports
"""
return self._send_request_and_transform_response(
SystemReports.get_system_reports(
name=name,
duration=duration,
start_time=start_time,
end_time=end_time,
brief=brief,
slave_id=slave_id,
)
)
def empty_trashcan(self) -> T:
"""Empty the trashcan
Remove all entities from the trashcan. **Attention:** this command can
not be reverted
"""
return self._send_request_and_transform_response(
TrashCan.empty_trashcan()
)
def restore_from_trashcan(self, entity_id: EntityID) -> T:
"""Restore an entity from the trashcan
Args:
entity_id: ID of the entity to be restored from the trashcan
"""
return self._send_request_and_transform_response(
TrashCan.restore_from_trashcan(entity_id)
)
def get_user_settings(self, *, filter_string: Optional[str] = None) -> T:
"""Request a list of user settings
Args:
filter_string: Filter term to use for the query
"""
return self._send_request_and_transform_response(
UserSettings.get_user_settings(filter_string=filter_string)
)
def get_user_setting(self, setting_id: EntityID) -> T:
"""Request a single user setting
Args:
setting_id: UUID of an existing setting
"""
return self._send_request_and_transform_response(
UserSettings.get_user_setting(setting_id)
)
def modify_user_setting(
self,
*,
setting_id: Optional[EntityID] = None,
name: Optional[str] = None,
value: Optional[str] = None,
) -> T:
"""Modifies an existing user setting.
Args:
setting_id: UUID of the setting to be changed.
name: The name of the setting. Either setting_id or name must be
passed.
value: The value of the setting.
"""
return self._send_request_and_transform_response(
UserSettings.modify_user_setting(
setting_id=setting_id, name=name, value=value
)
)
def clone_scan_config(self, config_id: EntityID) -> T:
"""Clone a scan config from an existing one
Args:
config_id: UUID of the existing scan config
"""
return self._send_request_and_transform_response(
ScanConfigs.clone_scan_config(config_id)
)
def create_scan_config(
self,
config_id: EntityID,
name: str,
*,
comment: Optional[str] = None,
) -> T:
"""Create a new scan config
Args:
config_id: UUID of the existing scan config
name: Name of the new scan config
comment: A comment on the config
"""
return self._send_request_and_transform_response(
ScanConfigs.create_scan_config(config_id, name, comment=comment)
)
def delete_scan_config(
self, config_id: EntityID, *, ultimate: Optional[bool] = False
) -> T:
"""Deletes an existing config
Args:
config_id: UUID of the config to be deleted.
ultimate: Whether to remove entirely, or to the trashcan.
"""
return self._send_request_and_transform_response(
ScanConfigs.delete_scan_config(config_id, ultimate=ultimate)
)
def get_scan_configs(
self,
*,
filter_string: Optional[str] = None,
filter_id: Optional[EntityID] = None,
trash: Optional[bool] = None,
details: Optional[bool] = None,
families: Optional[bool] = None,
preferences: Optional[bool] = None,
tasks: Optional[bool] = None,
) -> T:
"""Request a list of scan configs
Args:
filter_string: Filter term to use for the query
filter_id: UUID of an existing filter to use for the query
trash: Whether to get the trashcan scan configs instead
details: Whether to get config families, preferences, nvt selectors
and tasks.
families: Whether to include the families if no details are
requested
preferences: Whether to include the preferences if no details are
requested
tasks: Whether to get tasks using this config
"""
return self._send_request_and_transform_response(
ScanConfigs.get_scan_configs(
filter_string=filter_string,
filter_id=filter_id,
trash=trash,
details=details,
families=families,
preferences=preferences,
tasks=tasks,
)
)
def get_scan_config(
self, config_id: EntityID, *, tasks: Optional[bool] = None
) -> T:
"""Request a single scan config
Args:
config_id: UUID of an existing scan config
tasks: Whether to get tasks using this config
"""
return self._send_request_and_transform_response(
ScanConfigs.get_scan_config(config_id, tasks=tasks)
)
def get_scan_config_preferences(
self,
*,
nvt_oid: Optional[str] = None,
config_id: Optional[EntityID] = None,
) -> T:
"""Request a list of scan_config preferences
When the command includes a config_id attribute, the preference element
includes the preference name, type and value, and the NVT to which the
preference applies.
If the command includes a config_id and an nvt_oid, the preferences for
the given nvt in the config will be shown.
Args:
nvt_oid: OID of nvt
config_id: UUID of scan config of which to show preference values
"""
return self._send_request_and_transform_response(
ScanConfigs.get_scan_config_preferences(
nvt_oid=nvt_oid, config_id=config_id
)
)
def get_scan_config_preference(
self,
name: str,
*,
nvt_oid: Optional[str] = None,
config_id: Optional[EntityID] = None,
) -> T:
"""Request a nvt preference
Args:
name: name of a particular preference
nvt_oid: OID of nvt
config_id: UUID of scan config of which to show preference values
"""
return self._send_request_and_transform_response(
ScanConfigs.get_scan_config_preference(
name, nvt_oid=nvt_oid, config_id=config_id
)
)
def import_scan_config(self, config: str) -> T:
"""Import a scan config from XML
Args:
config: Scan Config XML as string to import. This XML must
contain a :code:`<get_configs_response>` root element.
"""
return self._send_request_and_transform_response(
ScanConfigs.import_scan_config(config)
)
def modify_scan_config_set_nvt_preference(
self,
config_id: EntityID,
name: str,
nvt_oid: str,
*,
value: Optional[str] = None,
) -> T:
"""Modifies the nvt preferences of an existing scan config.
Args:
config_id: UUID of scan config to modify.
name: Name for nvt preference to change.
nvt_oid: OID of the NVT associated with preference to modify
value: New value for the preference. None to delete the preference
and to use the default instead.
"""
return self._send_request_and_transform_response(
ScanConfigs.modify_scan_config_set_nvt_preference(
config_id, name, nvt_oid, value=value
)
)
def modify_scan_config_set_name(self, config_id: EntityID, name: str) -> T:
"""Modifies the name of an existing scan config
Args:
config_id: UUID of scan config to modify.
name: New name for the config.
"""
return self._send_request_and_transform_response(
ScanConfigs.modify_scan_config_set_name(config_id, name)
)
def modify_scan_config_set_comment(
self, config_id: EntityID, *, comment: Optional[str] = None
) -> T:
"""Modifies the comment of an existing scan config
Args:
config_id: UUID of scan config to modify.
comment: Comment to set on a config. Default is an
empty comment and the previous comment will be
removed.
"""
return self._send_request_and_transform_response(
ScanConfigs.modify_scan_config_set_comment(
config_id, comment=comment
)
)
def modify_scan_config_set_scanner_preference(
self,
config_id: EntityID,
name: str,
*,
value: Optional[str] = None,
) -> T:
"""Modifies the scanner preferences of an existing scan config
Args:
config_id: UUID of scan config to modify.
name: Name of the scanner preference to change
value: New value for the preference. None to delete the preference
and to use the default instead.
"""
return self._send_request_and_transform_response(
ScanConfigs.modify_scan_config_set_scanner_preference(
config_id, name, value=value
)
)
def modify_scan_config_set_nvt_selection(
self,
config_id: EntityID,
family: str,
nvt_oids: Union[tuple[str], list[str]],
) -> T:
"""Modifies the selected nvts of an existing scan config
The manager updates the given family in the config to include only the
given NVTs.
Arguments:
config_id: UUID of scan config to modify.
family: Name of the NVT family to include NVTs from
nvt_oids: List of NVTs to select for the family.
"""
return self._send_request_and_transform_response(
ScanConfigs.modify_scan_config_set_nvt_selection(
config_id, family, nvt_oids
)
)
def modify_scan_config_set_family_selection(
self,
config_id: EntityID,
families: list[tuple[str, bool, bool]],
*,
auto_add_new_families: Optional[bool] = True,
) -> T:
"""
Selected the NVTs of a scan config at a family level.
Args:
config_id: UUID of scan config to modify.
families: A list of tuples (str, bool, bool):
str: the name of the NVT family selected,
bool: add new NVTs to the family automatically,
bool: include all NVTs from the family
auto_add_new_families: Whether new families should be added to the
scan config automatically. Default: True.
"""
return self._send_request_and_transform_response(
ScanConfigs.modify_scan_config_set_family_selection(
config_id, families, auto_add_new_families=auto_add_new_families
)
)
def create_scanner(
self,
name: str,
host: str,
port: Union[str, int],
scanner_type: ScannerType,
credential_id: str,
*,
ca_pub: Optional[str] = None,
comment: Optional[str] = None,
) -> T:
"""Create a new scanner
Args:
name: Name of the new scanner
host: Hostname or IP address of the scanner
port: Port of the scanner
scanner_type: Type of the scanner
credential_id: UUID of client certificate credential for the
scanner
ca_pub: Certificate of CA to verify scanner certificate
comment: Comment for the scanner
"""
return self._send_request_and_transform_response(
Scanners.create_scanner(
name,
host,
port,
scanner_type,
credential_id,
ca_pub=ca_pub,
comment=comment,
)
)
def modify_scanner(
self,
scanner_id: EntityID,
*,
name: Optional[str] = None,
host: Optional[str] = None,
port: Optional[int] = None,
scanner_type: Optional[ScannerType] = None,
credential_id: Optional[EntityID] = None,
ca_pub: Optional[str] = None,
comment: Optional[str] = None,
) -> T:
"""Modify an existing scanner
Args:
scanner_id: UUID of the scanner to modify
name: New name of the scanner
host: New hostname or IP address of the scanner
port: New port of the scanner
scanner_type: New type of the scanner
credential_id: New UUID of client certificate credential for the
scanner
ca_pub: New certificate of CA to verify scanner certificate
comment: New comment for the scanner
"""
return self._send_request_and_transform_response(
Scanners.modify_scanner(
scanner_id,
name=name,
host=host,
port=port,
scanner_type=scanner_type,
credential_id=credential_id,
ca_pub=ca_pub,
comment=comment,
)
)
def get_scanners(
self,
*,
filter_string: Optional[str] = None,
filter_id: Optional[EntityID] = None,
trash: Optional[bool] = None,
details: Optional[bool] = None,
) -> T:
"""Request a list of scanners
Args:
filter_string: Filter term to use for the query
filter_id: UUID of an existing filter to use for the query
trash: Whether to get the trashcan scanners instead
details: Whether to include extra details like tasks using this
scanner
"""
return self._send_request_and_transform_response(
Scanners.get_scanners(
filter_string=filter_string,
filter_id=filter_id,
trash=trash,
details=details,
)
)
def get_scanner(self, scanner_id: EntityID) -> T:
"""Request a single scanner
Args:
scanner_id: UUID of an existing scanner
"""
return self._send_request_and_transform_response(
Scanners.get_scanner(scanner_id)
)
def verify_scanner(self, scanner_id: EntityID) -> T:
"""Verify an existing scanner
Args:
scanner_id: UUID of an existing scanner
"""
return self._send_request_and_transform_response(
Scanners.verify_scanner(scanner_id)
)
def clone_scanner(self, scanner_id: EntityID) -> T:
"""Clone an existing scanner
Args:
scanner_id: UUID of an existing scanner
"""
return self._send_request_and_transform_response(
Scanners.clone_scanner(scanner_id)
)
def delete_scanner(
self, scanner_id: EntityID, ultimate: Optional[bool] = False
) -> T:
"""Delete an existing scanner
Args:
scanner_id: UUID of an existing scanner
"""
return self._send_request_and_transform_response(
Scanners.delete_scanner(scanner_id, ultimate=ultimate)
)
def create_user(
self,
name: str,
*,
password: Optional[str] = None,
hosts: Optional[list[str]] = None,
hosts_allow: Optional[bool] = False,
role_ids: Optional[list[EntityID]] = None,
) -> T:
"""Create a new user
Args:
name: Name of the user
password: Password of the user
hosts: A list of host addresses (IPs, DNS names)
hosts_allow: If True allow only access to passed hosts otherwise
deny access. Default is False for deny hosts.
role_ids: A list of role UUIDs for the user
"""
return self._send_request_and_transform_response(
Users.create_user(
name,
password=password,
hosts=hosts,
hosts_allow=hosts_allow,
role_ids=role_ids,
)
)
def modify_user(
self,
user_id: EntityID,
*,
name: Optional[str] = None,
comment: Optional[str] = None,
password: Optional[str] = None,
auth_source: Optional[UserAuthType] = None,
role_ids: Optional[list[EntityID]] = None,
hosts: Optional[list[str]] = None,
hosts_allow: Optional[bool] = False,
group_ids: Optional[list[EntityID]] = None,
) -> T:
"""Modify an existing user.
Most of the fields need to be supplied
for changing a single field even if no change is wanted for those.
Else empty values are inserted for the missing fields instead.
Args:
user_id: UUID of the user to be modified.
name: The new name for the user.
comment: Comment on the user.
password: The password for the user.
auth_source: Source allowed for authentication for this user.
roles_id: List of roles UUIDs for the user.
hosts: User access rules: List of hosts.
hosts_allow: Defines how the hosts list is to be interpreted.
If False (default) the list is treated as a deny list.
All hosts are allowed by default except those provided by
the hosts parameter. If True the list is treated as a
allow list. All hosts are denied by default except those
provided by the hosts parameter.
group_ids: List of group UUIDs for the user.
"""
return self._send_request_and_transform_response(
Users.modify_user(
user_id,
name=name,
comment=comment,
password=password,
auth_source=auth_source,
role_ids=role_ids,
hosts=hosts,
hosts_allow=hosts_allow,
group_ids=group_ids,
)
)
def clone_user(self, user_id: EntityID) -> T:
"""Clone an existing user.
Args:
user_id: UUID of the user to be cloned.
"""
return self._send_request_and_transform_response(
Users.clone_user(user_id)
)
def delete_user(
self,
user_id: Optional[EntityID] = None,
*,
name: Optional[str] = None,
inheritor_id: Optional[EntityID] = None,
inheritor_name: Optional[str] = None,
) -> T:
"""Delete an existing user
Either user_id or name must be passed.
Args:
user_id: UUID of the task to be deleted.
name: The name of the user to be deleted.
inheritor_id: The UUID of the inheriting user or "self". Overrides
inheritor_name.
inheritor_name: The name of the inheriting user.
"""
return self._send_request_and_transform_response(
Users.delete_user(
user_id=user_id,
name=name,
inheritor_id=inheritor_id,
inheritor_name=inheritor_name,
)
)
def get_users(
self,
*,
filter_string: Optional[str] = None,
filter_id: Optional[EntityID] = None,
) -> T:
"""Request a list of users
Args:
filter_string: Filter term to use for the query
filter_id: UUID of an existing filter to use for the query
"""
return self._send_request_and_transform_response(
Users.get_users(filter_string=filter_string, filter_id=filter_id)
)
def get_user(self, user_id: EntityID) -> T:
"""Request a single user
Args:
user_id: UUID of the user to be requested.
"""
return self._send_request_and_transform_response(
Users.get_user(user_id)
)
def create_note(
self,
text: str,
nvt_oid: str,
*,
days_active: Optional[int] = None,
hosts: Optional[list[str]] = None,
port: Optional[str] = None,
result_id: Optional[EntityID] = None,
severity: Optional[Severity] = None,
task_id: Optional[EntityID] = None,
) -> T:
"""Create a new note
Args:
text: Text of the new note
nvt_id: OID of the nvt to which note applies
days_active: Days note will be active. -1 on
always, 0 off
hosts: A list of host addresses
port: Port to which the override applies, needs to be a string
in the form {number}/{protocol}
result_id: UUID of a result to which note applies
severity: Severity to which note applies
task_id: UUID of task to which note applies
"""
return self._send_request_and_transform_response(
Notes.create_note(
text,
nvt_oid,
days_active=days_active,
hosts=hosts,
port=port,
result_id=result_id,
severity=severity,
task_id=task_id,
)
)
def modify_note(
self,
note_id: EntityID,
text: str,
*,
days_active: Optional[int] = None,
hosts: Optional[list[str]] = None,
port: Optional[str] = None,
result_id: Optional[EntityID] = None,
severity: Optional[Severity] = None,
task_id: Optional[EntityID] = None,
) -> T:
"""Modify a note
Args:
note_id: The UUID of the note to modify
text: Text of the note
days_active: Days note will be active. -1 on always, 0 off
hosts: A list of host addresses
port: Port to which the override applies, needs to be a string
in the form {number}/{protocol}
result_id: UUID of a result to which note applies
severity: Severity to which note applies
task_id: UUID of task to which note applies
"""
return self._send_request_and_transform_response(
Notes.modify_note(
note_id,
text,
days_active=days_active,
hosts=hosts,
port=port,
result_id=result_id,
severity=severity,
task_id=task_id,
)
)
def clone_note(self, note_id: EntityID) -> T:
"""Clone an existing note
Args:
note_id: UUID of an existing note to clone from
"""
return self._send_request_and_transform_response(
Notes.clone_note(note_id)
)
def delete_note(
self, note_id: EntityID, *, ultimate: Optional[bool] = False
) -> T:
"""Delete an existing note
Args:
note_id: UUID of the note to be deleted.
ultimate: Whether to remove entirely or to the trashcan.
"""
return self._send_request_and_transform_response(
Notes.delete_note(note_id, ultimate=ultimate)
)
def get_notes(
self,
*,
filter_string: Optional[str] = None,
filter_id: Optional[EntityID] = None,
details: Optional[bool] = None,
result: Optional[bool] = None,
) -> T:
"""Request a list of notes
Args:
filter_string: Filter notes by a string
filter_string: Filter term to use for the query
filter_id: UUID of an existing filter to use for the query
details: Add info about connected results and tasks
result: Return the details of possible connected results.
"""
return self._send_request_and_transform_response(
Notes.get_notes(
filter_string=filter_string,
filter_id=filter_id,
details=details,
result=result,
)
)
def get_note(self, note_id: EntityID) -> T:
"""Request a single note
Arguments:
note_id: UUID of an existing note
"""
return self._send_request_and_transform_response(
Notes.get_note(note_id)
)
def create_override(
self,
text: str,
nvt_oid: str,
*,
days_active: Optional[int] = None,
hosts: Optional[list[str]] = None,
port: Optional[str] = None,
result_id: Optional[EntityID] = None,
severity: Optional[Severity] = None,
new_severity: Optional[Severity] = None,
task_id: Optional[EntityID] = None,
) -> T:
"""Create a new override
Args:
text: Text of the new override
nvt_id: OID of the nvt to which override applies
days_active: Days override will be active. -1 on always, 0 off
hosts: A list of host addresses
port: Port to which the override applies, needs to be a string
in the form {number}/{protocol}
result_id: UUID of a result to which override applies
severity: Severity to which override applies
new_severity: New severity for result
task_id: UUID of task to which override applies
"""
return self._send_request_and_transform_response(
Overrides.create_override(
text,
nvt_oid,
days_active=days_active,
hosts=hosts,
port=port,
result_id=result_id,
severity=severity,
new_severity=new_severity,
task_id=task_id,
)
)
def modify_override(
self,
override_id: EntityID,
text: str,
*,
days_active: Optional[int] = None,
hosts: Optional[list[str]] = None,
port: Optional[str] = None,
result_id: Optional[EntityID] = None,
severity: Optional[Severity] = None,
new_severity: Optional[Severity] = None,
task_id: Optional[EntityID] = None,
) -> T:
"""Modify an existing override.
Args:
override_id: UUID of override to modify.
text: The text of the override.
days_active: Days override will be active. -1 on always,
0 off.
hosts: A list of host addresses
port: Port to which the override applies, needs to be a string
in the form {number}/{protocol}
result_id: Result to which override applies.
severity: Severity to which override applies.
new_severity: New severity score for result.
task_id: Task to which override applies.
"""
return self._send_request_and_transform_response(
Overrides.modify_override(
override_id,
text,
days_active=days_active,
hosts=hosts,
port=port,
result_id=result_id,
severity=severity,
new_severity=new_severity,
task_id=task_id,
)
)
def clone_override(self, override_id: EntityID) -> T:
"""Clone an existing override
Args:
override_id: UUID of an existing override to clone from
"""
return self._send_request_and_transform_response(
Overrides.clone_override(override_id)
)
def delete_override(
self, override_id: EntityID, *, ultimate: Optional[bool] = False
) -> T:
"""Delete an existing override
Args:
override_id: UUID of an existing override to delete
ultimate: Whether to remove entirely, or to the trashcan.
"""
return self._send_request_and_transform_response(
Overrides.delete_override(override_id, ultimate=ultimate)
)
def get_overrides(
self,
*,
filter_string: Optional[str] = None,
filter_id: Optional[EntityID] = None,
details: Optional[bool] = None,
result: Optional[bool] = None,
) -> T:
"""Request a list of overrides
Args:
filter_string: Filter term to use for the query
filter_id: UUID of an existing filter to use for the query
details: Whether to include full details
result: Whether to include results using the override
"""
return self._send_request_and_transform_response(
Overrides.get_overrides(
filter_string=filter_string,
filter_id=filter_id,
details=details,
result=result,
)
)
def get_override(self, override_id: EntityID) -> T:
"""Request a single override
Args:
override_id: UUID of an existing override
"""
return self._send_request_and_transform_response(
Overrides.get_override(override_id)
)
def create_target(
self,
name: str,
*,
asset_hosts_filter: Optional[str] = None,
hosts: Optional[list[str]] = None,
comment: Optional[str] = None,
exclude_hosts: Optional[list[str]] = None,
ssh_credential_id: Optional[EntityID] = None,
ssh_credential_port: Optional[Union[int, str]] = None,
smb_credential_id: Optional[EntityID] = None,
esxi_credential_id: Optional[EntityID] = None,
snmp_credential_id: Optional[EntityID] = None,
alive_test: Optional[Union[str, AliveTest]] = None,
allow_simultaneous_ips: Optional[bool] = None,
reverse_lookup_only: Optional[bool] = None,
reverse_lookup_unify: Optional[bool] = None,
port_range: Optional[str] = None,
port_list_id: Optional[EntityID] = None,
) -> T:
"""Create a new target
Args:
name: Name of the target
asset_hosts_filter: Filter to select target host from assets hosts
hosts: List of hosts addresses to scan
exclude_hosts: List of hosts addresses to exclude from scan
comment: Comment for the target
ssh_credential_id: UUID of a ssh credential to use on target
ssh_credential_port: The port to use for ssh credential
smb_credential_id: UUID of a smb credential to use on target
snmp_credential_id: UUID of a snmp credential to use on target
esxi_credential_id: UUID of a esxi credential to use on target
alive_test: Which alive test to use
allow_simultaneous_ips: Whether to scan multiple IPs of the
same host simultaneously
reverse_lookup_only: Whether to scan only hosts that have names
reverse_lookup_unify: Whether to scan only one IP when multiple IPs
have the same name.
port_range: Port range for the target
port_list_id: UUID of the port list to use on target
"""
return self._send_request_and_transform_response(
Targets.create_target(
name,
asset_hosts_filter=asset_hosts_filter,
hosts=hosts,
comment=comment,
exclude_hosts=exclude_hosts,
ssh_credential_id=ssh_credential_id,
ssh_credential_port=ssh_credential_port,
smb_credential_id=smb_credential_id,
esxi_credential_id=esxi_credential_id,
snmp_credential_id=snmp_credential_id,
alive_test=alive_test,
allow_simultaneous_ips=allow_simultaneous_ips,
reverse_lookup_only=reverse_lookup_only,
reverse_lookup_unify=reverse_lookup_unify,
port_range=port_range,
port_list_id=port_list_id,
)
)
def modify_target(
self,
target_id: EntityID,
*,
name: Optional[str] = None,
comment: Optional[str] = None,
hosts: Optional[list[str]] = None,
exclude_hosts: Optional[list[str]] = None,
ssh_credential_id: Optional[EntityID] = None,
ssh_credential_port: Optional[Union[str, int]] = None,
smb_credential_id: Optional[EntityID] = None,
esxi_credential_id: Optional[EntityID] = None,
snmp_credential_id: Optional[EntityID] = None,
alive_test: Optional[Union[AliveTest, str]] = None,
allow_simultaneous_ips: Optional[bool] = None,
reverse_lookup_only: Optional[bool] = None,
reverse_lookup_unify: Optional[bool] = None,
port_list_id: Optional[EntityID] = None,
) -> T:
"""Modify an existing target.
Args:
target_id: UUID of target to modify.
comment: Comment on target.
name: Name of target.
hosts: List of target hosts.
exclude_hosts: A list of hosts to exclude.
ssh_credential_id: UUID of SSH credential to use on target.
ssh_credential_port: The port to use for ssh credential
smb_credential_id: UUID of SMB credential to use on target.
esxi_credential_id: UUID of ESXi credential to use on target.
snmp_credential_id: UUID of SNMP credential to use on target.
port_list_id: UUID of port list describing ports to scan.
alive_test: Which alive tests to use.
allow_simultaneous_ips: Whether to scan multiple IPs of the
same host simultaneously
reverse_lookup_only: Whether to scan only hosts that have names.
reverse_lookup_unify: Whether to scan only one IP when multiple IPs
have the same name.
"""
return self._send_request_and_transform_response(
Targets.modify_target(
target_id,
name=name,
comment=comment,
hosts=hosts,
exclude_hosts=exclude_hosts,
ssh_credential_id=ssh_credential_id,
ssh_credential_port=ssh_credential_port,
smb_credential_id=smb_credential_id,
esxi_credential_id=esxi_credential_id,
snmp_credential_id=snmp_credential_id,
alive_test=alive_test,
allow_simultaneous_ips=allow_simultaneous_ips,
reverse_lookup_only=reverse_lookup_only,
reverse_lookup_unify=reverse_lookup_unify,
port_list_id=port_list_id,
)
)
def clone_target(self, target_id: EntityID) -> T:
"""Clone an existing target.
Args:
target_id: UUID of an existing target to clone.
"""
return self._send_request_and_transform_response(
Targets.clone_target(target_id)
)
def delete_target(
self, target_id: EntityID, *, ultimate: Optional[bool] = False
) -> T:
"""Delete an existing target.
Args:
target_id: UUID of an existing target to delete.
ultimate: Whether to remove entirely or to the trashcan.
"""
return self._send_request_and_transform_response(
Targets.delete_target(target_id, ultimate=ultimate)
)
def get_target(
self, target_id: EntityID, *, tasks: Optional[bool] = None
) -> T:
"""Request a single target.
Args:
target_id: UUID of the target to request.
tasks: Whether to include list of tasks that use the target
"""
return self._send_request_and_transform_response(
Targets.get_target(target_id, tasks=tasks)
)
def get_targets(
self,
*,
filter_string: Optional[str] = None,
filter_id: Optional[EntityID] = None,
trash: Optional[bool] = None,
tasks: Optional[bool] = None,
) -> T:
"""Request a list of targets.
Args:
filter_string: Filter term to use for the query.
filter_id: UUID of an existing filter to use for the query.
trash: Whether to include targets in the trashcan.
tasks: Whether to include list of tasks that use the target.
"""
return self._send_request_and_transform_response(
Targets.get_targets(
filter_string=filter_string,
filter_id=filter_id,
trash=trash,
tasks=tasks,
)
)
def create_alert(
self,
name: str,
condition: AlertCondition,
event: AlertEvent,
method: AlertMethod,
*,
method_data: Optional[dict[str, str]] = None,
event_data: Optional[dict[str, str]] = None,
condition_data: Optional[dict[str, str]] = None,
filter_id: Optional[EntityID] = None,
comment: Optional[str] = None,
) -> T:
"""Create a new alert
Args:
name: Name of the new Alert
condition: The condition that must be satisfied for the alert
to occur; if the event is either 'Updated SecInfo arrived' or
'New SecInfo arrived', condition must be 'Always'. Otherwise,
condition can also be on of 'Severity at least', 'Filter count
changed' or 'Filter count at least'.
event: The event that must happen for the alert to occur, one
of 'Task run status changed', 'Updated SecInfo arrived' or 'New
SecInfo arrived'
method: The method by which the user is alerted, one of 'SCP',
'Send', 'SMB', 'SNMP', 'Syslog' or 'Email'; if the event is
neither 'Updated SecInfo arrived' nor 'New SecInfo arrived',
method can also be one of 'Start Task', 'HTTP Get', 'Sourcefire
Connector' or 'verinice Connector'.
condition_data: Data that defines the condition
event_data: Data that defines the event
method_data: Data that defines the method
filter_id: Filter to apply when executing alert
comment: Comment for the alert
"""
return self._send_request_and_transform_response(
Alerts.create_alert(
name,
condition,
event,
method,
method_data=method_data,
event_data=event_data,
condition_data=condition_data,
filter_id=filter_id,
comment=comment,
)
)
def modify_alert(
self,
alert_id: EntityID,
*,
name: Optional[str] = None,
comment: Optional[str] = None,
filter_id: Optional[EntityID] = None,
event: Optional[Union[AlertEvent, str]] = None,
event_data: Optional[dict] = None,
condition: Optional[Union[AlertCondition, str]] = None,
condition_data: Optional[dict[str, str]] = None,
method: Optional[Union[AlertMethod, str]] = None,
method_data: Optional[dict[str, str]] = None,
) -> T:
"""Modify an existing alert.
Args:
alert_id: UUID of the alert to be modified.
name: Name of the Alert.
condition: The condition that must be satisfied for the alert to
occur. If the event is either 'Updated SecInfo
arrived' or 'New SecInfo arrived', condition must be 'Always'.
Otherwise, condition can also be on of 'Severity at least',
'Filter count changed' or 'Filter count at least'.
condition_data: Data that defines the condition
event: The event that must happen for the alert to occur, one of
'Task run status changed', 'Updated SecInfo arrived' or
'New SecInfo arrived'
event_data: Data that defines the event
method: The method by which the user is alerted, one of 'SCP',
'Send', 'SMB', 'SNMP', 'Syslog' or 'Email';
if the event is neither 'Updated SecInfo arrived' nor
'New SecInfo arrived', method can also be one of 'Start Task',
'HTTP Get', 'Sourcefire Connector' or 'verinice Connector'.
method_data: Data that defines the method
filter_id: Filter to apply when executing alert
comment: Comment for the alert
"""
return self._send_request_and_transform_response(
Alerts.modify_alert(
alert_id,
name=name,
comment=comment,
filter_id=filter_id,
event=event,
event_data=event_data,
condition=condition,
condition_data=condition_data,
method=method,
method_data=method_data,
)
)
def clone_alert(self, alert_id: EntityID) -> T:
"""Clone an existing alert
Args:
alert_id: UUID of the alert to clone from
"""
return self._send_request_and_transform_response(
Alerts.clone_alert(alert_id)
)
def delete_alert(
self, alert_id: EntityID, *, ultimate: Optional[bool] = False
) -> T:
"""Delete an existing alert
Args:
alert_id: UUID of the alert to delete
ultimate: Whether to remove entirely or to the trashcan.
"""
return self._send_request_and_transform_response(
Alerts.delete_alert(alert_id, ultimate=ultimate)
)
def test_alert(self, alert_id: EntityID) -> T:
"""Run an alert
Invoke a test run of an alert
Args:
alert_id: UUID of the alert to be tested
"""
return self._send_request_and_transform_response(
Alerts.test_alert(alert_id)
)
def trigger_alert(
self,
alert_id: EntityID,
report_id: EntityID,
*,
filter_string: Optional[str] = None,
filter_id: Optional[EntityID] = None,
report_format_id: Optional[Union[EntityID, ReportFormatType]] = None,
delta_report_id: Optional[EntityID] = None,
) -> T:
"""Run an alert by ignoring its event and conditions
The alert is triggered to run immediately with the provided filtered
report by ignoring the even and condition settings.
Args:
alert_id: UUID of the alert to be run
report_id: UUID of the report to be provided to the alert
filter: Filter term to use to filter results in the report
filter_id: UUID of filter to use to filter results in the report
report_format_id: UUID of report format to use or ReportFormatType (enum)
delta_report_id: UUID of an existing report to compare report to.
"""
return self._send_request_and_transform_response(
Alerts.trigger_alert(
alert_id,
report_id,
filter_string=filter_string,
filter_id=filter_id,
report_format_id=report_format_id,
delta_report_id=delta_report_id,
)
)
def get_alerts(
self,
*,
filter_string: Optional[str] = None,
filter_id: Optional[EntityID] = None,
trash: Optional[bool] = None,
tasks: Optional[bool] = None,
) -> T:
"""Request a list of alerts
Args:
filter: Filter term to use for the query
filter_id: UUID of an existing filter to use for the query
trash: True to request the alerts in the trashcan
tasks: Whether to include the tasks using the alerts
"""
return self._send_request_and_transform_response(
Alerts.get_alerts(
filter_string=filter_string,
filter_id=filter_id,
trash=trash,
tasks=tasks,
)
)
def get_alert(
self, alert_id: EntityID, *, tasks: Optional[bool] = None
) -> T:
"""Request a single alert
Arguments:
alert_id: UUID of an existing alert
tasks: Whether to include the tasks using the alert
"""
return self._send_request_and_transform_response(
Alerts.get_alert(alert_id, tasks=tasks)
)
def create_audit(
self,
name: str,
policy_id: EntityID,
target_id: EntityID,
scanner_id: EntityID,
*,
alterable: Optional[bool] = None,
hosts_ordering: Optional[Union[HostsOrdering, str]] = None,
schedule_id: Optional[str] = None,
alert_ids: Optional[list[EntityID]] = None,
comment: Optional[str] = None,
schedule_periods: Optional[int] = None,
observers: Optional[list[EntityID]] = None,
preferences: Optional[dict[str, str]] = None,
) -> T:
"""Create a new audit
Args:
name: Name of the new audit
policy_id: UUID of policy to use by the audit
target_id: UUID of target to be scanned
scanner_id: UUID of scanner to use for scanning the target
comment: Comment for the audit
alterable: Whether the task should be alterable
alert_ids: List of UUIDs for alerts to be applied to the audit
hosts_ordering: The order hosts are scanned in
schedule_id: UUID of a schedule when the audit should be run.
schedule_periods: A limit to the number of times the audit will be
scheduled, or 0 for no limit
observers: List of names or ids of users which should be allowed to
observe this audit
preferences: Name/Value pairs of scanner preferences.
"""
return self._send_request_and_transform_response(
Audits.create_audit(
name,
policy_id,
target_id,
scanner_id,
alterable=alterable,
hosts_ordering=hosts_ordering,
schedule_id=schedule_id,
alert_ids=alert_ids,
comment=comment,
schedule_periods=schedule_periods,
observers=observers,
preferences=preferences,
)
)
def modify_audit(
self,
audit_id: EntityID,
*,
name: Optional[str] = None,
policy_id: Optional[EntityID] = None,
target_id: Optional[EntityID] = None,
scanner_id: Optional[EntityID] = None,
alterable: Optional[bool] = None,
hosts_ordering: Optional[Union[str, HostsOrdering]] = None,
schedule_id: Optional[EntityID] = None,
schedule_periods: Optional[int] = None,
comment: Optional[str] = None,
alert_ids: Optional[list[EntityID]] = None,
observers: Optional[list[EntityID]] = None,
preferences: Optional[dict[str, str]] = None,
) -> T:
"""Modifies an existing audit.
Args:
audit_id: UUID of audit to modify.
name: The name of the audit.
policy_id: UUID of policy to use by the audit
target_id: UUID of target to be scanned
scanner_id: UUID of scanner to use for scanning the target
comment: The comment on the audit.
alert_ids: List of UUIDs for alerts to be applied to the audit
hosts_ordering: The order hosts are scanned in
schedule_id: UUID of a schedule when the audit should be run.
schedule_periods: A limit to the number of times the audit will be
scheduled, or 0 for no limit.
observers: List of names or ids of users which should be allowed to
observe this audit
preferences: Name/Value pairs of scanner preferences.
"""
return self._send_request_and_transform_response(
Audits.modify_audit(
audit_id,
name=name,
policy_id=policy_id,
target_id=target_id,
scanner_id=scanner_id,
alterable=alterable,
hosts_ordering=hosts_ordering,
schedule_id=schedule_id,
alert_ids=alert_ids,
comment=comment,
schedule_periods=schedule_periods,
observers=observers,
preferences=preferences,
)
)
def clone_audit(self, audit_id: EntityID) -> T:
"""Clone an existing audit
Args:
audit_id: UUID of the audit to clone
"""
return self._send_request_and_transform_response(
Audits.clone_audit(audit_id)
)
def delete_audit(
self, audit_id: EntityID, *, ultimate: Optional[bool] = False
) -> T:
"""Delete an existing audit
Args:
audit_id: UUID of the audit to be deleted.
ultimate: Whether to remove entirely, or to the trashcan.
"""
return self._send_request_and_transform_response(
Audits.delete_audit(audit_id, ultimate=ultimate)
)
def get_audits(
self,
*,
filter_string: Optional[str] = None,
filter_id: Optional[EntityID] = None,
trash: Optional[bool] = None,
details: Optional[bool] = None,
schedules_only: Optional[bool] = None,
) -> T:
"""Request a list of audits
Args:
filter_string: Filter term to use for the query
filter_id: UUID of an existing filter to use for the query
trash: Whether to get the trashcan audits instead
details: Whether to include full audit details
schedules_only: Whether to only include id, name and schedule
details
"""
return self._send_request_and_transform_response(
Audits.get_audits(
filter_string=filter_string,
filter_id=filter_id,
trash=trash,
details=details,
schedules_only=schedules_only,
)
)
def get_audit(self, audit_id: EntityID) -> T:
"""Request a single audit
Args:
audit_id: UUID of an existing audit
"""
return self._send_request_and_transform_response(
Audits.get_audit(audit_id)
)
def resume_audit(self, audit_id: EntityID) -> T:
"""Resume an existing stopped audit
Args:
audit_id: UUID of the audit to be resumed
"""
return self._send_request_and_transform_response(
Audits.resume_audit(audit_id)
)
def start_audit(self, audit_id: EntityID) -> T:
"""Start an existing audit
Args:
audit_id: UUID of the audit to be started
"""
return self._send_request_and_transform_response(
Audits.start_audit(audit_id)
)
def stop_audit(self, audit_id: EntityID) -> T:
"""Stop an existing running audit
Args:
audit_id: UUID of the audit to be stopped
"""
return self._send_request_and_transform_response(
Audits.stop_audit(audit_id)
)
def clone_credential(self, credential_id: EntityID) -> T:
"""Clone an existing credential
Args:
credential_id: UUID of the credential to clone
"""
return self._send_request_and_transform_response(
Credentials.clone_credential(credential_id)
)
def create_credential(
self,
name: str,
credential_type: Union[CredentialType, str],
*,
comment: Optional[str] = None,
allow_insecure: Optional[bool] = None,
certificate: Optional[str] = None,
key_phrase: Optional[str] = None,
private_key: Optional[str] = None,
login: Optional[str] = None,
password: Optional[str] = None,
auth_algorithm: Optional[Union[SnmpAuthAlgorithm, str]] = None,
community: Optional[str] = None,
privacy_algorithm: Optional[Union[SnmpPrivacyAlgorithm, str]] = None,
privacy_password: Optional[str] = None,
public_key: Optional[str] = None,
) -> T:
"""Create a new credential
Create a new credential e.g. to be used in the method of an alert.
Currently the following credential types are supported:
- Username + Password
- Username + SSH-Key
- Client Certificates
- SNMPv1 or SNMPv2c protocol
- S/MIME Certificate
- OpenPGP Key
- Password only
Args:
name: Name of the new credential
credential_type: The credential type.
comment: Comment for the credential
allow_insecure: Whether to allow insecure use of the credential
certificate: Certificate for the credential.
Required for client-certificate and smime credential types.
key_phrase: Key passphrase for the private key.
Used for the username+ssh-key credential type.
private_key: Private key to use for login. Required
for usk credential type. Also used for the cc credential type.
The supported key types (dsa, rsa, ecdsa, ...) and formats (PEM,
PKC#12, OpenSSL, ...) depend on your installed GnuTLS version.
login: Username for the credential. Required for username+password,
username+ssh-key and snmp credential type.
password: Password for the credential. Used for username+password
and snmp credential types.
community: The SNMP community
auth_algorithm: The SNMP authentication algorithm. Required for snmp
credential type.
privacy_algorithm: The SNMP privacy algorithm
privacy_password: The SNMP privacy password
public_key: PGP public key in *armor* plain text format. Required
for pgp credential type.
Examples:
Creating a Username + Password credential
.. code-block:: python
gmp.create_credential(
name='UP Credential',
credential_type=CredentialType.USERNAME_PASSWORD,
login='foo',
password='bar',
)
Creating a Username + SSH Key credential
.. code-block:: python
with open('path/to/private-ssh-key') as f:
key = f.read()
gmp.create_credential(
name='USK Credential',
credential_type=CredentialType.USERNAME_SSH_KEY,
login='foo',
key_phrase='foobar',
private_key=key,
)
Creating a PGP credential
.. note::
A compatible public pgp key file can be exported with GnuPG via
::
$ gpg --armor --export alice@cyb.org > alice.asc
.. code-block:: python
with open('path/to/pgp.key.asc') as f:
key = f.read()
gmp.create_credential(
name='PGP Credential',
credential_type=CredentialType.PGP_ENCRYPTION_KEY,
public_key=key,
)
Creating a S/MIME credential
.. code-block:: python
with open('path/to/smime-cert') as f:
cert = f.read()
gmp.create_credential(
name='SMIME Credential',
credential_type=CredentialType.SMIME_CERTIFICATE,
certificate=cert,
)
Creating a Password-Only credential
.. code-block:: python
gmp.create_credential(
name='Password-Only Credential',
credential_type=CredentialType.PASSWORD_ONLY,
password='foo',
)
"""
return self._send_request_and_transform_response(
Credentials.create_credential(
name,
credential_type,
comment=comment,
allow_insecure=allow_insecure,
certificate=certificate,
key_phrase=key_phrase,
private_key=private_key,
login=login,
password=password,
auth_algorithm=auth_algorithm,
community=community,
privacy_algorithm=privacy_algorithm,
privacy_password=privacy_password,
public_key=public_key,
)
)
def delete_credential(
self, credential_id: EntityID, *, ultimate: Optional[bool] = False
) -> T:
"""Delete an existing credential
Args:
credential_id: UUID of the credential to delete
ultimate: Whether to remove entirely or to the trashcan.
"""
return self._send_request_and_transform_response(
Credentials.delete_credential(credential_id, ultimate=ultimate)
)
def get_credentials(
self,
*,
filter_string: Optional[str] = None,
filter_id: Optional[str] = None,
scanners: Optional[bool] = None,
trash: Optional[bool] = None,
targets: Optional[bool] = None,
) -> T:
"""Request a list of credentials
Args:
filter_string: Filter term to use for the query
filter_id: UUID of an existing filter to use for the query
scanners: Whether to include a list of scanners using the
credentials
trash: Whether to get the trashcan credentials instead
targets: Whether to include a list of targets using the credentials
"""
return self._send_request_and_transform_response(
Credentials.get_credentials(
filter_string=filter_string,
filter_id=filter_id,
scanners=scanners,
trash=trash,
targets=targets,
)
)
def get_credential(
self,
credential_id: str,
*,
scanners: Optional[bool] = None,
targets: Optional[bool] = None,
credential_format: Optional[Union[CredentialFormat, str]] = None,
) -> T:
"""Request a single credential
Args:
credential_id: UUID of an existing credential
scanners: Whether to include a list of scanners using the
credentials
targets: Whether to include a list of targets using the credentials
credential_format: One of "key", "rpm", "deb", "exe" or "pem"
"""
return self._send_request_and_transform_response(
Credentials.get_credential(
credential_id,
scanners=scanners,
targets=targets,
credential_format=credential_format,
)
)
def modify_credential(
self,
credential_id: str,
*,
name: Optional[str] = None,
comment: Optional[str] = None,
allow_insecure: Optional[bool] = None,
certificate: Optional[str] = None,
key_phrase: Optional[str] = None,
private_key: Optional[str] = None,
login: Optional[str] = None,
password: Optional[str] = None,
auth_algorithm: Optional[Union[SnmpAuthAlgorithm, str]] = None,
community: Optional[str] = None,
privacy_algorithm: Optional[Union[SnmpPrivacyAlgorithm, str]] = None,
privacy_password: Optional[str] = None,
public_key: Optional[str] = None,
) -> T:
"""Modifies an existing credential.
Args:
credential_id: UUID of the credential
name: Name of the credential
comment: Comment for the credential
allow_insecure: Whether to allow insecure use of the credential
certificate: Certificate for the credential
key_phrase: Key passphrase for the private key
private_key: Private key to use for login
login: Username for the credential
password: Password for the credential
auth_algorithm: The authentication algorithm for SNMP
community: The SNMP community
privacy_algorithm: The privacy algorithm for SNMP
privacy_password: The SNMP privacy password
public_key: PGP public key in *armor* plain text format
"""
return self._send_request_and_transform_response(
Credentials.modify_credential(
credential_id,
name=name,
comment=comment,
allow_insecure=allow_insecure,
certificate=certificate,
key_phrase=key_phrase,
private_key=private_key,
login=login,
password=password,
auth_algorithm=auth_algorithm,
community=community,
privacy_algorithm=privacy_algorithm,
privacy_password=privacy_password,
public_key=public_key,
)
)
def clone_filter(self, filter_id: EntityID) -> T:
"""Clone a filter
Args:
filter_id: ID of the filter to clone
"""
return self._send_request_and_transform_response(
Filters.clone_filter(filter_id)
)
def create_filter(
self,
name: str,
*,
filter_type: Optional[FilterType] = None,
comment: Optional[str] = None,
term: Optional[str] = None,
) -> T:
"""Create a new filter
Args:
name: Name of the new filter
filter_type: Filter for entity type
comment: Comment for the filter
term: Filter term e.g. 'name=foo'
"""
return self._send_request_and_transform_response(
Filters.create_filter(
name, filter_type=filter_type, comment=comment, term=term
)
)
def delete_filter(
self, filter_id: EntityID, *, ultimate: Optional[bool] = False
) -> T:
"""Deletes an existing filter
Args:
filter_id: UUID of the filter to be deleted.
ultimate: Whether to remove entirely, or to the trashcan.
"""
return self._send_request_and_transform_response(
Filters.delete_filter(filter_id, ultimate=ultimate)
)
def get_filters(
self,
*,
filter_string: Optional[str] = None,
filter_id: Optional[EntityID] = None,
trash: Optional[bool] = None,
alerts: Optional[bool] = None,
) -> T:
"""Request a list of filters
Args:
filter_string: Filter term to use for the query
filter_id: UUID of an existing filter to use for the query
trash: Whether to get the trashcan filters instead
alerts: Whether to include list of alerts that use the filter.
"""
return self._send_request_and_transform_response(
Filters.get_filters(
filter_string=filter_string,
filter_id=filter_id,
trash=trash,
alerts=alerts,
)
)
def get_filter(
self, filter_id: EntityID, *, alerts: Optional[bool] = None
) -> T:
"""Request a single filter
Args:
filter_id: UUID of an existing filter
alerts: Whether to include list of alerts that use the filter.
"""
return self._send_request_and_transform_response(
Filters.get_filter(filter_id, alerts=alerts)
)
def modify_filter(
self,
filter_id: EntityID,
*,
comment: Optional[str] = None,
name: Optional[str] = None,
term: Optional[str] = None,
filter_type: Optional[FilterType] = None,
) -> T:
"""Modifies an existing filter.
Args:
filter_id: UUID of the filter to be modified
comment: Comment on filter.
name: Name of filter.
term: Filter term.
filter_type: Resource type filter applies to.
"""
return self._send_request_and_transform_response(
Filters.modify_filter(
filter_id,
comment=comment,
name=name,
term=term,
filter_type=filter_type,
)
)
def clone_group(self, group_id: EntityID) -> T:
"""Clone an existing group
Args:
group_id: UUID of an existing group to clone from
"""
return self._send_request_and_transform_response(
Groups.clone_group(group_id)
)
def create_group(
self,
name: str,
*,
comment: Optional[str] = None,
special: Optional[bool] = False,
users: Optional[list[str]] = None,
) -> T:
"""Create a new group
Args:
name: Name of the new group
comment: Comment for the group
special: Create permission giving members full access to each
other's entities
users: List of user names to be in the group
"""
return self._send_request_and_transform_response(
Groups.create_group(
name, comment=comment, special=special, users=users
)
)
def delete_group(
self, group_id: EntityID, *, ultimate: Optional[bool] = False
) -> T:
"""Deletes an existing group
Args:
group_id: UUID of the group to be deleted.
ultimate: Whether to remove entirely, or to the trashcan.
"""
return self._send_request_and_transform_response(
Groups.delete_group(group_id, ultimate=ultimate)
)
def get_groups(
self,
*,
filter_string: Optional[str] = None,
filter_id: Optional[EntityID] = None,
trash: Optional[bool] = None,
) -> T:
"""Request a list of groups
Args:
filter_string: Filter term to use for the query
filter_id: UUID of an existing filter to use for the query
trash: Whether to get the trashcan groups instead
"""
return self._send_request_and_transform_response(
Groups.get_groups(
filter_string=filter_string, filter_id=filter_id, trash=trash
)
)
def get_group(self, group_id: EntityID) -> T:
"""Request a single group
Args:
group_id: UUID of an existing group
"""
return self._send_request_and_transform_response(
Groups.get_group(group_id)
)
def modify_group(
self,
group_id: EntityID,
*,
comment: Optional[str] = None,
name: Optional[str] = None,
users: Optional[list[str]] = None,
) -> T:
"""Modifies an existing group.
Args:
group_id: UUID of group to modify.
comment: Comment on group.
name: Name of group.
users: List of user names to be in the group
"""
return self._send_request_and_transform_response(
Groups.modify_group(
group_id, comment=comment, name=name, users=users
)
)
def create_host(self, name: str, *, comment: Optional[str] = None) -> T:
"""Create a new host host
Args:
name: Name for the new host host
comment: Comment for the new host host
"""
return self._send_request_and_transform_response(
Hosts.create_host(name, comment=comment)
)
def delete_host(self, host_id: EntityID) -> T:
"""Deletes an existing host
Args:
host_id: UUID of the single host to delete.
"""
return self._send_request_and_transform_response(
Hosts.delete_host(host_id)
)
def get_hosts(
self,
*,
filter_string: Optional[str] = None,
filter_id: Optional[EntityID] = None,
details: Optional[bool] = None,
) -> T:
"""Request a list of hosts
Args:
filter_string: Filter term to use for the query
filter_id: UUID of an existing filter to use for the query
details: Whether to include additional information (e.g. tags)
"""
return self._send_request_and_transform_response(
Hosts.get_hosts(
filter_string=filter_string,
filter_id=filter_id,
details=details,
)
)
def get_host(
self, host_id: EntityID, *, details: Optional[bool] = None
) -> T:
"""Request a single host
Arguments:
host_id: UUID of an existing host
details: Whether to include additional information (e.g. tags)
"""
return self._send_request_and_transform_response(
Hosts.get_host(host_id, details=details)
)
def modify_host(
self, host_id: EntityID, *, comment: Optional[str] = None
) -> T:
"""Modifies an existing host.
Args:
host_id: UUID of the host to be modified.
comment: Comment for the host. Not passing a comment
arguments clears the comment for this host.
"""
return self._send_request_and_transform_response(
Hosts.modify_host(host_id, comment=comment)
)
def delete_operating_system(
self,
operating_system_id: EntityID,
) -> T:
"""Deletes an existing operating system
Args:
operating_system_id: UUID of the single operating_system to delete.
"""
return self._send_request_and_transform_response(
OperatingSystems.delete_operating_system(operating_system_id)
)
def get_operating_systems(
self,
*,
filter_string: Optional[str] = None,
filter_id: Optional[EntityID] = None,
details: Optional[bool] = None,
) -> T:
"""Request a list of operating systems
Args:
filter_string: Filter term to use for the query
filter_id: UUID of an existing filter to use for the query
details: Whether to include additional information (e.g. tags)
"""
return self._send_request_and_transform_response(
OperatingSystems.get_operating_systems(
filter_string=filter_string,
filter_id=filter_id,
details=details,
)
)
def get_operating_system(
self, operating_system_id: EntityID, *, details: Optional[bool] = None
) -> T:
"""Request a single operating system
Args:
operating_system_id: UUID of an existing operating_system
details: Whether to include additional information (e.g. tags)
"""
return self._send_request_and_transform_response(
OperatingSystems.get_operating_system(
operating_system_id, details=details
)
)
def modify_operating_system(
self, operating_system_id: EntityID, *, comment: Optional[str] = None
) -> T:
"""Modifies an existing operating system.
Args:
operating_system_id: UUID of the operating_system to be modified.
comment: Comment for the operating_system. Not passing a comment
arguments clears the comment for this operating system.
"""
return self._send_request_and_transform_response(
OperatingSystems.modify_operating_system(
operating_system_id, comment=comment
)
)
def clone_permission(self, permission_id: EntityID) -> T:
"""Clone an existing permission
Args:
permission_id: UUID of an existing permission to clone from
"""
return self._send_request_and_transform_response(
Permissions.clone_permission(permission_id)
)
def create_permission(
self,
name: str,
subject_id: EntityID,
subject_type: Union[PermissionSubjectType, str],
*,
resource_id: Optional[str] = None,
resource_type: Optional[Union[EntityType, str]] = None,
comment: Optional[str] = None,
) -> T:
"""Create a new permission
Args:
name: Name of the new permission
subject_id: UUID of subject to whom the permission is granted
subject_type: Type of the subject user, group or role
comment: Comment for the permission
resource_id: UUID of entity to which the permission applies
resource_type: Type of the resource. For Super permissions user,
group or role
"""
return self._send_request_and_transform_response(
Permissions.create_permission(
name,
subject_id,
subject_type,
resource_id=resource_id,
resource_type=resource_type,
comment=comment,
)
)
def delete_permission(
self, permission_id: EntityID, *, ultimate: Optional[bool] = False
) -> T:
"""Deletes an existing permission
Args:
permission_id: UUID of the permission to be deleted.
ultimate: Whether to remove entirely, or to the trashcan.
"""
return self._send_request_and_transform_response(
Permissions.delete_permission(permission_id, ultimate=ultimate)
)
def get_permissions(
self,
*,
filter_string: Optional[str] = None,
filter_id: Optional[str] = None,
trash: Optional[bool] = None,
) -> T:
"""Request a list of permissions
Args:
filter_string: Filter term to use for the query
filter_id: UUID of an existing filter to use for the query
trash: Whether to get permissions in the trashcan instead
"""
return self._send_request_and_transform_response(
Permissions.get_permissions(
filter_string=filter_string, filter_id=filter_id, trash=trash
)
)
def get_permission(self, permission_id: EntityID) -> T:
"""Request a single permission
Args:
permission_id: UUID of an existing permission
"""
return self._send_request_and_transform_response(
Permissions.get_permission(permission_id)
)
def modify_permission(
self,
permission_id: EntityID,
*,
comment: Optional[str] = None,
name: Optional[str] = None,
resource_id: Optional[EntityID] = None,
resource_type: Optional[Union[EntityType, str]] = None,
subject_id: Optional[EntityID] = None,
subject_type: Optional[Union[PermissionSubjectType, str]] = None,
) -> T:
"""Modifies an existing permission.
Args:
permission_id: UUID of permission to be modified.
comment: The comment on the permission.
name: Permission name, currently the name of a command.
subject_id: UUID of subject to whom the permission is granted
subject_type: Type of the subject user, group or role
resource_id: UUID of entity to which the permission applies
resource_type: Type of the resource. For Super permissions user,
group or role
"""
return self._send_request_and_transform_response(
Permissions.modify_permission(
permission_id,
comment=comment,
name=name,
resource_id=resource_id,
resource_type=resource_type,
subject_id=subject_id,
subject_type=subject_type,
)
)
def clone_policy(self, policy_id: EntityID) -> T:
"""Clone a policy from an existing one
Args:
policy_id: UUID of the existing policy
"""
return self._send_request_and_transform_response(
Policies.clone_policy(policy_id)
)
def create_policy(
self,
name: str,
*,
policy_id: Optional[EntityID] = None,
comment: Optional[str] = None,
) -> T:
"""Create a new policy
Args:
name: Name of the new policy
policy_id: UUID of an existing policy as base. By default the empty
policy is used.
comment: A comment on the policy
"""
return self._send_request_and_transform_response(
Policies.create_policy(name, policy_id=policy_id, comment=comment)
)
def delete_policy(
self, policy_id: EntityID, *, ultimate: Optional[bool] = False
) -> T:
"""Deletes an existing policy
Args:
policy_id: UUID of the policy to be deleted.
ultimate: Whether to remove entirely, or to the trashcan.
"""
return self._send_request_and_transform_response(
Policies.delete_policy(policy_id, ultimate=ultimate)
)
def get_policies(
self,
*,
audits: Optional[bool] = None,
filter_string: Optional[str] = None,
filter_id: Optional[EntityID] = None,
details: Optional[bool] = None,
families: Optional[bool] = None,
preferences: Optional[bool] = None,
trash: Optional[bool] = None,
) -> T:
"""Request a list of policies
Args:
audits: Whether to get audits using the policy
filter_string: Filter term to use for the query
filter_id: UUID of an existing filter to use for the query
details: Whether to get families, preferences, nvt selectors
and tasks.
families: Whether to include the families if no details are
requested
preferences: Whether to include the preferences if no details are
requested
trash: Whether to get the trashcan audits instead
"""
return self._send_request_and_transform_response(
Policies.get_policies(
audits=audits,
filter_string=filter_string,
filter_id=filter_id,
details=details,
families=families,
preferences=preferences,
trash=trash,
)
)
def get_policy(
self, policy_id: EntityID, *, audits: Optional[bool] = None
) -> T:
"""Request a single policy
Args:
policy_id: UUID of an existing policy
audits: Whether to get audits using this policy
"""
return self._send_request_and_transform_response(
Policies.get_policy(policy_id, audits=audits)
)
def import_policy(self, policy: str) -> T:
"""Import a policy from XML
Args:
policy: Policy XML as string to import. This XML must
contain a :code:`<get_configs_response>` root element.
"""
return self._send_request_and_transform_response(
Policies.import_policy(policy)
)
def modify_policy_set_nvt_preference(
self,
policy_id: EntityID,
name: str,
nvt_oid: str,
*,
value: Optional[str] = None,
) -> T:
"""Modifies the nvt preferences of an existing policy.
Args:
policy_id: UUID of policy to modify.
name: Name for preference to change.
nvt_oid: OID of the NVT associated with preference to modify
value: New value for the preference. None to delete the preference
and to use the default instead.
"""
return self._send_request_and_transform_response(
Policies.modify_policy_set_nvt_preference(
policy_id, name, nvt_oid, value=value
)
)
def modify_policy_set_name(self, policy_id: EntityID, name: str) -> T:
"""Modifies the name of an existing policy
Args:
policy_id: UUID of policy to modify.
name: New name for the policy.
"""
return self._send_request_and_transform_response(
Policies.modify_policy_set_name(policy_id, name)
)
def modify_policy_set_comment(
self, policy_id: EntityID, comment: Optional[str] = None
) -> T:
"""Modifies the comment of an existing policy
Args:
policy_id: UUID of policy to modify.
comment: Comment to set on a policy. Default is an
empty comment and the previous comment will be
removed.
"""
return self._send_request_and_transform_response(
Policies.modify_policy_set_comment(policy_id, comment=comment)
)
def modify_policy_set_scanner_preference(
self, policy_id: EntityID, name: str, *, value: Optional[str] = None
) -> T:
"""Modifies the scanner preferences of an existing policy
Args:
policy_id: UUID of policy to modify.
name: Name of the scanner preference to change
value: New value for the preference. None to delete the preference
and to use the default instead.
"""
return self._send_request_and_transform_response(
Policies.modify_policy_set_scanner_preference(
policy_id, name, value=value
)
)
def modify_policy_set_nvt_selection(
self, policy_id: EntityID, family: str, nvt_oids: Sequence[str]
) -> T:
"""Modifies the selected nvts of an existing policy
The manager updates the given family in the policy to include only the
given NVTs.
Args:
policy_id: UUID of policy to modify.
family: Name of the NVT family to include NVTs from
nvt_oids: List of NVTs to select for the family.
"""
return self._send_request_and_transform_response(
Policies.modify_policy_set_nvt_selection(
policy_id, family, nvt_oids
)
)
def modify_policy_set_family_selection(
self,
policy_id: EntityID,
families: Sequence[tuple[str, bool, bool]],
*,
auto_add_new_families: Optional[bool] = True,
) -> T:
"""
Selected the NVTs of a policy at a family level.
Args:
policy_id: UUID of policy to modify.
families: A list of tuples with the first entry being the name
of the NVT family selected, second entry a boolean indicating
whether new NVTs should be added to the family automatically,
and third entry a boolean indicating whether all nvts from
the family should be included.
auto_add_new_families: Whether new families should be added to the
policy automatically. Default: True.
"""
return self._send_request_and_transform_response(
Policies.modify_policy_set_family_selection(
policy_id, families, auto_add_new_families=auto_add_new_families
)
)
def delete_report(self, report_id: EntityID) -> T:
"""Deletes an existing report
Args:
report_id: UUID of the report to be deleted.
"""
return self._send_request_and_transform_response(
Reports.delete_report(report_id)
)
def get_report(
self,
report_id: EntityID,
*,
filter_string: Optional[str] = None,
filter_id: Optional[str] = None,
delta_report_id: Optional[EntityID] = None,
report_format_id: Optional[Union[str, ReportFormatType]] = None,
ignore_pagination: Optional[bool] = None,
details: Optional[bool] = True,
) -> T:
"""Request a single report
Args:
report_id: UUID of an existing report
filter_string: Filter term to use to filter results in the report
filter_id: UUID of filter to use to filter results in the report
delta_report_id: UUID of an existing report to compare report to.
report_format_id: UUID of report format to use
or ReportFormatType (enum)
ignore_pagination: Whether to ignore the filter terms "first" and
"rows".
details: Request additional report information details
defaults to True
"""
return self._send_request_and_transform_response(
Reports.get_report(
report_id,
filter_string=filter_string,
filter_id=filter_id,
delta_report_id=delta_report_id,
report_format_id=report_format_id,
ignore_pagination=ignore_pagination,
details=details,
)
)
def get_reports(
self,
*,
filter_string: Optional[str] = None,
filter_id: Optional[EntityID] = None,
note_details: Optional[bool] = None,
override_details: Optional[bool] = None,
ignore_pagination: Optional[bool] = None,
details: Optional[bool] = None,
) -> T:
"""Request a list of reports
Args:
filter_string: Filter term to use for the query
filter_id: UUID of an existing filter to use for the query
note_details: If notes are included, whether to include note details
override_details: If overrides are included, whether to include
override details
ignore_pagination: Whether to ignore the filter terms "first" and
"rows".
details: Whether to exclude results
"""
return self._send_request_and_transform_response(
Reports.get_reports(
filter_string=filter_string,
filter_id=filter_id,
note_details=note_details,
override_details=override_details,
ignore_pagination=ignore_pagination,
details=details,
)
)
def import_report(
self,
report: str,
task_id: EntityID,
*,
in_assets: Optional[bool] = None,
) -> T:
"""Import a Report from XML
Args:
report: Report XML as string to import. This XML must contain
a :code:`<report>` root element.
task_id: UUID of task to import report to
in_asset: Whether to create or update assets using the report
"""
return self._send_request_and_transform_response(
Reports.import_report(report, task_id, in_assets=in_assets)
)
def get_result(self, result_id: EntityID) -> T:
"""Request a single result
Args:
result_id: UUID of an existing result
"""
return self._send_request_and_transform_response(
Results.get_result(result_id)
)
def get_results(
self,
*,
filter_string: Optional[str] = None,
filter_id: Optional[str] = None,
task_id: Optional[str] = None,
note_details: Optional[bool] = None,
override_details: Optional[bool] = None,
details: Optional[bool] = None,
) -> T:
"""Request a list of results
Args:
filter_string: Filter term to use for the query
filter_id: UUID of an existing filter to use for the query
task_id: UUID of task for note and override handling
note_details: If notes are included, whether to include note details
override_details: If overrides are included, whether to include
override details
details: Whether to include additional details of the results
"""
return self._send_request_and_transform_response(
Results.get_results(
filter_string=filter_string,
filter_id=filter_id,
task_id=task_id,
note_details=note_details,
override_details=override_details,
details=details,
)
)
def clone_role(self, role_id: EntityID) -> T:
"""Clone an existing role
Args:
role_id: UUID of an existing role to clone from
"""
return self._send_request_and_transform_response(
Roles.clone_role(role_id)
)
def create_role(
self,
name: str,
*,
comment: Optional[str] = None,
users: Optional[list[str]] = None,
) -> T:
"""Create a new role
Args:
name: Name of the role
comment: Comment for the role
users: List of user names to add to the role
"""
return self._send_request_and_transform_response(
Roles.create_role(name, comment=comment, users=users)
)
def delete_role(
self, role_id: str, *, ultimate: Optional[bool] = False
) -> T:
"""Deletes an existing role
Args:
role_id: UUID of the role to be deleted.
ultimate: Whether to remove entirely, or to the trashcan.
"""
return self._send_request_and_transform_response(
Roles.delete_role(role_id, ultimate=ultimate)
)
def get_roles(
self,
*,
filter_string: Optional[str] = None,
filter_id: Optional[EntityID] = None,
trash: Optional[bool] = None,
) -> T:
"""Request a list of roles
Args:
filter_string: Filter term to use for the query
filter_id: UUID of an existing filter to use for the query
trash: Whether to get the trashcan roles instead
"""
return self._send_request_and_transform_response(
Roles.get_roles(
filter_string=filter_string, filter_id=filter_id, trash=trash
)
)
def get_role(self, role_id: EntityID) -> T:
"""Request a single role
Args:
role_id: UUID of an existing role
"""
return self._send_request_and_transform_response(
Roles.get_role(role_id)
)
def modify_role(
self,
role_id: EntityID,
*,
comment: Optional[str] = None,
name: Optional[str] = None,
users: Optional[list[str]] = None,
) -> T:
"""Modifies an existing role.
Args:
role_id: UUID of role to modify.
comment: Name of role.
name: Comment on role.
users: List of user names.
"""
return self._send_request_and_transform_response(
Roles.modify_role(role_id, comment=comment, name=name, users=users)
)
def clone_schedule(self, schedule_id: EntityID) -> T:
"""Clone an existing schedule
Args:
schedule_id: UUID of an existing schedule to clone from
"""
return self._send_request_and_transform_response(
Schedules.clone_schedule(schedule_id)
)
def create_schedule(
self,
name: str,
icalendar: str,
timezone: str,
*,
comment: Optional[str] = None,
) -> T:
"""Create a new schedule based in `iCalendar <https://tools.ietf.org/html/rfc5545>`_ data.
Example:
Requires https://pypi.org/project/icalendar/
.. code-block:: python
import pytz
from datetime import datetime
from icalendar import Calendar, Event
cal = Calendar()
cal.add('prodid', '-//Foo Bar//')
cal.add('version', '2.0')
event = Event()
event.add('dtstamp', datetime.now(tz=pytz.UTC))
event.add('dtstart', datetime(2020, 1, 1, tzinfo=pytz.utc))
cal.add_component(event)
gmp.create_schedule(
name="My Schedule",
icalendar=cal.to_ical(),
timezone='UTC'
)
Args:
name: Name of the new schedule
icalendar: `iCalendar <https://tools.ietf.org/html/rfc5545>`_ (RFC 5545) based data.
timezone: Timezone to use for the icalendar events e.g
Europe/Berlin. If the datetime values in the icalendar data are
missing timezone information this timezone gets applied.
Otherwise the datetime values from the icalendar data are
displayed in this timezone
comment: Comment on schedule.
"""
return self._send_request_and_transform_response(
Schedules.create_schedule(
name, icalendar, timezone, comment=comment
)
)
def delete_schedule(
self, schedule_id: EntityID, *, ultimate: Optional[bool] = False
) -> T:
"""Deletes an existing schedule
Args:
schedule_id: UUID of the schedule to be deleted.
ultimate: Whether to remove entirely, or to the trashcan.
"""
return self._send_request_and_transform_response(
Schedules.delete_schedule(schedule_id, ultimate=ultimate)
)
def get_schedules(
self,
*,
filter_string: Optional[str] = None,
filter_id: Optional[EntityID] = None,
trash: Optional[bool] = None,
tasks: Optional[bool] = None,
) -> T:
"""Request a list of schedules
Args:
filter_string: Filter term to use for the query
filter_id: UUID of an existing filter to use for the query
trash: Whether to get the trashcan schedules instead
tasks: Whether to include tasks using the schedules
"""
return self._send_request_and_transform_response(
Schedules.get_schedules(
filter_string=filter_string,
filter_id=filter_id,
trash=trash,
tasks=tasks,
)
)
def get_schedule(
self, schedule_id: EntityID, *, tasks: Optional[bool] = None
) -> T:
"""Request a single schedule
Args:
schedule_id: UUID of an existing schedule
tasks: Whether to include tasks using the schedules
"""
return self._send_request_and_transform_response(
Schedules.get_schedule(schedule_id, tasks=tasks)
)
def modify_schedule(
self,
schedule_id: EntityID,
*,
name: Optional[str] = None,
icalendar: Optional[str] = None,
timezone: Optional[str] = None,
comment: Optional[str] = None,
) -> T:
"""Modifies an existing schedule
Args:
schedule_id: UUID of the schedule to be modified
name: Name of the schedule
icalendar: `iCalendar <https://tools.ietf.org/html/rfc5545>`_
(RFC 5545) based data.
timezone: Timezone to use for the icalendar events e.g
Europe/Berlin. If the datetime values in the icalendar data are
missing timezone information this timezone gets applied.
Otherwise the datetime values from the icalendar data are
displayed in this timezone
comment: Comment on schedule.
"""
return self._send_request_and_transform_response(
Schedules.modify_schedule(
schedule_id,
name=name,
icalendar=icalendar,
timezone=timezone,
comment=comment,
)
)
def get_nvt_families(self, *, sort_order: Optional[str] = None) -> T:
"""Request a list of nvt families
Args:
sort_order: Sort order
"""
return self._send_request_and_transform_response(
Nvts.get_nvt_families(sort_order=sort_order)
)
def get_scan_config_nvts(
self,
*,
details: Optional[bool] = None,
preferences: Optional[bool] = None,
preference_count: Optional[bool] = None,
timeout: Optional[bool] = None,
config_id: Optional[EntityID] = None,
preferences_config_id: Optional[EntityID] = None,
family: Optional[str] = None,
sort_order: Optional[str] = None,
sort_field: Optional[str] = None,
) -> T:
"""Request a list of nvts
Args:
details: Whether to include full details
preferences: Whether to include nvt preferences
preference_count: Whether to include preference count
timeout: Whether to include the special timeout preference
config_id: UUID of scan config to which to limit the NVT listing
preferences_config_id: UUID of scan config to use for preference
values
family: Family to which to limit NVT listing
sort_order: Sort order
sort_field: Sort field
"""
return self._send_request_and_transform_response(
Nvts.get_scan_config_nvts(
details=details,
preferences=preferences,
preference_count=preference_count,
timeout=timeout,
config_id=config_id,
preferences_config_id=preferences_config_id,
family=family,
sort_order=sort_order,
sort_field=sort_field,
)
)
def get_scan_config_nvt(self, nvt_oid: str) -> T:
"""Request a single nvt
Args:
nvt_oid: OID of an existing nvt
"""
return self._send_request_and_transform_response(
Nvts.get_scan_config_nvt(nvt_oid)
)
def get_nvts(
self,
*,
filter_string: Optional[str] = None,
filter_id: Optional[str] = None,
name: Optional[str] = None,
details: Optional[bool] = None,
extended: Optional[bool] = None,
preferences: Optional[bool] = None,
preference_count: Optional[bool] = None,
timeout: Optional[bool] = None,
config_id: Optional[str] = None,
preferences_config_id: Optional[str] = None,
family: Optional[str] = None,
sort_order: Optional[str] = None,
sort_field: Optional[str] = None,
) -> T:
"""Request a list of NVTs
Args:
filter_string: Filter term to use for the query
filter_id: UUID of an existing filter to use for the query
name: Name or identifier of the requested information
details: Whether to include information about references to this
information
extended: Whether to receive extended NVT information
(calls get_nvts, instead of get_info)
preferences: Whether to include NVT preferences (only for extended)
preference_count: Whether to include preference count (only for extended)
timeout: Whether to include the special timeout preference (only for extended)
config_id: UUID of scan config to which to limit the NVT listing (only for extended)
preferences_config_id: UUID of scan config to use for preference
values (only for extended)
family: Family to which to limit NVT listing (only for extended)
sort_order: Sort order (only for extended)
sort_field: Sort field (only for extended)
"""
return self._send_request_and_transform_response(
Nvts.get_nvts(
filter_string=filter_string,
filter_id=filter_id,
name=name,
details=details,
extended=extended,
preferences=preferences,
preference_count=preference_count,
timeout=timeout,
config_id=config_id,
preferences_config_id=preferences_config_id,
family=family,
sort_order=sort_order,
sort_field=sort_field,
)
)
def get_nvt(self, nvt_id: str, *, extended: Optional[bool] = None) -> T:
"""Request a single NVT
Args:
nvt_id: ID of an existing NVT
extended: Whether to receive extended NVT information
(calls get_nvts, instead of get_info)
"""
return self._send_request_and_transform_response(
Nvts.get_nvt(nvt_id, extended=extended)
)
def get_nvt_preferences(
self,
*,
nvt_oid: Optional[str] = None,
) -> T:
"""Request a list of preferences
The preference element includes just the
name and value, with the NVT and type built into the name.
Args:
nvt_oid: OID of nvt
"""
return self._send_request_and_transform_response(
Nvts.get_nvt_preferences(nvt_oid=nvt_oid)
)
def get_nvt_preference(
self,
name: str,
*,
nvt_oid: Optional[str] = None,
) -> T:
"""Request a nvt preference
Args:
name: name of a particular preference
nvt_oid: OID of nvt
config_id: UUID of scan config of which to show preference values
"""
return self._send_request_and_transform_response(
Nvts.get_nvt_preference(name, nvt_oid=nvt_oid)
)
def get_info(self, info_id: EntityID, info_type: InfoType) -> T:
"""Request a single secinfo
Arguments:
info_id: ID of an existing secinfo
info_type: Type must be either CERT_BUND_ADV, CPE, CVE,
DFN_CERT_ADV, OVALDEF, NVT
"""
return self._send_request_and_transform_response(
SecInfo.get_info(info_id, info_type)
)
def get_info_list(
self,
info_type: InfoType,
*,
filter_string: Optional[str] = None,
filter_id: Optional[str] = None,
name: Optional[str] = None,
details: Optional[bool] = None,
) -> T:
"""Request a list of security information
Args:
info_type: Type must be either CERT_BUND_ADV, CPE, CVE,
DFN_CERT_ADV, OVALDEF or NVT
filter_string: Filter term to use for the query
filter_id: UUID of an existing filter to use for the query
name: Name or identifier of the requested information
details: Whether to include information about references to this
information
"""
return self._send_request_and_transform_response(
SecInfo.get_info_list(
info_type,
filter_string=filter_string,
filter_id=filter_id,
name=name,
details=details,
)
)
def get_cves(
self,
*,
filter_string: Optional[str] = None,
filter_id: Optional[EntityID] = None,
name: Optional[str] = None,
details: Optional[bool] = None,
) -> T:
"""Request a list of CVEs
Args:
filter_string: Filter term to use for the query
filter_id: UUID of an existing filter to use for the query
name: Name or identifier of the requested information
details: Whether to include information about references to this
information
"""
return self._send_request_and_transform_response(
Cves.get_cves(
filter_string=filter_string,
filter_id=filter_id,
name=name,
details=details,
)
)
def get_cve(self, cve_id: str) -> T:
"""Request a single CVE
Args:
cve_id: ID of an existing CVE
"""
return self._send_request_and_transform_response(Cves.get_cve(cve_id))
def get_cpes(
self,
*,
filter_string: Optional[str] = None,
filter_id: Optional[EntityID] = None,
name: Optional[str] = None,
details: Optional[bool] = None,
) -> T:
"""Request a list of CPEs
Args:
filter_string: Filter term to use for the query
filter_id: UUID of an existing filter to use for the query
name: Name or identifier of the requested information
details: Whether to include information about references to this
information
"""
return self._send_request_and_transform_response(
Cpes.get_cpes(
filter_string=filter_string,
filter_id=filter_id,
name=name,
details=details,
)
)
def get_cpe(self, cpe_id: str) -> T:
"""Request a single CPE
Args:
cpe_id: ID of an existing CPE
"""
return self._send_request_and_transform_response(Cpes.get_cpe(cpe_id))
def get_dfn_cert_advisories(
self,
*,
filter_string: Optional[str] = None,
filter_id: Optional[EntityID] = None,
name: Optional[str] = None,
details: Optional[bool] = None,
) -> T:
"""Request a list of DFN-CERT Advisories
Args:
filter_string: Filter term to use for the query
filter_id: UUID of an existing filter to use for the query
name: Name or identifier of the requested information
details: Whether to include information about references to this
information
"""
return self._send_request_and_transform_response(
DfnCertAdvisories.get_dfn_cert_advisories(
filter_string=filter_string,
filter_id=filter_id,
name=name,
details=details,
)
)
def get_dfn_cert_advisory(self, cert_id: EntityID) -> T:
"""Request a single DFN-CERT Advisory
Args:
cert_id: ID of an existing DFN-CERT Advisory
"""
return self._send_request_and_transform_response(
DfnCertAdvisories.get_dfn_cert_advisory(cert_id)
)
def get_cert_bund_advisories(
self,
*,
filter_string: Optional[str] = None,
filter_id: Optional[EntityID] = None,
name: Optional[str] = None,
details: Optional[bool] = None,
) -> T:
"""Request a list of CERT-BUND Advisories
Args:
filter_string: Filter term to use for the query
filter_id: UUID of an existing filter to use for the query
name: Name or identifier of the requested information
details: Whether to include information about references to this
information
"""
return self._send_request_and_transform_response(
CertBundAdvisories.get_cert_bund_advisories(
filter_string=filter_string,
filter_id=filter_id,
name=name,
details=details,
)
)
def get_cert_bund_advisory(self, cert_id: EntityID) -> T:
"""Request a single CERT-BUND Advisory
Args:
cert_id: ID of an existing CERT-BUND Advisory
"""
return self._send_request_and_transform_response(
CertBundAdvisories.get_cert_bund_advisory(cert_id)
)
def clone_tag(self, tag_id: EntityID) -> T:
"""Clone an existing tag
Args:
tag_id: UUID of an existing tag to clone from
"""
return self._send_request_and_transform_response(Tags.clone_tag(tag_id))
def create_tag(
self,
name: str,
resource_type: EntityType,
*,
resource_filter: Optional[str] = None,
resource_ids: Optional[list[EntityID]] = None,
value: Optional[str] = None,
comment: Optional[str] = None,
active: Optional[bool] = None,
) -> T:
"""Create a tag
Args:
name: Name of the tag. A full tag name consisting of namespace and
predicate e.g. `foo:bar`.
resource_type: Entity type the tag is to be attached to.
resource_filter: Filter term to select resources the tag is to be
attached to. Only one of resource_filter or resource_ids can be
provided.
resource_ids: IDs of the resources the tag is to be attached to.
Only one of resource_filter or resource_ids can be provided.
value: Value associated with the tag.
comment: Comment for the tag.
active: Whether the tag should be active.
"""
return self._send_request_and_transform_response(
Tags.create_tag(
name,
resource_type,
resource_filter=resource_filter,
resource_ids=resource_ids,
value=value,
comment=comment,
active=active,
)
)
def delete_tag(
self, tag_id: EntityID, *, ultimate: Optional[bool] = False
) -> T:
"""Deletes an existing tag
Args:
tag_id: UUID of the tag to be deleted.
ultimate: Whether to remove entirely, or to the trashcan.
"""
return self._send_request_and_transform_response(
Tags.delete_tag(tag_id, ultimate=ultimate)
)
def get_tags(
self,
*,
filter_string: Optional[str] = None,
filter_id: Optional[EntityID] = None,
trash: Optional[bool] = None,
names_only: Optional[bool] = None,
) -> T:
"""Request a list of tags
Args:
filter_string: Filter term to use for the query
filter_id: UUID of an existing filter to use for the query
trash: Whether to get tags from the trashcan instead
names_only: Whether to get only distinct tag names
"""
return self._send_request_and_transform_response(
Tags.get_tags(
filter_string=filter_string,
filter_id=filter_id,
trash=trash,
names_only=names_only,
)
)
def get_tag(self, tag_id: EntityID) -> T:
"""Request a single tag
Args:
tag_id: UUID of an existing tag
"""
return self._send_request_and_transform_response(Tags.get_tag(tag_id))
def modify_tag(
self,
tag_id: EntityID,
*,
comment: Optional[str] = None,
name: Optional[str] = None,
value: Optional[str] = None,
active: Optional[bool] = None,
resource_action: Optional[str] = None,
resource_type: Optional[EntityType] = None,
resource_filter: Optional[str] = None,
resource_ids: Optional[list[EntityID]] = None,
) -> T:
"""Modifies an existing tag.
Args:
tag_id: UUID of the tag.
comment: Comment to add to the tag.
name: Name of the tag.
value: Value of the tag.
active: Whether the tag is active.
resource_action: Whether to add or remove resources instead of
overwriting. One of '', 'add', 'set' or 'remove'.
resource_type: Type of the resources to which to attach the tag.
Required if resource_filter is set.
resource_filter: Filter term to select resources the tag is to be
attached to.
resource_ids: IDs of the resources to which to attach the tag.
"""
return self._send_request_and_transform_response(
Tags.modify_tag(
tag_id,
comment=comment,
name=name,
value=value,
active=active,
resource_action=resource_action,
resource_type=resource_type,
resource_filter=resource_filter,
resource_ids=resource_ids,
)
)
def clone_task(self, task_id: EntityID) -> T:
"""Clone an existing task
Args:
task_id: UUID of existing task to clone from
"""
return self._send_request_and_transform_response(
Tasks.clone_task(task_id)
)
def create_container_task(
self, name: str, *, comment: Optional[str] = None
) -> T:
"""Create a new container task
A container task is a "meta" task to import and view reports from other
systems.
Args:
name: Name of the task
comment: Comment for the task
"""
return self._send_request_and_transform_response(
Tasks.create_container_task(name, comment=comment)
)
def create_task(
self,
name: str,
config_id: EntityID,
target_id: EntityID,
scanner_id: EntityID,
*,
alterable: Optional[bool] = None,
hosts_ordering: Optional[HostsOrdering] = None,
schedule_id: Optional[EntityID] = None,
alert_ids: Optional[Sequence[EntityID]] = None,
comment: Optional[str] = None,
schedule_periods: Optional[int] = None,
observers: Optional[Sequence[str]] = None,
preferences: Optional[Mapping[str, SupportsStr]] = None,
) -> T:
"""Create a new scan task
Args:
name: Name of the new task
config_id: UUID of config to use by the task
target_id: UUID of target to be scanned
scanner_id: UUID of scanner to use for scanning the target
comment: Comment for the task
alterable: Whether the task should be alterable
alert_ids: List of UUIDs for alerts to be applied to the task
hosts_ordering: The order hosts are scanned in
schedule_id: UUID of a schedule when the task should be run.
schedule_periods: A limit to the number of times the task will be
scheduled, or 0 for no limit
observers: List of names or ids of users which should be allowed to
observe this task
preferences: Name/Value pairs of scanner preferences.
"""
return self._send_request_and_transform_response(
Tasks.create_task(
name,
config_id,
target_id,
scanner_id,
alterable=alterable,
hosts_ordering=hosts_ordering,
schedule_id=schedule_id,
alert_ids=alert_ids,
comment=comment,
schedule_periods=schedule_periods,
observers=observers,
preferences=preferences,
)
)
def delete_task(
self, task_id: EntityID, *, ultimate: Optional[bool] = False
) -> T:
"""Deletes an existing task
Args:
task_id: UUID of the task to be deleted.
ultimate: Whether to remove entirely, or to the trashcan.
"""
return self._send_request_and_transform_response(
Tasks.delete_task(task_id, ultimate=ultimate)
)
def get_tasks(
self,
*,
filter_string: Optional[str] = None,
filter_id: Optional[EntityID] = None,
trash: Optional[bool] = None,
details: Optional[bool] = None,
schedules_only: Optional[bool] = None,
ignore_pagination: Optional[bool] = None,
) -> T:
"""Request a list of tasks
Args:
filter_string: Filter term to use for the query
filter_id: UUID of an existing filter to use for the query
trash: Whether to get the trashcan tasks instead
details: Whether to include full task details
schedules_only: Whether to only include id, name and schedule
details
ignore_pagination: Whether to ignore pagination settings (filter
terms "first" and "rows"). Default is False.
"""
return self._send_request_and_transform_response(
Tasks.get_tasks(
filter_string=filter_string,
filter_id=filter_id,
trash=trash,
details=details,
schedules_only=schedules_only,
ignore_pagination=ignore_pagination,
)
)
def get_task(self, task_id: EntityID) -> T:
"""Request a single task
Args:
task_id: UUID of an existing task
"""
return self._send_request_and_transform_response(
Tasks.get_task(task_id)
)
def modify_task(
self,
task_id: EntityID,
*,
name: Optional[str] = None,
config_id: Optional[EntityID] = None,
target_id: Optional[EntityID] = None,
scanner_id: Optional[EntityID] = None,
alterable: Optional[bool] = None,
hosts_ordering: Optional[HostsOrdering] = None,
schedule_id: Optional[EntityID] = None,
schedule_periods: Optional[int] = None,
comment: Optional[str] = None,
alert_ids: Optional[Sequence[EntityID]] = None,
observers: Optional[Sequence[str]] = None,
preferences: Optional[Mapping[str, SupportsStr]] = None,
) -> T:
"""Modifies an existing task.
Args:
task_id: UUID of task to modify.
name: The name of the task.
config_id: UUID of scan config to use by the task
target_id: UUID of target to be scanned
scanner_id: UUID of scanner to use for scanning the target
comment: The comment on the task.
alert_ids: List of UUIDs for alerts to be applied to the task
hosts_ordering: The order hosts are scanned in
schedule_id: UUID of a schedule when the task should be run.
schedule_periods: A limit to the number of times the task will be
scheduled, or 0 for no limit.
observers: List of names or ids of users which should be allowed to
observe this task
preferences: Name/Value pairs of scanner preferences.
"""
return self._send_request_and_transform_response(
Tasks.modify_task(
task_id,
name=name,
config_id=config_id,
target_id=target_id,
scanner_id=scanner_id,
alterable=alterable,
hosts_ordering=hosts_ordering,
schedule_id=schedule_id,
schedule_periods=schedule_periods,
comment=comment,
alert_ids=alert_ids,
observers=observers,
preferences=preferences,
)
)
def move_task(
self, task_id: EntityID, *, slave_id: Optional[EntityID] = None
) -> T:
"""Move an existing task to another GMP slave scanner or the master
Args:
task_id: UUID of the task to be moved
slave_id: UUID of the sensor to reassign the task to, empty for master.
"""
return self._send_request_and_transform_response(
Tasks.move_task(task_id, slave_id=slave_id)
)
def start_task(self, task_id: EntityID) -> T:
"""Start an existing task
Args:
task_id: UUID of the task to be started
"""
return self._send_request_and_transform_response(
Tasks.start_task(task_id)
)
def resume_task(self, task_id: EntityID) -> T:
"""Resume an existing stopped task
Args:
task_id: UUID of the task to be resumed
"""
return self._send_request_and_transform_response(
Tasks.resume_task(task_id)
)
def stop_task(self, task_id: EntityID) -> T:
"""Stop an existing running task
Args:
task_id: UUID of the task to be stopped
"""
return self._send_request_and_transform_response(
Tasks.stop_task(task_id)
)
def clone_ticket(self, ticket_id: EntityID) -> T:
"""Clone an existing ticket
Args:
ticket_id: UUID of an existing ticket to clone from
"""
return self._send_request_and_transform_response(
Tickets.clone_ticket(ticket_id)
)
def create_ticket(
self,
*,
result_id: EntityID,
assigned_to_user_id: EntityID,
note: str,
comment: Optional[str] = None,
) -> T:
"""Create a new ticket
Args:
result_id: UUID of the result the ticket applies to
assigned_to_user_id: UUID of a user the ticket should be assigned to
note: A note about opening the ticket
comment: Comment for the ticket
"""
return self._send_request_and_transform_response(
Tickets.create_ticket(
result_id=result_id,
assigned_to_user_id=assigned_to_user_id,
note=note,
comment=comment,
)
)
def delete_ticket(
self, ticket_id: EntityID, *, ultimate: Optional[bool] = False
) -> T:
"""Deletes an existing ticket
Args:
ticket_id: UUID of the ticket to be deleted.
ultimate: Whether to remove entirely, or to the trashcan.
"""
return self._send_request_and_transform_response(
Tickets.delete_ticket(ticket_id, ultimate=ultimate)
)
def get_tickets(
self,
*,
trash: Optional[bool] = None,
filter_string: Optional[str] = None,
filter_id: Optional[EntityID] = None,
) -> T:
"""Request a list of tickets
Args:
filter_string: Filter term to use for the query
filter_id: UUID of an existing filter to use for the query
trash: True to request the tickets in the trashcan
"""
return self._send_request_and_transform_response(
Tickets.get_tickets(
filter_string=filter_string, filter_id=filter_id, trash=trash
)
)
def get_ticket(self, ticket_id: EntityID) -> T:
"""Request a single ticket
Args:
ticket_id: UUID of an existing ticket
"""
return self._send_request_and_transform_response(
Tickets.get_ticket(ticket_id)
)
def modify_ticket(
self,
ticket_id: EntityID,
*,
status: Optional[Union[TicketStatus, str]] = None,
note: Optional[str] = None,
assigned_to_user_id: Optional[EntityID] = None,
comment: Optional[str] = None,
) -> T:
"""Modify a single ticket
Args:
ticket_id: UUID of an existing ticket
status: New status for the ticket
note: Note for the status change. Required if status is set.
assigned_to_user_id: UUID of the user the ticket should be assigned
to
comment: Comment for the ticket
"""
return self._send_request_and_transform_response(
Tickets.modify_ticket(
ticket_id,
status=status,
note=note,
assigned_to_user_id=assigned_to_user_id,
comment=comment,
)
)
def clone_tls_certificate(self, tls_certificate_id: EntityID) -> T:
"""Modifies an existing TLS certificate.
Args:
tls_certificate_id: The UUID of an existing TLS certificate
"""
return self._send_request_and_transform_response(
TLSCertificates.clone_tls_certificate(tls_certificate_id)
)
def create_tls_certificate(
self,
name: str,
certificate: str,
*,
comment: Optional[str] = None,
trust: Optional[bool] = None,
) -> T:
"""Create a new TLS certificate
Args:
name: Name of the TLS certificate, defaulting to the MD5
fingerprint.
certificate: The Base64 encoded certificate data (x.509 DER or PEM).
comment: Comment for the TLS certificate.
trust: Whether the certificate is trusted.
"""
return self._send_request_and_transform_response(
TLSCertificates.create_tls_certificate(
name, certificate, comment=comment, trust=trust
)
)
def delete_tls_certificate(self, tls_certificate_id: EntityID) -> T:
"""Deletes an existing tls certificate
Args:
tls_certificate_id: UUID of the tls certificate to be deleted.
"""
return self._send_request_and_transform_response(
TLSCertificates.delete_tls_certificate(tls_certificate_id)
)
def get_tls_certificates(
self,
*,
filter_string: Optional[str] = None,
filter_id: Optional[EntityID] = None,
include_certificate_data: Optional[bool] = None,
details: Optional[bool] = None,
) -> T:
"""Request a list of TLS certificates
Args:
filter_string: Filter term to use for the query
filter_id: UUID of an existing filter to use for the query
include_certificate_data: Whether to include the certificate data in
the response
details: Whether to include additional details of the
tls certificates
"""
return self._send_request_and_transform_response(
TLSCertificates.get_tls_certificates(
filter_string=filter_string,
filter_id=filter_id,
include_certificate_data=include_certificate_data,
details=details,
)
)
def get_tls_certificate(self, tls_certificate_id: EntityID) -> T:
"""Request a single TLS certificate
Args:
tls_certificate_id: UUID of an existing TLS certificate
"""
return self._send_request_and_transform_response(
TLSCertificates.get_tls_certificate(tls_certificate_id)
)
def modify_tls_certificate(
self,
tls_certificate_id: EntityID,
*,
name: Optional[str] = None,
comment: Optional[str] = None,
trust: Optional[bool] = None,
) -> T:
"""Modifies an existing TLS certificate.
Args:
tls_certificate_id: UUID of the TLS certificate to be modified.
name: Name of the TLS certificate, defaulting to the MD5 fingerprint
comment: Comment for the TLS certificate.
trust: Whether the certificate is trusted.
"""
return self._send_request_and_transform_response(
TLSCertificates.modify_tls_certificate(
tls_certificate_id, name=name, comment=comment, trust=trust
)
)
def get_vulnerabilities(
self,
*,
filter_string: Optional[str] = None,
filter_id: Optional[EntityID] = None,
) -> T:
"""Request a list of vulnerabilities
Args:
filter_string: Filter term to use for the query
filter_id: UUID of an existing filter to use for the query
"""
return self._send_request_and_transform_response(
Vulnerabilities.get_vulnerabilities(
filter_string=filter_string, filter_id=filter_id
)
)
def get_vulnerability(self, vulnerability_id: EntityID) -> T:
"""Request a single vulnerability
Args:
vulnerability_id: ID of an existing vulnerability
"""
return self._send_request_and_transform_response(
Vulnerabilities.get_vulnerability(vulnerability_id)
)
def clone_report_format(
self, report_format_id: Union[EntityID, ReportFormatType]
) -> T:
"""Clone a report format from an existing one
Args:
report_format_id: UUID of the existing report format
or ReportFormatType (enum)
"""
return self._send_request_and_transform_response(
ReportFormats.clone_report_format(report_format_id)
)
def delete_report_format(
self,
report_format_id: Union[EntityID, ReportFormatType],
*,
ultimate: Optional[bool] = False,
) -> T:
"""Deletes an existing report format
Args:
report_format_id: UUID of the report format to be deleted.
or ReportFormatType (enum)
ultimate: Whether to remove entirely, or to the trashcan.
"""
return self._send_request_and_transform_response(
ReportFormats.delete_report_format(
report_format_id, ultimate=ultimate
)
)
def get_report_formats(
self,
*,
filter_string: Optional[str] = None,
filter_id: Optional[EntityID] = None,
trash: Optional[bool] = None,
alerts: Optional[bool] = None,
params: Optional[bool] = None,
details: Optional[bool] = None,
) -> T:
"""Request a list of report formats
Args:
filter_string: Filter term to use for the query
filter_id: UUID of an existing filter to use for the query
trash: Whether to get the trashcan report formats instead
alerts: Whether to include alerts that use the report format
params: Whether to include report format parameters
details: Include report format file, signature and parameters
"""
return self._send_request_and_transform_response(
ReportFormats.get_report_formats(
filter_string=filter_string,
filter_id=filter_id,
trash=trash,
alerts=alerts,
params=params,
details=details,
)
)
def get_report_format(
self, report_format_id: Union[EntityID, ReportFormatType]
) -> T:
"""Request a single report format
Args:
report_format_id: UUID of an existing report format
or ReportFormatType (enum)
"""
return self._send_request_and_transform_response(
ReportFormats.get_report_format(report_format_id)
)
def import_report_format(self, report_format: str) -> T:
"""Import a report format from XML
Args:
report_format: Report format XML as string to import. This XML must
contain a :code:`<get_report_formats_response>` root element.
"""
return self._send_request_and_transform_response(
ReportFormats.import_report_format(report_format)
)
def modify_report_format(
self,
report_format_id: Union[EntityID, ReportFormatType],
*,
active: Optional[bool] = None,
name: Optional[str] = None,
summary: Optional[str] = None,
param_name: Optional[str] = None,
param_value: Optional[str] = None,
) -> T:
"""Modifies an existing report format.
Args:
report_format_id: UUID of report format to modify
or ReportFormatType (enum)
active: Whether the report format is active.
name: The name of the report format.
summary: A summary of the report format.
param_name: The name of the param.
param_value: The value of the param.
"""
return self._send_request_and_transform_response(
ReportFormats.modify_report_format(
report_format_id,
active=active,
name=name,
summary=summary,
param_name=param_name,
param_value=param_value,
)
)
def verify_report_format(
self, report_format_id: Union[EntityID, ReportFormatType]
) -> T:
"""Verify an existing report format
Verifies the trust level of an existing report format. It will be
checked whether the signature of the report format currently matches the
report format. This includes the script and files used to generate
reports of this format. It is *not* verified if the report format works
as expected by the user.
Args:
report_format_id: UUID of the report format to be verified
or ReportFormatType (enum)
"""
return self._send_request_and_transform_response(
ReportFormats.verify_report_format(report_format_id)
)
|