Cloud Native应用交付

  • 首页
  • 关于本站
  • 个人介绍
  • Downloads
  • Repo
    • Github
    • Container
  • F5
    • F5 Python SDK
    • F5-container
    • F5-LBaaS
  • 社交
    • 联系我
    • 微信/微博
    • 公众号
    • 打赏赞助
行至水穷处 坐看云起时
Cloud Native Application Services: cnadn.net
  1. 首页
  2. F5技术
  3. 正文

一个很强大很强大的超级http monitor,可惜没怎么看懂

2008年08月6日 7784点热度 0人点赞 0条评论
Super HTTP Monitor

Enter a topic name to show or a new topic name to create; then press Enter

.

Contributed by: kirkbauer

Description

Super HTTP supports GET and POST requests, HTTP 1.0 and 1.1, Host headers, User-Agent headers, HTTP and HTTPS. It supports cookies. It supports authentication (basic, digest, and ntlm). It supports checking through a proxy. Most notably it supports chains of HTTP requests with cookie preservation between them, which I think will be very useful for LTM and GTM allowing you to validate end-to-end functionality.

Note that this monitor will do just about whatever you need, but if you just want to a simple HTTP monitor try the built-in monitor first. Although this is fairly efficient (i.e. doesn't do more work than it needs to) it can never be anywhere as efficient as the built-in monitor.

Implementation

Create a new file containing the code below in /usr/bin/monitors on the LTM filesystem. Permissions on the file must be 700 or better, giving root rwx access to the file. See comments within the code for documentation.

Monitor Source

1
2
3
4
5
6
7
<font face="Arial">#!/bin/bash# (c) Copyright 2007 F5 Networks, Inc.# Kirk Bauer# Version 1.1, Mar 11, 2007# Revision History# 3/11/07: Version 1.1: Added ability for multiple regexes in MATCH_REGEX# 2/28/07: Version 1.0.1: Initial Release# When defining an external monitor using this script, the argument# field may contain the path for the request.  In addition a large# number of variables may be defined as described below.# # The argument field can contain an optional path for the request,# if nothing is specified the default path of / is assumed.  This# is also where you can put query parameters.  Some examples:#    /index.asp#    /verify_user.html?user=testuser ## This script can retrieve a chain of URLs.  This is useful for two# scenarios.  The first is if you want to check a number of different# pages on a site, you can use one custom monitor that checks all of# them instead of defining a bunch of separate monitors.## The other scenario is when you want to perform a test that requires# more than one page in sequence, such as something that tracks state# with cookies.  In order to do a test login on some sites, for example,# you must first go to one URL where you are assigned a cookie, then# you must login through another URL with that cookie along with your# username/password.  This script automatically stores and sends cookies# for chains of requests.## The next section describes per-request variables.  These are options # that can be specified a number of times for a number of separate# requests.  In the most basic case, you must specify the URI_PATH for # each request.  The only exception is that the last path is taken from# the &quot;argument&quot; string if URI_PATH is not specified.  So, to do three# requests in a row, specify:#    URI_PATH_1=/path/to/request1#    STATUS_CODE_1=200#    URI_PATH_2=/path/to/request2#    STATUS_CODE_2=200#    URI_PATH=/path/to/request3#    MATCH_REGEX=&quot;you are logged in&quot;# # It is important to understand that there is always at least one# request and that last request uses variables with no number appended# to them.  All other requests are done in numerical order before that# last request.  If you have more than 10 requests you need to use# 2-digit numbers instead of 1 in the example above.############################################################### Per-request Variables# (names provided are for the last (possibly only) request,#  for other requests append a _# on the end as described#  above).##############################################################  Define the request:#     URI_PATH: the full path you want to request, such as /index.html.#        This is required for every request, except that it need not#        be defined for the last (sometimes onyl) request if you specify #        the path in the &quot;argument&quot; field.  You may include a query string#        at the end, like /index.html?test=true#     QUERY_STRING: Y
 
ou may specify the GET que
ry string here instead of#        appending it to the URI_PATH.  Example: #           name1=value1&amp;name2=value2#     NODE_ADDR: The IP address to connect to.  By default this will be#        the pool member IP that is being checked.  Can also be a hostname#        if DNS resolution works on the BIG-IP.#     NODE_PORT: The port to connect to.  By default this will be the#        port of the pool member being checked.#     PROTOCOL: Either http or https.  If not specified, assumed to be #        http unless the port is 443.#     POST_DATA: You may define post data to make this a POST request,#        such as: #           name1=value1&amp;name2=value2#     HOST_HEADER: The host header to send to the remote server.  Default#        will be the value of NODE_ADDR.#     REFERER: The referer URL to send in the request (this variable is#        misspelled just like the HTTP header is).##  Authentication options for each request:#     USERNAME: provide this username to the webserver#     PASSWORD: provide this password to the webserver#     AUTHTYPE: &quot;basic&quot;, &quot;digest&quot;, or &quot;ntlm&quot; (default is basic)##  The following variables may be defined and determine what constitutes#  an &quot;up&quot; status.  If none of these are specified, the script will return#  &quot;up&quot; only if the web server returns a status of 200 (OK).  Any or all#  of these may be specified.#     HTTPS_HOSTNAME: you may optionally specify the hostname that the#        certificate should present for https checks.#     STATUS_CODE: numerical status code to match#     NOT_STATUS_CODE: numerical status code that shouldn't be matched#     MATCH_REGEX: regular expression that should be matched in the headers#        or body.  OPTIONAL: multiple regexes to match may be specified using#        the format:#           MATCH_REGEX = &amp;regex1&reg;ex2&reg;ex3#        If using multiple regexes, you must start the string with &amp; and#        the regexes themselves cannot contain the &amp; character#     NOT_MATCH_REGEX: regular expression that should not be matched in the#        headers or body.  ############################################################### Cookies############################################################## You can set any number of cookies by specifying one or more variables# named COOKIE_Name.  So if you set the variables COOKIE_country = usa# and COOKIE_language = en, then the cookie string would be# &quot;Cookie: country=usa; language=en&quot;.  These cookies will be sent for# every request.  If you are doing multiple requests then any cookies# sent by the server will replace any existing cookie of the same name# in future requests.  This script does not consider domain or path# but instead just sends all cookies for all requests.############################################################### Global Variables##############################################################  HTTP/HTTPS Options (apply to all requests):#     USER_AGENT: set to the user agent string you want to send.#        Default is something similar to:#        curl/7.15.3 (i686-redhat-linux-gnu) libcurl/7.15.3 OpenSSL/0.9.7i zlib/1.1.4#     HTTP_VERSION: set to &quot;1.0&quot; or &quot;1.1&quot;, defaults to 1.1.#     SSL_VERSION: set to &quot;tlsv1&quot;, &quot;sslv2&quot;, or &quot;sslv3&quot;.#     CIPHERS: override SSL ciphers that can be used (see &quot;man#        ciphers&quot;), default is &quot;DEFAULT&quot;.##  Global Proxy Settings (optional):#     PROXY_HOST: IP address of the proxy to use (or hostname if DNS resolution works)#     PROXY_PORT: Port to connect to on the proxy (required if PROXY_HOST is specified)#     PROXY_TYPE: &quot;http&quot;, &quot;socks4&quot;, or &quot;socks5&quot; (defaults to http)#     PROXY_AUTHTYPE: &quot;basic&quot;, &quot;digest&quot;, or &quot;ntlm&quot; (basic is default if a username is specified)#     PROXY_USERNAME: username to provide to the proxy#     PROXY_PASSWORD: password to provide to the proxy##  Other Variables:#     LOG_FAILURES: set to &quot;1&quot; to enable logging of failures which will #        log monitor failures to /var/log/ltm (viewable in the GUI under#        System -&gt; Logs -&gt; Local Traffic(tab)#     LOG_COOKIES: set to &quot;1&quot; to log cookie activity to /var/log/ltm (also#        logs each request as it is made).#     DEBUG: set to &quot;1&quot; to create .output and .trace files in /var/run for#        each request for debugging purposes.# Collect arguments global_node_ip=$(echo &quot;$1&quot; | sed 's/::ffff://')global_port=&quot;${2:-80}&quot;[ -z &quot;$URI_PATH&quot; ] &amp;&amp; URI_PATH=&quot;${3:-/}&quot;# Handle PID filepidfile=&quot;/var/run/$MON_TMPL_NAME.$global_node_ip.$global_port.pid&quot;tmpfile=&quot;/var/run/$MON_TMPL_NAME.$global_node_ip.$global_port.tmp&quot;[ -f &quot;$pidfile&quot; ] &amp;&amp; kill -9 $(cat $pidfile) &gt;/dev/null 2&gt;&amp;1rm -f &quot;$pidfile&quot; ; echo &quot;$$&quot; &gt; &quot;$pidfile&quot;rm -f &quot;$tmpfile&quot;fail () {   [ -n &quot;$LOG_FAILURES&quot; ] &amp;&amp; [ -n &quot;$*&quot; ] &amp;&amp; logger -p local0.notice \      &quot;$MON_TMPL_NAME($global_node_ip:$global_port): $*&quot;   rm -f &quot;$tmpfile&quot;   rm -f &quot;$pidfile&quot;   exit 1}make_request () {   # First argument is blank for last request or &quot;_#&quot; for others   local id=&quot;$1&quot;   # Collect the arguments to use for this request, first start with ones   # that have default values if not specified   local node_ip=&quot;$global_node_ip&quot;   [ -n &quot;$(eval echo \$NODE_ADDR$id)&quot; ] &amp;&amp; node_ip=&quot;$(eval echo \$NODE_ADDR$id)&quot;   local port=&quot;$global_port&quot;   [ -n &quot;$(eval echo \$NODE_PORT$id)&quot; ] &amp;&amp; port=&quot;$(eval echo \$NODE_PORT$id)&quot;   local protocol=&quot;http&quot;   [ &quot;$port&quot; -eq &quot;443&quot; ] &amp;&amp; protocol=&quot;https&quot;   [ -n &quot;$(eval echo \$PROTOCOL$id)&quot; ] &amp;&amp; protocol=&quot;$(eval echo \$PROTOCOL$id)&quot;   # Now the rest come straight from the environment variables   local authtype=&quot;$(eval echo \$AUTHTYPE$id)&quot;   local username=&quot;$(eval echo \$USERNAME$id)&quot;   local password=&quot;$(eval echo \$PASSWORD$id)&quot;   local host_header=&quot;$(eval echo \$HOST_HEADER$id)&quot;   local referer=&quot;$(eval echo \$REFERER$id)&quot;   local uri_path=&quot;$(eval echo \$URI_PATH$id)&quot;   local query_string=&quot;$(eval echo \$QUERY_STRING$id)&quot;   [ -n &quot;$query_string&quot; ] &amp;&amp; query_string=&quot;?$query_string&quot;   local post_data=&quot;$(eval echo \$POST_DATA$id)&quot;   local https_hostname=&quot;$(eval echo \$HTTPS_HOSTNAME$id)&quot;   local status_code=&quot;$(eval echo \$STATUS_CODE$id)&quot;   local not_status_code=&quot;$(eval echo \$NOT_STATUS_CODE$id)&quot;   local match_regex=&quot;$(eval echo \$MATCH_REGEX$id)&quot;   local not_match_regex=&quot;$(eval echo \$NOT_MATCH_REGEX$id)&quot;   # Determine what we are checking for   [ -z &quot;$match_regex&quot; ] &amp;&amp; [ -z &quot;$not_match_regex&quot; ] &amp;&amp; \      [ -z &quot;$status_code&quot; ] &amp;&amp; [ -z &quot;$not_status_code&quot; ] \      &amp;&amp; status_code=200   [ -n &quot;$https_hostname&quot; ] &amp;&amp; [ &quot;$protocol&quot; == &quot;https&quot; ] &amp;&amp; {      # The cert will contain a hostname but curl is going by IP       # so it will fail but give us the hostname in the error      local actual_ssl_hostname=$(curl $global_args --cacert \         '/config/ssl/ssl.crt/ca-bundle.crt' \         &quot;$protocol://$node_ip:$port$uri_path$query_string&quot; \         2&gt;&amp;1 | sed -n \         &quot;s/^.*SSL: certificate subject name '\(.*\)' does not match target host name.*$/\1/p&quot;)      [ &quot;$actual_ssl_hostname&quot; == &quot;$https_hostname&quot; ] || fail \         &quot;HTTPS Hostname '$actual_ssl_hostname' does not match HTTPS_HOSTNAME$id=$https_hostname&quot;   }   # Determine argument string for curl   local args=&quot;&quot;   [ -n &quot;$host_header&quot; ] &amp;&amp; args=&quot;$args --header 'Host: $host_header'&quot;   [ -n &quot;$referer&quot; ] &amp;&amp; args=&quot;$args --referer '$referer'&quo
 
 
t;   [ -n &quot;$post_data&quot; ] &amp;&amp; args=&quot;$args --data '$post_data'&quot;   # IP used in URL will never match hostname in cert, use HTTPS_HOSTNAME to check separately   [ &quot;$protocol&quot; == &quot;https&quot; ] &amp;&amp; args=&quot;$args --insecure&quot;   [ -n &quot;$DEBUG&quot; ] &amp;&amp; args=&quot;$args --trace-ascii '$tmpfile.trace$id'&quot;   [ -n &quot;$username&quot; ] &amp;&amp; {      # Specify authentication information      args=&quot;$args --user '$username:$password'&quot;      [ &quot;$authtype&quot; == &quot;digest&quot; ] &amp;&amp; args=&quot;$args --digest&quot;      [ &quot;$authtype&quot; == &quot;ntlm&quot; ] &amp;&amp; args=&quot;$args --ntlm&quot;   }   # Determine cookies to send, if any   local cookie_str=&quot;&quot;   for i in ${!COOKIE_*} ; do      cookie_name=$(echo $i | sed 's/^COOKIE_//')      cookie_str=&quot;$cookie_str; $cookie_name=$(eval echo &quot;$&quot;$i)&quot;   done   cookie_str=&quot;$(echo &quot;$cookie_str&quot; | sed 's/^; //')&quot;   [ -n &quot;$LOG_COOKIES&quot; ] &amp;&amp; logger -p local0.notice \      &quot;$MON_TMPL_NAME($global_node_ip:$global_port): $protocol://$node_ip:$port$uri_path$query_string: cookie string [$cookie_str]&quot;   [ -n &quot;$cookie_str&quot; ] &amp;&amp; args=&quot;$args --cookie '$cookie_str'&quot;   # Make request   eval curl -i $global_args $args &quot;'$protocol://$node_ip:$port$uri_path$query_string'&quot; &gt;&quot;$tmpfile&quot; 2&gt;/dev/null || \fail &quot;$protocol://$node_ip:$port$uri_path$query_string: Request failed: $!&quot;   [ -n &quot;$DEBUG&quot; ] &amp;&amp; cp &quot;$tmpfile&quot; &quot;$tmpfile.debug$id&quot;   # Validate Check Conditions   [ -n &quot;$status_code&quot; ] || [ -n &quot;$not_status_code&quot; ] &amp;&amp; {      local actual_status_code=$(head -n 1 &quot;$tmpfile&quot; | sed &quot;s/^HTTP\/.\.. \([0123456789][0123456789][0123456789]\) .*$/\1/&quot;)      [ -n &quot;$status_code&quot; ] &amp;&amp; [ &quot;$actual_status_code&quot; -ne &quot;$status_code&quot; ] &amp;&amp; fail \         &quot;$protocol://$node_ip:$port$uri_path$query_string: Status code ($actual_status_code) not what was expected \(STATUS_CODE$id=$status_code)&quot;      [ -n &quot;$not_status_code&quot; ] &amp;&amp; [ &quot;$not_status_code&quot; -eq &quot;$status_code&quot; ] &amp;&amp; fail \         &quot;$protocol://$node_ip:$port$uri_path$query_string: Status code ($actual_status_code) was what was not expected \(NOT_STATUS_CODE$id=$not_status_code)&quot;   }   [ -n &quot;$match_regex&quot; ] &amp;&amp; {      if echo &quot;$match_regex&quot; | grep -q '^&amp;' ; then         IFS=&quot;&amp;&quot;         match_regex=&quot;$(echo &quot;$match_regex&quot; | sed 's/^&amp;//')&quot;         for regex in $match_regex ; do            egrep -q &quot;$regex&quot; &quot;$tmpfile&quot; || fail \               &quot;$protocol://$node_ip:$port$uri_path$query_string: Did not find [MATCH_REGEX$id=$regex] in response&quot;         done         unset IFS      else         egrep -q &quot;$match_regex&quot; &quot;$tmpfile&quot; || fail \            &quot;$protocol://$node_ip:$port$uri_path$query_string: Did not find [MATCH_REGEX$id=$match_regex] in response&quot;      fi   }   [ -n &quot;$not_match_regex&quot; ] &amp;&amp; egrep -q &quot;$not_match_regex&quot; &quot;$tmpfile&quot; &amp;&amp; fail \      &quot;$protocol://$node_ip:$port$uri_path$query_string: Found [NOT_MATCH_REGEX$id=$not_match_regex] in response&quot;   # Store cookies from response for next request (if any)   [ -z &quot;$id&quot; ] &amp;&amp; return   `sed -n &quot;s/^Set-Cookie: \([^=]\+\)=\([^;]\+\); .*$/export COOKIE_\1='\2';/p&quot; &quot;$tmpfile&quot;`}# Build global option stringglobal_args=&quot;&quot;[ &quot;$HTTP_VERSION&quot; == &quot;1.0&quot; ] &amp;&amp; global_args=&quot;$global_args --http1.0&quot;[ &quot;$SSL_VERSION&quot; == &quot;tlsv1&quot; ] &amp;&amp; global_args=&quot;$global_args --tlsv1&quot;[ &quot;$SSL_VERSION&quot; == &quot;sslv2&quot; ] &amp;&amp; global_args=&quot;$global_args --sslv2&quot;[ &quot;$SSL_VERSION&quot; == &quot;sslv3&quot; ] &amp;&amp; global_args=&quot;$global_args --sslv3&quot;[ -n &quot;$USER_AGENT&quot; ] &amp;&amp; global_args=&quot;$global_args --user-agent '$USER_AGENT'&quot;[ -n &quot;$CIPHERS&quot; ] &amp;&amp; global_args=&quot;$global_args --ciphers '$CIPHERS'&quot;[ -n &quot;$PROXY_HOST&quot; ] &amp;&amp; [ -n &quot;$PROXY_PORT&quot; ] &amp;&amp; {   if [ &quot;$PROXY_TYPE&quot; == &quot;socks4&quot; ] ; then      global_args=&quot;$global_args --socks4 '$PROXY_HOST:$PROXY_PORT'&quot;   elif [ &quot;$PROXY_TYPE&quot; == &quot;socks5&quot; ] ; then      global_args=&quot;$global_args --socks5 '$PROXY_HOST:$PROXY_PORT'&quot;   else      global_args=&quot;$global_args --proxy '$PROXY_HOST:$PROXY_PORT'&quot;   fi   [ -n &quot;$PROXY_USERNAME&quot; ] &amp;&amp; {      global_args=&quot;$global_args --proxy-user '$PROXY_USERNAME:$PROXY_PASSWORD'&quot;      [ &quot;$PROXY_AUTHTYPE&quot; == &quot;digest&quot; ] &amp;&amp; global_args=&quot;$global_args --proxy-digest&quot;      [ &quot;$PROXY_AUTHTYPE&quot; == &quot;ntlm&quot; ] &amp;&amp; global_args=&quot;$global_args --proxy-ntlm&quot;   }}requests=&quot;$(echo ${!URI_PATH_*} | sort)&quot;for request in $requests ; do   id=$(echo $request | sed 's/^URI_PATH//')      make_request &quot;$id&quot;done# Perform last requestmake_request &quot;&quot;# If we got here without calling fail() and exiting, status was goodrm -f &quot;$tmpfile&quot;echo &quot;up&quot;rm -f &quot;$pidfile&quot;exit 0</font>

相关文章

  • 未命名文章
  • 密码保护:F5OS tenant部署后的容器情况、网络接口情况
  • 密码保护:F5OS tenant镜像实例化后信息
  • 密码保护:F5OS docker-compose.yml
  • 密码保护:F5OS 底层容器、网络及k8s状态
本作品采用 知识共享署名-非商业性使用 4.0 国际许可协议 进行许可
标签: http monitor
最后更新:2008年08月6日

纳米

linjing.io

打赏 点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理。

页面AI聊天助手
文章目录
  • Description
  • Implementation
  • Monitor Source

纳米

linjing.io

☁️迈向Cloud Native ADC ☁️

认证获得:
TOGAF: ID 152743
Kubernetes: CKA #664
Microsoft: MCSE MCDBA
Cisco: CCNP
Juniper: JNCIS
F5:
F5 Certified Solution Expert, Security
F5 Certified Technology Specialist, LTM/GTM/APM/ASM
F5 Certified BIG-IP Administrator
  • 点击查看本博技术要素列表
  • 归档
    分类
    • AI
    • Automation
    • Avi Networks
    • Cisco ACI
    • CISCO资源
    • F5 with ELK
    • F5-Tech tips
    • F5技术
    • Juniper
    • Linux
    • NGINX
    • SDN
    • ServiceMesh
    • WEB编程
    • WINDOWS相关
    • 业界文章
    • 交换机技术
    • 化云为雨/Openstack
    • 协议原理
    • 容器/k8s
    • 我的工作
    • 我的生活
    • 网站技术
    • 路由器技术
    • 项目案例
    标签聚合
    k8s DNS gtm nginx bigip api network istio irule openstack neutron docker F5 envoy flannel
    最近评论
    汤姆 发布于 8 个月前(09月10日) 嗨,楼主,里面的json怎么下载啊,怎么收费啊?
    汤姆 发布于 8 个月前(09月09日) 大佬,kib的页面可以分享下吗?谢谢
    zhangsha 发布于 1 年前(05月12日) 资料发给我下,谢谢纳米同志!!!!lyx895@qq.com
    李成才 发布于 1 年前(01月02日) 麻烦了,谢谢大佬
    纳米 发布于 1 年前(01月02日) 你好。是的,因为以前下载系统插件在一次升级后将所有的下载生成信息全弄丢了。所以不少文件无法下载。DN...
    浏览次数
    • Downloads - 183,773 views
    • 联系我 - 118,966 views
    • 迄今为止最全最深入的BIGIP-DNS/GTM原理及培训资料 - 116,512 views
    • Github - 103,661 views
    • F5常见log日志解释 - 79,774 views
    • 从传统ADC迈向CLOUD NATIVE ADC - 下载 - 74,627 views
    • Sniffer Pro 4 70 530抓包软件 中文版+视频教程 - 74,320 views
    • 迄今为止最全最深入的BIGIP-DNS/GTM原理及培训资料 - 67,770 views
    • 关于本站 - 60,913 views
    • 这篇文档您是否感兴趣 - 55,495 views
    链接表
    • F5SE创新
    • Jimmy Song‘s Blog
    • SDNlab
    • Service Mesh社区
    • 三斗室
    • 个人profile
    • 云原生社区

    COPYRIGHT © 2023 Cloud Native 应用交付. ALL RIGHTS RESERVED.

    Theme Kratos Made By Seaton Jiang

    京ICP备14048088号-1

    京公网安备 11010502041506号