Monitor monitoring runbooks
Hi,
could anyone advise how to monitor and restart monitoring runbooks?
We have some monitoring runbooks which have to run all the time.
They use to stop sometimes (Orchestrator server loses connection to its database/SCSM server, server restarts, any other failures, etc).
We need to know about these failures and restart those monitoring runbooks automatically.
My searching of the web was unsuccessful, I only found some clues to check runbook statuses directly in the Orchestrator database. Thank you.
Best Answer
-
Brian_Wiest Customer Super IT Monkey ✭✭✭✭✭
I accomplish this by a Schedule task that runs every hour to make sure the jobs are running. Just place in your paths and it will make sure there is a running job.
if ( !(Get-Module -Name OrchestratorServiceModule -ErrorAction SilentlyContinue) ) {Import-Module E:\Powershell\SCOrchestratorServicePowerShellV1_2\OrchestratorServiceModule.psm1}
$scorh_url = "http://orchestrator.local:81/Orchestrator2012/orchestrator.svc/"
$Runbook_folders = @('Runbookpath1','Runbookpath2')
foreach ($Runbook_folder in $Runbook_folders)
{
$Runbooks = Get-OrchestratorRunbook -ServiceUrl $scorh_url -RunbookPath $Runbook_folder
foreach ($Runbook in $Runbooks)
{
$Runbookid = Get-OrchestratorRunbook -ServiceUrl $scorh_url -RunbookId $Runbook.id
$RunningJob = Get-OrchestratorJob -ServiceUrl $scorh_url -RunbookId $Runbookid.id | Where-Object {$_.Status -eq 'Running'}
If($Runningjob -eq $null)
{
$Runbook = Get-OrchestratorRunbook -ServiceUrl $scorh_url -RunbookId $Runbookid.id
Start-OrchestratorRunbook -Runbook $Runbook
}
Else {}
}
}
1
Answers
I accomplish this by a Schedule task that runs every hour to make sure the jobs are running. Just place in your paths and it will make sure there is a running job.
if ( !(Get-Module -Name OrchestratorServiceModule -ErrorAction SilentlyContinue) ) {Import-Module E:\Powershell\SCOrchestratorServicePowerShellV1_2\OrchestratorServiceModule.psm1}
$scorh_url = "http://orchestrator.local:81/Orchestrator2012/orchestrator.svc/"
$Runbook_folders = @('Runbookpath1','Runbookpath2')
foreach ($Runbook_folder in $Runbook_folders)
{
$Runbooks = Get-OrchestratorRunbook -ServiceUrl $scorh_url -RunbookPath $Runbook_folder
foreach ($Runbook in $Runbooks)
{
$Runbookid = Get-OrchestratorRunbook -ServiceUrl $scorh_url -RunbookId $Runbook.id
$RunningJob = Get-OrchestratorJob -ServiceUrl $scorh_url -RunbookId $Runbookid.id | Where-Object {$_.Status -eq 'Running'}
If($Runningjob -eq $null)
{
$Runbook = Get-OrchestratorRunbook -ServiceUrl $scorh_url -RunbookId $Runbookid.id
Start-OrchestratorRunbook -Runbook $Runbook
}
Else {}
}
}
@Brian_Wiest perfect, thank you for this solution, seems to work!
For those who don't know what's OrchestratorServiceModule.psm1, I found it here on GitHub published in 2014. Let me know if you have any more current version: https://github.com/dwj7738/PowershellModules/tree/master/OrchestratorServieModule