33from pycentral .utils .url_utils import generate_url
44
55from ..exceptions import ParameterError
6+ import re
67
78
89def build_timestamp_filter (
@@ -37,17 +38,11 @@ def build_timestamp_filter(
3738
3839 # --- Validation ---
3940 if (start_time or end_time ) and duration :
40- raise ValueError (
41- "Cannot specify start/end timestamps together with duration."
42- )
41+ raise ValueError ("Cannot specify start/end timestamps together with duration." )
4342 if (start_time and not end_time ) or (end_time and not start_time ):
44- raise ValueError (
45- "Both start_time and end_time must be provided together."
46- )
43+ raise ValueError ("Both start_time and end_time must be provided together." )
4744 if not duration and not (start_time and end_time ):
48- raise ValueError (
49- "Provide either both start_time and end_time or a duration."
50- )
45+ raise ValueError ("Provide either both start_time and end_time or a duration." )
5146
5247 # --- Case 1: Start + End (pass-through) ---
5348 if start_time and end_time :
@@ -161,9 +156,7 @@ def simplified_site_resp(site):
161156 ),
162157 }
163158 site ["alerts" ] = {
164- "critical" : site .get ("alerts" , {})
165- .get ("groups" , [{}])[0 ]
166- .get ("count" , 0 )
159+ "critical" : site .get ("alerts" , {}).get ("groups" , [{}])[0 ].get ("count" , 0 )
167160 if site .get ("alerts" , {}).get ("groups" )
168161 else 0 ,
169162 "total" : site .get ("alerts" , {}).get ("totalCount" , 0 ),
@@ -185,11 +178,7 @@ def _groups_to_dict(groups_list):
185178 result = {"Poor" : 0 , "Fair" : 0 , "Good" : 0 }
186179 if isinstance (groups_list , list ):
187180 for group in groups_list :
188- if (
189- isinstance (group , dict )
190- and "name" in group
191- and "value" in group
192- ):
181+ if isinstance (group , dict ) and "name" in group and "value" in group :
193182 result [group ["name" ]] = group ["value" ]
194183 return result
195184
@@ -246,3 +235,30 @@ def merged_dict_to_sorted_list(merged):
246235 except Exception :
247236 keys = sorted (merged .keys ())
248237 return [{"timestamp" : ts , ** merged [ts ]} for ts in keys ]
238+
239+
240+ def _validate_mac_address (mac ):
241+ """
242+ Validate a MAC address string and return True if valid.
243+ Accepts the format AA:BB:CC:DD:EE:FF
244+
245+ Args:
246+ mac (str): MAC address string to validate.
247+
248+ Returns:
249+ (bool): True if the MAC address is valid.
250+
251+ Raises:
252+ ParameterError: If mac is missing or does not match the expected format.
253+
254+ Note:
255+ Internal SDK function
256+ """
257+ _MAC_PATTERN = re .compile (r"^([0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}$" )
258+ if not mac :
259+ raise ParameterError ("MAC address is required" )
260+ if not isinstance (mac , str ) or not _MAC_PATTERN .match (mac ):
261+ raise ParameterError (
262+ f"Invalid MAC address format: '{ mac } '. Expected format: AA:BB:CC:DD:EE:FF"
263+ )
264+ return True
0 commit comments