Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit bfe59ec

Browse files
Update ConvertTo-DbaTimeline.ps1
1 parent a58c3b9 commit bfe59ec

File tree

1 file changed

+36
-52
lines changed

1 file changed

+36
-52
lines changed

‎functions/ConvertTo-DbaTimeline.ps1

Lines changed: 36 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,44 @@
1-
#------------------------------------------------------------------------------------------------------------------------------------------------
2-
# helper function to generate color based on the job statu
3-
# this may need renaming to Get-DbaTimelineStatusColor or similar
4-
#------------------------------------------------------------------------------------------------------------------------------------------------
5-
Function Get-StatusColor ([string]$Status) {
6-
$out = switch($Status){
7-
"Failed" {"#FF3D3D"}
8-
"Succeeded" {"#36B300"}
9-
"Retry" {"#FFFF00"}
10-
"Canceled" {"#C2C2C2"}
11-
"In Progress" {"#00CCFF"}
12-
default {"#FF00CC"}
13-
}
14-
return $out
15-
}
1+
function ConvertTo-DbaTimeline {
2+
<#
3+
.SYNOPSIS
4+
Converts InputObject to a html timeline using Google Chart
5+
6+
.DESCRIPTION
7+
This function accepts input as pipeline from the following psdbatools functions:
8+
Get-DbaAgentJobHistory
9+
Get-DbaBackupHistory
10+
(more to come...)
11+
And generates Bootstrap based, HTML file with Google Chart Timeline
12+
13+
.PARAMETER InputObject
14+
15+
Pipe input, must an output from the above functions.
16+
17+
.NOTES
18+
Tags: Internal
19+
Author: Marcin Gminski (@marcingminski)
20+
21+
Dependency: ConvertTo-JsDate, Convert-DbaTimelineStatusColor
22+
Requirements: None
23+
24+
Website: https://dbatools.io
25+
Copyright: (C) Chrissy LeMaire, clemaire@gmail.com
26+
- License: MIT https://opensource.org/licenses/MIT
27+
28+
.LINK
29+
https://dbatools.io/ConvertTo-DbaTimeline
1630
17-
#------------------------------------------------------------------------------------------------------------------------------------------------
18-
# helper function to convert human time to java script time format: new Date( Year, Month, Day, Hour, Minute, Second)
19-
# Java script time is zero base which means January = 0 and December = 11
20-
#------------------------------------------------------------------------------------------------------------------------------------------------
21-
Function ConvertTo-JsDate ([datetime]$InputDate) {
22-
$out = "new Date($(Get-Date $InputDate -format "yyyy"), $($(Get-Date $InputDate -format "MM")-1), $(Get-Date $InputDate -format "dd"), $(Get-Date $InputDate -format "HH"), $(Get-Date $InputDate -format "mm"), $(Get-Date $InputDate -format "ss"))"
23-
return $out
24-
}
31+
.EXAMPLE
32+
Get-DbaAgentJobHistory -SqlInstance sql-1 -StartDate ‘2018年08月13日 00:00’ -EndDate ‘2018年08月13日 23:59’ -NoJobSteps | ConvertTo-DbaTimeline | Out-File C:\temp\DbaAgentJobHistory.html -Encoding ASCII
33+
Get-DbaBackupHistory -SqlInstance sql-1 -Since ‘2018年08月13日 00:00’ | ConvertTo-DbaTimeline | Out-File C:\temp\DbaBackupHistory.html -Encoding ASCII
2534
26-
#------------------------------------------------------------------------------------------------------------------------------------------------
27-
# function to convert to timeline
28-
#------------------------------------------------------------------------------------------------------------------------------------------------
29-
Function ConvertTo-DbaTimeline {
35+
#>
36+
37+
[CmdletBinding()]
3038
Param (
3139
[parameter(Mandatory = $true, ValueFromPipeline = $true)]
3240
[object[]]$InputObject
3341
)
34-
3542
begin {
3643
#need to capture calling process to know what we are being asked for i.e. JobHistory, BackupHistory etc?
3744
#I dont know of any way apart from Get-PSCallStack but that return the whole stack but in order to the last
@@ -42,23 +49,18 @@ Function ConvertTo-DbaTimeline {
4249
<html>
4350
<head>
4451
<!-- Developed by Marcin Gminski, https://marcin.gminski.net, 2018 -->
45-
4652
<!-- Load jQuery required to autosize timeline -->
4753
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
48-
4954
<!-- Load Bootstrap -->
5055
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
5156
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
5257
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
53-
5458
<!-- Load Google Charts library -->
5559
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
56-
5760
<!-- a bit of custom styling to work with bootstrap grid -->
5861
<style>
5962
6063
html,body{height:100%;background-color:#c2c2c2;}
61-
6264
.viewport {height:100%}
6365
6466
.chart{
@@ -71,18 +73,15 @@ Function ConvertTo-DbaTimeline {
7173
box-shadow:1px 1px 3px 0 rgba(0,0,0,.45)
7274
}
7375
.badge-custom{background-color:#939}
74-
7576
.container {
7677
height:100%;
7778
}
78-
7979
.fill{
8080
width:100%;
8181
height:100%;
8282
min-height:100%;
8383
padding:10px;
8484
}
85-
8685
.timeline-tooltip{
8786
border:1px solid #E0E0E0;
8887
font-family:Arial,Helvetica;
@@ -91,12 +90,10 @@ Function ConvertTo-DbaTimeline {
9190
}
9291
.timeline-tooltip div{padding:6px}
9392
.timeline-tooltip span{font-weight:700}
94-
9593
</style>
9694
<script type="text/javascript">
9795
google.charts.load('43', {'packages':['timeline']});
9896
google.charts.setOnLoadCallback(drawChart);
99-
10097
function drawChart() {
10198
var container = document.getElementById('Chart');
10299
var chart = new google.visualization.Timeline(container);
@@ -117,7 +114,7 @@ Function ConvertTo-DbaTimeline {
117114
#This is where do column mapping:
118115
if ($caller.Position -Like "*Get-DbaAgentJobHistory*") {
119116
$CallerName = "Get-DbaAgentJobHistory"
120-
$data = $input | Select @{ Name="SqlInstance"; Expression = {$_.SqlInstance}}, @{ Name="InstanceName"; Expression = {$_.InstanceName}}, @{ Name="vLabel"; Expression = {$_.Job} }, @{ Name="hLabel"; Expression = {$_.Status} }, @{ Name="Style"; Expression = {$(Get-StatusColor($_.Status))} }, @{ Name="StartDate"; Expression = {$(ConvertTo-JsDate($_.StartDate))} }, @{ Name="EndDate"; Expression = {$(ConvertTo-JsDate($_.EndDate))} }
117+
$data = $input | Select @{ Name="SqlInstance"; Expression = {$_.SqlInstance}}, @{ Name="InstanceName"; Expression = {$_.InstanceName}}, @{ Name="vLabel"; Expression = {$_.Job} }, @{ Name="hLabel"; Expression = {$_.Status} }, @{ Name="Style"; Expression = {$(Convert-DbaTimelineStatusColor($_.Status))} }, @{ Name="StartDate"; Expression = {$(ConvertTo-JsDate($_.StartDate))} }, @{ Name="EndDate"; Expression = {$(ConvertTo-JsDate($_.EndDate))} }
121118

122119
}
123120

@@ -133,41 +130,33 @@ Function ConvertTo-DbaTimeline {
133130
var paddingHeight = 20;
134131
var rowHeight = dataTable.getNumberOfRows() * 41;
135132
var chartHeight = rowHeight + paddingHeight;
136-
137133
dataTable.insertColumn(2, {type: 'string', role: 'tooltip', p: {html: true}});
138-
139134
var dateFormat = new google.visualization.DateFormat({
140135
pattern: 'dd/MM/yy HH:mm:ss'
141136
});
142-
143137
for (var i = 0; i < dataTable.getNumberOfRows(); i++) {
144138
var duration = (dataTable.getValue(i, 5).getTime() - dataTable.getValue(i, 4).getTime()) / 1000;
145139
var hours = parseInt( duration / 3600 ) % 24;
146140
var minutes = parseInt( duration / 60 ) % 60;
147141
var seconds = duration % 60;
148-
149142
var tooltip = '<div class="timeline-tooltip"><span>' +
150143
dataTable.getValue(i, 1).split(",").join("<br />") + '</span></div><div class="timeline-tooltip"><span>' +
151144
dataTable.getValue(i, 0) + '</span>: ' +
152145
dateFormat.formatValue(dataTable.getValue(i, 4)) + ' - ' +
153146
dateFormat.formatValue(dataTable.getValue(i, 5)) + '</div>' +
154147
'<div class="timeline-tooltip"><span>Duration: </span>' +
155148
hours + 'h ' + minutes + 'm ' + seconds + 's ';
156-
157149
dataTable.setValue(i, 2, tooltip);
158150
}
159-
160151
var options = {
161152
timeline: {
162153
rowLabelStyle: { },
163154
barLabelStyle: { },
164155
},
165156
hAxis: {
166157
format: 'dd/MM HH:mm',
167-
168158
},
169159
}
170-
171160
// Autosize chart. It would not be enough to just count rows and expand based on row height as there can be overlappig rows.
172161
// this will draw the chart, get the size of the underlying div and apply that size to the parent container and redraw:
173162
chart.draw(dataTable, options);
@@ -177,7 +166,6 @@ Function ConvertTo-DbaTimeline {
177166
options.height=realheight
178167
// draw again:
179168
chart.draw(dataTable, options);
180-
181169
}
182170
</script>
183171
</head>
@@ -196,7 +184,3 @@ Function ConvertTo-DbaTimeline {
196184
"@
197185
}
198186
}
199-
200-
#execution
201-
#Get-DbaAgentJobHistory -SqlInstance sql-1 -StartDate ‘2018年08月13日 00:00’ -EndDate ‘2018年08月13日 23:59’ -NoJobSteps | ConvertTo-DbaTimeline | Out-File C:\temp\DbaAgentJobHistory.html -Encoding ASCII
202-
#Get-DbaBackupHistory -SqlInstance sql-1 -Since ‘2018年08月13日 00:00’ | ConvertTo-DbaTimeline | Out-File C:\temp\DbaBackupHistory.html -Encoding ASCII

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /