|
| 1 | +import logging |
| 2 | +from .base_command import BaseCommand |
| 3 | +from . import query |
| 4 | +from ..exception import CTERAException |
| 5 | + |
| 6 | + |
| 7 | +class RansomProtect(BaseCommand): |
| 8 | + """ |
| 9 | + Ransomware Protect APIs |
| 10 | + """ |
| 11 | + |
| 12 | + def get_configuration(self): |
| 13 | + """ |
| 14 | + Get Ransom Protect Configuration |
| 15 | +
|
| 16 | + :return cterasdk.common.object.Object: Configuration |
| 17 | + """ |
| 18 | + return self._gateway.get('/config/ransomProtect/') |
| 19 | + |
| 20 | + def enable(self): |
| 21 | + """Enable Ransom Protect service""" |
| 22 | + logging.getLogger().info('Enabling Ransom Protect.') |
| 23 | + self._gateway.put('/config/ransomProtect/enabled', True) |
| 24 | + logging.getLogger().info('Ransom Protect enabled.') |
| 25 | + |
| 26 | + def disable(self): |
| 27 | + """Enable Ransom Protect service""" |
| 28 | + logging.getLogger().info('Disabling Ransom Protect.') |
| 29 | + self._gateway.put('/config/ransomProtect/enabled', False) |
| 30 | + logging.getLogger().info('Ransom Protect disabled.') |
| 31 | + |
| 32 | + def is_disabled(self): |
| 33 | + """Check if Ransom Protect is disabled""" |
| 34 | + return self._gateway.get('/config/ransomProtect/enabled') is not True |
| 35 | + |
| 36 | + def modify(self, block_users=None, detection_threshold=None, detection_interval=None): |
| 37 | + """ |
| 38 | + Modify Ransom Protect Configuration. |
| 39 | +
|
| 40 | + :param bool,optional block_users: Enable/Disable Block Users |
| 41 | + :param int,optional detection_threshold: Detection threshold (number of events) |
| 42 | + :param int,optional detection_interval: Detection interval (seconds) |
| 43 | + """ |
| 44 | + param = self.get_configuration() |
| 45 | + if not param.enabled: |
| 46 | + raise CTERAException('Ransom Protect must be enabled to modify its configuration') |
| 47 | + if block_users is not None: |
| 48 | + param.shouldBlockUser = block_users |
| 49 | + if detection_threshold is not None: |
| 50 | + param.minimalNumOfFilesForPositiveDetection = detection_threshold |
| 51 | + if detection_interval is not None: |
| 52 | + param.detectionInterval = detection_interval |
| 53 | + self._gateway.put('/config/ransomProtect/', param) |
| 54 | + |
| 55 | + def incidents(self): |
| 56 | + """ |
| 57 | + List Ransomware Incidents |
| 58 | +
|
| 59 | + :return list[cterasdk.common.object.Object]: List of incidents |
| 60 | + """ |
| 61 | + return self._gateway.execute('/proc/rpsrv', 'getListOfIncidents') |
| 62 | + |
| 63 | + def details(self, incident): |
| 64 | + """ |
| 65 | + Retrieve Ransomware Incident Details |
| 66 | +
|
| 67 | + :param int incident: Incident identifier, or an incident object |
| 68 | + """ |
| 69 | + param = query.QueryParamBuilder() |
| 70 | + param.put('incidentId', incident if isinstance(incident, int) else incident.incident_id) |
| 71 | + return query.iterator(self._gateway, '/proc/rpsrv', param.build(), 'getIncidentDetails') |
0 commit comments