cytopia / check_http_expect
Nagios 插件,用于检查网页上的字符串/正则表达式。也可以在 .htaccess 和 POST 登录之后工作。
0.5
2018-11-05 09:22 UTC
This package is auto-updated.
Last update: 2024-09-16 19:05:54 UTC
README
Nagios 插件,用于检查网站(在 .htacess 和/或 POST 登录之后)是否包含基于简单字符串或正则表达式的预期字符串。
1. 使用方法
Usage: check_http_expect --url <url> --find <string> [--find <another string>] [--huser <user>] [--hpass <pass>] [--lurl <url>] [--cookie <cookie-string> [--cookie <cookie-string>]] [--ldata <data> [--ldata <data>]] --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. 通用示例
2.1 搜索简单字符串
检查网站是否包含单词 google
$ 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: ---------------------------------------- <A HREF=https://www.google.de/?gfe_rd=cr&ei=B9AxVr7RJerj8weKoa2IBA>here</A>
2.2 通过正则表达式搜索
检查网站是否包含以下正则表达式 [0-9]+
$ 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: ---------------------------------------- <HTML><HEAD><meta http-equiv=content-type content=text/html;charset=utf-8> <TITLE>302 Moved</TITLE></HEAD><BODY> <H1>302 Moved</H1> <A HREF=https://www.google.de/?gfe_rd=cr&ei=Q9AxVs-AAurj8weKoa2IBA>here</A>.
2.3 .htaccess 保护
检查受 .htaccess 保护网站中的字符串 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 登录
使用 POST 数据 usernameFieldName=John
、passwordFieldName=pass
、submit=1
登录到 http://www.example.com/login.php
,然后转到 http://www.example.com
并检查正则表达式 [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:
注意: htaccess 和 POST 登录也可以结合使用。
2.5 设置 Cookie
发送带有自定义 Cookie 的请求
$ 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: ---------------------------------------- <A HREF=https://www.google.de/?gfe_rd=cr&ei=B9AxVr7RJerj8weKoa2IBA>here</A>
2.6 多个搜索字符串和不同的用户代理
当在同一个页面上搜索多个字符串时,不需要进行多次请求。只需指定所需的 find
参数即可。您还可以通过参数 ua
改变用户代理,以避免不希望的重定向。
$ check_hmg_http_expect --url "https://duckduckgo.com" --find "<title>DuckDuckGo — Privacy, simplified.</title>" --find "<span class=\"logo_homepage__tt\">Duck it\!</span>" --find "NO-MATCH" --ua "curl/7.37.0" [WARN] Not all matches found for: "<title>DuckDuckGo — Privacy, simplified.</title> <span class="logo_homepage__tt">Duck it\!</span> NO-MATCH" | 'Results'=2 but expected: 3 Http version: HTTP/2 Http code: 200 Http info: Server: Url: https://duckduckgo.com Search: <title>DuckDuckGo — Privacy, simplified.</title> <span class="logo_homepage__tt">Duck it\!</span> NO-MATCH Num matches: 2 Matches: ---------------------------------------- <title>DuckDuckGo — Privacy, simplified.</title> <span class="logo_homepage__tt">Duck it!</span>
如果只有一些指定的搜索字符串匹配,则返回警告。
3. 特定示例
3.1 登录到 wordpress.com
在 WordPress.com 控制面板中查找字符串
$ 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: ---------------------------------------- <div id=activity-widget><div id=published-posts class=activity-block><h4>Recently Published</h4><ul><li><span>Feb 20th, 1:41 am</span> <a href=https://dashboard.wordpress.com/2014/02/20/test/>Test</a></li><li><span>Jun 2nd, 6:10 pm</span> <a href=https://dashboard.wordpress.com/2011/06/02/life-would-be-so-different-if-everyone-j/>Life would be so different if everyone j</a></li><li><span>Jun 1st, 10:08 pm</span> <a href=https://dashboard.wordpress.com/2011/06/01/for-those-of-you-who-are-still-paying-re/>for those of you who are still paying re</a></li><li><span>Jun 1st, 9:52 pm</span> <a href=https://dashboard.wordpress.com/2011/06/01/having-a-great-day-so-far-and-i-hope-all/>Having a great day so far and I hope all</a></li><li><span>May 26th, 10:37 pm</span> <a href=https://dashboard.wordpress.com/2011/05/26/in-this-video-you-will-find-out-how-to-r/>In this video you will find out how to r</a></li></ul></div></div></div>