-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathInvoke-ImeAnalization
More file actions
67 lines (56 loc) · 2.01 KB
/
Invoke-ImeAnalization
File metadata and controls
67 lines (56 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"""
Invoke-ImeAnalization - Analyze Intune Management Extension logs with Azure OpenAI.
Reads the local IME log file and sends it to Azure OpenAI for error analysis
and troubleshooting suggestions.
Author: Jannik Reinhard (jannikreinhard.com)
Version: 1.1
Release: v1.0 - Init
v1.1 - Security: use environment variables for credentials, added error handling
"""
import os
import sys
from openai import AzureOpenAI
# Configuration via environment variables
openai_azure_endpoint = os.environ.get("AZURE_OPENAI_ENDPOINT", "")
openai_key = os.environ.get("AZURE_OPENAI_KEY", "")
if not openai_azure_endpoint or not openai_key:
print("Error: Set AZURE_OPENAI_ENDPOINT and AZURE_OPENAI_KEY environment variables.", file=sys.stderr)
sys.exit(1)
file_path = os.path.join(
"C:\\", "ProgramData", "Microsoft", "IntuneManagementExtension", "Logs", "IntuneManagementExtension.log"
)
try:
with open(file_path, "r") as file:
log_content = file.read()
except FileNotFoundError:
print(f"Error: Log file not found at {file_path}", file=sys.stderr)
sys.exit(1)
except OSError as exc:
print(f"Error reading log file: {exc}", file=sys.stderr)
sys.exit(1)
prompt = f"""
You are a senior Intune engineer. Your task is to find errors in the [Intune Management Extension log]. Give the user a summary of the log and point them to errors in a structured way. Explain what each error means and how to check and troubleshoot it.
[Intune Management Extension log]
{log_content}
[END Intune Management Extension log]
"""
client = AzureOpenAI(
azure_endpoint=openai_azure_endpoint,
api_key=openai_key,
api_version="2024-02-01",
)
try:
completion = client.chat.completions.create(
model="gpt-4o",
temperature=0,
messages=[
{
"role": "user",
"content": prompt,
}
],
)
print(completion.choices[0].message.content)
except Exception as exc:
print(f"Error calling Azure OpenAI: {exc}", file=sys.stderr)
sys.exit(1)