xWyatt / check_rest_api

Nagios Core plugin to check output from a RESTful JSON API
GNU General Public License v3.0
10 stars 5 forks source link

Format of API response data #23

Closed cruelnovo closed 1 year ago

cruelnovo commented 1 year ago

Is it possible to have the non scientific notation value used in the comparison? Following is the call and the response:

./check_rest_api -H http://syvo.javerity.com:8000/info -K backendTipHeight,tipHeight,difficulty -d == Info: Trying 66.94.106.235:8000... == Info: TCP_NODELAY set == Info: Connected to syvo.javerity.com (66.94.106.235) port 8000 (#0) => Send header, 0000000065 bytes (0x00000041) 0000: 47 45 54 20 2f 69 6e 66 6f 20 48 54 54 50 2f 31 GET /info HTTP/1 0010: 2e 31 0d 0a 48 6f 73 74 3a 20 73 79 76 6f 2e 6a .1..Host: syvo.j 0020: 61 76 65 72 69 74 79 2e 63 6f 6d 3a 38 30 30 30 averity.com:8000 0030: 0d 0a 41 63 63 65 70 74 3a 20 2a 2f 2a 0d 0a 0d ..Accept: /... 0040: 0a . == Info: Mark bundle as not supporting multiuse <= Recv header, 0000000017 bytes (0x00000011) 0000: 48 54 54 50 2f 31 2e 31 20 32 30 30 20 4f 4b 0d HTTP/1.1 200 OK. 0010: 0a . <= Recv header, 0000000032 bytes (0x00000020) 0000: 43 6f 6e 74 65 6e 74 2d 54 79 70 65 3a 20 61 70 Content-Type: ap 0010: 70 6c 69 63 61 74 69 6f 6e 2f 6a 73 6f 6e 0d 0a plication/json.. <= Recv header, 0000000037 bytes (0x00000025) 0000: 44 61 74 65 3a 20 4d 6f 6e 2c 20 32 36 20 53 65 Date: Mon, 26 Se 0010: 70 20 32 30 32 32 20 32 30 3a 35 31 3a 34 34 20 p 2022 20:51:44 0020: 47 4d 54 0d 0a GMT.. <= Recv header, 0000000020 bytes (0x00000014) 0000: 43 6f 6e 74 65 6e 74 2d 4c 65 6e 67 74 68 3a 20 Content-Length: 0010: 38 31 0d 0a 81.. <= Recv header, 0000000002 bytes (0x00000002) 0000: 0d 0a .. <= Recv data, 0000000081 bytes (0x00000051) 0000: 7b 22 62 61 63 6b 65 6e 64 54 69 70 48 65 69 67 {"backendTipHeig 0010: 68 74 22 3a 31 38 34 38 30 30 31 2c 22 64 69 66 ht":1848001,"dif 0020: 66 69 63 75 6c 74 79 22 3a 32 31 37 2e 34 37 33 ficulty":217.473 0030: 30 37 30 31 39 32 34 39 34 36 35 2c 22 74 69 70 07019249465,"tip 0040: 48 65 69 67 68 74 22 3a 31 38 34 38 30 30 31 7d Height":1848001} 0050: 0a . == Info: Connection #0 to host syvo.javerity.com left intact OK - 'backendTipHeight'=1.848e+06, 'tipHeight'=1.848e+06, 'difficulty'=217.473 | backendtipheight=1.848e+06 'backendTipHeight' is '1.848e+06' (OK) 'tipHeight' is '1.848e+06' (OK) 'difficulty' is '217.473' (OK) | tipheight=1.848e+06 difficulty=217.473

No matter the values for '-w' and '-c' it will always alert. I'm trying to only alarm if the backendTipHeight or tipHeight is ever == 0. So, alarm if <1. However, when i attempt to configure this it doesn't work as expected:

./check_rest_api -H http://syvo.javerity.com:8000/info -K backendTipHeight,tipHeight -c 1:,1: CRITICAL - 'backendTipHeight'=1.848e+06, 'tipHeight'=1.848e+06 | backendtipheight=1.848e+06 'backendTipHeight' is '1.848e+06' (Critical) 'tipHeight' is '1.848e+06' (Critical) | tipheight=1.848e+06

Any thoughts on how to configure the alert? Everything is great so long as it's > 0

xWyatt commented 1 year ago

Hi Matthew. The scientific notation you're seeing is just how it's being displayed back to the console with %g from fprintf() - the program is actually treating that as a number without the exponents.

Will your value ever be < 0? If not you should be able to get by with specifying a lower bound of 0 and an upper of an arbitrary value that will always be greater than backendTipHeight since these values are not inclusive unless you specify @. Example: -c 0:99999999 would alert if the value is <= 0 or >= 99999999.

xWyatt commented 1 year ago

Going to close for now - reopen if you have further issues. Thanks!