https://github.com/cytopia/check_http_expect
[sh] Nagios plugin that will check a website (behind .htacess and/or behind POST login) for an expected string or regex expression.
https://github.com/cytopia/check_http_expect
Last synced: about 1 month ago
JSON representation
[sh] Nagios plugin that will check a website (behind .htacess and/or behind POST login) for an expected string or regex expression.
- Host: GitHub
- URL: https://github.com/cytopia/check_http_expect
- Owner: cytopia
- License: mit
- Created: 2015-10-28T09:20:49.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2021-07-16T13:01:59.000Z (almost 4 years ago)
- Last Synced: 2025-01-10T21:41:55.810Z (5 months ago)
- Language: Shell
- Homepage:
- Size: 35.2 KB
- Stars: 6
- Watchers: 3
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# check_http_expect
Nagios plugin that will check a website (behind .htacess and/or behind POST login) for an expected string based on a simple string or regex expression.
[](https://travis-ci.org/cytopia/check_http_expect)
[](https://packagist.org/packages/cytopia/check_http_expect) [](https://packagist.org/packages/cytopia/check_http_expect) [](https://packagist.org/packages/cytopia/check_http_expect) [](http://opensource.org/licenses/MIT)
[](https://en.wikipedia.org/?title=POSIX)
[](https://en.wikipedia.org/?title=Bourne_shell)---
| [](https://github.com/cytopia/awesome-nagios-plugins) | Find more plugins at [Awesome Nagios](https://github.com/cytopia/awesome-nagios-plugins) |
|---|---|
| [](https://exchange.icinga.com/cytopia) | **Find more plugins at [Icinga Exchange](https://exchange.icinga.com/cytopia)** |
| [](https://exchange.nagios.org/directory/Owner/cytopia/1) | **Find more plugins at [Nagios Exchange](https://exchange.nagios.org/directory/Owner/cytopia/1)** |---
## 1. Usage
```shell
Usage: check_http_expect --url --find [--find ] [--huser ] [--hpass ] [--lurl ] [--cookie [--cookie ]] [--ldata [--ldata ]]--url Target URL
--find Find string in source of Target URL ('grep -E'-style regex allowed / can be specified multiple times)
--huser (Optional) htaccess username
--hpass (Optional) htaccess password
--lurl (Optional) Url for POST login
--ldata (Optional) POST data (can be specified multiple times)
--cookie (Optional) set cookies for request
--ua (Optional) use this user-agent instead of the default one
```## 2. Generic Examples
### 2.1 Search simple string
Check if a website contains the word `google`
```shell
$ check_http_expect --url https://google.com --find google
[OK] 1 match found for: "google".
Http version: HTTP/1.1
Http code: 302
Http info: Found
Server: GFE/2.0
Url: https://google.com
Search: google
Num matches: 1
Matches:
----------------------------------------
here
```### 2.2 Search via regex
Check if a website contains the the following regex `[0-9]+`
```shell
$ check_http_expect --url https://google.com --find '[0-9]+'
[OK] 4 matches found for: "[0-9]+".
Http version: HTTP/1.1
Http code: 302
Http info: Found
Server: GFE/2.0
Url: https://google.com
Search: [0-9]+
Num matches: 4
Matches:
----------------------------------------
302 Moved302 Moved
here.
```### 2.3 .htaccess protection
Check behind a .htaccess protected website for the string `Your site is secured`
```
$ check_http_expect --url "http://www.example.com" --find 'Your site is secured' --huser john --hpass "Password"
[ERROR] No matches found for: "Your site is secured".
Http version: HTTP/1.1
Http code: 302
Http info: Found
Server: Apache/2.4.16 (Amazon) PHP/5.5.30
Url: http://www.example.com
Search: Your site is secured
Num matches: 0
Matches:
----------------------------------------
```### 2.4 POST Login
Login to at `http://www.example.com/login.php` with POST data `usernameFieldName=John`, `passwordFieldName=pass`, `submit=1`, go to `http://www.example.com` and check for the regex `[0-9]+`
```
$ check_http_expect --url "http://www.example.com" --find '[0-9]+' --lurl "http://www.example.com/login.php" --ldata "usernameFieldName=John" --ldata "passwordFieldName=pass" --ldata "submit=1"
[ERROR] No matches found for: "[0-9]+".
Http version: HTTP/1.1
Http code: 302
Http info: Found
Server: Apache/2.4.16 (Amazon) PHP/5.5.30
Url: http://www.example.com
Search: Your site is secured
Num matches: 0
Matches:
```**Note:** htaccess and POST login can also be combined.
### 2.5 Set Cookies
Send a request with a custom cookie
```shell
$ check_http_expect --url https://google.com --find google --cookie "username=test"
[OK] 1 match found for: "google".
Http version: HTTP/1.1
Http code: 302
Http info: Found
Server: GFE/2.0
Url: https://google.com
Search: google
Num matches: 1
Matches:
----------------------------------------
here
```### 2.6 Multiple Search-Strings and different user-agent
When searching for multiple strings on the same page, its not necessary to do multiple requests.
Just specify as many `find`-parameters as you need.
You may want to change the user-agent with the parameter `ua` as well, in order to avoid undesired redirects.
```shell
$ check_hmg_http_expect --url "https://duckduckgo.com" --find "DuckDuckGo — Privacy, simplified." --find "Duck it\!" --find "NO-MATCH" --ua "curl/7.37.0"
[WARN] Not all matches found for: "DuckDuckGo — Privacy, simplified.
Duck it\!
NO-MATCH" | 'Results'=2 but expected: 3
Http version: HTTP/2
Http code: 200
Http info:
Server:
Url: https://duckduckgo.com
Search: DuckDuckGo — Privacy, simplified.
Duck it\!
NO-MATCH
Num matches: 2
Matches:
----------------------------------------
DuckDuckGo — Privacy, simplified. Duck it!
```
If only some of the specified search-strings are matched, then a warning is returned.## 3. Specific Examples
### 3.1 Log into wordpress.com
Find String in Wordpress.com dashboard
```shell
$ check_http_expect --url "https://dashboard.wordpress.com/wp-admin/" --find "Recently Published" --lurl "https://wordpress.com/wp-login.php" --ldata "log=USER@EMAIL" --ldata "pwd=PASSWORD" --ldata "rememberme=forever" --ldata "testcookie=1"
[OK] 1 match found for: "Recently Published".
Http version: HTTP/1.1
Http code: 200
Http info: OK
Server: nginx
Url: https://dashboard.wordpress.com/wp-admin/
Search: Recently Published
Num matches: 1
Matches:
----------------------------------------Recently Published
Feb 20th, 1:41 am Test
Jun 2nd, 6:10 pm Life would be so different if everyone j
Jun 1st, 10:08 pm for those of you who are still paying re
Jun 1st, 9:52 pm Having a great day so far and I hope all
May 26th, 10:37 pm In this video you will find out how to r
```## 4. Awesome
Added by the following [](https://github.com/sindresorhus/awesome) lists:
* [awesome-nagios-plugins](https://github.com/cytopia/awesome-nagios-plugins)