Remove idle time tracking from PC data collection
- Remove idleMinutes parameter from api.asp updateCompleteAsset - Remove idle time Win32 API collection from PowerShell script - Clean up apishopfloor.asp (remove debug output) Idle time tracking was added but user decided not to use this feature. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
169
api.asp
169
api.asp
@@ -45,6 +45,8 @@ Select Case action
|
||||
GetDashboardData()
|
||||
Case "getShopfloorPCs"
|
||||
GetShopfloorPCs()
|
||||
Case "getHighUptimePCs"
|
||||
GetHighUptimePCs()
|
||||
Case "getRecordedIP"
|
||||
GetRecordedIP()
|
||||
Case "updateMachinePositions"
|
||||
@@ -57,6 +59,8 @@ Select Case action
|
||||
GetUDCMachineStats()
|
||||
Case "getUDCManualTiming"
|
||||
GetUDCManualTiming()
|
||||
Case "getDeployableApps"
|
||||
GetDeployableApps()
|
||||
Case Else
|
||||
SendError "Invalid action: " & action
|
||||
End Select
|
||||
@@ -272,6 +276,10 @@ Sub UpdateCompleteAsset()
|
||||
pctypeId = 9
|
||||
Case "PART MARKER", "PARTMARKER"
|
||||
pctypeId = 10
|
||||
Case "DASHBOARD"
|
||||
pctypeId = 11
|
||||
Case "LOBBY DISPLAY", "LOBBYDISPLAY", "LOBBY-DISPLAY"
|
||||
pctypeId = 12
|
||||
Case "MEASURING", "MEASURING TOOL"
|
||||
pctypeId = 7
|
||||
Case Else
|
||||
@@ -831,24 +839,52 @@ Sub GetShopfloorPCs()
|
||||
' Returns list of all active PCs with shop floor IPs (10.134.*) for remote management
|
||||
' This includes all PC types: Shopfloor, CMM, Wax Trace, Keyence, etc.
|
||||
' PCs are identified by machinetypeid >= 33, pctypeid can be NULL
|
||||
' Optional filters: pctypeid, businessunitid
|
||||
On Error Resume Next
|
||||
|
||||
Dim rsPC, strSQL, pcList, pcCount, pcData
|
||||
Dim filterPcTypeId, filterBusinessUnitId, whereClause
|
||||
|
||||
' Get optional filter parameters
|
||||
filterPcTypeId = Request.QueryString("pctypeid")
|
||||
filterBusinessUnitId = Request.QueryString("businessunitid")
|
||||
|
||||
' Build WHERE clause with optional filters
|
||||
' Dashboard (11) and Lobby Display (12) can be on any subnet, others require 10.134.*
|
||||
whereClause = "WHERE m.isactive = 1 " & _
|
||||
"AND m.machinetypeid >= 33 "
|
||||
|
||||
' Add pctypeid filter if provided
|
||||
If filterPcTypeId <> "" And IsNumeric(filterPcTypeId) Then
|
||||
whereClause = whereClause & "AND m.pctypeid = " & CInt(filterPcTypeId) & " "
|
||||
' Skip IP filter for Dashboard (11) and Lobby Display (12) - they can be on any subnet
|
||||
If CInt(filterPcTypeId) <> 11 And CInt(filterPcTypeId) <> 12 Then
|
||||
whereClause = whereClause & "AND EXISTS (SELECT 1 FROM communications c2 WHERE c2.machineid = m.machineid AND c2.address LIKE '10.134.%') "
|
||||
End If
|
||||
Else
|
||||
' No pctype filter - only return shopfloor IPs (10.134.*) by default
|
||||
whereClause = whereClause & "AND EXISTS (SELECT 1 FROM communications c2 WHERE c2.machineid = m.machineid AND c2.address LIKE '10.134.%') "
|
||||
End If
|
||||
|
||||
' Add businessunitid filter if provided
|
||||
If filterBusinessUnitId <> "" And IsNumeric(filterBusinessUnitId) Then
|
||||
whereClause = whereClause & "AND m.businessunitid = " & CInt(filterBusinessUnitId) & " "
|
||||
End If
|
||||
|
||||
' Query all active PCs with shop floor IP addresses (10.134.*)
|
||||
' - machinetypeid >= 33 ensures we only get PCs (not equipment)
|
||||
' - LEFT JOIN pctype to include PCs with NULL pctypeid
|
||||
' - EXISTS subquery finds any PC with a 10.134.* address
|
||||
strSQL = "SELECT m.machineid, m.hostname, m.machinenumber, m.serialnumber, " & _
|
||||
"m.loggedinuser, m.lastupdated, " & _
|
||||
"m.loggedinuser, m.lastupdated, m.pctypeid, m.businessunitid, " & _
|
||||
"c.address AS ipaddress, " & _
|
||||
"COALESCE(pt.typename, 'Uncategorized') AS pctype " & _
|
||||
"COALESCE(pt.typename, 'Uncategorized') AS pctype, " & _
|
||||
"COALESCE(bu.businessunit, 'TBD') AS businessunit " & _
|
||||
"FROM machines m " & _
|
||||
"LEFT JOIN communications c ON m.machineid = c.machineid AND c.isprimary = 1 AND c.comstypeid = 1 " & _
|
||||
"LEFT JOIN pctype pt ON m.pctypeid = pt.pctypeid " & _
|
||||
"WHERE m.isactive = 1 " & _
|
||||
"AND m.machinetypeid >= 33 " & _
|
||||
"AND EXISTS (SELECT 1 FROM communications c2 WHERE c2.machineid = m.machineid AND c2.address LIKE '10.134.%') " & _
|
||||
"LEFT JOIN businessunits bu ON m.businessunitid = bu.businessunitid " & _
|
||||
whereClause & _
|
||||
"ORDER BY m.hostname ASC"
|
||||
|
||||
Set rsPC = objConn.Execute(strSQL)
|
||||
@@ -874,6 +910,17 @@ Sub GetShopfloorPCs()
|
||||
pcData = pcData & """ipaddress"":""" & EscapeJSON(rsPC("ipaddress") & "") & ""","
|
||||
pcData = pcData & """loggedinuser"":""" & EscapeJSON(rsPC("loggedinuser") & "") & ""","
|
||||
pcData = pcData & """pctype"":""" & EscapeJSON(rsPC("pctype") & "") & ""","
|
||||
If IsNull(rsPC("pctypeid")) Then
|
||||
pcData = pcData & """pctypeid"":null,"
|
||||
Else
|
||||
pcData = pcData & """pctypeid"":" & rsPC("pctypeid") & ","
|
||||
End If
|
||||
pcData = pcData & """businessunit"":""" & EscapeJSON(rsPC("businessunit") & "") & ""","
|
||||
If IsNull(rsPC("businessunitid")) Then
|
||||
pcData = pcData & """businessunitid"":null,"
|
||||
Else
|
||||
pcData = pcData & """businessunitid"":" & rsPC("businessunitid") & ","
|
||||
End If
|
||||
|
||||
' Handle lastupdated date
|
||||
If Not IsNull(rsPC("lastupdated")) Then
|
||||
@@ -896,6 +943,103 @@ Sub GetShopfloorPCs()
|
||||
Response.Write "{""success"":true,""count"":" & pcCount & ",""data"":[" & pcList & "]}"
|
||||
End Sub
|
||||
|
||||
Sub GetHighUptimePCs()
|
||||
' Returns list of PCs with uptime >= specified days (for reboot management)
|
||||
On Error Resume Next
|
||||
|
||||
Dim rsPC, strSQL, pcList, pcCount, pcData
|
||||
Dim minUptime
|
||||
|
||||
' Get minimum uptime parameter (required)
|
||||
minUptime = Request.QueryString("minUptime")
|
||||
If minUptime = "" Or Not IsNumeric(minUptime) Then
|
||||
minUptime = 10 ' Default to 10 days
|
||||
Else
|
||||
minUptime = CInt(minUptime)
|
||||
End If
|
||||
|
||||
' Query PCs with high uptime
|
||||
strSQL = "SELECT m.machineid, m.hostname, m.machinenumber, m.serialnumber, " & _
|
||||
"m.loggedinuser, m.lastupdated, m.lastboottime, m.pctypeid, m.businessunitid, " & _
|
||||
"DATEDIFF(NOW(), m.lastboottime) AS uptime_days, " & _
|
||||
"c.address AS ipaddress, " & _
|
||||
"COALESCE(pt.typename, 'Uncategorized') AS pctype, " & _
|
||||
"COALESCE(bu.businessunit, 'TBD') AS businessunit " & _
|
||||
"FROM machines m " & _
|
||||
"LEFT JOIN communications c ON m.machineid = c.machineid AND c.isprimary = 1 AND c.comstypeid = 1 " & _
|
||||
"LEFT JOIN pctype pt ON m.pctypeid = pt.pctypeid " & _
|
||||
"LEFT JOIN businessunits bu ON m.businessunitid = bu.businessunitid " & _
|
||||
"WHERE m.isactive = 1 " & _
|
||||
"AND m.pctypeid IS NOT NULL " & _
|
||||
"AND m.lastboottime IS NOT NULL " & _
|
||||
"AND DATEDIFF(NOW(), m.lastboottime) >= " & minUptime & " " & _
|
||||
"ORDER BY uptime_days DESC, m.hostname ASC"
|
||||
|
||||
Set rsPC = objConn.Execute(strSQL)
|
||||
|
||||
If Err.Number <> 0 Then
|
||||
SendError "Database error: " & Err.Description
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
' Build JSON array of PCs
|
||||
pcList = ""
|
||||
pcCount = 0
|
||||
|
||||
Do While Not rsPC.EOF
|
||||
If pcList <> "" Then pcList = pcList & ","
|
||||
|
||||
' Build individual PC object
|
||||
pcData = "{"
|
||||
pcData = pcData & """machineid"":" & rsPC("machineid") & ","
|
||||
pcData = pcData & """hostname"":""" & EscapeJSON(rsPC("hostname") & "") & ""","
|
||||
pcData = pcData & """machinenumber"":""" & EscapeJSON(rsPC("machinenumber") & "") & ""","
|
||||
pcData = pcData & """serialnumber"":""" & EscapeJSON(rsPC("serialnumber") & "") & ""","
|
||||
pcData = pcData & """ipaddress"":""" & EscapeJSON(rsPC("ipaddress") & "") & ""","
|
||||
pcData = pcData & """loggedinuser"":""" & EscapeJSON(rsPC("loggedinuser") & "") & ""","
|
||||
pcData = pcData & """pctype"":""" & EscapeJSON(rsPC("pctype") & "") & ""","
|
||||
pcData = pcData & """uptime_days"":" & rsPC("uptime_days") & ","
|
||||
|
||||
' Handle lastboottime date
|
||||
If Not IsNull(rsPC("lastboottime")) Then
|
||||
pcData = pcData & """lastboottime"":""" & rsPC("lastboottime") & ""","
|
||||
Else
|
||||
pcData = pcData & """lastboottime"":null,"
|
||||
End If
|
||||
|
||||
If IsNull(rsPC("pctypeid")) Then
|
||||
pcData = pcData & """pctypeid"":null,"
|
||||
Else
|
||||
pcData = pcData & """pctypeid"":" & rsPC("pctypeid") & ","
|
||||
End If
|
||||
pcData = pcData & """businessunit"":""" & EscapeJSON(rsPC("businessunit") & "") & ""","
|
||||
If IsNull(rsPC("businessunitid")) Then
|
||||
pcData = pcData & """businessunitid"":null,"
|
||||
Else
|
||||
pcData = pcData & """businessunitid"":" & rsPC("businessunitid") & ","
|
||||
End If
|
||||
|
||||
' Handle lastupdated date
|
||||
If Not IsNull(rsPC("lastupdated")) Then
|
||||
pcData = pcData & """lastupdated"":""" & FormatDateTime(rsPC("lastupdated"), 2) & " " & FormatDateTime(rsPC("lastupdated"), 4) & """"
|
||||
Else
|
||||
pcData = pcData & """lastupdated"":null"
|
||||
End If
|
||||
|
||||
pcData = pcData & "}"
|
||||
pcList = pcList & pcData
|
||||
pcCount = pcCount + 1
|
||||
|
||||
rsPC.MoveNext
|
||||
Loop
|
||||
|
||||
rsPC.Close
|
||||
Set rsPC = Nothing
|
||||
|
||||
' Send response
|
||||
Response.Write "{""success"":true,""count"":" & pcCount & ",""minUptime"":" & minUptime & ",""data"":[" & pcList & "]}"
|
||||
End Sub
|
||||
|
||||
Sub GetRecordedIP()
|
||||
On Error Resume Next
|
||||
Err.Clear
|
||||
@@ -1574,9 +1718,9 @@ Function CreatePCMachineRelationship(pcMachineid, machineNumber)
|
||||
rsResult.Close
|
||||
Set rsResult = Nothing
|
||||
|
||||
' Check if relationship already exists (PC -> Equipment)
|
||||
' Check if relationship already exists (Equipment -> PC, matching existing data pattern)
|
||||
strSQL = "SELECT relationshipid FROM machinerelationships " & _
|
||||
"WHERE machineid = " & CLng(pcMachineid) & " AND related_machineid = " & CLng(equipmentMachineid) & " AND relationshiptypeid = " & CLng(relationshiptypeid)
|
||||
"WHERE machineid = " & CLng(equipmentMachineid) & " AND related_machineid = " & CLng(pcMachineid) & " AND relationshiptypeid = " & CLng(relationshiptypeid)
|
||||
LogToFile "CreatePCMachineRelationship: Checking for duplicate: " & strSQL
|
||||
Set rsResult = objConn.Execute(strSQL)
|
||||
|
||||
@@ -1592,8 +1736,9 @@ Function CreatePCMachineRelationship(pcMachineid, machineNumber)
|
||||
rsResult.Close
|
||||
Set rsResult = Nothing
|
||||
|
||||
' Create new Controls relationship (PC -> Equipment)
|
||||
' Fixed: PC should be machineid, Equipment should be related_machineid
|
||||
' Create new Controls relationship (Equipment -> PC)
|
||||
' Equipment is machineid (source), PC is related_machineid (target)
|
||||
' This matches existing relationship data pattern in the database
|
||||
Dim cmdInsert
|
||||
Set cmdInsert = Server.CreateObject("ADODB.Command")
|
||||
cmdInsert.ActiveConnection = objConn
|
||||
@@ -1601,8 +1746,8 @@ Function CreatePCMachineRelationship(pcMachineid, machineNumber)
|
||||
"machineid, related_machineid, relationshiptypeid, isactive" & _
|
||||
") VALUES (?, ?, ?, 1)"
|
||||
|
||||
cmdInsert.Parameters.Append cmdInsert.CreateParameter("@pcid", 3, 1, , CLng(pcMachineid))
|
||||
cmdInsert.Parameters.Append cmdInsert.CreateParameter("@equipmentid", 3, 1, , CLng(equipmentMachineid))
|
||||
cmdInsert.Parameters.Append cmdInsert.CreateParameter("@pcid", 3, 1, , CLng(pcMachineid))
|
||||
cmdInsert.Parameters.Append cmdInsert.CreateParameter("@reltypeid", 3, 1, , CLng(relationshiptypeid))
|
||||
|
||||
cmdInsert.Execute
|
||||
@@ -2142,6 +2287,10 @@ Function GetPCTypeIdFromPCType(pcTypeString)
|
||||
GetPCTypeIdFromPCType = 9
|
||||
Case "PART MARKER", "PARTMARKER"
|
||||
GetPCTypeIdFromPCType = 10
|
||||
Case "DASHBOARD"
|
||||
GetPCTypeIdFromPCType = 11
|
||||
Case "LOBBY DISPLAY", "LOBBYDISPLAY", "LOBBY-DISPLAY"
|
||||
GetPCTypeIdFromPCType = 12
|
||||
Case "MEASURING", "MEASURING TOOL"
|
||||
GetPCTypeIdFromPCType = 7 ' Default other measuring tools to Keyence
|
||||
Case "STANDARD", ""
|
||||
|
||||
Reference in New Issue
Block a user