1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
# Copyright (C) 2020 Greenbone Networks GmbH |
3
|
|
|
# |
4
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later |
5
|
|
|
# |
6
|
|
|
# This program is free software: you can redistribute it and/or modify |
7
|
|
|
# it under the terms of the GNU General Public License as published by |
8
|
|
|
# the Free Software Foundation, either version 3 of the License, or |
9
|
|
|
# (at your option) any later version. |
10
|
|
|
# |
11
|
|
|
# This program is distributed in the hope that it will be useful, |
12
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
13
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14
|
|
|
# GNU General Public License for more details. |
15
|
|
|
# |
16
|
|
|
# You should have received a copy of the GNU General Public License |
17
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
18
|
|
|
from enum import Enum |
19
|
|
|
|
20
|
|
|
from typing import Optional |
21
|
|
|
|
22
|
|
|
from gvm.errors import InvalidArgument |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
from gvm.protocols.gmpv208.types import ( |
26
|
|
|
AlertCondition, |
27
|
|
|
AlertEvent, |
28
|
|
|
AlertMethod, |
29
|
|
|
AliveTest, |
30
|
|
|
AssetType, |
31
|
|
|
CredentialFormat, |
32
|
|
|
CredentialType, |
33
|
|
|
EntityType, |
34
|
|
|
FeedType, |
35
|
|
|
FilterType, |
36
|
|
|
HostsOrdering, |
37
|
|
|
InfoType, |
38
|
|
|
PermissionSubjectType, |
39
|
|
|
PortRangeType, |
40
|
|
|
ScannerType, |
41
|
|
|
SnmpAuthAlgorithm, |
42
|
|
|
SnmpPrivacyAlgorithm, |
43
|
|
|
TicketStatus, |
44
|
|
|
TimeUnit, |
45
|
|
|
get_alert_condition_from_string, |
46
|
|
|
get_alert_event_from_string, |
47
|
|
|
get_alert_method_from_string, |
48
|
|
|
get_alive_test_from_string, |
49
|
|
|
get_asset_type_from_string, |
50
|
|
|
get_credential_format_from_string, |
51
|
|
|
get_credential_type_from_string, |
52
|
|
|
get_entity_type_from_string, |
53
|
|
|
get_feed_type_from_string, |
54
|
|
|
get_filter_type_from_string, |
55
|
|
|
get_hosts_ordering_from_string, |
56
|
|
|
get_info_type_from_string, |
57
|
|
|
get_permission_subject_type_from_string, |
58
|
|
|
get_port_range_type_from_string, |
59
|
|
|
get_scanner_type_from_string, |
60
|
|
|
get_snmp_auth_algorithm_from_string, |
61
|
|
|
get_snmp_privacy_algorithm_from_string, |
62
|
|
|
get_ticket_status_from_string, |
63
|
|
|
get_time_unit_from_string, |
64
|
|
|
) |
65
|
|
|
|
66
|
|
|
|
67
|
|
|
__all__ = [ |
68
|
|
|
"AlertCondition", |
69
|
|
|
"AlertEvent", |
70
|
|
|
"AlertMethod", |
71
|
|
|
"AliveTest", |
72
|
|
|
"AssetType", |
73
|
|
|
"CredentialFormat", |
74
|
|
|
"CredentialType", |
75
|
|
|
"EntityType", |
76
|
|
|
"FeedType", |
77
|
|
|
"FilterType", |
78
|
|
|
"HostsOrdering", |
79
|
|
|
"InfoType", |
80
|
|
|
"PermissionSubjectType", |
81
|
|
|
"PortRangeType", |
82
|
|
|
"ScannerType", |
83
|
|
|
"SeverityLevel", |
84
|
|
|
"SnmpAuthAlgorithm", |
85
|
|
|
"SnmpPrivacyAlgorithm", |
86
|
|
|
"TicketStatus", |
87
|
|
|
"TimeUnit", |
88
|
|
|
"get_alert_condition_from_string", |
89
|
|
|
"get_alert_event_from_string", |
90
|
|
|
"get_alert_method_from_string", |
91
|
|
|
"get_alive_test_from_string", |
92
|
|
|
"get_asset_type_from_string", |
93
|
|
|
"get_credential_format_from_string", |
94
|
|
|
"get_credential_type_from_string", |
95
|
|
|
"get_entity_type_from_string", |
96
|
|
|
"get_feed_type_from_string", |
97
|
|
|
"get_filter_type_from_string", |
98
|
|
|
"get_hosts_ordering_from_string", |
99
|
|
|
"get_info_type_from_string", |
100
|
|
|
"get_permission_subject_type_from_string", |
101
|
|
|
"get_port_range_type_from_string", |
102
|
|
|
"get_scanner_type_from_string", |
103
|
|
|
"get_severity_level_from_string", |
104
|
|
|
"get_snmp_auth_algorithm_from_string", |
105
|
|
|
"get_snmp_privacy_algorithm_from_string", |
106
|
|
|
"get_ticket_status_from_string", |
107
|
|
|
"get_time_unit_from_string", |
108
|
|
|
] |
109
|
|
|
|
110
|
|
|
|
111
|
|
|
class SeverityLevel(Enum): |
112
|
|
|
""" Enum for severity levels """ |
113
|
|
|
|
114
|
|
|
HIGH = "High" |
115
|
|
|
MEDIUM = "Medium" |
116
|
|
|
LOW = "Low" |
117
|
|
|
LOG = "Log" |
118
|
|
|
ALARM = "Alarm" |
119
|
|
|
|
120
|
|
|
|
121
|
|
View Code Duplication |
def get_severity_level_from_string( |
|
|
|
|
122
|
|
|
severity_level: Optional[str], |
123
|
|
|
) -> Optional[SeverityLevel]: |
124
|
|
|
""" Convert a severity level string into a SeverityLevel instance """ |
125
|
|
|
if not severity_level: |
126
|
|
|
return None |
127
|
|
|
|
128
|
|
|
try: |
129
|
|
|
return SeverityLevel[severity_level.upper()] |
130
|
|
|
except KeyError: |
131
|
|
|
raise InvalidArgument( |
132
|
|
|
argument='severity_level', |
133
|
|
|
function=get_severity_level_from_string.__name__, |
134
|
|
|
) from None |
135
|
|
|
|