@@ -191,6 +191,8 @@ def get_os_variants(category: str, os_map: dict) -> set:
191
191
if not device ["reachable" ]:
192
192
continue # Skip unreachable devices.
193
193
194
+ print (target_tag )
195
+ print (device ["device_tags" ])
194
196
if target_tag and target_tag not in device ["device_tags" ]:
195
197
continue
196
198
@@ -208,6 +210,7 @@ async def gather_targets(meshbook: dict, group_list: dict[str, list[dict]], os_c
208
210
209
211
target_list = []
210
212
target_os = meshbook .get ("target_os" )
213
+ target_tag = meshbook .get ("target_tag" )
211
214
212
215
async def process_device_or_group (pseudo_target , group_list , os_categories , target_os ) -> list [str ]:
213
216
'''
@@ -221,7 +224,7 @@ async def process_device_or_group(pseudo_target, group_list, os_categories, targ
221
224
matched_devices .append (device )
222
225
223
226
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 )
225
228
return []
226
229
227
230
match meshbook :
@@ -243,7 +246,7 @@ async def process_device_or_group(pseudo_target, group_list, os_categories, targ
243
246
244
247
case {"group" : pseudo_target }: # Single group target
245
248
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 )
247
250
target_list .extend (matched_devices )
248
251
elif pseudo_target not in group_list :
249
252
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
254
257
if isinstance (pseudo_target , list ):
255
258
for sub_pseudo_target in pseudo_target :
256
259
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 )
258
261
target_list .extend (matched_devices )
259
262
if pseudo_target .lower () == "all" :
260
263
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 )
262
265
target_list .extend (matched_devices )
263
266
else :
264
267
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
294
297
}
295
298
round += 1
296
299
297
- console (("-" * 40 ))
300
+ console (text_color . reset + ("-" * 40 ))
298
301
if args .indent :
299
302
console ((json .dumps (responses_list ,indent = 4 )), True )
300
303
@@ -333,7 +336,7 @@ async def main():
333
336
The following section mainly displays used variables and first steps of the program to the console.
334
337
'''
335
338
336
- console (("-" * 40 ))
339
+ console (text_color . reset + ("-" * 40 ))
337
340
console ("meshbook: " + text_color .yellow + args .meshbook )
338
341
console ("Operating System Categorisation file: " + text_color .yellow + args .oscategories )
339
342
console ("Configuration file: " + text_color .yellow + args .conf )
@@ -352,7 +355,7 @@ async def main():
352
355
console ("Silent: " + text_color .yellow + "False" ) # Can be pre-defined because if silent flag was passed then none of this would be printed.
353
356
354
357
session = await init_connection (credentials )
355
- console (("-" * 40 ))
358
+ console (text_color . reset + ("-" * 40 ))
356
359
console (text_color .italic + "Trying to load the MeshCentral account credential file..." )
357
360
console (text_color .italic + "Trying to load the meshbook yaml file and compile it into something workable..." )
358
361
console (text_color .italic + "Trying to load the Operating System categorisation JSON file..." )
@@ -368,10 +371,10 @@ async def main():
368
371
369
372
if len (targets_list ) == 0 :
370
373
console (text_color .red + "No targets found or targets unreachable, quitting." , True )
371
- console (("-" * 40 ), True )
374
+ console (text_color . reset + ("-" * 40 ), True )
372
375
373
376
else :
374
- console (("-" * 40 ))
377
+ console (text_color . reset + ("-" * 40 ))
375
378
376
379
match meshbook :
377
380
case {"group" : candidate_target_name }:
@@ -395,8 +398,9 @@ async def main():
395
398
console (text_color .yellow + "{}..." .format (x + 1 )) # Countdown!
396
399
await asyncio .sleep (1 )
397
400
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)
400
404
401
405
await session .close ()
402
406
0 commit comments