@@ -6,27 +6,33 @@ $splunkTAPSLogFile=Join-Path -Path $splunkTAOtelLogDir -ChildPath Splunk_TA_otel
6
6
function otelLogWrite
7
7
{
8
8
Param ([string ]$logstring )
9
-
10
- Add-content $splunkTAPSLogFile - value $ logstring
9
+ $timestamp = Get-Date - Format " yyyy-MM-dd HH:mm:ss.fff K "
10
+ Add-content $splunkTAPSLogFile - value " $timestamp $ logstring"
11
11
}
12
12
13
13
function isOtelProcessRunning ($processName )
14
14
{
15
15
$parent = (Get-WmiObject win32_process | ? processid -eq $PID ).parentprocessid
16
16
$Global :parentPid = $parent
17
+ otelLogWrite " INFO Parent process id: $parent "
17
18
$child = (Get-WmiObject win32_process | ? parentprocessid -eq $parent | ? processname -eq $processName ).processid
18
19
$Global :otelPid = $child
20
+ otelLogWrite " INFO Collector process id: $child "
19
21
$otelProcess = Get-Process - Id $child
20
22
if ($otelProcess )
21
23
{
22
- otelLogWrite " INFO Otel agent running"
23
- return 1
24
+ return $true
25
+ }
26
+ else
27
+ {
28
+ return $false
24
29
}
25
30
}
26
31
27
32
function waitForExit ($parent )
28
33
{
29
34
Wait-Process - Id $parent
35
+ otelLogWrite " INFO Parent process exited"
30
36
}
31
37
32
38
function forceStopOtelProcess ($processId )
@@ -45,9 +51,13 @@ function CheckOtelProcessStop($processId)
45
51
}
46
52
}
47
53
54
+ otelLogWrite " INFO Splunk_TA_otelutils.ps1 started"
48
55
start-sleep - s 3
49
- isOtelProcessRunning($otelProcessName )
50
-
51
- waitForExit($parentPid )
52
- forceStopOtelProcess($otelPid )
53
- CheckOtelProcessStop($otelPid )
56
+ if (isOtelProcessRunning($otelProcessName )) {
57
+ otelLogWrite " INFO Otel agent running"
58
+ waitForExit($parentPid )
59
+ forceStopOtelProcess($otelPid )
60
+ CheckOtelProcessStop($otelPid )
61
+ } else {
62
+ otelLogWrite " ERROR Otel agent not running"
63
+ }
0 commit comments