1
|
|
|
# Copyright (C) 2014-2020 Greenbone Networks GmbH |
2
|
|
|
# |
3
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later |
4
|
|
|
# |
5
|
|
|
# This program is free software: you can redistribute it and/or modify |
6
|
|
|
# it under the terms of the GNU Affero General Public License as |
7
|
|
|
# published by the Free Software Foundation, either version 3 of the |
8
|
|
|
# License, or (at your option) any later version. |
9
|
|
|
# |
10
|
|
|
# This program is distributed in the hope that it will be useful, |
11
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
12
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13
|
|
|
# GNU Affero General Public License for more details. |
14
|
|
|
# |
15
|
|
|
# You should have received a copy of the GNU Affero General Public License |
16
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
17
|
|
|
|
18
|
|
|
# pylint: disable=too-many-lines |
19
|
|
|
|
20
|
|
|
""" Class for handling list of resutls. |
21
|
|
|
""" |
22
|
|
|
|
23
|
|
|
from collections import OrderedDict |
24
|
|
|
from typing import ( |
25
|
|
|
List, |
26
|
|
|
Dict, |
27
|
|
|
Optional, |
28
|
|
|
) |
29
|
|
|
from ospd.misc import ResultType |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
class ResultList: |
33
|
|
|
""" Class for handling list of resutls.""" |
34
|
|
|
|
35
|
|
|
def __init__(self): |
36
|
|
|
self._result_list = list() |
37
|
|
|
|
38
|
|
|
def __len__(self): |
39
|
|
|
return len(self._result_list) |
40
|
|
|
|
41
|
|
|
def add_scan_host_detail_to_list( |
42
|
|
|
self, |
43
|
|
|
host: str = '', |
44
|
|
|
hostname: str = '', |
45
|
|
|
name: str = '', |
46
|
|
|
value: str = '', |
47
|
|
|
) -> None: |
48
|
|
|
""" Adds a host detail result to result list. """ |
49
|
|
|
self.add_result_to_list( |
50
|
|
|
ResultType.HOST_DETAIL, host, hostname, name, value, |
51
|
|
|
) |
52
|
|
|
|
53
|
|
|
def add_scan_error_to_list( |
54
|
|
|
self, |
55
|
|
|
host: str = '', |
56
|
|
|
hostname: str = '', |
57
|
|
|
name: str = '', |
58
|
|
|
value: str = '', |
59
|
|
|
port: str = '', |
60
|
|
|
test_id='', |
61
|
|
|
) -> None: |
62
|
|
|
""" Adds an error result to result list. """ |
63
|
|
|
self.add_result_to_list( |
64
|
|
|
ResultType.ERROR, host, hostname, name, value, port, test_id, |
65
|
|
|
) |
66
|
|
|
|
67
|
|
|
def add_scan_log_to_list( |
68
|
|
|
self, |
69
|
|
|
host: str = '', |
70
|
|
|
hostname: str = '', |
71
|
|
|
name: str = '', |
72
|
|
|
value: str = '', |
73
|
|
|
port: str = '', |
74
|
|
|
test_id: str = '', |
75
|
|
|
qod: str = '', |
76
|
|
|
) -> None: |
77
|
|
|
""" Adds log result to a list of results. """ |
78
|
|
|
self.add_result_to_list( |
79
|
|
|
ResultType.LOG, |
80
|
|
|
host, |
81
|
|
|
hostname, |
82
|
|
|
name, |
83
|
|
|
value, |
84
|
|
|
port, |
85
|
|
|
test_id, |
86
|
|
|
'0.0', |
87
|
|
|
qod, |
88
|
|
|
) |
89
|
|
|
|
90
|
|
|
def add_scan_alarm_to_list( |
91
|
|
|
self, |
92
|
|
|
host: str = '', |
93
|
|
|
hostname: str = '', |
94
|
|
|
name: str = '', |
95
|
|
|
value: str = '', |
96
|
|
|
port: str = '', |
97
|
|
|
test_id: str = '', |
98
|
|
|
severity: str = '', |
99
|
|
|
qod: str = '', |
100
|
|
|
) -> None: |
101
|
|
|
""" Adds an alarm result to a result list. """ |
102
|
|
|
self.add_result_to_list( |
103
|
|
|
ResultType.ALARM, |
104
|
|
|
host, |
105
|
|
|
hostname, |
106
|
|
|
name, |
107
|
|
|
value, |
108
|
|
|
port, |
109
|
|
|
test_id, |
110
|
|
|
severity, |
111
|
|
|
qod, |
112
|
|
|
) |
113
|
|
|
|
114
|
|
|
def add_result_to_list( |
115
|
|
|
self, |
116
|
|
|
result_type: int, |
117
|
|
|
host: str = '', |
118
|
|
|
hostname: str = '', |
119
|
|
|
name: str = '', |
120
|
|
|
value: str = '', |
121
|
|
|
port: str = '', |
122
|
|
|
test_id: str = '', |
123
|
|
|
severity: str = '', |
124
|
|
|
qod: str = '', |
125
|
|
|
) -> None: |
126
|
|
|
|
127
|
|
|
result = OrderedDict() # type: Dict |
128
|
|
|
result['type'] = result_type |
129
|
|
|
result['name'] = name |
130
|
|
|
result['severity'] = severity |
131
|
|
|
result['test_id'] = test_id |
132
|
|
|
result['value'] = value |
133
|
|
|
result['host'] = host |
134
|
|
|
result['hostname'] = hostname |
135
|
|
|
result['port'] = port |
136
|
|
|
result['qod'] = qod |
137
|
|
|
|
138
|
|
|
self._result_list.append(result) |
139
|
|
|
|
140
|
|
|
def __iter__(self): |
141
|
|
|
return iter(self._result_list) |
142
|
|
|
|