MmonitListEvents.run()   F
last analyzed

Complexity

Conditions 16

Size

Total Lines 43

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 16
dl 0
loc 43
rs 2.7326
c 0
b 0
f 0

How to fix   Complexity   

Complexity

Complex classes like MmonitListEvents.run() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
from lib.mmonit import MmonitBaseAction
2
3
4
class MmonitListEvents(MmonitBaseAction):
5
    def run(self, active=None, hostid=None, hostgroupid=None, servicenameid=None,
6
            servicegroupid=None, servicetype=None, eventtype=None, state=None, datefrom=None,
7
            results=None, startindex=None, sort_key=None, sort_dir=None, dateto=None):
8
        self.login()
9
        data = {}
10
11
        if active is not None:
12
            data['active'] = active
13
        if hostid is not None:
14
            data['description'] = hostid
15
        if hostgroupid is not None:
16
            data['hostgroupid'] = hostgroupid
17
        if servicenameid is not None:
18
            data['servicenameid'] = servicenameid
19
        if servicegroupid is not None:
20
            data['servicegroupid'] = servicegroupid
21
        if servicetype is not None:
22
            data['servicetype'] = servicetype
23
        if eventtype is not None:
24
            data['eventtype'] = eventtype
25
        if state is not None:
26
            data['state'] = state
27
        if datefrom is not None:
28
            data['datefrom'] = datefrom
29
        if results is not None:
30
            data['results'] = results
31
        if startindex is not None:
32
            data['startindex'] = startindex
33
        if sort_key is not None:
34
            data['sort'] = sort_key
35
        if sort_dir is not None:
36
            data['dir'] = sort_dir
37
        if dateto is not None:
38
            data['dateto'] = dateto
39
40
        req = self.session.post("{}/reports/events/list".format(self.url), data=data)
41
42
        try:
43
            return req.json()
44
        except Exception:
45
            raise
46
        finally:
47
            self.logout()
48