Passed
Pull Request — master (#244)
by
unknown
01:25
created

delete-overrides-by-filter.gmp   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 25
dl 0
loc 69
rs 10
c 0
b 0
f 0
wmc 7

3 Functions

Rating   Name   Duplication   Size   Complexity  
A delete_overrides() 0 16 4
A check_args() 0 15 2
A main() 0 8 1
1
# -*- coding: utf-8 -*-
2
# Copyright (C) 2017-2019 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
19
import time
20
21
22
def check_args(args):
23
    len_args = len(args.script) - 1
24
25
    if len_args is not 1:
26
        message = """
27
        This script deletes overrides with a specific filter value
28
29
        <filter>  -- the parameter for the filter.
30
31
        Example:
32
            $ gvm-script --gmp-username name --gmp-password pass \
33
    ssh --hostname <gsm> scripts/delete-overrides-by-filter.gmp.py <filter>
34
        """
35
        print(message)
36
        quit()
37
38
39
def delete_overrides(gmp, filter_value):
40
    filters = gmp.get_overrides(filter=filter_value)
41
42
    if not filters.xpath('override'):
43
        print('No overrides with filter: %s' % filter_value)
44
45
    for f_id in filters.xpath('override/@id'):
46
        print('Delete override: %s' % f_id, end='')
47
        res = gmp.delete_override(f_id)
48
49
        if 'OK' in res.xpath('@status_text')[0]:
50
            print(' OK')
51
        else:
52
            print(' ERROR')
53
54
        time.sleep(60)
55
56
57
def main(gmp, args):
58
    # pylint: disable=undefined-variable
59
60
    check_args(args)
61
62
    filter_value = args.script[1]
63
64
    delete_overrides(gmp, filter_value)
65
66
67
if __name__ == '__gmp__':
68
    main(gmp, args)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable args does not seem to be defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable gmp does not seem to be defined.
Loading history...
69