Check if a CSS selector exists in the HTML DOM of a specified URL.
go-check-css-selector -U <URL> -S <CSS_SELECTOR>
This plugin fetches the specified URL and checks whether the given CSS selector exists in the HTML DOM. It returns:
OKif the selector is foundCRITICALif the selector is not foundUNKNOWNif there is an error accessing the URL or parsing the HTML
go install github.com/kga/go-check-css-selector@latest
git clone https://github.com/kga/go-check-css-selector.git
cd go-check-css-selector
go build
go-check-css-selector -U https://example.com -S "div.content"
Add the following configuration to your mackerel-agent.conf:
[plugin.checks.go-check-css-selector-sample]
command = ["go-check-css-selector", "-U", "https://example.com", "-S", "div.content"]
-U, --url= URL to check (required)
-S, --selector= CSS selector to find in the DOM (required)
Check if a specific element exists on a page:
go-check-css-selector -U https://example.com -S "#main-content"
Check for a button with a specific class:
go-check-css-selector -U https://example.com -S "button.submit-btn"
Check for nested elements:
go-check-css-selector -U https://example.com -S "div.header nav.menu ul li"