Add PC uptime tracking feature

- Database: Add lastboottime column to machines table
- API: Accept lastBootUpTime parameter and store in lastboottime column
- PowerShell: Collect LastBootUpTime from Win32_OperatingSystem
  - Update-PC-Minimal.ps1: Add last boot time collection
  - Update-ShopfloorPCs-Remote.ps1: Add last boot time collection and API posting
- Display: Add Uptime column to displaypcs.asp with color-coded badges
  - > 90 days: red badge
  - > 30 days: yellow badge
  - > 7 days: blue badge
  - <= 7 days: muted text
- Filter: Add "Uptime > X days" filter dropdown (7, 30, 90 days)
- SQL: Production migration script for lastboottime column

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
cproudlock
2025-12-09 09:36:23 -05:00
parent 01d4aae38d
commit cd9058d81e
5 changed files with 125 additions and 11 deletions

51
api.asp
View File

@@ -115,6 +115,13 @@ Sub UpdateCompleteAsset()
Dim hasWinRM
hasWinRM = Trim(Request.Form("hasWinRM") & "")
' Last boot time (optional) - accepts both lastBootUpTime and lastBootTime
Dim lastBootTime
lastBootTime = Trim(Request.Form("lastBootUpTime") & "")
If lastBootTime = "" Then
lastBootTime = Trim(Request.Form("lastBootTime") & "")
End If
' DNC/GE registry data
dncDualPathEnabled = Request.Form("dncDualPathEnabled")
dncPath1Name = Trim(Request.Form("dncPath1Name") & "")
@@ -290,7 +297,14 @@ Sub UpdateCompleteAsset()
winrmValue = 0
End If
strSQL = "UPDATE machines SET serialnumber='" & safeSerial & "', modelnumberid=" & modelId & ", machinetypeid=" & machineTypeId & ", osid=" & osid & ", isvnc=" & vncValue & ", iswinrm=" & winrmValue & ", lastupdated=NOW() WHERE machineid=" & machineid
' Build UPDATE with optional lastboottime
Dim lastBootPart
If lastBootTime <> "" Then
lastBootPart = ", lastboottime='" & Replace(lastBootTime, "'", "''") & "'"
Else
lastBootPart = ""
End If
strSQL = "UPDATE machines SET serialnumber='" & safeSerial & "', modelnumberid=" & modelId & ", machinetypeid=" & machineTypeId & ", osid=" & osid & ", isvnc=" & vncValue & ", iswinrm=" & winrmValue & lastBootPart & ", lastupdated=NOW() WHERE machineid=" & machineid
objConn.Execute strSQL
If Err.Number <> 0 Then
SendError debugMsg & "10-UPDATE failed: " & Err.Description
@@ -321,7 +335,16 @@ Sub UpdateCompleteAsset()
winrmValueInsert = 0
End If
strSQL = "INSERT INTO machines (hostname, serialnumber, modelnumberid, machinetypeid, osid, machinestatusid, isvnc, iswinrm, lastupdated) VALUES ('" & safeHostname & "', '" & safeSerial & "', " & modelId & ", " & machineTypeId & ", " & osid & ", " & pcstatusid & ", " & vncValueInsert & ", " & winrmValueInsert & ", NOW())"
' Build INSERT with optional lastboottime
Dim lastBootColInsert, lastBootValInsert
If lastBootTime <> "" Then
lastBootColInsert = ", lastboottime"
lastBootValInsert = ", '" & Replace(lastBootTime, "'", "''") & "'"
Else
lastBootColInsert = ""
lastBootValInsert = ""
End If
strSQL = "INSERT INTO machines (hostname, serialnumber, modelnumberid, machinetypeid, osid, machinestatusid, isvnc, iswinrm, lastupdated" & lastBootColInsert & ") VALUES ('" & safeHostname & "', '" & safeSerial & "', " & modelId & ", " & machineTypeId & ", " & osid & ", " & pcstatusid & ", " & vncValueInsert & ", " & winrmValueInsert & ", NOW()" & lastBootValInsert & ")"
objConn.Execute strSQL
If Err.Number <> 0 Then
SendError debugMsg & "10-INSERT failed: " & Err.Description
@@ -922,6 +945,14 @@ Function InsertOrUpdatePC(conn, hostname, serialnumber, manufacturer, model, pcT
sqlStatusId = "NULL"
End If
' Build lastboottime part for UPDATE
Dim sqlLastBoot
If lastBootTime <> "" Then
sqlLastBoot = "lastboottime = '" & Replace(lastBootTime, "'", "''") & "', "
Else
sqlLastBoot = ""
End If
strSQL = "UPDATE machines SET " & _
"serialnumber = '" & safeSerial & "', " & _
"modelnumberid = " & sqlModelId & ", " & _
@@ -930,6 +961,7 @@ Function InsertOrUpdatePC(conn, hostname, serialnumber, manufacturer, model, pcT
"machinenumber = " & sqlMachineNum & ", " & _
"osid = " & sqlOsId & ", " & _
"machinestatusid = " & sqlStatusId & ", " & _
sqlLastBoot & _
"lastupdated = NOW() " & _
"WHERE machineid = " & CLng(machineid) & " AND pctypeid IS NOT NULL"
@@ -967,7 +999,16 @@ Function InsertOrUpdatePC(conn, hostname, serialnumber, manufacturer, model, pcT
' Build SQL in parts to isolate error
Dim sqlPart1, sqlPart2, sqlPart3
sqlPart1 = "INSERT INTO machines (hostname, serialnumber, modelnumberid, machinetypeid, pctypeid, loggedinuser, machinenumber, osid, machinestatusid, isactive, lastupdated) VALUES ("
' Add lastboottime column if provided
Dim sqlLastBootCol, sqlLastBootVal
If lastBootTime <> "" Then
sqlLastBootCol = ", lastboottime"
sqlLastBootVal = ", '" & Replace(lastBootTime, "'", "''") & "'"
Else
sqlLastBootCol = ""
sqlLastBootVal = ""
End If
sqlPart1 = "INSERT INTO machines (hostname, serialnumber, modelnumberid, machinetypeid, pctypeid, loggedinuser, machinenumber, osid, machinestatusid, isactive, lastupdated" & sqlLastBootCol & ") VALUES ("
sqlPart2 = "'" & safeHostname & "', '" & safeSerial & "', "
If modelId > 0 Then
@@ -998,9 +1039,9 @@ Function InsertOrUpdatePC(conn, hostname, serialnumber, manufacturer, model, pcT
End If
If pcstatusid > 0 Then
sqlPart3 = sqlPart3 & CLng(pcstatusid) & ", 1, NOW())"
sqlPart3 = sqlPart3 & CLng(pcstatusid) & ", 1, NOW()" & sqlLastBootVal & ")"
Else
sqlPart3 = sqlPart3 & "NULL, 1, NOW())"
sqlPart3 = sqlPart3 & "NULL, 1, NOW()" & sqlLastBootVal & ")"
End If
strSQL = sqlPart1 & sqlPart2 & sqlPart3