Please note that VisualCron support is not actively monitoring this community forum. Please use our contact page for contacting the VisualCron support directly.


MgSam
  •  MgSam
  • No customer Topic Starter
2016-03-29T15:48:49Z
I'm looking to make a generic notification email that contains the status of all tasks within a job. I'd then set this to run as part of the Flow for each job.

I'd like this to be formatted in an HTML table. The tricky part is that the number of tasks per job varies, so it would have to be able to loop through each task and add a row to the HTML table. Is it possible to use logic like this in the email template? Is there any other way to accomplish what I'm trying to do?

Thanks.
Sponsor
Forum information
Support
2016-04-01T21:14:57Z
No built in functionailty for this. You might want to accomplish this with the .NET Code Task but it requires some work.
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
MgSam
  •  MgSam
  • No customer Topic Starter
2016-04-04T17:42:57Z
Originally Posted by: Support 

No built in functionailty for this. You might want to accomplish this with the .NET Code Task but it requires some work.



Any further detail on how this might work?
bbusse
2016-04-05T03:38:15Z
I just made this using PowerShell to call the VisualCron API using examples found here and ultimately on Github. Basically, you create a Notification that is a PowerShell task/type and paste this code in. Set each job to run the notification on Completion.

It's entirely possible you'll need to change the entries for username/password in the code. Preferably since it's in plain text... it would be an ID that has read-only access to VisualCron instead of my testing with the built-in default 'admin' account on a fresh install.



function Get-VCAPIPath
{
    $programFilesPath = if (${Env:PROCESSOR_ARCHITECTURE} -eq 'x86') { ${Env:ProgramFiles} } else { ${Env:ProgramFiles(x86)} }
    Join-Path $programFilesPath VisualCron\VisualCronAPI.dll
}

function Get-VCServer
{
    [CmdletBinding()]
    param ([string]$ComputerName, 
           [int]$Port,
           [System.Management.Automation.PSCredential]$Credential)

    $apiPath = Get-VCAPIPath
    if (!(Test-Path $apiPath)) { Throw "VisualCron does not appear to be installed. API library not found at `"$apiPath`"." }
    [Reflection.Assembly]::LoadFrom($apiPath) | Out-Null
    $conn = New-Object VisualCronAPI.Connection
    $conn.Address = if ([String]::IsNullOrEmpty($ComputerName)) { ${Env:COMPUTERNAME} } else { $ComputerName }
    if (!($credential -eq $null)) 
    {
        $conn.UseADLogon = $true
        $netcred = $credential.GetNetworkCredential()
        $conn.UserName = $netcred.UserName
        $conn.Password = $netcred.Password
    }
    $client = New-Object VisualCronAPI.Client
    $client.Connect($conn)
}




$S = Get-VCServer -ComputerName localhost

$VCJob = $s.Jobs.Get("{JOB(Active|Id)}")

$VCtasks = ($s.Jobs.get("{JOB(Active|Id)}")).tasks | sort Order 

$JobName = $VCJob.Name

#Create Array to hold results:
$ObjArray = @()

foreach ($VCTask in $VCTasks){ 
#Create a new object for every task so we can trap results
$ObjData = New-Object System.Object

#Each value needs to be added to the array. 
$ObjData | Add-Member -type NoteProperty -name TaskName -value $VCTask.Name
$ObjData | Add-Member -type NoteProperty -name Result -value $VCTask.Stats.Result
$ObjData | Add-Member -type NoteProperty -name LastRun -value $VCTask.Stats.DateLastExited

   #Add the completed single entry into the Array/Table
   $objArray += $ObjData
    }
$s.disconnect()
$s.dispose()
   
#You would need to enter code here to send an e-mail formatted however you wish.   I'm just writing the output to a file in c:\Temp\ with the JobName.htm as an example.

$objarray | ConvertTo-Html | out-file -FilePath "C:\Temp\{JOB(Active|Name)}.htm" -Encoding ascii



Brian
Support
2016-04-06T14:05:00Z
Originally Posted by: bbusse 

I just made this using PowerShell to call the VisualCron API using examples found here and ultimately on Github.

Brian



Great job! We have some plans to make a global repository of PowerShell and .NET code for easier sharing - and at the same time be able to call PowerShell or .NET code through a Variable.
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
bbusse
2016-04-06T14:55:49Z
Originally Posted by: Support 


Great job! We have some plans to make a global repository of PowerShell and .NET code for easier sharing - and at the same time be able to call PowerShell or .NET code through a Variable.



Thanks. It's not perfect, doesn't take into account what happens if you have a Loop (will only get the most recent status of the tasks), etc. Also, I'm hoping I am closing the session properly by doing the $s.disconnect() and $s.dispose() - I saw a bunch of API connections in the list of client connections but they were slowly falling off. Not sure what would happen if you have 100 jobs all trying to fire off that task in a short period of time ramping the number of client/API connections up to several hundred for a bit. Thoughts?

Brian
Support
2016-04-06T14:59:08Z
Originally Posted by: bbusse 

Originally Posted by: Support 


Great job! We have some plans to make a global repository of PowerShell and .NET code for easier sharing - and at the same time be able to call PowerShell or .NET code through a Variable.



Thanks. It's not perfect, doesn't take into account what happens if you have a Loop (will only get the most recent status of the tasks), etc. Also, I'm hoping I am closing the session properly by doing the $s.disconnect() and $s.dispose() - I saw a bunch of API connections in the list of client connections but they were slowly falling off. Not sure what would happen if you have 100 jobs all trying to fire off that task in a short period of time ramping the number of client/API connections up to several hundred for a bit. Thoughts?

Brian



Why would you get several hundred connections?
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
bbusse
2016-04-06T17:51:26Z
Originally Posted by: Support 



Why would you get several hundred connections?



Maybe it was leftover from my earlier testing from before I included the .Dispose and .Disconnect at the end of the script. It seemed as though even when i ran the job the connnections would show up and not disappear for a little while. 100 jobs means 100 connections, but since they should each be disconnecting/disposing of the connection when done i'd assume they should drop off that list quickly.

Is there any known limit/threshold for the number of connections via clients/API/etc.. that the VisualCron Service can handle without causing issues? Thinking of organizations that might have jobs that run every minute or every 5 minutes and they have hundreds of jobs. Just thinking worst case scenario... you have 2500 jobs all running in a 5 minute period, all triggering this task as part of their notification/flow on complete.. Other than system resources getting angry at that many powershell instances in the background, what kinda limits would you say we're working within as far as VisualCron itself goes?

Brian
jeff benedict
2021-06-24T15:57:00Z
I realize this particular thread is 5 yr old. Has there been any native advances in how to accomplish this inside of VC w/o having to call a powershell script?? My desire does not have to be HTML based, I'm fine with Plain Text.
Scroll to Top