2024-03-04 11:30:02 -05:00
|
|
|
param (
|
|
|
|
|
[string]$ServiceName = '',
|
|
|
|
|
[string]$TmpFilePath = ''
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
Use-Icinga -Minimal;
|
|
|
|
|
|
|
|
|
|
[string]$ErrMsg = "";
|
|
|
|
|
[hashtable]$ServiceData = @{
|
|
|
|
|
'Status' = '';
|
|
|
|
|
'Present' = $FALSE;
|
2024-03-14 12:16:09 -04:00
|
|
|
'Name' = $ServiceName;
|
|
|
|
|
'DisplayName' = $ServiceName;
|
|
|
|
|
'User' = 'Unknown';
|
|
|
|
|
'ServicePath' = '';
|
2024-03-04 11:30:02 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
try {
|
2024-03-14 12:16:09 -04:00
|
|
|
$SvcData = Get-IcingaServices "$ServiceName" -ErrorAction Stop;
|
|
|
|
|
|
2025-02-03 06:37:37 -05:00
|
|
|
if ($null -ne $SvcData -And $SvcData.Count -ne 0) {
|
2025-01-30 10:48:34 -05:00
|
|
|
$ServiceConfig = $SvcData."$ServiceName".configuration;
|
|
|
|
|
$ServiceMeta = $SvcData."$ServiceName".metadata;
|
2025-01-31 09:02:26 -05:00
|
|
|
$ServiceData.Status = [string]$ServiceConfig.Status.value;
|
|
|
|
|
$ServiceData.User = [string]$ServiceConfig.ServiceUser;
|
|
|
|
|
$ServiceData.ServicePath = [string]$ServiceConfig.ServicePath;
|
|
|
|
|
$ServiceData.Name = $ServiceMeta.metadata.ServiceName;
|
|
|
|
|
$ServiceData.DisplayName = $ServiceMeta.metadata.DisplayName;
|
2024-03-14 12:16:09 -04:00
|
|
|
$ServiceData.Present = $TRUE;
|
|
|
|
|
}
|
2024-03-04 11:30:02 -05:00
|
|
|
} catch {
|
|
|
|
|
$ErrMsg = [string]::Format('Failed to get data for service "{0}": {1}', $ServiceName, $_.Exception.Message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Write-IcingaFileSecure -File "$TmpFilePath" -Value (
|
|
|
|
|
@{
|
|
|
|
|
'Service' = $ServiceData;
|
|
|
|
|
'Message' = [string]::Format('Successfully fetched data for service "{0}"', $ServiceName);
|
|
|
|
|
'ErrMsg' = $ErrMsg;
|
|
|
|
|
} | ConvertTo-Json -Depth 100
|
|
|
|
|
);
|