Run the git pull sequence Ragnar uses, returning status metadata.
(repo_path: str, prepared: bool = False)
| 9353 | |
| 9354 | # The card numbers follow live presence; the stored-status counts |
| 9355 | # above still drive the port total and the notification snapshot. |
| 9356 | try: |
| 9357 | live_counts = _live_target_counts(hosts, _presence_snapshot_for_request()) |
| 9358 | aggregated_targets = live_counts['active'] |
| 9359 | total_target_count = live_counts['total'] |
| 9360 | inactive_target_count = live_counts['inactive'] |
| 9361 | except Exception as e: |
| 9362 | live_counts = None |
| 9363 | logger.debug(f"Live target count unavailable, using stored status: {e}") |
| 9364 | |
| 9365 | old_targets = shared_data.targetnbr |
| 9366 | old_ports = shared_data.portnbr |
| 9367 | |
| 9368 | shared_data.targetnbr = aggregated_targets |
| 9369 | shared_data.total_targetnbr = total_target_count |
| 9370 | shared_data.inactive_targetnbr = inactive_target_count |
| 9371 | shared_data.portnbr = aggregated_ports |
| 9372 | shared_data.networkkbnbr = total_target_count |
| 9373 | |
| 9374 | if old_targets != aggregated_targets or old_ports != aggregated_ports: |
| 9375 | logger.info(f"✅ Updated counts from SQLite database:") |
| 9376 | logger.info(f" - Targets: {old_targets} -> {aggregated_targets}") |
| 9377 | logger.info(f" - Ports: {old_ports} -> {aggregated_ports}") |
| 9378 | logger.info(f" - Total hosts: {total_target_count}") |
| 9379 | logger.info(f" - Inactive hosts: {inactive_target_count}") |
| 9380 | else: |
| 9381 | logger.debug(f"Counts unchanged: targets={aggregated_targets}, ports={aggregated_ports}") |
| 9382 | |
| 9383 | # Track new and lost hosts |
| 9384 | previous_snapshot = getattr(shared_data, 'network_hosts_snapshot', {}) or {} |
| 9385 | previous_active_hosts = {ip for ip, meta in previous_snapshot.items() if meta.get('alive', True)} |
| 9386 | current_active_hosts = {ip for ip, meta in current_snapshot.items() if meta.get('alive', True)} |
| 9387 | |
| 9388 | new_active_hosts = current_active_hosts - previous_active_hosts |
| 9389 | lost_active_hosts = previous_active_hosts - current_active_hosts |
| 9390 | |
| 9391 | shared_data.network_hosts_snapshot = current_snapshot |
| 9392 | if live_counts is not None: |
| 9393 | # A diff between two consecutive syncs is gone 15 seconds |
| 9394 | # later; the card shows the last TARGET_RECENT_HOURS instead. |
| 9395 | shared_data.new_target_ips = live_counts['new_ips'] |
| 9396 | shared_data.lost_target_ips = live_counts['lost_ips'] |
| 9397 | else: |
| 9398 | shared_data.new_target_ips = sorted(new_active_hosts) |
| 9399 | shared_data.lost_target_ips = sorted(lost_active_hosts) |
| 9400 | shared_data.new_targets = len(shared_data.new_target_ips) |
| 9401 | shared_data.lost_targets = len(shared_data.lost_target_ips) |
| 9402 | |
| 9403 | # ── Pushover: new / lost device notifications ── |
| 9404 | try: |
| 9405 | from pushover_service import PushoverService |
| 9406 | _po = getattr(shared_data, '_pushover_service', None) |
| 9407 | if _po is None: |
| 9408 | _po = PushoverService(shared_data) |
| 9409 | shared_data._pushover_service = _po |
| 9410 | if new_active_hosts: |
| 9411 | _po.notify_new_devices(new_active_hosts) |
| 9412 | _po.notify_device_back_online(new_active_hosts) |
no test coverage detected