有一个网站,在电脑上能打开,但在prometheus上执行
curl -s https://cps.aa***n.com/dmj-front/index/bestZone?reqttime=1663229804743&sign=d2180aea2e01508a34e4479571073f7a&themeId=29&apiversion=20&device_type=IMEI&devversion=130&userid=16743&islogin=1&devtype=00&device_encrypt=MD5¤t=1&size=10&merchantid=2&device_value=d41d8cd98f00b204e9800998ecf8427e
就会返回
{"result":"2","msgstr":"签名错误!","msg":"签名错误!","success":false,"data":null,"code":200,"nowTime":1688033477,"message":"签名错误!","exMessage":null,"severity":null}
而不是像windows电脑那样能正常打开网站
blackbox.yml 的配置如下,求,如何修改才能监控这种返回码是200,但又报签名错误的网站,谢谢!注意,不能监控网站返回内容,除非能做到监控A网站返回内容是AAA,B网站返回的内容是BBB,所有网站的内容都没有相同的地方,也不能用自定义的方式监控,因为网站的服务器不给操作。
cat blackbox.yml
modules:
http_2xx:
prober: http
http_post_2xx:
prober: http
http:
method: POST
tcp_connect:
prober: tcp
pop3s_banner:
prober: tcp
tcp:
query_response:
- expect: "^+OK"
tls: true
tls_config:
insecure_skip_verify: false
grpc:
prober: grpc
grpc:
tls: true
preferred_ip_protocol: "ip4"
grpc_plain:
prober: grpc
grpc:
tls: false
service: "service1"
ssh_banner:
prober: tcp
tcp:
query_response:
- expect: "^SSH-2.0-"
- send: "SSH-2.0-blackbox-ssh-check"
irc_banner:
prober: tcp
tcp:
query_response:
- send: "NICK prober"
- send: "USER prober prober prober :prober"
- expect: "PING :([^ ]+)"
send: "PONG ${1}"
- expect: "^:[^ ]+ 001"
icmp:
prober: icmp
可以尝试使用http_2xx模块的自定义配置,在blackbox.yml中添加以下内容:
http_2xx_with_error:
prober: http
http:
valid_http_versions: [HTTP/1.1]
valid_http_methods: [GET, POST]
fail_if_ssl: true
fail_if_not_ssl: false
fail_if_matches_regexp:
- "签名错误!"
然后在prometheus的配置文件中,将http_2xx模块替换为http_2xx_with_error模块。重新加载配置文件后,prometheus将监控返回码为200但报签名错误的网站。
要监控一个返回码为200但报签名错误的网站,可以通过自定义探针来实现。你可以使用Prometheus的exporter来编写一个自定义的探针来监控网站的返回内容是否包含签名错误的信息。一个示例的配置给你参考,展示如何创建一个自定义的探针来监控网站返回内容中是否包含签名错误:
modules:
http_custom:
prober: http
timeout: 5s
http:
valid_http_versions: [ "HTTP/1.1", "HTTP/2" ]
valid_http_methods: [ "GET" ]
fail_if_ssl: false
fail_if_not_ssl: false
fail_if_matches_regexp:
- '.*"msg":"签名错误".*'
fail_if_not_matches_regexp:
- '.*"result":"2".*'
上述配置将创建一个名为http_custom的自定义探针。它使用HTTP探针进行检测,并在返回内容中出现签名错误或result
字段为2时视为失败。timeout参数指定了请求的超时时间,可以根据需要进行调整。请注意,在上述配置中,通过正则表达式来匹配返回内容中的特定信息。你可以根据实际情况进行调整,以确保能够准确匹配到签名错误的信息。将上述配置添加到你的blackbox.yml文件中,并重新加载Prometheus配置。接下来,Prometheus将在监控过程中使用该自定义的探针来检测网站返回内容中是否包含签名错误。
只需要修改状态码吗?其他错误不管吗
以下是一种修改blackbox.yml配置文件的方法,以实现此目标:
添加一个新的模块:http_custom
modules:
http_custom:
prober: http
http:
method: GET
headers:
User-Agent: "Blackbox Prober" # 设置一个自定义的User-Agent,避免被网站屏蔽
url: "https://cps.aa***n.com/dmj-front/index/bestZone?reqttime=1663229804743&sign=d2180aea2e01508a34e4479571073f7a&themeId=29&apiversion=20&device_type=IMEI&devversion=130&userid=16743&islogin=1&devtype=00&device_encrypt=MD5¤t=1&size=10&merchantid=2&device_value=d41d8cd98f00b204e9800998ecf8427e"
#在blackbox.yml文件中的modules部分添加一个新的探测顺序
探测顺序:
- http_custom
Prometheus Blackbox Exporter 配置文件blackbox.yml
主要由两部分组成: modules
和 scrape_configs
。
modules
定义了各种探测模式,如HTTP、TCP、ICMP等,每一种模式都可以设置一些特定的参数。例如,HTTP模式可以设置HTTP方法、超时时间、有效的HTTP状态码等。
scrape_configs
是Prometheus用来从Blackbox Exporter获取监控数据的配置,其中需要指定Blackbox Exporter的地址和端口,以及要使用的探测模式。
以下是一个示例配置:
modules:
http_2xx:
prober: http
timeout: 5s
http:
valid_http_versions: [HTTP/1.1, HTTP/2]
valid_status_codes: [] # Defaults to 2xx
method: GET
fail_if_ssl: false
fail_if_major_http_version_mismatch: true
scrape_configs:
- job_name: 'blackbox'
metrics_path: /probe
params:
module: [http_2xx]
static_configs:
- targets:
- http://prometheus.io # Target to probe with http.
- https://prometheus.io # Target to probe with http.
- http://example.com:8080 # Target to probe with http on port 8080.
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: blackbox:9115 # Address of the Blackbox exporter
上述配置定义了一个名为http_2xx
的HTTP探测模式,该模式检测HTTP/1.1和HTTP/2协议,期望的HTTP状态码为2xx,使用GET方法。
scrape_configs
部分定义了一个名为blackbox
的任务,该任务使用http_2xx
模式探测三个目标:http://prometheus.io
, https://prometheus.io
和 http://example.com:8080
。其中relabel_configs
部分将每个目标的地址添加到了标签__param_target
,并将Blackbox Exporter的地址设置为blackbox:9115
。
在实际使用过程中,你可能需要根据自己的需求调整这些配置。如果遇到具体的问题,可以提供更多的信息,我会尽量帮你解答。
Prometheus监控实战之Blackbox_exporter黑盒监测
非常详细,可以借鉴下
https://blog.csdn.net/ygq13572549874/article/details/129718039
https://blog.csdn.net/ygq13572549874/article/details/129718039
按照正常请求返回的参数,原模原样的请求
考虑是否是签名算法和密钥、数据请求格式、权限和身份验证、SSL证书等方面是否存在问题。关于blackbox.yml的配置,你可以参考下别人是怎么配置的:
blackbox+prometheus实现黑盒监控:https://www.cnblogs.com/c-moon/p/17219305.html
服务端加密了吧
根据你提供的信息,你想要通过配置blackbox.yml
来监控一个网站,该网站在电脑上可以正常打开,但在使用Prometheus执行curl命令获取网站内容时返回一个签名错误的错误消息。
首先,你需要了解一些关于blackbox_exporter
的基本知识。blackbox_exporter
是一个用于Ping、HTTP、TCP和其他网络协议探测的监控工具,可以与Prometheus一起使用。它使用预定义的探测模块来监控不同协议的目标。
在你提供的配置文件blackbox.yml
中,有不同的模块配置来对不同类型的目标进行探测。其中,http_2xx
模块用于监测HTTP请求返回的状态码为2xx的情况,即成功的情况。
要修改配置文件以监控返回状态码为200但出现签名错误的网站,你可以尝试在配置文件中添加一个新的模块来对此进行监测。下面是一种可能的配置方式:
http_200_with_signature_error:
prober: http
fail_if_ssl: true
http:
method: GET
headers:
Host: "cps.aa***n.com"
User-Agent: "Mozilla/5.0 (X11; Linux x86_64; rv:86.0) Gecko/20100101 Firefox/86.0"
valid_http_versions: [HTTP/1.1]
valid_http_versions: [HTTP/2]
http_config:
tls_ca_file: "/path/to/ca.crt" # 可选项,根据实际需要提供根证书
timeout: 5s
在这个配置中,我们创建了一个新的模块http_200_with_signature_error
。它使用了http
探测器来进行HTTP请求,并设置了一些请求参数和头部信息,以模拟正常的浏览器请求。fail_if_ssl
参数被设置为true
,以便在SSL/TLS握手失败时失败探测。此外,我们还为HTTP版本提供了一些限制,以防止HTTP/0.9和HTTP/1.0请求被接受。
最后,请确保在你的Prometheus配置文件中添加以下内容来启用blackbox_exporter
:
scrape_configs:
- job_name: 'blackbox'
metrics_path: /probe
params:
module: [http_200_with_signature_error]
static_configs:
- targets:
- 'https://cps.aa***n.com/dmj-front/index/bestZone?reqttime=1663229804743&sign=d2180aea2e01508a34e4479571073f7a&themeId=29&apiversion=20&device_type=IMEI&devversion=130&userid=16743&islogin=1&devtype=00&device_encrypt=MD5¤t=1&size=10&merchantid=2&device_value=d41d8cd98f00b204e9800998ecf8427e'
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: blackbox_exporter:9115 # 修改为你的blackbox_exporter监听地址
通过这样的配置,Prometheus将定期探测指定的网站,并返回探测结果。你可以在Prometheus的Web界面上查看这些结果并进行监控。
请注意,以上配置仅供参考,你需要根据具体情况进行调整和修改。此外,确保你已经正确安装和配置了blackbox_exporter
和Prometheus。