Skip to content

Commit 1d4b89a

Browse files
committed
Targeting tags seems to work well. Needing doc update.
1 parent b2bf899 commit 1d4b89a

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

meshbook.py

+15-11
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ def get_os_variants(category: str, os_map: dict) -> set:
191191
if not device["reachable"]:
192192
continue # Skip unreachable devices.
193193

194+
print(target_tag)
195+
print(device["device_tags"])
194196
if target_tag and target_tag not in device["device_tags"]:
195197
continue
196198

@@ -208,6 +210,7 @@ async def gather_targets(meshbook: dict, group_list: dict[str, list[dict]], os_c
208210

209211
target_list = []
210212
target_os = meshbook.get("target_os")
213+
target_tag = meshbook.get("target_tag")
211214

212215
async def process_device_or_group(pseudo_target, group_list, os_categories, target_os) -> list[str]:
213216
'''
@@ -221,7 +224,7 @@ async def process_device_or_group(pseudo_target, group_list, os_categories, targ
221224
matched_devices.append(device)
222225

223226
if matched_devices:
224-
return await filter_targets(matched_devices, os_categories, target_os)
227+
return await filter_targets(matched_devices, os_categories, target_os, target_tag)
225228
return []
226229

227230
match meshbook:
@@ -243,7 +246,7 @@ async def process_device_or_group(pseudo_target, group_list, os_categories, targ
243246

244247
case {"group": pseudo_target}: # Single group target
245248
if isinstance(pseudo_target, str) and pseudo_target in group_list:
246-
matched_devices = await filter_targets(group_list[pseudo_target], os_categories, target_os)
249+
matched_devices = await filter_targets(group_list[pseudo_target], os_categories, target_os, target_tag)
247250
target_list.extend(matched_devices)
248251
elif pseudo_target not in group_list:
249252
console(text_color.yellow + "Targeted group not found on the MeshCentral server.", True)
@@ -254,11 +257,11 @@ async def process_device_or_group(pseudo_target, group_list, os_categories, targ
254257
if isinstance(pseudo_target, list):
255258
for sub_pseudo_target in pseudo_target:
256259
if sub_pseudo_target in group_list:
257-
matched_devices = await filter_targets(group_list[sub_pseudo_target], os_categories, target_os)
260+
matched_devices = await filter_targets(group_list[sub_pseudo_target], os_categories, target_os, target_tag)
258261
target_list.extend(matched_devices)
259262
if pseudo_target.lower() == "all":
260263
for group in group_list:
261-
matched_devices = await filter_targets(group_list[group], os_categories, target_os)
264+
matched_devices = await filter_targets(group_list[group], os_categories, target_os, target_tag)
262265
target_list.extend(matched_devices)
263266
else:
264267
console(text_color.yellow + "The 'groups' method is being used, but only one string is given. Did you mean 'group'?", True)
@@ -294,7 +297,7 @@ async def execute_meshbook(session: meshctrl.Session, targets: dict, meshbook: d
294297
}
295298
round += 1
296299

297-
console(("-" * 40))
300+
console(text_color.reset + ("-" * 40))
298301
if args.indent:
299302
console((json.dumps(responses_list,indent=4)), True)
300303

@@ -333,7 +336,7 @@ async def main():
333336
The following section mainly displays used variables and first steps of the program to the console.
334337
'''
335338

336-
console(("-" * 40))
339+
console(text_color.reset + ("-" * 40))
337340
console("meshbook: " + text_color.yellow + args.meshbook)
338341
console("Operating System Categorisation file: " + text_color.yellow + args.oscategories)
339342
console("Configuration file: " + text_color.yellow + args.conf)
@@ -352,7 +355,7 @@ async def main():
352355
console("Silent: " + text_color.yellow + "False") # Can be pre-defined because if silent flag was passed then none of this would be printed.
353356

354357
session = await init_connection(credentials)
355-
console(("-" * 40))
358+
console(text_color.reset + ("-" * 40))
356359
console(text_color.italic + "Trying to load the MeshCentral account credential file...")
357360
console(text_color.italic + "Trying to load the meshbook yaml file and compile it into something workable...")
358361
console(text_color.italic + "Trying to load the Operating System categorisation JSON file...")
@@ -368,10 +371,10 @@ async def main():
368371

369372
if len(targets_list) == 0:
370373
console(text_color.red + "No targets found or targets unreachable, quitting.", True)
371-
console(("-" * 40), True)
374+
console(text_color.reset + ("-" * 40), True)
372375

373376
else:
374-
console(("-" * 40))
377+
console(text_color.reset + ("-" * 40))
375378

376379
match meshbook:
377380
case {"group": candidate_target_name}:
@@ -395,8 +398,9 @@ async def main():
395398
console(text_color.yellow + "{}...".format(x+1)) # Countdown!
396399
await asyncio.sleep(1)
397400

398-
console(("-" * 40))
399-
await execute_meshbook(session, targets_list, meshbook, group_list)
401+
console(text_color.reset + ("-" * 40))
402+
print(json.dumps(targets_list,indent=4))
403+
#await execute_meshbook(session, targets_list, meshbook, group_list)
400404

401405
await session.close()
402406

0 commit comments

Comments
 (0)