Notification

Icon
Error

Days since last update, including "last seen" clause, last reboot, and some colour

Posted: Thursday, January 28, 2021 5:57:26 PM(UTC)
cgrieves

cgrieves

Member Original PosterPosts: 1
4
Like
I've created this report and maybe others might find it useful- we needed a "Quick glance" "Days since last update" report, suitable for consumption by our technical management and compliance teams. I've found that the tblQuickFixEngineering query often reports correctly on update installation, but this isn't much use where a reboot is required, so I've included a "Days since reboot" column to make it easier to check for these cases.

Our platform goes through regular changes, so any servers that haven't been seen in 2 days are excluded.

It also colours the output depending on the duration since the last update (red = bad)

(TODO- highlight where the last reboot time is significantly longer than the last update time. For the moment we just manually sort by that column to check)

Code:
Select Top 1000000 tblAssets.AssetID,
  tblAssets.AssetName,
  tblAssets.Domain,
  tsysOS.OSname,
  tblAssets.Username As LastUserLogin,
  tblAssets.IPAddress,
  tblAssets.Description,
  DateDiff(day, Max(Convert(datetime,tblAssets.Lastseen)), GetDate()) As
  DaysSinceSeen,
  DateDiff(day, Max(Convert(datetime,tblQuickFixEngineering.InstalledOn)),
  GetDate()) As DaysSincePatched,
  Convert(Decimal(12,0),tblAssets.Uptime / 86400) As UptimeDays,
  Case
    When
      DateDiff(day, Max(Convert(datetime,tblQuickFixEngineering.InstalledOn)),
      GetDate()) Between 0 And 7 Then '#6efa72'
    When
      DateDiff(day, Max(Convert(datetime,tblQuickFixEngineering.InstalledOn)),
      GetDate()) Between 7 And 12 Then '#77ea6b'
    When
      DateDiff(day, Max(Convert(datetime,tblQuickFixEngineering.InstalledOn)),
      GetDate()) Between 12 And 16 Then '#80d965'
    When
      DateDiff(day, Max(Convert(datetime,tblQuickFixEngineering.InstalledOn)),
      GetDate()) Between 16 And 20 Then '#89c95e'
    When
      DateDiff(day, Max(Convert(datetime,tblQuickFixEngineering.InstalledOn)),
      GetDate()) Between 20 And 24 Then '#93b958'
    When
      DateDiff(day, Max(Convert(datetime,tblQuickFixEngineering.InstalledOn)),
      GetDate()) Between 24 And 28 Then '#9ca951'
    When
      DateDiff(day, Max(Convert(datetime,tblQuickFixEngineering.InstalledOn)),
      GetDate()) Between 28 And 32 Then '#a5984b'
    When
      DateDiff(day, Max(Convert(datetime,tblQuickFixEngineering.InstalledOn)),
      GetDate()) Between 32 And 36 Then '#ae8844'
    When
      DateDiff(day, Max(Convert(datetime,tblQuickFixEngineering.InstalledOn)),
      GetDate()) Between 36 And 40 Then '#b7783d'
    When
      DateDiff(day, Max(Convert(datetime,tblQuickFixEngineering.InstalledOn)),
      GetDate()) Between 40 And 44 Then '#c06737'
    When
      DateDiff(day, Max(Convert(datetime,tblQuickFixEngineering.InstalledOn)),
      GetDate()) Between 44 And 48 Then '#c95730'
    When
      DateDiff(day, Max(Convert(datetime,tblQuickFixEngineering.InstalledOn)),
      GetDate()) Between 48 And 52 Then '#d3472a'
    When
      DateDiff(day, Max(Convert(datetime,tblQuickFixEngineering.InstalledOn)),
      GetDate()) Between 52 And 56 Then '#dc3723'
    When
      DateDiff(day, Max(Convert(datetime,tblQuickFixEngineering.InstalledOn)),
      GetDate()) Between 56 And 60 Then '#e5261d'
    Else '#f7caca'
  End As backgroundcolor
From tblQuickFixEngineering
  Join tblAssets On tblAssets.AssetID = tblQuickFixEngineering.AssetID
  Join tsysOS On tblAssets.OScode = tsysOS.OScode
Where tblAssets.Lastseen > GetDate() - 2
Group By tblAssets.AssetID,
  tblAssets.AssetName,
  tblAssets.Domain,
  tsysOS.OSname,
  tblAssets.Username,
  tblAssets.IPAddress,
  tblAssets.Description,
  tblAssets.Lastseen,
  tblAssets.Uptime
Order By DaysSincePatched
ldockery
#1ldockery Member Posts: 7  
posted: 3/30/2021 7:56:48 PM(UTC)
Generates this error:

Quote:
The conversion of a nvarchar data type to a datetime data type resulted in an out-of-range value.
Attila
#2Attila Member Posts: 1  
posted: 7/15/2021 4:14:02 PM(UTC)
Thanks , works great
Madrilleno
#3Madrilleno Member Posts: 3  
posted: 7/27/2021 2:24:53 PM(UTC)
Originally Posted by: ldockery Go to Quoted Post
Generates this error:

Quote:
The conversion of a nvarchar data type to a datetime data type resulted in an out-of-range value.


Same error for me.

Active Discussions

Lansweeper Sync information
by  prighi61   Go to last post Go to first unread
Last post: Yesterday at 2:34:06 PM(UTC)
Lansweeper Deleting, removing or hiding default ticket states
by  prighi61  
Go to last post Go to first unread
Last post: Yesterday at 1:16:52 PM(UTC)
Lansweeper Switch Dell S4128 Scan error
by  matteor   Go to last post Go to first unread
Last post: Yesterday at 1:04:03 PM(UTC)
Lansweeper Patch Tuesday report showing wrong results
by  NoZart  
Go to last post Go to first unread
Last post: Yesterday at 11:44:58 AM(UTC)
Lansweeper How do I create a new ticket using the API?
by  prighi61   Go to last post Go to first unread
Last post: Yesterday at 9:36:39 AM(UTC)
Lansweeper IP Location "undefined"
by  Kboyer  
Go to last post Go to first unread
Last post: 9/23/2021 9:25:46 PM(UTC)
Lansweeper Modify root cause list
by  Arno Butter   Go to last post Go to first unread
Last post: 9/23/2021 8:38:25 PM(UTC)
Lansweeper scanning network devices
by  mattscratt  
Go to last post Go to first unread
Last post: 9/23/2021 8:04:43 PM(UTC)