Skip to content

Commit 796a1a7

Browse files
authored
Add SynoSecurity status_by_check + add outOfDate test (#54)
1 parent 1286f4a commit 796a1a7

5 files changed

Lines changed: 251 additions & 111 deletions

File tree

synology_dsm/api/core/security.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def update(self, raw_data):
1818

1919
@property
2020
def checks(self):
21-
"""Gets the checklist."""
21+
"""Gets the checklist by check category."""
2222
return self._data.get("items", {})
2323

2424
@property
@@ -43,5 +43,13 @@ def progress(self):
4343

4444
@property
4545
def status(self):
46-
"""Gets the last scan status (safe, ...)."""
46+
"""Gets the last scan status (safe, danger, info, outOfDate, risk, warning)."""
4747
return self._data.get("sysStatus")
48+
49+
@property
50+
def status_by_check(self):
51+
"""Gets the last scan status per check."""
52+
status = {}
53+
for category in self.checks:
54+
status[category] = self.checks[category]["failSeverity"]
55+
return status

tests/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
DSM_6_CORE_UTILIZATION,
3030
DSM_6_CORE_UTILIZATION_ERROR_1055,
3131
DSM_6_CORE_SECURITY,
32+
DSM_6_CORE_SECURITY_UPDATE_OUTOFDATE,
3233
DSM_6_STORAGE_STORAGE_DS213_PLUS_SHR1_2DISKS_2VOLS,
3334
DSM_6_STORAGE_STORAGE_DS918_PLUS_RAID5_3DISKS_1VOL,
3435
DSM_6_STORAGE_STORAGE_DS1819_PLUS_SHR2_8DISKS_1VOL,
@@ -183,6 +184,8 @@ def _execute_request(self, method, url, params, **kwargs):
183184
return API_SWITCHER[self.dsm_version]["DSM_NETWORK"]
184185

185186
if SynoCoreSecurity.API_KEY in url:
187+
if self.error:
188+
return DSM_6_CORE_SECURITY_UPDATE_OUTOFDATE
186189
return API_SWITCHER[self.dsm_version]["CORE_SECURITY"]
187190

188191
if SynoCoreUtilization.API_KEY in url:

tests/api_data/dsm_6/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
DSM_6_CORE_UTILIZATION,
1010
DSM_6_CORE_UTILIZATION_ERROR_1055,
1111
)
12-
from .core.const_6_core_security import DSM_6_CORE_SECURITY
12+
from .core.const_6_core_security import (
13+
DSM_6_CORE_SECURITY,
14+
DSM_6_CORE_SECURITY_UPDATE_OUTOFDATE,
15+
)
1316
from .dsm.const_6_dsm_info import DSM_6_DSM_INFORMATION
1417
from .dsm.const_6_dsm_network import DSM_6_DSM_NETWORK
1518
from .storage.const_6_storage_storage import (

tests/api_data/dsm_6/core/const_6_core_security.py

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,106 @@
103103
},
104104
"success": True,
105105
}
106+
107+
DSM_6_CORE_SECURITY_UPDATE_OUTOFDATE = {
108+
"data": {
109+
"items": {
110+
"malware": {
111+
"category": "malware",
112+
"fail": {
113+
"danger": 0,
114+
"info": 0,
115+
"outOfDate": 0,
116+
"risk": 0,
117+
"warning": 0,
118+
},
119+
"failSeverity": "safe",
120+
"progress": 100,
121+
"runningItem": "",
122+
"total": 3,
123+
"waitNum": 0,
124+
},
125+
"network": {
126+
"category": "network",
127+
"fail": {
128+
"danger": 0,
129+
"info": 0,
130+
"outOfDate": 0,
131+
"risk": 0,
132+
"warning": 0,
133+
},
134+
"failSeverity": "safe",
135+
"progress": 100,
136+
"runningItem": "",
137+
"total": 4,
138+
"waitNum": 0,
139+
},
140+
"securitySetting": {
141+
"category": "securitySetting",
142+
"fail": {
143+
"danger": 0,
144+
"info": 0,
145+
"outOfDate": 0,
146+
"risk": 0,
147+
"warning": 0,
148+
},
149+
"failSeverity": "safe",
150+
"progress": 100,
151+
"runningItem": "",
152+
"total": 0,
153+
"waitNum": 0,
154+
},
155+
"systemCheck": {
156+
"category": "systemCheck",
157+
"fail": {
158+
"danger": 0,
159+
"info": 0,
160+
"outOfDate": 0,
161+
"risk": 0,
162+
"warning": 0,
163+
},
164+
"failSeverity": "safe",
165+
"progress": 100,
166+
"runningItem": "",
167+
"total": 6,
168+
"waitNum": 0,
169+
},
170+
"update": {
171+
"category": "update",
172+
"fail": {
173+
"danger": 0,
174+
"info": 0,
175+
"outOfDate": 1,
176+
"risk": 0,
177+
"warning": 0,
178+
},
179+
"failSeverity": "outOfDate",
180+
"progress": 100,
181+
"runningItem": "",
182+
"total": 4,
183+
"waitNum": 0,
184+
},
185+
"userInfo": {
186+
"category": "userInfo",
187+
"fail": {
188+
"danger": 0,
189+
"info": 0,
190+
"outOfDate": 0,
191+
"risk": 0,
192+
"warning": 0,
193+
},
194+
"failSeverity": "safe",
195+
"progress": 100,
196+
"runningItem": "",
197+
"total": 6,
198+
"waitNum": 0,
199+
},
200+
},
201+
"lastScanTime": "1590717640",
202+
"startTime": "",
203+
"success": True,
204+
"sysProgress": 100,
205+
"sysStatus": "outOfDate",
206+
},
207+
"success": True,
208+
}

0 commit comments

Comments
 (0)