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
3
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 Last user, login time and null entries
by  RC62N   Go to last post Go to first unread
Last post: Today at 9:41:41 PM(UTC)
Lansweeper Stale Tickets
by  brodiemac-too  
Go to last post Go to first unread
Last post: Today at 8:47:09 PM(UTC)
Lansweeper MacOS IOMobileFrameBuffer 0-day Report
by  Esben.D   Go to last post Go to first unread
Last post: Today at 2:56:46 PM(UTC)
Lansweeper Software per AD group
by  CPappas  
Go to last post Go to first unread
Last post: Today at 10:11:56 AM(UTC)
Lansweeper SeriousSAM Vulnerability
by  Esben.D   Go to last post Go to first unread
Last post: Today at 9:40:05 AM(UTC)
Lansweeper Building "Basic" Report User Assets
by  Cripple.Zero  
Go to last post Go to first unread
Last post: Yesterday at 8:16:50 PM(UTC)
Lansweeper PetitPotam
by  Esben.D  
Go to last post Go to first unread
Last post: 7/26/2021 3:12:48 PM(UTC)