diff --git a/instruct/handlers.py b/instruct/handlers.py index 21c7cbd..36ae045 100644 --- a/instruct/handlers.py +++ b/instruct/handlers.py @@ -94,11 +94,11 @@ def get_ad_user_info(user_id: str) -> dict | None: raw_mail = str(entry.mail) if 'mail' in entry else "" # mail может быть "[]" (пустой LDAP объект), "" или "N/A" — фильтруем mail = raw_mail if raw_mail and raw_mail not in ("[]", "N/A", "") else None - # Fallback: используем UPN если mail пустой, конвертируем @sibcem.ru → @tcs.sibcem.ru + # Fallback: используем UPN если mail пустой if not mail: raw_upn = str(entry.userPrincipalName) if 'userPrincipalName' in entry else "" if raw_upn and raw_upn not in ("[]", "N/A", ""): - mail = raw_upn.replace("@sibcem.ru", "@tcs.sibcem.ru") + mail = raw_upn city = str(entry.l) if 'l' in entry and entry.l.value else "Кемерово" return {"cn": cn, "mail": mail, "city": city} except Exception as e: @@ -121,7 +121,7 @@ async def _send_sd_api_request(requester_email: str, subject: str, description: group_id = None try: url_groups = f"{SD_URL.rstrip('/')}/api/v3/groups" - headers = {"TECHNICIAN_KEY": SD_TOKEN} + headers = {"authtoken": SD_TOKEN, "Accept": "application/vnd.manageengine.sdp.v3+json"} async with httpx.AsyncClient(verify=False) as client: resp = await client.get(url_groups, headers=headers, timeout=10.0) if resp.status_code == 200: @@ -138,7 +138,7 @@ async def _send_sd_api_request(requester_email: str, subject: str, description: tech_id = None try: url_techs = f"{SD_URL.rstrip('/')}/api/v3/technicians" - headers = {"TECHNICIAN_KEY": SD_TOKEN} + headers = {"authtoken": SD_TOKEN, "Accept": "application/vnd.manageengine.sdp.v3+json"} async with httpx.AsyncClient(verify=False) as client: resp = await client.get(url_techs, headers=headers, timeout=10.0) if resp.status_code == 200: @@ -151,10 +151,11 @@ async def _send_sd_api_request(requester_email: str, subject: str, description: except Exception as e: logger.warning(f"Failed to fetch SD technicians: {e}") + html_desc = f"

{description.replace(chr(10), '
')}



Создано через TrueConf КЛЕВЕР

" payload = { "request": { "subject": subject, - "description": description, + "description": html_desc, "requester": requester_payload, "udf_fields": { "udf_pick_301": city @@ -168,12 +169,11 @@ async def _send_sd_api_request(requester_email: str, subject: str, description: payload["request"]["assigned_to"] = {"id": tech_id} url = f"{SD_URL.rstrip('/')}/api/v3/requests" - headers = {"TECHNICIAN_KEY": SD_TOKEN} - data = {"input_data": json.dumps(payload)} + headers = {"authtoken": SD_TOKEN, "Accept": "application/vnd.manageengine.sdp.v3+json"} async with httpx.AsyncClient(verify=False) as client: - response = await client.post(url, headers=headers, data=data, timeout=15.0) - + response = await client.post(url, headers=headers, json=payload, timeout=15.0) + if response.status_code in (200, 201): res_json = response.json() ticket_id = res_json.get("request", {}).get("id")