KS-Soft. Network Management Solutions
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister    ProfileProfile    Log inLog in 

problem getting json value

 
Post new topic   Reply to topic    KS-Soft Forum Index -> Configuration, Maintenance, Troubleshooting
View previous topic :: View next topic  
Author Message
menno



Joined: 21 May 2010
Posts: 157

PostPosted: Fri May 12, 2023 6:06 am    Post subject: problem getting json value Reply with quote

Hi support

I am builing a test that gets the info from a json reply

The http request result in this output

http get command gives :
Code:

{"code":0,"msg":"success","time":"1683896070","data":{"degrees":{"celsius":{"time":"1683892112","unit":"","value":"6"}}}}

readable output is:

Code:

 {
    "code":0,
    "msg":"success",
    "time":"1683892176",
    "data":
    {
        "degrees":
        {
            "celsius":
            {
                "time":"1683892112",
                "unit":"",
                "value":"6"
            }
        }
    }
 }


i am interessted only in the "value":"6" line and then in this case / example the 6
We just want to check is the value is not below 1 and not higher as 10

i tried to use this help but i did not manage to get it working
https://www.ks-soft.net/cgi-bin/phpBB/viewtopic.php?t=8333&highlight=json

i played with the Tune up reply value but didn't succeed.
i tried : [('%data%' getword 1 == 'value') and ('%data%' getnumber 1 >= 9)]

I hope you can help me out here.
many thanks in advance

m
Code:
Back to top
View user's profile Send private message
KS-Soft



Joined: 03 Apr 2002
Posts: 12791
Location: USA

PostPosted: Fri May 12, 2023 10:45 am    Post subject: Reply with quote

1) HostMonitor version?
2) Test method? URL?

3) Where did you find %data% variable?
There is %HttpPage% variable, %SuggestedReply% variable.

Quote:
{"code":0,"msg":"success","time":"1683896070","data":{"degrees":{"celsius":{"time":"1683892112","unit":"","value":"6"}}}}
i am interessted only in the "value":"6" line and then in this case / example the 6
[('%data%' getword 1 == 'value') and ('%data%' getnumber 1 >= 9)]

4) There are no spaces, no CR, LF characters in this JSON string so entire string looks to "getword" operator as just 1 word

5) getnumber may help. But why did you set "getnumber 1"? I though you want to get 4th number, not first.

So if you want to set Warning or Normal test status you may try expression like
("%HttpPage%" getnumber 4 > 0) and ("%HttpPage%" getnumber 4 < 11)

Quote:
i played with the Tune up reply value but didn't succeed.
i tried : [('%data%' getword 1 == 'value') and ('%data%' getnumber 1 >= 9)]

I am confised. If you want to check value, then you want to do something depending on the value, right? Then I should ask why do you use this expression in TuneUpReply option?
Either you should use different expression and set some reply... or you should use different options like "Set Warning status if ...".

Regards
Alex
Back to top
View user's profile Send private message Visit poster's website
menno



Joined: 21 May 2010
Posts: 157

PostPosted: Fri May 12, 2023 11:09 am    Post subject: Reply with quote

Thx Alex !
for your info :
-HM version 13.50
-Test method : URL test ( also tried HTTP )

The solution you provided is good enough so i will use that.

Again many Thanks
m
Back to top
View user's profile Send private message
KS-Soft



Joined: 03 Apr 2002
Posts: 12791
Location: USA

PostPosted: Fri May 12, 2023 12:05 pm    Post subject: Reply with quote

You are welcome

Regards
Alex
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    KS-Soft Forum Index -> Configuration, Maintenance, Troubleshooting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group

KS-Soft Forum Index