mirror of
https://github.com/myronblair/jarvis
synced 2026-06-30 17:50:23 -05:00
90e4ded7c9
- ha-poller: replace recursive main() retry with while loop (stack overflow fix) - ha-poller: advance last_push on empty HA response (log spam fix) - ha-poller: use datetime.now(timezone.utc) instead of deprecated utcnow() - ping-probe: always call update_status() unconditionally so offline devices register as offline - agent.php: heartbeat reads status from payload instead of hardcoding 'online' - phone-probe: delegate JSON building to python3 (bash concatenation injection fix) - netscan + phone-probe: read registration key from /etc/jarvis-agent/reg-key - admin/index.php: sync ha_list skipDomains with ha.php (14 missing domains added) - facts_collector: self-check JARVIS via 127.0.0.1 instead of Cloudflare hairpin
68 lines
1.7 KiB
Bash
68 lines
1.7 KiB
Bash
#!/bin/bash
|
|
# JARVIS Network Scanner — runs on PVE1, pushes nmap results to JARVIS
|
|
# Cron: */3 * * * * /usr/local/bin/jarvis-netscan.sh >/dev/null 2>&1
|
|
|
|
JARVIS_URL="http://10.48.200.211"
|
|
JARVIS_HOST="jarvis.orbishosting.com"
|
|
REG_KEY=$(cat /etc/jarvis-agent/reg-key 2>/dev/null)
|
|
if [ -z "$REG_KEY" ]; then
|
|
echo "$(date): ERROR: /etc/jarvis-agent/reg-key not found" >&2
|
|
exit 1
|
|
fi
|
|
SUBNET="10.48.200.0/24"
|
|
|
|
TMPFILE=$(mktemp)
|
|
nmap -sn --send-ip "$SUBNET" 2>/dev/null > "$TMPFILE"
|
|
|
|
if [ ! -s "$TMPFILE" ]; then
|
|
echo "$(date): nmap produced no output" >&2
|
|
rm -f "$TMPFILE"
|
|
exit 1
|
|
fi
|
|
|
|
JSON=$(python3 - "$TMPFILE" <<'PYEOF'
|
|
import sys, re, json
|
|
|
|
with open(sys.argv[1]) as f:
|
|
data = f.read()
|
|
|
|
devices = []
|
|
cur = None
|
|
|
|
for line in data.splitlines():
|
|
line = line.strip()
|
|
m = re.match(r'Nmap scan report for (?:(\S+) \()?(\d+\.\d+\.\d+\.\d+)\)?', line)
|
|
if m:
|
|
if cur:
|
|
devices.append(cur)
|
|
hn = m.group(1) if m.group(1) and m.group(1) != m.group(2) else ''
|
|
cur = {'ip': m.group(2), 'hostname': hn, 'mac': '', 'vendor': ''}
|
|
elif cur:
|
|
m2 = re.match(r'MAC Address: ([0-9A-Fa-f:]{17}) \(([^)]+)\)', line)
|
|
if m2:
|
|
cur['mac'] = m2.group(1).lower()
|
|
cur['vendor'] = '' if m2.group(2) == 'Unknown' else m2.group(2)
|
|
|
|
if cur:
|
|
devices.append(cur)
|
|
|
|
print(json.dumps({'devices': devices}))
|
|
PYEOF
|
|
)
|
|
|
|
rm -f "$TMPFILE"
|
|
|
|
if [ -z "$JSON" ]; then
|
|
echo "$(date): JSON parse failed" >&2
|
|
exit 1
|
|
fi
|
|
|
|
RESPONSE=$(curl -sk --max-time 15 \
|
|
-X POST "$JARVIS_URL/api/netscan" \
|
|
-H "Host: $JARVIS_HOST" \
|
|
-H "Content-Type: application/json" \
|
|
-H "X-Registration-Key: $REG_KEY" \
|
|
-d "$JSON" 2>/dev/null)
|
|
|
|
echo "$(date): $RESPONSE"
|