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
75 lines
2.3 KiB
Bash
75 lines
2.3 KiB
Bash
#!/bin/bash
|
|
# JARVIS VoIP Phone Probe — runs every minute on PVE1
|
|
# Pings all Yealink phones + checks FusionPBX SIP registration (read-only)
|
|
# 200.3 is on an external FusionPBX — ping only, no SIP check
|
|
|
|
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
|
|
FUSION_HOST="134.209.72.226"
|
|
|
|
# IP|alias|extension(none=skip SIP check)|mac
|
|
PHONES=(
|
|
"10.48.200.2|Yealink — Myron Main (Ext 1000)|1000|80:5e:c0:35:04:77"
|
|
"10.48.200.3|Yealink — United Mirror & Glass (External SIP)|none|c4:fc:22:28:63:71"
|
|
"10.48.200.43|Yealink T48S — Tommy Main (Ext 1001)|1001|80:5e:0c:15:0c:4f"
|
|
"10.48.200.86|Yealink — Myron Vanguard WiFi (Offline During Work Hrs)|none|"
|
|
"10.48.200.65|Yealink — Myron Vanguard Work (Ext 1003)|1003|c4:fc:22:13:e1:89"
|
|
)
|
|
|
|
# Get SIP registrations from FusionPBX (read-only)
|
|
REG_OUTPUT=$(ssh -o StrictHostKeyChecking=no -o ConnectTimeout=5 -o BatchMode=yes \
|
|
root@$FUSION_HOST "fs_cli -x 'show registrations'" 2>/dev/null || echo "")
|
|
|
|
# Collect results as TSV, delegate JSON building to python3 to avoid injection
|
|
RESULTS=""
|
|
for PHONE in "${PHONES[@]}"; do
|
|
IFS='|' read -r IP ALIAS EXT MAC <<< "$PHONE"
|
|
|
|
if ping -c 1 -W 2 "$IP" > /dev/null 2>&1; then
|
|
STATUS="online"
|
|
else
|
|
STATUS="offline"
|
|
fi
|
|
|
|
if [ "$EXT" = "none" ]; then
|
|
SIP="external"
|
|
elif [ -n "$REG_OUTPUT" ] && echo "$REG_OUTPUT" | grep -q "^${EXT},"; then
|
|
SIP="registered"
|
|
else
|
|
SIP="unregistered"
|
|
fi
|
|
|
|
RESULTS="${RESULTS}${IP}\t${ALIAS}\t${MAC}\t${STATUS}\t${SIP}\t${EXT}\n"
|
|
done
|
|
|
|
JSON=$(printf "%b" "$RESULTS" | python3 -c "
|
|
import sys, json
|
|
devices = []
|
|
for line in sys.stdin:
|
|
line = line.rstrip('\n')
|
|
if not line:
|
|
continue
|
|
parts = line.split('\t')
|
|
if len(parts) < 6:
|
|
continue
|
|
ip, alias, mac, status, sip, ext = parts[:6]
|
|
devices.append({
|
|
'ip': ip, 'alias': alias, 'mac': mac,
|
|
'vendor': 'Yealink', 'status': status,
|
|
'sip_status': sip, 'extension': ext,
|
|
})
|
|
print(json.dumps({'devices': devices}))
|
|
")
|
|
|
|
curl -sk --max-time 10 \
|
|
-X POST "$JARVIS_URL/api/netscan" \
|
|
-H "Host: $JARVIS_HOST" \
|
|
-H "Content-Type: application/json" \
|
|
-H "X-Registration-Key: $REG_KEY" \
|
|
-d "$JSON" > /dev/null 2>&1
|