2323# SOFTWARE.
2424#
2525###############################################################################
26+ import re
2627from typing import Optional
2728
2829from nodescraper .enums import EventCategory , EventPriority , ExecutionStatus
@@ -39,6 +40,36 @@ class StorageAnalyzer(DataAnalyzer[StorageDataModel, StorageAnalyzerArgs]):
3940
4041 DATA_MODEL = StorageDataModel
4142
43+ def _matches_device_filter (
44+ self , device_name : str , exp_devices : list [str ], regex_match : bool
45+ ) -> bool :
46+ """Check if the device name matches any of the expected devices""
47+
48+ Args:
49+ device_name (str): device name to check
50+ exp_devices (list[str]): list of expected devices to match against
51+ regex_match (bool): if True, use regex matching; otherwise, use exact match
52+
53+ Returns:
54+ bool: True if the device name matches any of the expected devices, False otherwise
55+ """
56+ for exp_device in exp_devices :
57+ if regex_match :
58+ try :
59+ device_regex = re .compile (exp_device )
60+ except re .error :
61+ self ._log_event (
62+ category = EventCategory .STORAGE ,
63+ description = f"Invalid regex pattern: { exp_device } " ,
64+ priority = EventPriority .ERROR ,
65+ )
66+ continue
67+ if device_regex .match (device_name ):
68+ return True
69+ elif device_name == exp_device :
70+ return True
71+ return False
72+
4273 def analyze_data (
4374 self , data : StorageDataModel , args : Optional [StorageAnalyzerArgs ] = None
4475 ) -> TaskResult :
@@ -68,8 +99,15 @@ def analyze_data(
6899 return self .result
69100
70101 for device_name , device_data in data .storage_data .items ():
71- if args .ignore_devices and device_name in args .ignore_devices :
102+ if args .check_devices and not self ._matches_device_filter (
103+ device_name , args .check_devices , args .regex_match
104+ ):
72105 continue
106+ elif args .ignore_devices and self ._matches_device_filter (
107+ device_name , args .ignore_devices , args .regex_match
108+ ):
109+ continue
110+
73111 condition = False
74112 if args .min_required_free_space_abs :
75113 min_free_abs = convert_to_bytes (args .min_required_free_space_abs )
0 commit comments