I would like to be able to report back status of process on remote PC's and populate a status virt device in HS. Is that possible or has anyone done this?
Cheers,
Darren
Cheers,
Darren
If this is your first visit, be sure to check out the FAQ. You must register before you can post.
IMPORTANT: Your first post will be checked for appropriate content. This may take a bit of time.
Dim proc As String Dim dev As String Sub Main(ByVal param As Object) 'Organizing devices Dim input() As String = param.ToString.Split(CChar(";")) If input.GetLength(0) < 1 Then hs.WriteLog("Script", "Not enough parameters") Exit Sub Else proc = input(0).ToString dev = input(1).ToString End If Dim p() As System.Diagnostics.Process = System.Diagnostics.Process.GetProcessesByName(proc) hs.Writelog("Test", p.Length & " - " & proc & " - " & dev) If p.Length = 0 Then UpdateDevice(0) ElseIf p.Length > 1 Then UpdateDevice(1) ElseIf p.Length = 1 Then If p(0).Responding Then UpdateDevice(2) Else 'not responding UpdateDevice(3) End If End If End Sub Sub UpdateDevice(ByVal status As Integer) Select Case status Case Is = 0 hs.SetDeviceString(dev, proc & " is not running") Case Is = 1 hs.SetDeviceString(dev, proc & " has multiple instances") Case Is = 2 hs.SetDeviceString(dev, proc & " is alive and kicking") Case Is = 3 hs.SetDeviceString(dev, proc & " does not respond") End Select hs.SetDeviceStatus(dev, status) End Sub
Dim bolAllAreRunning As Boolean = True For Each pr As Process In p If Not pr.Responding Then bolAllAreRunning = False Next If p.Length = 0 Then UpdateDevice(0) ElseIf bolAllAreRunning Then UpdateDevice(2) Else UpdateDevice(3) End If
Dim proc As String Dim dev As String Public Sub Main(ByVal param As String) 'Organizing devices Dim input() As String = param.ToString.Split(CChar(";")) If input.GetLength(0) < 1 Then hs.WriteLog("Script", "Not enough parameters") Exit Sub Else proc = input(0).ToString dev = input(1).ToString End If Dim p() As System.Diagnostics.Process = System.Diagnostics.Process.GetProcessesByName(proc) If p.Length = 0 Then UpdateDevice(0) ElseIf p.Length > 1 Then UpdateDevice(1) ElseIf p.Length = 1 Then If p(0).Responding Then Dim s As String = ProcDescription(p(0)) UpdateDevice(2, s) Else 'not responding UpdateDevice(3) End If End If End Sub Private Sub UpdateDevice(ByVal status As Integer, Optional ByVal str As String = Nothing) Select Case status Case Is = 0 hs.SetDeviceString(dev, proc & " is <b><font color=""red"">not running</font></b>") 'hs.WriteLog("ProcStat", proc & " is not running") Case Is = 1 hs.SetDeviceString(dev, proc & " has many instances") 'hs.WriteLog("procStat", proc & " has many instances") Case Is = 2 hs.SetDeviceString(dev, "<b>" & proc & "</b> is <b><font color=""green"">running</font></b>" & str) 'hs.WriteLog("ProcStat", "<b>" & proc & "</b> is running" & str) Case Is = 3 hs.SetDeviceString(dev, proc & " is <b><font color=""red"">not responding</font></b>") 'hs.WriteLog("ProcStat", proc & " does not respond!") End Select hs.SetDeviceStatus(dev, status) hs.SetDeviceLastChange(dev, Date.Now) End Sub Private Function ProcDescription(ByVal p As System.Diagnostics.Process) As String Dim s As String = "<br>" _ & "Processor time: " & p.TotalProcessorTime.Days.ToString("00") & ":" & p.TotalProcessorTime.Hours.ToString("00") & ":" & p.TotalProcessorTime.Minutes.ToString("00") & ":" & p.TotalProcessorTime.Seconds.ToString("00") & "<br>" _ & "Used memory: " & Math.Round(p.WorkingSet64 / (1024 ^ 2), 1) & " MB" Return s End Function Public Sub ListProcesses() Dim p2() As System.Diagnostics.Process = System.Diagnostics.Process.GetProcesses Dim s As String = Nothing For Each pr As System.Diagnostics.Process In p2 s &= pr.ProcessName & "<br>" Next hs.WriteLog("Available processes", s) End Sub
Comment