Although with SMS it is possible to email reports on a schedule, whilst you can create a graphical report through the console, if you try and email it via an automation rule, the report gets converted to text.
I have been able to overcome this limitation by exporting the required data to a CSV via the connector settings and creating a powershell script that reads the data and sends the email. Only tested with 7.1
The first stage is to create the report of the specific monitoring data you wish to have emailed e.g. The SQL below will show the 'Memory - Available MB' data for the specified server for the last 7 days.
SELECT dbo.vMonitorAllMetricData.TimeStamp, dbo.Inv_AeX_AC_Identification.Name, dbo.vMonitorAllMetricData.Instance, dbo.vMonitorAllMetricData.NumValue, dbo.vMonitorAllMetricData.Min, dbo.vMonitorAllMetricData.Max, dbo.vMonitorAllMetricData.Duration
FROM dbo.vMonitorAllMetricData INNER JOIN dbo.Inv_AeX_AC_Identification ON dbo.vMonitorAllMetricData.ResourceGuid = dbo.Inv_AeX_AC_Identification._ResourceGuid
WHERE (dbo.Inv_AeX_AC_Identification.Name LIKE 'ServerName%') AND (dbo.vMonitorAllMetricData.TimeStamp >= DATEADD(Day, - 7, DATEDIFF(Day, 0, GETDATE()))) AND (dbo.vMonitorAllMetricData.TimeStamp <= DATEADD(Day, 0, DATEDIFF(Day, 0, GETDATE()))) AND (dbo.vMonitorAllMetricData.Instance LIKE 'Memory - Available MB') |
The second stage is to create an export data source and rule :
Settings / All Settings, Notification Server / Connector / Data Sources - Right Click on Data Sources, select New CSV File Data Source.
Give the data source a name, select the 'Allow Export' tick box, change the drop-down to 'Write data to a specified file' Enter the path and filename to a directory that the Altiris account has rights to, and select the two options to create file / overwrite.
Save it, then create a new export rule - Right click the Import / Export Rules and chose New Report Export Rule
Name it, then select your datasource, and the report, then tick the box to Overwrite Existing Data, then create a schedule to run the export. Selecting Run Now will create the CSV and give you an indication how long it will take to run
The next stage is to create the powershell script - pre-requisite are powershell,
.NET Framework 3.5
and
Microsoft Chart Controls for Microsoft .NET Framework 3.5
The powershell script is as follows
Param([String]$InputFileName,[String]$MailTo,[String]$MailCC,[String]$Title,[String]$smtpServer,[String]$MailFrom,[String]$TempDir,[String]$MaxMin)
[void][Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms.DataVisualization")
[void][Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$scriptpath = Split-Path -parent $MyInvocation.MyCommand.Definition
$currentDate = (get-date).ToString("dd")+'/'+(get-date).ToString("MM")+'/'+(get-date).ToString("yyyy")
$data = import-csv $InputFileName
$servers= $data | select -ExpandProperty Name -Unique | sort
$timestamp = $data | select -ExpandProperty TimeStamp -Unique | sort foreach ($server in $servers)
{ $msg = new-object Net.Mail.MailMessage $smtp = new-object Net.Mail.SmtpClient($smtpServer) $msg.From = $MailFrom foreach( $To in $MailTo ) { $msg.To.Add($To)
} $msg.Subject = $server +" "+$Title+" "+$currentDate $msg.Body ="" $msg.IsBodyHtml = $true
$tmp = $data | Where-Object {( $_.Name -eq $server )}
$instances = $tmp | select -ExpandProperty Instance -Unique | sort foreach ($instance in $instances) { # chart object $chart1 = New-object System.Windows.Forms.DataVisualization.Charting.Chart $chart1.Width = 2000 $chart1.Height = 800 $chart1.BackColor = [System.Drawing.Color]::White # title [void]$chart1.Titles.Add($server+" "+$instance+" "+$Title) $chart1.Titles[0].Font = "Arial,13pt" $chart1.Titles[0].Alignment = "topLeft" # chart area $chartarea = New-Object System.Windows.Forms.DataVisualization.Charting.ChartArea $chartarea.Name = "ChartArea1" $chartarea.AxisY.Title = $server+" "+$instance+" "+$Title $chartarea.AxisX.Title = "Time" #$chartarea.AxisY.Interval = 100 $chartarea.AxisX.Interval = 2 $chart1.ChartAreas.Add($chartarea) # legend $legend = New-Object system.Windows.Forms.DataVisualization.Charting.Legend $legend.name = "Legend1" $chart1.Legends.Add($legend) # data source $datasource = $data # data series [void]$chart1.Series.Add($server+" "+$instance+" "+$Title ) $chart1.Series[$server+" "+$instance+" "+$Title ].ChartType = "Column" $chart1.Series[$server+" "+$instance+" "+$Title ].BorderWidth = 3 $chart1.Series[$server+" "+$instance+" "+$Title ].IsVisibleInLegend = $true $chart1.Series[$server+" "+$instance+" "+$Title ].chartarea = "ChartArea1" $chart1.Series[$server+" "+$instance+" "+$Title ].Legend = "Legend1" $chart1.Series[$server+" "+$instance+" "+$Title ].color = "#62B5CC" $points = $data | Where-Object {( $_.Name -eq $server -and $_.Instance -eq $instance)} IF ($MaxMin -eq "Max" ) { foreach ($point in $points) { $chart1.Series[$server+" "+$instance+" "+$Title].Points.addxy( $point.TimeStamp , $point.Max) } $maxValuePoint = $chart1.Series[$server+" "+$instance+" "+$Title].Points.FindMaxByValue() $maxValuePoint.Color = [System.Drawing.Color]::Red $minValuePoint = $chart1.Series[$server+" "+$instance+" "+$Title].Points.FindMinByValue() $minValuePoint.Color = [System.Drawing.Color]::Green } ELSE { foreach ($point in $points) { $chart1.Series[$server+" "+$instance+" "+$Title].Points.addxy( $point.TimeStamp , $point.Min) } $maxValuePoint = $chart1.Series[$server+" "+$instance+" "+$Title].Points.FindMaxByValue() $maxValuePoint.Color = [System.Drawing.Color]::Green $minValuePoint = $chart1.Series[$server+" "+$instance+" "+$Title].Points.FindMinByValue() $minValuePoint.Color = [System.Drawing.Color]::Red } $filename=$server+'_'+$instance.replace(':','_')+$Title $chart1.SaveImage("$TempDir\"+ $filename +".png","png") $att = new-object Net.Mail.Attachment("$TempDir\"+ $filename + ".png") $msg.Body = $msg.Body + $server +" "+$instance+" "+$Title+"<br>" $msg.Attachments.Add($att) } $smtp.Send($msg)
} |
You may have to set powershell to run unsigned scripts - start powershell then set-executionpolicy remotesigned
The script takes several inputs :
InputFileName - Name of the CSV file to be imported
MailTo - Email address to send to (multiple can be added by separating with a comma)
MailCC - Email address(es) to be cc'd to
Title - Title of the report
smtpServer - name of your SMTP server
MailFrom - Email from address
TempDir - Location of temporary directory
MaxMin - To enable whether the Max or Min fields are used
The next stage is to create a task to run the powershell script e.g.
Command script
d:
cd temp
powershell -file d:\temp\graphs2.ps1 -InputFileName d:\temp\<csvfile> -MailTo <emailaddress> -Title "Free Space Report" -smtpServer <smtpserver> -MailFrom <altirisserveremail> -TempDir d:\temp -MaxMin Max del *.png |
Note i'm not the best in powershell, so likely could be improved, also I found that the script can sometimes hold the png files open, hence deleting them afterwards, the MaxMin switch is there as some metrics you are interested in the Maximum levels - eg CPU usage, others the Minimum levels, eg Disc Space.
Phil