zabbix自动发现 url 以及对http返回状态码监控实现 告警
2019-06-04 18:39:12
目的:批量监控业务URL的返回状态码,通过zabbix监控判断业务好坏。
1、zabbix安装
请查看此永久链接:https://www.cnblogs.com/small-wei/p/10911769.html
2、编写监控脚本
cd /usr/lib/zabbix/externalscripts #本人存放脚本路径,存放路径可以自定义,这个定义文件在zabbix_server.conf中,及zabbix-server服务配置文件。
vim web_site_code_status.sh
#!/bin/bash source /etc/profile >/dev/null 2>&1
WEB_SITE_discovery () {
WEB_SITE=($(grep -v "^#" /usr/local/zabbix/etc/zabbix_script.d/WEBURL.txt))
printf '{\n'
printf '\t"data":[\n'
for((i=0;i<${#WEB_SITE[@]};++i))
{
num=$(echo $((${#WEB_SITE[@]}-1)))
if [[ "$i" != ${num} ]]
then
printf "\t\t{ \n"
printf "\t\t\t\"{#SITENAME}\":\"${WEB_SITE[$i]}\"},\n"
else
printf "\t\t{ \n"
printf "\t\t\t\"{#SITENAME}\":\"${WEB_SITE[$num]}\"}]}\n"
fi
}
} web_site_code () {
#下面注释的是也可以使用域名+端口号
# host=$(echo "$1"|awk -F "/" '{print $3}')
# port=$(echo "$1"|awk -F "/" '{print $3}'|awk -F':' '{print $2}')
# if [[ -z $port ]]
# then
# ntlocal="127.0.0.1"
# else
# ntlocal="127.0.0.1:$port"
# fi
# http_uri=$(echo "$1"|awk -F "/" '{for(i=4;i<=NF;i++) printf "/" $i;printf "\n"}')
# /usr/bin/curl -H "Host:$host" -o /dev/null -s -w %{http_code} $ntlocal${http_uri}
/usr/bin/curl -I "$1" 2> /dev/null | grep 'HTTP' | awk '{print $2}'
} case "$1" in
web_site_discovery)
WEB_SITE_discovery
;;
web_site_code)
web_site_code $2
;;
*)
echo "Usage:$0 {web_site_discovery|web_site_code URL}"
;;
esac
3、创建URL列表
cat /etc/zabbix/zabbix_script.d/web_url_list.txt #这个文件在上面的脚本中定义。
www.baidu.com
www.qq.com
www.redhat.com
https://www.redhat.com/en
https://www/zabbix.com
注意:这里也可以在后面加端口号
4、在zabbix_agentd.conf中添加相关的key
vim /etc/zabbix/zabbix_agentd.conf #客户端配置文件中添加&修改如下内容
UnsafeUserParameters=1 #允许将参数中的所有字符传递给用户定义的参数。
UserParameter=web.site.discovery,/usr/lib/zabbix/externalscripts/web_site_code_status.sh web_site_discovery
UserParameter=web.site.code[*],/usr/lib/zabbix/externalscripts/web_site_code_status.sh web_site_code $1
5、重启zabbix-agent
Linux6:
service zabbix-agent restart
Linux7:
systemctl restart zabbix-agent
6、导入zabbix监控模板文件。
复制如下代码,在本地计算机中创建一个文件:zbx_export_templates.xml (自定义创建):
<?xml version="1.0" encoding="UTF-8"?>
<zabbix_export>
<version>3.4</version>
<date>2019-06-04T18:15:17Z</date>
<groups>
<group>
<name>http_status_code</name>
</group>
</groups>
<templates>
<template>
<template>Automatically discover http_code</template>
<name>Automatically discover http_code</name>
<description>automatically discover http_status_code</description>
<groups>
<group>
<name>http_status_code</name>
</group>
</groups>
<applications/>
<items/>
<discovery_rules>
<discovery_rule>
<name>Disvover http url</name>
<type>0</type>
<snmp_community/>
<snmp_oid/>
<key>web.site.discovery</key>
<delay>30s</delay>
<status>0</status>
<allowed_hosts/>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authprotocol>0</snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol>0</snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<params/>
<ipmi_sensor/>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<filter>
<evaltype>0</evaltype>
<formula/>
<conditions/>
</filter>
<lifetime>30d</lifetime>
<description/>
<item_prototypes>
<item_prototype>
<name>http url $1</name>
<type>0</type>
<snmp_community/>
<snmp_oid/>
<key>web.site.code[{#SITENAME}]</key>
<delay>30s</delay>
<history>90d</history>
<trends>365d</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units/>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authprotocol>0</snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol>0</snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<params/>
<ipmi_sensor/>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications/>
<valuemap>
<name>HTTP response status code</name>
</valuemap>
<logtimefmt/>
<preprocessing/>
<jmx_endpoint/>
<application_prototypes/>
<master_item_prototype/>
</item_prototype>
</item_prototypes>
<trigger_prototypes>
<trigger_prototype>
<expression>{Automatically discover http_code:web.site.code[{#SITENAME}].last(#3,15)}>=500 and
{Automatically discover http_code:web.site.code[{#SITENAME}].last(,0)}</expression>
<recovery_mode>0</recovery_mode>
<recovery_expression/>
<name>web.site.code {#SITENAME} greater 500</name>
<correlation_mode>0</correlation_mode>
<correlation_tag/>
<url/>
<status>0</status>
<priority>4</priority>
<description/>
<type>0</type>
<manual_close>0</manual_close>
<dependencies/>
<tags/>
</trigger_prototype>
<trigger_prototype>
<expression>{Automatically discover http_code:web.site.code[{#SITENAME}].last(#3,15)}<>200 and
{Automatically discover http_code:web.site.code[{#SITENAME}].last(,0)}</expression>
<recovery_mode>0</recovery_mode>
<recovery_expression/>
<name>web.site.code {#SITENAME} is not 200</name>
<correlation_mode>0</correlation_mode>
<correlation_tag/>
<url/>
<status>0</status>
<priority>0</priority>
<description/>
<type>0</type>
<manual_close>0</manual_close>
<dependencies/>
<tags/>
</trigger_prototype>
</trigger_prototypes>
<graph_prototypes>
<graph_prototype>
<name>web.site.code.on {#SITENAME}</name>
<width>900</width>
<height>200</height>
<yaxismin>0.0000</yaxismin>
<yaxismax>100.0000</yaxismax>
<show_work_period>1</show_work_period>
<show_triggers>1</show_triggers>
<type>0</type>
<show_legend>1</show_legend>
<show_3d>0</show_3d>
<percent_left>0.0000</percent_left>
<percent_right>0.0000</percent_right>
<ymin_type_1>0</ymin_type_1>
<ymax_type_1>0</ymax_type_1>
<ymin_item_1>0</ymin_item_1>
<ymax_item_1>0</ymax_item_1>
<graph_items>
<graph_item>
<sortorder>0</sortorder>
<drawtype>0</drawtype>
<color>1A7C11</color>
<yaxisside>0</yaxisside>
<calc_fnc>2</calc_fnc>
<type>0</type>
<item>
<host>Automatically discover http_code</host>
<key>web.site.code[{#SITENAME}]</key>
</item>
</graph_item>
</graph_items>
</graph_prototype>
</graph_prototypes>
<host_prototypes/>
<jmx_endpoint/>
</discovery_rule>
</discovery_rules>
<httptests/>
<macros/>
<templates/>
<screens/>
</template>
</templates>
<value_maps>
<value_map>
<name>HTTP response status code</name>
<mappings>
<mapping>
<value>100</value>
<newvalue>Continue</newvalue>
</mapping>
<mapping>
<value>101</value>
<newvalue>Switching Protocols</newvalue>
</mapping>
<mapping>
<value>102</value>
<newvalue>Processing</newvalue>
</mapping>
<mapping>
<value>200</value>
<newvalue>OK</newvalue>
</mapping>
<mapping>
<value>201</value>
<newvalue>Created</newvalue>
</mapping>
<mapping>
<value>202</value>
<newvalue>Accepted</newvalue>
</mapping>
<mapping>
<value>203</value>
<newvalue>Non-Authoritative Information</newvalue>
</mapping>
<mapping>
<value>204</value>
<newvalue>No Content</newvalue>
</mapping>
<mapping>
<value>205</value>
<newvalue>Reset Content</newvalue>
</mapping>
<mapping>
<value>206</value>
<newvalue>Partial Content</newvalue>
</mapping>
<mapping>
<value>207</value>
<newvalue>Multi-Status</newvalue>
</mapping>
<mapping>
<value>208</value>
<newvalue>Already Reported</newvalue>
</mapping>
<mapping>
<value>226</value>
<newvalue>IM Used</newvalue>
</mapping>
<mapping>
<value>300</value>
<newvalue>Multiple Choices</newvalue>
</mapping>
<mapping>
<value>301</value>
<newvalue>Moved Permanently</newvalue>
</mapping>
<mapping>
<value>302</value>
<newvalue>Found</newvalue>
</mapping>
<mapping>
<value>303</value>
<newvalue>See Other</newvalue>
</mapping>
<mapping>
<value>304</value>
<newvalue>Not Modified</newvalue>
</mapping>
<mapping>
<value>305</value>
<newvalue>Use Proxy</newvalue>
</mapping>
<mapping>
<value>306</value>
<newvalue>Switch Proxy</newvalue>
</mapping>
<mapping>
<value>307</value>
<newvalue>Temporary Redirect</newvalue>
</mapping>
<mapping>
<value>308</value>
<newvalue>Permanent Redirect/Resume Incomplete</newvalue>
</mapping>
<mapping>
<value>400</value>
<newvalue>Bad Request</newvalue>
</mapping>
<mapping>
<value>401</value>
<newvalue>Unauthorized</newvalue>
</mapping>
<mapping>
<value>402</value>
<newvalue>Payment Required</newvalue>
</mapping>
<mapping>
<value>403</value>
<newvalue>Forbidden</newvalue>
</mapping>
<mapping>
<value>404</value>
<newvalue>Not Found</newvalue>
</mapping>
<mapping>
<value>405</value>
<newvalue>Method Not Allowed</newvalue>
</mapping>
<mapping>
<value>406</value>
<newvalue>Not Acceptable</newvalue>
</mapping>
<mapping>
<value>407</value>
<newvalue>Proxy Authentication Required</newvalue>
</mapping>
<mapping>
<value>408</value>
<newvalue>Request Timeout</newvalue>
</mapping>
<mapping>
<value>409</value>
<newvalue>Conflict</newvalue>
</mapping>
<mapping>
<value>410</value>
<newvalue>Gone</newvalue>
</mapping>
<mapping>
<value>411</value>
<newvalue>Length Required</newvalue>
</mapping>
<mapping>
<value>412</value>
<newvalue>Precondition Failed</newvalue>
</mapping>
<mapping>
<value>413</value>
<newvalue>Payload Too Large</newvalue>
</mapping>
<mapping>
<value>414</value>
<newvalue>Request-URI Too Long</newvalue>
</mapping>
<mapping>
<value>415</value>
<newvalue>Unsupported Media Type</newvalue>
</mapping>
<mapping>
<value>416</value>
<newvalue>Requested Range Not Satisfiable</newvalue>
</mapping>
<mapping>
<value>417</value>
<newvalue>Expectation Failed</newvalue>
</mapping>
<mapping>
<value>418</value>
<newvalue>I'm a Teapot</newvalue>
</mapping>
<mapping>
<value>419</value>
<newvalue>Authentication Timeout</newvalue>
</mapping>
<mapping>
<value>420</value>
<newvalue>Method Failure/Enhance Your Calm</newvalue>
</mapping>
<mapping>
<value>421</value>
<newvalue>Misdirected Request</newvalue>
</mapping>
<mapping>
<value>422</value>
<newvalue>Unprocessable Entity</newvalue>
</mapping>
<mapping>
<value>423</value>
<newvalue>Locked</newvalue>
</mapping>
<mapping>
<value>424</value>
<newvalue>Failed Dependency</newvalue>
</mapping>
<mapping>
<value>426</value>
<newvalue>Upgrade Required</newvalue>
</mapping>
<mapping>
<value>428</value>
<newvalue>Precondition Required</newvalue>
</mapping>
<mapping>
<value>429</value>
<newvalue>Too Many Requests</newvalue>
</mapping>
<mapping>
<value>431</value>
<newvalue>Request Header Fields Too Large</newvalue>
</mapping>
<mapping>
<value>440</value>
<newvalue>Login Timeout</newvalue>
</mapping>
<mapping>
<value>444</value>
<newvalue>No Response</newvalue>
</mapping>
<mapping>
<value>449</value>
<newvalue>Retry With</newvalue>
</mapping>
<mapping>
<value>450</value>
<newvalue>Blocked by Windows Parental Controls</newvalue>
</mapping>
<mapping>
<value>451</value>
<newvalue>Unavailable for Legal Reasons/Redirect</newvalue>
</mapping>
<mapping>
<value>494</value>
<newvalue>Request Header Too Large</newvalue>
</mapping>
<mapping>
<value>495</value>
<newvalue>Cert Error</newvalue>
</mapping>
<mapping>
<value>496</value>
<newvalue>No Cert</newvalue>
</mapping>
<mapping>
<value>497</value>
<newvalue>HTTP to HTTPS</newvalue>
</mapping>
<mapping>
<value>498</value>
<newvalue>Token Expired/Invalid</newvalue>
</mapping>
<mapping>
<value>499</value>
<newvalue>Client Closed Request/Token Required</newvalue>
</mapping>
<mapping>
<value>500</value>
<newvalue>Internal Server Error</newvalue>
</mapping>
<mapping>
<value>501</value>
<newvalue>Not Implemented</newvalue>
</mapping>
<mapping>
<value>502</value>
<newvalue>Bad Gateway</newvalue>
</mapping>
<mapping>
<value>503</value>
<newvalue>Service Unavailable</newvalue>
</mapping>
<mapping>
<value>504</value>
<newvalue>Gateway Timeout</newvalue>
</mapping>
<mapping>
<value>505</value>
<newvalue>HTTP Version Not Supported</newvalue>
</mapping>
<mapping>
<value>506</value>
<newvalue>Variant Also Negotiates</newvalue>
</mapping>
<mapping>
<value>507</value>
<newvalue>Insufficient Storage</newvalue>
</mapping>
<mapping>
<value>508</value>
<newvalue>Loop Detected</newvalue>
</mapping>
<mapping>
<value>509</value>
<newvalue>Bandwidth Limit Exceeded</newvalue>
</mapping>
<mapping>
<value>510</value>
<newvalue>Not Extended</newvalue>
</mapping>
<mapping>
<value>511</value>
<newvalue>Network Authentication Required</newvalue>
</mapping>
<mapping>
<value>520</value>
<newvalue>Unknown Error</newvalue>
</mapping>
<mapping>
<value>598</value>
<newvalue>Network Read Timeout Error</newvalue>
</mapping>
<mapping>
<value>599</value>
<newvalue>Network Connect Timeout Error</newvalue>
</mapping>
</mappings>
</value_map>
</value_maps>
</zabbix_export>
7、导入模板文件zbx_export_templates.xml
登录zabbix,登录过程跳过;



导入成功后可以看到如下名称的模板:

8、验证查看监控:
至此url监控完毕。

参考链接:https://blog.csdn.net/qq_34857250/article/details/78323780
参考链接:https://www.zabbix.com
zabbix自动发现 url 以及对http返回状态码监控实现 告警的更多相关文章
- zabbix自动发现功能实现批量web url监控
需求: 现在有大量url需要监控,形式如http://www.baidu.com ,要求url状态不为200即报警. 需求详细分析: 大量的url,且url经常变化,现在监控用的是zabbix,如果手 ...
- zabbix 自动发现(LLD)
概述 自动发现(LLD)提供了一种在计算机上为不同实体自动创建监控项,触发器和图形的方法.例如,Zabbix可以在你的机器上自动开始监控文件系统或网络接口,而无需为每个文件系统或网络接口手动创建监控项 ...
- 使用 zabbix 自动发现监控 MySQL
介绍 使用 zabbix 的 low-level 自动发现功能完成单主机多端口的监控, 详见low_level_discovery, 整体上监控类似 percona 的 zabbix 监控插件, 不过 ...
- 转 zabbix 自动发现和 zabbix自定义用户key与参数User parameters
########31 https://www.cnblogs.com/yjt1993/p/10883345.html 1.概念 在配置Iterms的过程中,有时候需要对类似的Iterms进行添加,这些 ...
- zabbix 自动发现端口并添加监控设置
自动发现端口并添加监控设置UserParameter=net.listen.discovery,sudo /etc/zabbix/scripts/discovery_listport.sh #!/bi ...
- zabbix/自动发现规则
对于zabbix 我们并不陌生 他是开源的监控系统,现在的一部分企业都在用zabbix,今天给大家分享的是企业级监控zabbix的自动发现规则,有了它我们自定义健康的时候根据宏值可以让他自动发现对 ...
- zabbix自动发现主机并加入组绑定模板
在被监控主机多的情况下,怎样将这些主机加入zabbix server进行监控呢?下面将介绍下zabbix自动发现功能 1.创建自动发现规则 创建“规则名称,配置ip范围及检查方式”,点击“增加”,完成 ...
- zabbix 自动发现
转自:https://blog.csdn.net/yyy72999/article/details/76065374 zabbix自动发现/zabbix自动发现规则 置顶2017年07月25日 14: ...
- zabbix 自动发现 相关
zabbix自动发现,是zabbix精髓所在. 生产中,一台服务器上可能会存在多个监控实例,比如:A服务器2个,B服务器4个, C服务器1个.单单靠套模板来完成监控,做法那太糟糕了.比如小明有100台 ...
随机推荐
- ios Autolayout 按比例相对布局
看到一篇讲ios storyboard 按比例相对布局的博客,挺不错的转下来了! 可到liumh.com查看. 本文记录如何在 UIStoryboard 或者 xib 中进行百分比布局,包括 View ...
- Magicodes.IE已支持导出Word、Pdf和Html
关于Magicodes.IE 导入导出通用库,通过导入导出DTO模型来控制导入和导出,支持Excel.Word.Pdf和Html. GitHub地址:https://github.com/xin-la ...
- forEach,map,every,some,filter简单用法实例
平时简单总结:不足之处还望见谅: 实例: 11.1 forEach:只能进行取值操作,不能进行修改 arr.forEach(function(element,index,arr){});//注意参数: ...
- RocketMQ实战:生产环境中,autoCreateTopicEnable为什么不能设置为true
1.现象 很多网友会问,为什么明明集群中有多台Broker服务器,autoCreateTopicEnable设置为true,表示开启Topic自动创建,但新创建的Topic的路由信息只包含在其中一台B ...
- Python SQLAlchemy入门教程
本文将以Mysql举例,介绍sqlalchemy的基本用法.其中,Python版本为2.7,sqlalchemy版本为1.1.6. 一. 介绍 SQLAlchemy是Python中最有名的ORM工具. ...
- svn:"Update item to this version"、"Revert to this version"及"Revert changes from this version"详细说明
背景: 今天在svn分支上做了一些课题性研究,发现当前的环境版本不稳定, 和领导研究后决定还原到前面的版本以继续进行课题. 问题: 因此遇到了问题,是应该选择“Update item to this ...
- Java基础系列4:抽象类与接口的前世今生
该系列博文会告诉你如何从入门到进阶,一步步地学习Java基础知识,并上手进行实战,接着了解每个Java知识点背后的实现原理,更完整地了解整个Java技术体系,形成自己的知识框架. 1.抽象类: 当编写 ...
- day1-习题
# 1.使用while循环输入 1 2 3 4 5 6 8 9 10 count = 1 while count<11 : #使用while语句循环输入123...10 if count == ...
- Java基础 ArrayList源码分析 JDK1.8
一.概述 本篇文章记录通过阅读JDK1.8 ArrayList源码,结合自身理解分析其实现原理. ArrayList容器类的使用频率十分频繁,它具有以下特性: 其本质是一个数组,因此它是有序集合 通过 ...
- thinkphp5中取消了3.2版本中的单字母函数,初用tp5可能不大适应,下边给出两者的对应参照表,以便查阅。
3.2版本 5.0版本 C config E exception G debug L lang T 废除 I input N 废除 D model M db A controller R action ...