feat: include host.ipv4 in SAC payload and release 1.2.7-SAC
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -229,6 +229,7 @@ sac_send_event() {
|
||||
SAC_AGENT_ID="$(sac_agent_instance_id)" \
|
||||
SAC_PRODUCT_VERSION="${SSH_MONITOR_VERSION:-unknown}" \
|
||||
SAC_SERVER_DISPLAY_NAME="${SERVER_DISPLAY_NAME:-}" \
|
||||
SAC_HOST_IPV4="${SERVER_IPV4:-}" \
|
||||
python3 <<'PY'
|
||||
import json, os, socket, uuid
|
||||
from datetime import datetime, timezone
|
||||
@@ -239,8 +240,39 @@ def details():
|
||||
return None
|
||||
return json.loads(raw)
|
||||
|
||||
def valid_ipv4(value: str) -> bool:
|
||||
try:
|
||||
parts = value.split(".")
|
||||
return len(parts) == 4 and all(0 <= int(p) <= 255 for p in parts)
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
def detect_host_ipv4() -> str:
|
||||
manual = os.environ.get("SAC_HOST_IPV4", "").strip()
|
||||
if manual and valid_ipv4(manual):
|
||||
return manual
|
||||
try:
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
s.connect(("1.1.1.1", 53))
|
||||
ip = s.getsockname()[0]
|
||||
s.close()
|
||||
if valid_ipv4(ip) and not ip.startswith(("127.", "169.254.")):
|
||||
return ip
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
infos = socket.getaddrinfo(socket.gethostname(), None, family=socket.AF_INET)
|
||||
for info in infos:
|
||||
ip = info[4][0]
|
||||
if valid_ipv4(ip) and not ip.startswith(("127.", "169.254.")):
|
||||
return ip
|
||||
except Exception:
|
||||
pass
|
||||
return ""
|
||||
|
||||
host = socket.gethostname()
|
||||
display = os.environ.get("SAC_SERVER_DISPLAY_NAME", "").strip()
|
||||
host_ipv4 = detect_host_ipv4()
|
||||
etype = os.environ["SAC_EVENT_TYPE"]
|
||||
if etype.startswith(("ssh.", "auth.", "rdp.")):
|
||||
category = "auth"
|
||||
@@ -267,6 +299,7 @@ payload = {
|
||||
"hostname": host,
|
||||
"os_family": "linux",
|
||||
**({"display_name": display} if display else {}),
|
||||
**({"ipv4": host_ipv4} if host_ipv4 else {}),
|
||||
},
|
||||
"category": category,
|
||||
"type": os.environ["SAC_EVENT_TYPE"],
|
||||
|
||||
Reference in New Issue
Block a user