SWQL qery assistant: multiple

hi everyone

I have customized a PowerShell script that reruns the Veeam job status. I believe the outcome is elegant.
here is my script:

#my veeam server
$remotehosts="192.168.1.11"
#in nested remoting use username as an example below
$username = "ENT-BACKUP-1\rservice"
$password = "xxxxxxxxx" | ConvertTo-SecureString -AsPlainText -Force

#Region Define Exite code
$ExitCode=@{
    Up=0
    Down=1
    Warning=2
    Critical=3
    Unknown=4
}

# Create a PSCredential object using the username and password
$credential = New-Object System.Management.Automation.PSCredential ($username, $password)

#prepare Deployer configuration
$remotsession=New-PSSession -ComputerName $remotehosts -Credential $credential -Name rtunnel

Invoke-Command -Session $remotsession -ScriptBlock {
# Retrieve all Veeam Backup jobs
$job_name = Get-VBRJob
if ($job_name -ne $null)
{
# Iterate over each job and output its name, last result, and current state
foreach ($job in $job_name) {
    $jobName = $job.Name
    $job_Result = (Get-VBRJob -Name $jobName).GetLastResult()
    $job_State = (Get-VBRJob -Name $jobName).GetLastState()
    $job_session = (Get-VBRJob -Name $jobName).FindLastSession()

    # Output the job information
    [PSCustomObject]@{
        JobName     = $jobName
        LastResult  = $job_Result
        LastState   = $job_State
        job_session = $job_session
    }

if ( $job_session -eq $null )
{ $stat3=$stat4=$stat5=$stat6=0; }
else
{
$stat3=$job_session.jobtypestring;
$temp_stat4=$job_session.CreationTime;
$temp_stat5=$job_session.EndTime;
$stat4 = $temp_stat4.tostring("yyyy.MM.dd HH:mm")
$stat5 = $temp_stat5.tostring("yyyy.MM.dd HH:mm")
}
}
}
    else {
        Write-Host "Message: review powershell code"
        $status = "Critical"
        }

} | Export-Csv -Path E:\PWSH_script\temp_veeamjobsstatus.csv
$temp_veeam = Import-Csv -Path E:\PWSH_script\temp_veeamjobsstatus.csv
$temp_veeam | select JobName,LastResult,LastState | Export-Csv E:\PWSH_script\Veeam_jobs.csv

     switch ($temp_veeam.LastResult) 
     { 
     "Success" { $stat1=0 } 
     "None" { $stat1=1 } 
     "Failed" { $stat1=2 } 
     default { $stat1=3 }
     }
    switch ($temp_veeam.LastState) 
     { 
     "Stopped" { $stat2=0 } 
     "Starting" { $stat2=1 } 
     "Working" { $stat2=2 } 
     "Stopping" { $stat2=3 } 
     "Resuming" { $stat2=4 } 
     "Pausing" { $stat2=5 } 
     default { $stat2=6 }
     }
foreach ($taskName in ($temp_veeam).JobName) {
    $lresult= $temp_veeam | Where-Object {$_.JobName -eq $taskName}
    Write-host "Message.jobs_name: $taskname"
    Write-host "Statistic.jobs_name: $stat1"
    Write-host "Message.jobs_status: $($lresult.LastResult)"
    Write-host "Statistic.jobs_status: $stat2"
    $status = "up"
}
exit $ExitCode[$Status];

i use this code on my SAM module. and here is the output:

how can i separated each result on separate line, per jobs_name.


here is my moderm dashboard table:

my SWQL query:

SELECT           
         [table].ComponentName
        ,[table].ComponentMessage
        ,[table].MultiValueStatistics
FROM Orion.APM.ComponentAlert AS [table]
-- find component ID from Orion.APM.CurrentStatistics table
WHERE [table].ApplicationID = 39

  • You can have up to 10 output pairs in a script as long as your name them uniquely.

    Statistic.name1

    Message.name1

    Statistic.name2

    Message.name2

    Statistic.name3

    Message.name3

    etc

    In your case, you'd have to update your foreach loop to output something similar to the following:

    Statistic.jobs_name_Rep_Pfsense: 0

    Message.jobs_name_Rep_Pfsense: "text"

    Statistic.jobs_name_Rep_Vcenter: 0

    Message.jobs_name_Rep_Vcenter: "text"

    Statistic.jobs_name_EnterPrise_Service: 0

    Message.jobs_name_EnterPrise_Service: "text"

    Since you have named outputs, you could consider dropping the 'jobs_name' part from the Statistic part.

    You can also check out this article:

     SAM Script Component Monitors - Everything you need to know