It is currently September 21st, 2020, 11:50 am

Website status checking

Get help with installing and using Rainmeter.
Jimmy401
Posts: 6
Joined: September 9th, 2020, 7:31 am

Website status checking

Post by Jimmy401 »

Hi, I've got a few websites which I own that I want to keep tabs on how much up / down time they have. I decided doing a simple webparse of the title was easiest and saving result to a text file. I set this up and it works great.

My only problem / niggle with this is that each time the skin is loaded it initially returns a "false" result and then a second later it corrects this to the proper value. I presume it's related to how the webparser runs, if anyone has any suggestions on how to work around this it would be greatly appreciated.

Here is basic code example of what I am doing.

Code: Select all

[Rainmeter]
Update=1000

[Variables]
webURL=https://www.google.com
LogFile=site.log
LocalLog=#CURRENTPATH#site.log
Font=Arial
FCL=FFFFFF
FCD=13A7C7
GreenFF = 7CFC00
RedFF = FF0000
FSize = 14

[StyleLabel]
Meter=String
FontFace=#Font#
FontColor=#FCD#
FontSize=#FSize#
FontEffectColor=20,20,20,125
StringEffect=Shadow
StringAlign=Left
Antialias=1

[WebMeasure]
Measure=Webparser
URL=#webURL#
RegExp=(?siU)<title>(.*)</title>
StringIndex=1
IfMatch=Google
IfMatchAction=[!SetOption WebMeter Text "Good"][!SetOption WebMeter FontColor #GreenFF#]
IfNotMatchAction=[!SetOption WebMeter Text "Down!"][!SetOption WebMeter FontColor #RedFF#]
IfMatchMode=1
OnChangeAction=[!CommandMeasure "MeasureLuaScript" "LogState(1)"]

[WebsiteLabel]
Meter=String
MeterStyle=StyleLabel
x=0
Text=Google:

[WebMeter]
Meter=String
MeterStyle=StyleLabel
MeasureName=WebMeasure
x=5R
Text=Title: %1

mak_kawa
Posts: 867
Joined: December 30th, 2015, 9:47 am

Re: Website status checking

Post by mak_kawa »

Hi Jimmy401

The reason is that when the IfMatch evaluation is launched, [WebMeasure] is accessing the site and has no value yet, so IfMatch is failed.

To avoid this, set another measure for IfMatch evaluation, and it is enabled with FinishAction in the [WebMeasure], like as;

Code: Select all

[Rainmeter]
Update=1000

[Variables]
webURL=https://www.google.com
LogFile=site.log
LocalLog=#CURRENTPATH#site.log
Font=Arial
FCL=FFFFFF
FCD=13A7C7
GreenFF = 7CFC00
RedFF = FF0000
FSize = 14

[StyleLabel]
Meter=String
FontFace=#Font#
FontColor=#FCD#
FontSize=#FSize#
FontEffectColor=20,20,20,125
StringEffect=Shadow
StringAlign=Left
Antialias=1

[WebMeasure]
Measure=Webparser
URL=#webURL#
RegExp=(?siU)<title>(.*)</title>
StringIndex=1
FinishAction=[!EnableMeasure WebStatus]

[WebStatus]
Measure=String
String=[WebMeasure]
IfMatch=Google
IfMatchAction=[!SetOption WebMeter Text "Good"][!SetOption WebMeter FontColor #GreenFF#]
IfNotMatchAction=[!SetOption WebMeter Text "Down!"][!SetOption WebMeter FontColor #RedFF#]
;IfMatchMode=1
;OnChangeAction=[!CommandMeasure "MeasureLuaScript" "LogState(1)"]
DynamicVariables=1
Disabled=1

[WebsiteLabel]
Meter=String
MeterStyle=StyleLabel
x=0
Text=Google:

[WebMeter]
Meter=String
MeterStyle=StyleLabel
x=5R
Text="Loading..."
mak_kawa
Posts: 867
Joined: December 30th, 2015, 9:47 am

Re: Website status checking

Post by mak_kawa »

Hi Jimmy401

But I think... by this method, if the site is down, status text is forever "Loading...", and "Down!" status text is never displayed...?

Probably, it is necessary that the OnConnectErrorAction has to be used, I think.
Jimmy401
Posts: 6
Joined: September 9th, 2020, 7:31 am

Re: Website status checking

Post by Jimmy401 »

This is brilliant!!

I will force a false and see if it gets stuck "loading" and try your suggestion

Thank you!
User avatar
balala
Rainmeter Sage
Posts: 11372
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Website status checking

Post by balala »

mak_kawa wrote: September 9th, 2020, 8:24 am The reason is that when the IfMatch evaluation is launched, [WebMeasure] is accessing the site and has no value yet, so IfMatch is failed.

To avoid this, set another measure for IfMatch evaluation, and it is enabled with FinishAction in the [WebMeasure], like as;

Code: Select all

[Rainmeter]
Update=1000

[Variables]
webURL=https://www.google.com
LogFile=site.log
LocalLog=#CURRENTPATH#site.log
Font=Arial
FCL=FFFFFF
FCD=13A7C7
GreenFF = 7CFC00
RedFF = FF0000
FSize = 14

[StyleLabel]
Meter=String
FontFace=#Font#
FontColor=#FCD#
FontSize=#FSize#
FontEffectColor=20,20,20,125
StringEffect=Shadow
StringAlign=Left
Antialias=1

[WebMeasure]
Measure=Webparser
URL=#webURL#
RegExp=(?siU)<title>(.*)</title>
StringIndex=1
FinishAction=[!EnableMeasure WebStatus]

[WebStatus]
Measure=String
String=[WebMeasure]
IfMatch=Google
IfMatchAction=[!SetOption WebMeter Text "Good"][!SetOption WebMeter FontColor #GreenFF#]
IfNotMatchAction=[!SetOption WebMeter Text "Down!"][!SetOption WebMeter FontColor #RedFF#]
;IfMatchMode=1
;OnChangeAction=[!CommandMeasure "MeasureLuaScript" "LogState(1)"]
DynamicVariables=1
Disabled=1

[WebsiteLabel]
Meter=String
MeterStyle=StyleLabel
x=0
Text=Google:

[WebMeter]
Meter=String
MeterStyle=StyleLabel
x=5R
Text="Loading..."
I'd add only one option to the above code: an OnConnectErrorAction=[!EnableMeasure WebStatus] option to the [WebMeasure] measure. If you're using only the FinishAction, if the connection fails, the skin won't indicate anything, because you don't get enabled the [WebStatus] measure. With the above OnConnectErrorAction option you do this as well and you'll see the real status of the site, no matter if the site is up or down.
Jimmy401
Posts: 6
Joined: September 9th, 2020, 7:31 am

Re: Website status checking

Post by Jimmy401 »

I did test and yes the onconnectionerroraction was needed.

however unless I missed something when altering my code, in my log file it's only registering once on refresh But it's stating "loading..." rather than Down or Good.

ideally it should register current sites actual state
mak_kawa
Posts: 867
Joined: December 30th, 2015, 9:47 am

Re: Website status checking

Post by mak_kawa »

Hi Jimmy401

I am not sure... but did you remove ";" at the head of OnChangeAction in [WebStatus]? I have inserted it for my testing without the script file.
Jimmy401
Posts: 6
Joined: September 9th, 2020, 7:31 am

Re: Website status checking

Post by Jimmy401 »

I can confirm, the script is nothing fancy. it just grabs the text from [WebMeter] writes out a datetime value and the text value.

it's a big improvement that it's only triggering once now on load, just getting wrong value
Jimmy401
Posts: 6
Joined: September 9th, 2020, 7:31 am

Re: Website status checking

Post by Jimmy401 »

now that it's only triggering once on load, I will probably look at re-writing my lua... perhaps there is a more easier / efficient way to do this.
User avatar
balala
Rainmeter Sage
Posts: 11372
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Website status checking

Post by balala »

Jimmy401 wrote: September 9th, 2020, 10:01 am now that it's only triggering once on load, I will probably look at re-writing my lua... perhaps there is a more easier / efficient way to do this.
Please post the current and complete code of your skin.