Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


  • 0

[VD] Scene & VD Debug Watchdog 1.1


AutoFrank

Question

Hi 

 

UPDATED 1.1

 

UPDATED THIS VD FROM A SCENE WATCHDOG TO A SCENE & VIRTUAL DEVICE WATCHDOG

Hopefully this will be a useful little VD to some users

It was inspired by a comment made by @tinman (I think) 

 

This VD Enables a user to scan all scene and virtual device DEBUG MESSAGES and trigger on predefined key words in the debug messages.

This may be useful to see if a scene develops an error or perhaps you are just looking for a keyword for a different reason

  • All scenes and virtual devices are included by default
  • Specific scenes and virtual device id's can be flagged to exclusion
  • Separate watch lists for scenes and virtual devices
  • A watchdog report is sent for all matches identified.
  • Can be sent via email or smart message hub
  • You get one email or message per id flagged ( not per watch word)
  • It will send message if no match in either vd or scene is found (added in v 1.1)
  • Suggested icon included below
  •  

              

Please login or register to see this image.

/monthly_2017_07/watchdog.png.053d2b2b2433c2a01bf526af79058585.png" alt="watchdog.png.053d2b2b2433c2a01bf526af79058585.png" />

 

Note: If you use the Smart Message Hub please add that scene ID into the exclusion list as that scene will be 
flagged by the watchdog after the first use.
  
This can be run on demand or on a schedule using Main Scene by @Sankotronic or similar.
I run it on a schedule once per day

 

Installation 

  • Import the VD
  • Configure the following as required

Please login or register to see this code.

  • Place on a scheduler if required

 

The VD has a status label and when it was last run

 

 watch.PNG.3ba1125c1bf4c5cba0c2c5b4aa2036df.PNGwatch1.PNG.b31653c26fea066e89d95fea10dbf911.PNGwatch2.PNG.07ad9270adbd029e6bfb9fb4d6a46d4e.PNG       

 

and this is what the report looks like on pushover

 

Please login or register to see this attachment.

 

VD attached

 

 

 

 

 

Please login or register to see this attachment.

Edited by AutoFrank
Link to comment
Share on other sites

Recommended Posts

  • 0
  • Inquirer
  • 2 minutes ago, Bodyart said:

    Hi @AutoFrank,

     

    coul'd you please make your debug picture a bit greater, because they are hardly readable.

     

    oops @Bodyart :oops:

    Is this better  ?

     

    Please login or register to see this attachment.

    Link to comment
    Share on other sites

    • 0

    Beautiful and perfectly readable :-) Thanks a lot.

    Not everybody (meaning me in this case) had such good eyes ...

    Edited by Bodyart
    Link to comment
    Share on other sites

    • 0

    I bet "found T_END at character 1" could be caused by json.decode. I can't reproduce it, can you tell me what caused the red error? I quite sure the script that calls the json.decode  (or other function that raises an exception) does not handle the error (using pcall or xpcall statement wrapper). So, the error goes up one level, and that level is the interpreter above your script.  Technically speaking it's no longer a debug output, but a crash of the lua program. I'm speculating a bit, I've never tried to capture "red debug text". I try to "not to make red debug text" :-):-):-) 

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • 2 minutes ago, petergebruers said:

    I bet "found T_END at character 1" could be caused by json.decode. I can't reproduce it, can you tell me what caused the red error? I quite sure the script that calls the json.decode  (or other function that raises an exception) does not handle the error (using pcall or xpcall statement wrapper). So, the error goes up one level, and that level is the interpreter above your script.  Technically speaking it's no longer a debug output, but a crash of the lua program. I'm speculating a bit, I've never tried to capture "red debug text". I try to "not to make red debug text" :-):-):-) 

     

    Hi @petergebruers

     

    Thanks for the reply - It is caused by a http call where the json response is nil and this can sometimes happen if my sonos http api becomes unavailable when my VD is updating.

    I wrote the code a while back and have never revisited to harden it  

    This was the code 

     

    Please login or register to see this code.

     

    and the fix is a simple check for nil before trying to utilise elements of the response table parameters

     

    Please login or register to see this code.

    (or I could have captured the error response and triggered from that )

     

    I should have been clearer (sorry) in that I knew what the fix was but was using it as an example that I was trying to look for with my new watchdog

    I have found some scene that can sometimes start to fail because something else becomes unavailable

    In may cases this is because my code isn't 'strong' enough to catch all possible scenarios and I was going to use the VD to surface these faster so I could fix them 

     

    _f

     

     

    Link to comment
    Share on other sites

    • 0

    @AutoFrank that's OK. Testing for "nil" is very good, I'd certainly do that, so you can give a meaningful error message and attempt to recover from this error without going into infinite or very fast loops, causing even more trouble. To catch ANY kind of error from a function call, you need something even better than a nil test...

     

    First, let's cause a weird error. Please run this scene:

     

    Please login or register to see this code.

    What do you observe?

     

    You get "Bad JSON decode script start." which is to be expected.

    Then you get "line 61: attempt to perform arithmetic on field 'active_state' (a nil value)" - this is weird, there is no line 61, at least not in THIS script.

    You don't get "Bad JSON decode script end.". It appears that the script stopped working, at line 2 or 3...

     

    Let's fix this! Try this improved version:

     

    Please login or register to see this code.

     

    This is what I call "wrap the json.decode in a pcall". The output of this script is:

     

    Please login or register to see this code.

    See, the "line 61" reference makes sense after all?

    And... The script ran till the end!

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • 1 minute ago, petergebruers said:

    @AutoFrank that's OK. Testing for "nil" is very good, I'd certainly do that, so you can give a meaningful error message and attempt to recover from this error without going into infinite or very fast loops, causing even more trouble. To catch ANY kind of error from a function call, you need something even better than a nil test...

     

    First, let's cause a weird error. Please run this scene:

     

    Please login or register to see this code.

    What do you observe?

     

    You get "Bad JSON decode script start." which is to be expected.

    Then you get "line 61: attempt to perform arithmetic on field 'active_state' (a nil value)" - this is weird, there is no line 61, at least not in THIS script.

    You don't get "Bad JSON decode script end.". It appears that the script stopped working, at line 2 or 3...

     

    Let's fix this! Try this improved version:

     

    Please login or register to see this code.

     

    This is what I call "wrap the json.decode in a pcall". The output of this script is:

     

    Please login or register to see this code.

    See, the "line 61" reference makes sense after all?

    And... The script ran till the end!

     

    @petergebruers

     

    yes, that's a better approach and as it puts a more meaningful error in the [DEBUG] message I can 'watch for that periodically 

    I'll see later how I can incorporate that in my code 

     

    Thanks for sharing...

    Link to comment
    Share on other sites

    • 0
    1 hour ago, AutoFrank said:

     

    Hi @Sankotronic

    Is the type you are trying to match against above (type = "ERROR")  for a DEBUG message  of a (red) ERROR message (see below)

    Please login or register to see this attachment.

     

    Thanks

     

     

    Here is explanation how to setup Watchdog scene from old version:

    Please login or register to see this code.

    Don't know why is this explanation removed from last version.

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • 4 minutes ago, Sankotronic said:

     

    Here is explanation how to setup Watchdog scene from old version:

    Please login or register to see this code.

    Don't know why is this explanation removed from last version.

     

    Thanks @Sankotronic, it looks like there is a way to capture the red message in a VD but it doesn't exist in scenes anymore

    Please login or register to see this code.

    I must search the api json a bit more and see if I can find it

    Link to comment
    Share on other sites

    • 0

    My VD's that I setup in Watchdog scene are usually restarted everyday early in the morning. Also Main scene was restarted every morning at the moment when I made it to add delay to align execution to be exactly at xx:xx:00. This was necessary because time on HC2 is still drifting so I have Sync clock VD that first sync time to internet server every day at 02:00 o'clock and then Main scene aligns it's execution at 02:10 o'clock to be exactly when seconds are on 0.

     

    For VD's I really don't know why have to be restarted and will investigate when I come back home. What I think is that VD main loop is not really executed at specified interval, but sometimes that interval is longer. For Main scene I had to extend time when it is checked by Watchdog scene to give enough time for that time alignment.

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • 30 minutes ago, Sankotronic said:

    My VD's that I setup in Watchdog scene are usually restarted everyday early in the morning. Also Main scene was restarted every morning at the moment when I made it to add delay to align execution to be exactly at xx:xx:00. This was necessary because time on HC2 is still drifting so I have Sync clock VD that first sync time to internet server every day at 02:00 o'clock and then Main scene aligns it's execution at 02:10 o'clock to be exactly when seconds are on 0.

     

    For VD's I really don't know why have to be restarted and will investigate when I come back home. What I think is that VD main loop is not really executed at specified interval, but sometimes that interval is longer. For Main scene I had to extend time when it is checked by Watchdog scene to give enough time for that time alignment.

     

    Hi @Sankotronic

    it's very strange that the VD has to be constantly restarted

    I have a few with main loops that run constantly and I had one that stopped periodically and that was because of poor coding on my side which Peter has given me a good solution (pcall for json.decode)

    I had a few main loops that I converted to upgrade button with Main Scene 

    Other that than all of my VD's are working fine...including the VD's I got from you ...SunSet/Sunrise/Timer/weather 1.0

     

    I'd be interested in what you find

     

    Link to comment
    Share on other sites

    • 0

    HI @AutoFrank, thanks for the VD. It's very welcom while migration all my HCL scenes to HC2 Lua scenes.
    Is it possible there is a problem for reporting the 'watch flags' in a mail if the string was only found once in a scene?
    See below screenshots. For 1 it is working if it occurs frequently. The other one, where it is only once in the debug, the watch flags are not reported.

    Strings to search for are 'CRITICAL' and 'MAJOR'. The white screen below the debug window is the content of the mail.

     

     

    Please login or register to see this attachment.

    Please login or register to see this attachment.

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • 10 hours ago, wpeeters said:

    HI @AutoFrank, thanks for the VD. It's very welcom while migration all my HCL scenes to HC2 Lua scenes.
    Is it possible there is a problem for reporting the 'watch flags' in a mail if the string was only found once in a scene?
    See below screenshots. For 1 it is working if it occurs frequently. The other one, where it is only once in the debug, the watch flags are not reported.

    Strings to search for are 'CRITICAL' and 'MAJOR'. The white screen below the debug window is the content of the mail.

     

     

    Please login or register to see this attachment.

    Please login or register to see this attachment.

     

    Hi @wpeeters

    I'm glad its helping (partially :-) )

    I'm wasn't seeing that issue but will take a look later when I get home

     

    There are 4 sleeps in the code (2 for scenes and 2 for virtual devices)

    Could you make all these fibaro:sleep(1000) and see if that makes any difference

     

    Thanks

    _f

     

     

     

    Link to comment
    Share on other sites

    • 0

    @AutoFrank. No, changing all sleeps to 1000 does not solve it. I also compared strings between in both scenes and changed both to opposite string (critical to major and major to critical). It does not help.
    Thanks for looking at it.

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • 4 minutes ago, wpeeters said:

    @AutoFrank. No, changing all sleeps to 1000 does not solve it. I also compared strings between in both scenes and changed both to opposite string (critical to major and major to critical). It does not help.
    Thanks for looking at it.

    @wpeeters

    could you send me the debug output you expect and I'll recreate that later and see if my VD triggers 

    Is is just scenes or vd's as well ?

    Link to comment
    Share on other sites

    • 0

    @AutoFrank
    I only tested with scenes. Not yet with VD.

     

    Scene debug action:

    info("red", "[CRITICAL] AlarmCheck failed. Set runningfail to 1.");


    Based upon the other scene which is working:
    info("red", "[MAJOR] Condition sceneactivation not matching")

    I expect something to see as:

    Please login or register to see this code.

    Link to comment
    Share on other sites

    • 0

    I'm not saying this is your issue, but I'm surprised by the number of backslashes...

    Link to comment
    Share on other sites

    • 0

    @petergebruers. yes, I noticed them as well but I have no idea why.
    This is my debug setup:
     

    local debug = false --set to false to stop debug messages --> log
    local logInfo = true --set to false to stop debug messages --> info
    function log(color, message) if debug then fibaro:debug(string.format('<%s style="color:%s;">%s</%s>', "span", color, message, "span"));  end; end
    function info(color, message) if logInfo then fibaro:debug(string.format('<%s style="color:%s;">%s</%s>', "span", color, message, "span"));  end; end

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Hi @wpeeters

     

    I replicated the issue using email

    leave it with me as I need to do some more checks

     

    Thanks

     

     

    Update - I found a bug that may or ma not have been your problem

    Essentially I was missing one count of a match within a scene 

     

    So when you reported you had one received one watch match when you really should have two matches then - that's fixed

    I've updated the VD in the first post to 1.0d 

     

    Please give that a try

     

     

    With regard to the backslashes - thats an odd one and something to do with the way the message the contains html formatting is sent by the HC2 email server

     

    I tried a few experiments

     

    If I use this in a scene

     

    Please login or register to see this code.

    then the result over email is

    Please login or register to see this code.

    and it doesn't matter if it gmail or private email

     

    Now if I execute this in a scene (which is equivalent to your function code)

    Please login or register to see this code.

    and run it 6 times 

     

    Please login or register to see this attachment.

     

    Then I received this in email

     

    Please login or register to see this code.

    yet if I look at it through /docs I get the expected html tags and the same with a browsers api call

     

    Please login or register to see this attachment.

        

    Please login or register to see this attachment.

     

    Pushover seem to interpret the html better as the result is

     

    Please login or register to see this attachment.

     

    In summary I fixed the bug (thanks for finding) but I don't have a solution to the unusual tags seen over email

     

    _f

     

     

     

     

     

     

     

     

     

     

     

    Edited by AutoFrank
    Link to comment
    Share on other sites

    • 0

    Here's one to spoil your weekend - nudge your brain. Try one of the following characters in a message and see if your scene can match it (and...your email/pushover/browser can receive it...)

     

    &

    <

    >

    "

    ° (like in ° Celsius)

     

    I could do that, but I'm enjoying a nice beer and I would be unable to determine if an anomaly was due to the beer or the code...

    I know, it's early, but I am celebrating a temperature drop from 34 °C to 25 °C.

    See where I got my inspiration? Degrees, as in "alcohol", "Celsius", "Fahrenheit" ;-)

     

    Spoiler alert:

    & < > " are special characters in html.

    ° is not available in ASCII, but it exist in the oh-so-common Latin 1 aka ISO-8859-1 encoding, but because it has a 8-bit value of 176 (decimal) it is invalid in the oh-so-common UTF-8 encoding. Fun ensues.

     

    Spoiler alert 2:

    This code will print in colour and fixes the issues with html text derailing on certain characters:

     

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Answer this question...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

    ×
    ×
    • Create New...