Announcement

Collapse
No announcement yet.

Running Plugin Check

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • bsobel
    replied
    There where forum issues, so I was talking with Sparkman directly. A couple notes from what I sent them; the main thing is the VBNC is VB6 so Linq is not supported. Also the implementation of arrays doesn't support IEnumerable as arrays normally do. This means to convert the scripts you need to copy the array to a list, and any linq logic needs to be reimplemented not using linq.

    Best
    Bill

    (original notes

    You are running into the same issue with all those examples, they assume that the array is convertible to IEnumerable (btw still seeing this on the latest mono, so maybe a vb compiler issue as c# certainly supports this) Anyhow, you need to create the list by hand, e.g. (just tested):

    Sub Main(parm as object)
    dim slist as object
    slist = hs.GetPluginsList()
    dim list2 as new System.Collections.Generic.List(of string)
    For index As Integer = 0 To slist.length - 1
    list2.add(slist(index))
    Next
    hs.WriteLog("script","Len: " & slist.length)
    hs.writelog("script","plugin: " & slist(0))
    End Sub

    Leave a comment:


  • MattL0
    replied
    Works perfectly here. Thank all !! What a nice script

    Leave a comment:


  • S-F
    replied
    Nifty script. Thanks. One of the reasons I'm into home automation is because I have the memory capacity of a goldfish.

    Leave a comment:


  • sparkman
    replied
    Thanks to bsobel and zwolfpack for testing under various flavors of linux/mono and modifying the code so that it works under it too, the script in the first post has been updated to a version that works under both Windows and linux.

    Leave a comment:


  • zwolfpack
    replied
    Thanks - 'Import System.Linq' was the first thing I tried, no joy. Still searching...

    Leave a comment:


  • sparkman
    replied
    Sorry, gents. I should have known better. I had the Dim RunningPlugins() As String = hs.GetPluginsList in a different script and defined it as an object there, but the HS documentation shows it as returning a string, so I modified it for this script.

    The script uses a Linq function to compare two arrays. The 'Except' call is that function. My understanding is that the latest versions of HS now import Linq automatically when it compiles scripts, but maybe that's only the case in Windows. Try adding this line as the first line in the script:
    Code:
    Imports System.Linq
    If that still throws errors, then perhaps that function is not available under mono.

    Leave a comment:


  • MattL0
    replied
    That script would be nice too, as a starting script in the startup.vb
    just have to put a delay of 3 minutes in the event that run the script.

    Leave a comment:


  • MattL0
    replied
    Originally posted by zwolfpack View Post
    Thanks! Works as advertised on Windows.

    On Linux, errors as shown by MattL0

    1st error "Value of type 'Object' cannot be converted to 'System.String[]'." is fixed by changing line
    Code:
     Dim RunningPlugins() As String = hs.GetPluginsList
    to
    Code:
     Dim RunningPlugins() As String = New String() {hs.GetPluginsList}
    Still working on the missing 'Except' method ...
    thanks ! now like you said :


    Code:
     
    Jan-24 05:21:09 Error Compiling script /HomeSeer/scripts/PluginsChek.vb: 'Except' is not a member of 'System.String[]'.
    Jan-24 05:21:09 Error Compiling script /HomeSeer/scripts/PluginsChek.vb: The import 'System.Core' could not be found.

    Code:
    Sub Main(ByVal Parms As String)
    
        Dim RequiredPlugins() As String = {"AirplaySpeak:","APCUPSD:","Big5:","Cps Links:","Cps Tags:","EasyTrigger:","JowiHue:","Kodi:","LutronCaseta:","mcsMQTT:","MediaController:","MeiHarmonyHub:","PHLocation2:","SceneMaster:","SqueezeBox:","UltraLog3:","Z-Wave:"}
    
        Dim Debug As Boolean = False
        Dim logName As String = "Plugin Check"
        Dim NonRunningPlugins As String = ""
    
        Try
            Dim RunningPlugins() As String = New String() {hs.GetPluginsList}
            If RunningPlugins IsNot Nothing AndAlso RunningPlugins.Length > 0 Then
                NonRunningPlugins = String.Join(", ", RequiredPlugins.Except(RunningPlugins))
                If Debug Then hs.writelog(logName,"***" & NonRunningPlugins & "***")
                If NonRunningPlugins > "" Then
                    'Do Something
                    'Send Pushover Message
                        Dim CO(8) As Object
                        CO(0) = "All Clients" 'must be matched with a device name already in the plugin or 'All Clients' CASE SENSITIVE
                        CO(1) = NonRunningPlugins 'message body
                        CO(2) = "Plugins Not Running" 'message subject
                        CO(3) = "normal" 'low/normal/high/emergency
                        CO(4) = "pushover" 'message sound from list: pushover,bike,bugle,cashregister,classical,cosmic,falling,gamelan,incoming,intermission,magic,mechanical,pianobar,siren,spacealarm,tugboat,alien,climb,persistent,echo,updown,none
                        CO(5) = Nothing
                        CO(6) = Nothing
                        CO(7) = Nothing
                        CO(8) = Nothing
                        hs.PluginFunction("Pushover 3P", "", "Pushscript", CO)
                Else
                    'All Good
                    If Debug Then hs.writelog(logName,"All required plugins are running")
                End If
            Else
                hs.writelog(logName,"Nothing to see here.  Move along.")
            End If
    
        Catch ex As Exception
            hs.WriteLog(logname, "Exception " & ex.ToString)
        End Try
    End Sub

    Leave a comment:


  • zwolfpack
    replied
    Thanks! Works as advertised on Windows.

    On Linux, errors as shown by MattL0

    1st error "Value of type 'Object' cannot be converted to 'System.String[]'." is fixed by changing line
    Code:
            Dim RunningPlugins() As String = hs.GetPluginsList
    to
    Code:
            Dim RunningPlugins() As String = New String() {hs.GetPluginsList}
    Still working on the missing 'Except' method ...

    Leave a comment:


  • MattL0
    replied
    I am 30. I think it will help me :P Thanks!

    edit : I got this in the hs log

    Code:
     
    Jan-24 01:39:01 Error Compiling script /HomeSeer/scripts/PluginsChek.vb: 'Except' is not a member of 'System.String[]'.
    Jan-24 01:39:01 Error Compiling script /HomeSeer/scripts/PluginsChek.vb: Value of type 'Object' cannot be converted to 'System.String[]'.
    Jan-24 01:39:01 Error Compiling script /HomeSeer/scripts/PluginsChek.vb: The import 'System.Core' could not be found.
    My script:

    Code:
    Sub Main(ByVal Parms As String)
    
        Dim RequiredPlugins() As String = {"AirplaySpeak:","APCUPSD:","Big5:","Cps Links:","Cps Tags:","EasyTrigger:","JowiHue:","Kodi:","LutronCaseta:","mcsMQTT:","MediaController:","MeiHarmonyHub:","PHLocation2:","SceneMaster:","SqueezeBox:","UltraLog3:","Z-Wave:"}
    
        Dim Debug As Boolean = False
        Dim logName As String = "Plugin Check"
        Dim NonRunningPlugins As String = ""
    
        Try
            Dim RunningPlugins() As String = hs.GetPluginsList
            If RunningPlugins IsNot Nothing AndAlso RunningPlugins.Length > 0 Then
                NonRunningPlugins = String.Join(", ", RequiredPlugins.Except(RunningPlugins))
                If Debug Then hs.writelog(logName,"***" & NonRunningPlugins & "***")
                If NonRunningPlugins > "" Then
                    'Do Something
                    'Send Pushover Message
                        Dim CO(8) As Object
                        CO(0) = "All Clients" 'must be matched with a device name already in the plugin or 'All Clients' CASE SENSITIVE
                        CO(1) = NonRunningPlugins 'message body
                        CO(2) = "Plugins Not Running" 'message subject
                        CO(3) = "normal" 'low/normal/high/emergency
                        CO(4) = "pushover" 'message sound from list: pushover,bike,bugle,cashregister,classical,cosmic,falling,gamelan,incoming,intermission,magic,mechanical,pianobar,siren,spacealarm,tugboat,alien,climb,persistent,echo,updown,none
                        CO(5) = Nothing
                        CO(6) = Nothing
                        CO(7) = Nothing
                        CO(8) = Nothing
                        hs.PluginFunction("Pushover 3P", "", "Pushscript", CO)
                Else
                    'All Good
                    If Debug Then hs.writelog(logName,"All required plugins are running")
                End If
            Else
                hs.writelog(logName,"Nothing to see here.  Move along.")
            End If
    
        Catch ex As Exception
            hs.WriteLog(logname, "Exception " & ex.ToString)
        End Try
    End Sub

    Leave a comment:


  • sparkman
    started a topic Running Plugin Check

    Running Plugin Check

    Every once in a while, I've disabled a plugin for troubleshooting or upgrade purposes and have forgotten to turn it back on. A few hours/days/etc. later, I may notice that something is not happening that should have and then realize that I've done so. Since I'm getting older and more forgetful, I'm guessing this will happen more and more over time , so I created a script that I run on a regular schedule that compares what I've defined as should be running to what is actually running and if there's a plugin that is not active, it will send me a Pushover alert. If you don't use Pushover, you should , but you could replace that portion of the script with another notification method. Hope this helps others in the over 50 crowd . To set it up for your plugins, just edit the line Dim RequiredPlugins() As String to list the plugins that you use. Note that the name must be exactly as it appears in the PLUG-INS - MANAGE HS page, followed by a colon. Add as many as you have. Also, if you use Pushover, edit the line CO(0) to define the Pushover devices you want to send the message to, and the subsequent lines can be customized as well for the sound you want, etc.

    Code:
    Sub Main(ByVal Parms As String)
    
        Dim RequiredPlugins() As String = {"Plugin1:","Plugin2:","Z-Wave:"}
    
        Dim Debug As Boolean = False
        Dim logName As String = "Plugin Check"
        Dim NonRunningPlugins As String
    
        Try
            Dim RunningPlugins As Object = hs.GetPluginsList
            If RunningPlugins IsNot Nothing AndAlso RunningPlugins.Length > 0 Then
                ' loop thru required list
                For index As Integer = 0 To RequiredPlugins.Length - 1
                    ' search running list for this required
                    For Each RunningPlugin As String In RunningPlugins
                        If RequiredPlugins(index) = RunningPlugin Then
                            ' this plugin is running, so no longer required!
                            RequiredPlugins(index) = Nothing
                            Exit For
                        End If
                    Next
                Next
                ' format & pretty up the list
                NonRunningPlugins = String.Join("", RequiredPlugins).Replace(":", ", ").Trim()
                If NonRunningPlugins.Length > 0 Then NonRunningPlugins = Left(NonRunningPlugins,NonRunningPlugins.Length - 1)
                If Debug Then hs.WriteLog(logName,"***" & NonRunningPlugins & "***")
                If NonRunningPlugins > "" Then
                    'Do Something
                    'Send Pushover Message
                        Dim CO(8) As Object
                        CO(0) = "All Clients" 'must be matched with a device name already in the plugin or 'All Clients' CASE SENSITIVE
                        CO(1) = NonRunningPlugins 'message body
                        CO(2) = "Plugins Not Running" 'message subject
                        CO(3) = "normal" 'low/normal/high/emergency
                        CO(4) = "pushover" 'message sound from list: pushover,bike,bugle,cashregister,classical,cosmic,falling,gamelan,incoming,intermission,magic,mechanical,pianobar,siren,spacealarm,tugboat,alien,climb,persistent,echo,updown,none
                        CO(5) = Nothing
                        CO(6) = Nothing
                        CO(7) = Nothing
                        CO(8) = Nothing
                        hs.PluginFunction("Pushover 3P", "", "Pushscript", CO)
                Else
                    'All Good
                    If Debug Then hs.WriteLog(logName,"All required plugins are running")
                End If
            Else
                hs.WriteLog(logName,"Nothing to see here.  Move along.")
            End If
    
        Catch ex As Exception
            hs.WriteLogEx(logname, "Exception " & ex.ToString, "#ff0000")
        End Try
    End Sub
Working...
X