fix: use service_desk API format in instruct (authtoken, Accept header, json=payload, html description)
This commit is contained in:
@@ -94,11 +94,11 @@ def get_ad_user_info(user_id: str) -> dict | None:
|
|||||||
raw_mail = str(entry.mail) if 'mail' in entry else ""
|
raw_mail = str(entry.mail) if 'mail' in entry else ""
|
||||||
# mail может быть "[]" (пустой LDAP объект), "" или "N/A" — фильтруем
|
# mail может быть "[]" (пустой LDAP объект), "" или "N/A" — фильтруем
|
||||||
mail = raw_mail if raw_mail and raw_mail not in ("[]", "N/A", "") else None
|
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:
|
if not mail:
|
||||||
raw_upn = str(entry.userPrincipalName) if 'userPrincipalName' in entry else ""
|
raw_upn = str(entry.userPrincipalName) if 'userPrincipalName' in entry else ""
|
||||||
if raw_upn and raw_upn not in ("[]", "N/A", ""):
|
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 "Кемерово"
|
city = str(entry.l) if 'l' in entry and entry.l.value else "Кемерово"
|
||||||
return {"cn": cn, "mail": mail, "city": city}
|
return {"cn": cn, "mail": mail, "city": city}
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -121,7 +121,7 @@ async def _send_sd_api_request(requester_email: str, subject: str, description:
|
|||||||
group_id = None
|
group_id = None
|
||||||
try:
|
try:
|
||||||
url_groups = f"{SD_URL.rstrip('/')}/api/v3/groups"
|
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:
|
async with httpx.AsyncClient(verify=False) as client:
|
||||||
resp = await client.get(url_groups, headers=headers, timeout=10.0)
|
resp = await client.get(url_groups, headers=headers, timeout=10.0)
|
||||||
if resp.status_code == 200:
|
if resp.status_code == 200:
|
||||||
@@ -138,7 +138,7 @@ async def _send_sd_api_request(requester_email: str, subject: str, description:
|
|||||||
tech_id = None
|
tech_id = None
|
||||||
try:
|
try:
|
||||||
url_techs = f"{SD_URL.rstrip('/')}/api/v3/technicians"
|
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:
|
async with httpx.AsyncClient(verify=False) as client:
|
||||||
resp = await client.get(url_techs, headers=headers, timeout=10.0)
|
resp = await client.get(url_techs, headers=headers, timeout=10.0)
|
||||||
if resp.status_code == 200:
|
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:
|
except Exception as e:
|
||||||
logger.warning(f"Failed to fetch SD technicians: {e}")
|
logger.warning(f"Failed to fetch SD technicians: {e}")
|
||||||
|
|
||||||
|
html_desc = f"<p>{description.replace(chr(10), '<br>')}</p><br><hr><p style='color:#555;font-size:12px;'><i>Создано через TrueConf КЛЕВЕР</i></p>"
|
||||||
payload = {
|
payload = {
|
||||||
"request": {
|
"request": {
|
||||||
"subject": subject,
|
"subject": subject,
|
||||||
"description": description,
|
"description": html_desc,
|
||||||
"requester": requester_payload,
|
"requester": requester_payload,
|
||||||
"udf_fields": {
|
"udf_fields": {
|
||||||
"udf_pick_301": city
|
"udf_pick_301": city
|
||||||
@@ -168,11 +169,10 @@ async def _send_sd_api_request(requester_email: str, subject: str, description:
|
|||||||
payload["request"]["assigned_to"] = {"id": tech_id}
|
payload["request"]["assigned_to"] = {"id": tech_id}
|
||||||
|
|
||||||
url = f"{SD_URL.rstrip('/')}/api/v3/requests"
|
url = f"{SD_URL.rstrip('/')}/api/v3/requests"
|
||||||
headers = {"TECHNICIAN_KEY": SD_TOKEN}
|
headers = {"authtoken": SD_TOKEN, "Accept": "application/vnd.manageengine.sdp.v3+json"}
|
||||||
data = {"input_data": json.dumps(payload)}
|
|
||||||
|
|
||||||
async with httpx.AsyncClient(verify=False) as client:
|
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):
|
if response.status_code in (200, 201):
|
||||||
res_json = response.json()
|
res_json = response.json()
|
||||||
|
|||||||
Reference in New Issue
Block a user