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 Ticket Content Default Value
by  CPG   Go to last post Go to first unread
Last post: Today at 8:45:12 PM(UTC)
Lansweeper New status to mimic Closed
by  chris.anderson  
Go to last post Go to first unread
Last post: Today at 7:14:27 PM(UTC)
Lansweeper Active Directory Groups not scanned properly
by  cross_eur   Go to last post Go to first unread
Last post: Today at 5:45:00 PM(UTC)
Lansweeper Change Management - Voting and Tracking
by  brodiemac-too  
Go to last post Go to first unread
Last post: Today at 2:48:01 PM(UTC)
Lansweeper No incoming Mails after update 8.4.100.9
by  EDELL   Go to last post Go to first unread
Last post: Today at 2:38:50 PM(UTC)
Lansweeper Anti-Virus on Mac
by  Ian.Prentice  
Go to last post Go to first unread
Last post: Today at 9:30:32 AM(UTC)
Lansweeper how to scan intune managed win10 clients?
by  brodiemac-too   Go to last post Go to first unread
Last post: Yesterday at 9:17:07 PM(UTC)
Lansweeper Sort by in Helpdesk
by  brodiemac-too  
Go to last post Go to first unread
Last post: Yesterday at 9:15:05 PM(UTC)