forked from greenbone/gvm-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clean-sensor.gmp.py
84 lines (69 loc) · 2.71 KB
/
clean-sensor.gmp.py
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
# -*- coding: utf-8 -*-
# Copyright (C) 2017-2019 Greenbone Networks GmbH
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
def clean_sensor(gmp):
tasks = gmp.get_tasks(
filter="rows=-1 not status=Running and "
"not status=Requested and not "
"status="Stop Requested""
)
for tid in tasks.xpath('task/@id'):
print('Removing task %s ... ' % tid)
status_text = gmp.delete_task(tid, ultimate=True).xpath('@status_text')[
0
]
print(status_text)
targets = gmp.get_targets(filter="rows=-1 not _owner=""")
for tid in targets.xpath('target/@id'):
print('Removing target %s ... ' % tid)
status_text = gmp.delete_target(tid, ultimate=True).xpath(
'@status_text'
)[0]
print(status_text)
configs = gmp.get_configs(filter="rows=-1 not _owner=""")
for cid in configs.xpath('config/@id'):
print('Removing config %s ... ' % cid)
status_text = gmp.delete_config(cid, ultimate=True).xpath(
'@status_text'
)[0]
print(status_text)
port_lists = gmp.get_port_lists(filter="rows=-1 not _owner=""")
for pid in port_lists.xpath('port_list/@id'):
print('Removing port_list %s ... ' % pid)
status_text = gmp.delete_port_list(pid, ultimate=True).xpath(
'@status_text'
)[0]
print(status_text)
credentials = gmp.get_credentials(filter="rows=-1 not _owner=""")
for cid in credentials.xpath('credential/@id'):
print('Removing credential %s ... ' % cid)
status_text = gmp.delete_credential(cid, ultimate=True).xpath(
'@status_text'
)[0]
print(status_text)
print('Emptying trash... ')
status_text = gmp.empty_trashcan().xpath('@status_text')[0]
print(status_text)
def main(gmp, args):
# pylint: disable=undefined-variable
message = """
This script removes all resources from a sensor, except active tasks.
"""
print(message)
clean_sensor(gmp)
if __name__ == '__gmp__':
main(gmp, args)