Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http(s) - header-query #3568

Open
1 task done
obfusk opened this issue Aug 12, 2023 · 5 comments
Open
1 task done

http(s) - header-query #3568

obfusk opened this issue Aug 12, 2023 · 5 comments
Labels
area:monitor Everything related to monitors feature-request Request for new features to be added type:new proposing to add a new monitor

Comments

@obfusk
Copy link
Contributor

obfusk commented Aug 12, 2023

⚠️ Please verify that this feature request has NOT been suggested before.

  • I checked and didn't find similar feature request

🏷️ Feature Request Type

New Monitor

🔖 Feature description

Following up on #3299, it would be great to have a way of checking HTTP headers, specifically whether the last-modified header is less than X hours/days/weeks/whatever old.

We would probably be happy with a last-modified type that merely checks the date in that specific header isn't older than X days, but I think it makes sense to make this extensible.

cc @TheLastProject

✔️ Solution

For our use case, we'd like to be able to do something like this:

let res = await axios.request({url: "https://f-droid.org/repo/index-v1.jar", method: "HEAD"});

...
} else if (this.type === "last-modified") {
    if (new Date(res.headers['last-modified']) > Date.now() - this.seconds * 1000) {
        bean.status = UP;
    } else {
        throw new Error(...);
    }
} else if (...) {
...

However, with jsonata (already used for json-query) we should be able to do something extensible/generic like this:

...
} else if (this.type === "header-query") {
    let headers = res.headers;
    let expression = jsonata(this.jsonPath);
    let result = await expression.evaluate(headers);
    if (result.toString() === this.expectedValue) {
        bean.status = UP;
    } else {
        throw new Error(...);
    }
} else if (...) {
...

Which would allow us to use a jsonata query to check the last-modified header is less than a week old, which is exactly what we wanted :)

$toMillis(`last-modified`, '[FNn,-3], [D] [MNn,-3] [Y] [H]:[m]:[s] GMT') > $millis() - 1000 * 60 * 60 * 24 * 7

For a quick stand-alone PoC, see https://gist.github.com/obfusk/fc5e7e4e129c0e4192d8fd6f7aa90f14

❓ Alternatives

No response

📝 Additional Context

No response

@obfusk obfusk added the feature-request Request for new features to be added label Aug 12, 2023
@richie-tt
Copy link

richie-tt commented Nov 5, 2023

It would be nice to check the response headers. This could trigger an alarm when for example, the website doesn't meet the required security headers,

@CommanderStorm
Copy link
Collaborator

@kingfisher77

This comment was marked as resolved.

@CommanderStorm
Copy link
Collaborator

CommanderStorm commented Dec 31, 2023

it would be nice to open up this issue again

Cannot reproduce, this issue was never closed.

I think implementing this should be slotted after #3919 to save on neeeded effort

@stormshaker
Copy link

stormshaker commented May 12, 2024

Just chiming in that I went looking for a way to monitor my Zigbee/ethernet bridge today with Kuma, and found the status is added to the HTTP response headers, and the body reads these in javascript.

Response
HTTP/1.1 200 OK
Connection: close
Content-Encoding: gzip
Content-Length: 943
Content-Type: text/html
respValuesArr: {"VERSION":"0.2.6 (prod-solo)","connectedSocketStatus":"Yes, 1 connections","connectedSocket":"0 d 00:20:52","operationalMode":"Zigbee-to-Ethernet","ethDhcp":"On","connectedEther":"Yes","ethConnection":"Connected","ethMac":"10:06:1C:A6:D9:27","ethSpd":"100 Mbps","ethIp":"192.168.1.246","etchMask":"255.255.255.0","ethGate":"192.168.1.1","uptime":"0 d 07:38:03","deviceTemp":"39.11","hwRev":"UZG-01","espModel":"ESP32-D0WD-V3","espCores":"2","espFreq":"160","espHeapFree":"248","espHeapSize":"324","zigbeeFwRev":"20230507","zigbeeHwRev":"CC2652P7","espFlashType":"external","espFlashSize":"4","wifiMac":"10:06:1C:A6:D9:24","wifiEnabled":"No","wifiConnected":"Not connected","wifiMode":"Off","wifiSsid":"Off","wifiIp":"Off","wifiMask":"Off","wifiGate":"Off","wifiRssi":"Off","wifiDhcp":"Off","wifiModeAP":"No","wifiModeAPStatus":"Not started","wgDeviceAddr":"","wgRemoteAddr":"","wgInit":"No"}

[SNIP]
                            <tr>
                                <td>Socket client connected:</td>
                                <td data-replace="connectedSocketStatus"></td>
                            </tr>
[/SNIP]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:monitor Everything related to monitors feature-request Request for new features to be added type:new proposing to add a new monitor
Projects
None yet
Development

No branches or pull requests

5 participants