├── Hardware ├── Zabbix 监控硬件.docx ├── zbx_check_hardware.xml └── zbx_export_templates.xml ├── README.md ├── apache ├── LinuxIDC.com.png ├── README ├── apache.xml └── apache_status.sh ├── install ├── Zabbix 监控vmware.docx ├── Zabbix 监控硬件.docx ├── centos7下安装mysql5.6.32文档.docx └── centos7下安装zabbix3.0.docx ├── io_monitor ├── dev-discovery.sh ├── extra.conf ├── iostat-check.sh ├── iostat-cron.sh └── zbx_export_templates.xml ├── memcached ├── README ├── memcached_stats.pl └── memcached_t.xml ├── nginx ├── README.md ├── nginx_status ├── nginx_status.sh └── nginx_status.xml ├── oracle ├── asm │ ├── asm.conf │ ├── check_asm.sh │ ├── check_asm_status.sh │ └── readme.md └── tablespace │ ├── orabbix.md │ ├── oracle_check.sh │ ├── oracle_cron.sh │ ├── oracle_discovery.sh │ ├── oracle_tablespace.xml │ ├── readme.md │ └── tablespace.conf ├── phpfpm ├── README.md ├── php-fpm_status ├── php-fpm_status.sh └── php-fpm_status.xml ├── port-discovery ├── port-discovery.sh ├── port-discovery.xml └── port.conf ├── redis ├── README └── redis_t.xml ├── squid ├── README.md ├── check_squid_status.sh ├── squid_status.conf └── zbx_squid_status.xml ├── varnish ├── README └── varnish_t.xml ├── zabbix-agent-bi-rpm ├── BUILD │ └── .gitignore ├── RPMS │ └── .gitignore ├── SOURCES │ ├── 1 │ ├── cron.conf │ ├── dev-discovery.sh │ ├── extra.conf │ ├── iostat-check.sh │ ├── iostat-cron.sh │ ├── path.patch │ ├── port-discovery.sh │ └── zabbix-2.2.5.tar.gz ├── SPECS │ └── zabbix-agent.spec ├── SRPMS │ └── .gitignore └── rpmbuild │ ├── BUILD │ └── .gitignore │ ├── RPMS │ └── .gitignore │ ├── SOURCES │ ├── cron.conf │ ├── dev-discovery.sh │ ├── extra.conf │ ├── iostat-check.sh │ ├── iostat-cron.sh │ ├── path.patch │ ├── port-discovery.sh │ └── zabbix-2.2.5.tar.gz │ ├── SPECS │ └── zabbix-agent.spec │ └── SRPMS │ └── .gitignore └── zabbix_send_alarm ├── action.xml ├── readme.md └── send_mail_image.py /Hardware/Zabbix 监控硬件.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kerncai/zabbix/53cad73d345a55677c3238ca2ac4855dc8df2bfa/Hardware/Zabbix 监控硬件.docx -------------------------------------------------------------------------------- /Hardware/zbx_export_templates.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 3.0 4 | 2016-08-29T06:17:40Z 5 | 6 | 7 | _PingAn-Templates 8 | 9 | 10 | 11 | 394 | 395 | 396 | 397 | {A_PingAn OS HardWare Temp:storage_disk.last()}=1 398 | Command MegaCli64 Not found on {HOST.NAME} 399 | 400 | 0 401 | 2 402 | 403 | 0 404 | 405 | 406 | 407 | {A_PingAn OS HardWare Temp:storage_disk.last()}=2 408 | Disk With Raid Error on {HOST.NAME} 409 | 410 | 0 411 | 3 412 | 413 | 0 414 | 415 | 416 | 417 | 418 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | zabbix 2 | ====== 3 | 4 | The template of apache.memcached.redis.squid and varnish what the zabbix haved 5 | 6 | 通过zabbix的自定义脚本监控web的中间件服务,强大的zabbix,只要脚本能写出来,就能做到监控! 7 | 8 | 上面提到的监控,仓库内都是有脚本和模板的.例子:监控squid 9 | 10 | [root@monitor_test /]# cat check_squid_status.sh 11 | 12 | #!/bin/bash 13 | 14 | five_min(){ 15 | squidclient -h localhost -p 3128 mgr:info |grep 'Request Hit Ratios:' |awk '{print$5/100}' #5分钟的命中率 16 | } 17 | 18 | six_min(){ 19 | squidclient -h localhost -p 3128 mgr:info |grep 'Request Hit Ratios:' |awk '{print$7/100}' #60分钟内的命中率 20 | } 21 | 22 | objects(){ 23 | squidclient -h localhost -p 3128 mgr:info |grep 'on-disk objects' |awk '{print$1}' #缓存的数量 24 | } 25 | 26 | space(){ 27 | cat /var/log/squid.txt |grep 'Filesystem Space in use:' |awk -F '/' '{print$1}'|awk '{s+=$5};END{printf "%4.2f\n",s/1024/1024}'#缓存的大小,已经换算成G. 28 | } 29 | 30 | $1 31 | 32 | -------------------------------------------------------------------------------- /apache/LinuxIDC.com.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kerncai/zabbix/53cad73d345a55677c3238ca2ac4855dc8df2bfa/apache/LinuxIDC.com.png -------------------------------------------------------------------------------- /apache/README: -------------------------------------------------------------------------------- 1 | Usage: 2 | 3 | You have to enable ExtendedStatus in httpd for this 4 | to work correctly. 5 | 6 | Add an user parameter to zabbix: 7 | UserParameter=apache[*],/path/to/apache-status.sh $1 8 | -------------------------------------------------------------------------------- /apache/apache.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 0 6 | 1 7 | 8 | 127.0.0.1 9 | 10050 10 | 3 11 | 0 12 | 127.0.0.1 13 | 623 14 | 0 15 | 2 16 | 17 | 18 | 19 | Templates 20 | smeonline.sk farma 21 | 22 | 23 | 24 | 25 | Apache: Total accesses 26 | 27 | 60 28 | 30 29 | 365 30 | 0 31 | 0 32 | 33 | 0 34 | 0 35 | 1 36 | 0 37 | 38 | 39 | 0 40 | 41 | 42 | 43 | 44 | 45 | localhost 46 | public 47 | interfaces.ifTable.ifEntry.ifInOctets.1 48 | 161 49 | 50 | 0 51 | 52 | 53 | 0 54 | 55 | Apache statistics 56 | 57 | 58 | 59 | Apache: Busy workers 60 | 61 | 60 62 | 30 63 | 365 64 | 0 65 | 0 66 | 67 | 0 68 | 0 69 | 1 70 | 0 71 | 72 | 73 | 0 74 | 75 | 76 | 77 | 78 | 79 | localhost 80 | public 81 | interfaces.ifTable.ifEntry.ifInOctets.1 82 | 161 83 | 84 | 0 85 | 86 | 87 | 0 88 | 89 | Apache statistics 90 | 91 | 92 | 93 | Apache: Bytes per request 94 | 95 | 60 96 | 30 97 | 365 98 | 0 99 | 0 100 | b 101 | 1 102 | 0 103 | 8 104 | 0 105 | 106 | 107 | 0 108 | 109 | 110 | 111 | 112 | 113 | localhost 114 | public 115 | interfaces.ifTable.ifEntry.ifInOctets.1 116 | 161 117 | 118 | 0 119 | 120 | 121 | 0 122 | 123 | Apache statistics 124 | 125 | 126 | 127 | Apache: BPS 128 | 129 | 30 130 | 30 131 | 365 132 | 0 133 | 0 134 | bps 135 | 1 136 | 0 137 | 8 138 | 0 139 | 140 | 141 | 0 142 | 143 | 144 | 145 | 146 | 147 | localhost 148 | public 149 | interfaces.ifTable.ifEntry.ifInOctets.1 150 | 161 151 | 152 | 0 153 | 154 | 155 | 0 156 | 157 | Apache statistics 158 | 159 | 160 | 161 | Apache: Idle workers 162 | 163 | 60 164 | 30 165 | 365 166 | 0 167 | 0 168 | 169 | 0 170 | 0 171 | 1 172 | 0 173 | 174 | 175 | 0 176 | 177 | 178 | 179 | 180 | 181 | localhost 182 | public 183 | interfaces.ifTable.ifEntry.ifInOctets.1 184 | 161 185 | 186 | 0 187 | 188 | 189 | 0 190 | 191 | Apache statistics 192 | 193 | 194 | 195 | Apache: Total kBytes 196 | 197 | 30 198 | 30 199 | 365 200 | 0 201 | 0 202 | B 203 | 1 204 | 0 205 | 1024 206 | 0 207 | 208 | 209 | 0 210 | 211 | 212 | 213 | 214 | 215 | localhost 216 | public 217 | interfaces.ifTable.ifEntry.ifInOctets.1 218 | 161 219 | 220 | 0 221 | 222 | 223 | 0 224 | 225 | Apache statistics 226 | 227 | 228 | 229 | Apache: Requests per second 230 | 231 | 60 232 | 30 233 | 365 234 | 0 235 | 0 236 | 237 | 0 238 | 0 239 | 1 240 | 0 241 | 242 | 243 | 0 244 | 245 | 246 | 247 | 248 | 249 | localhost 250 | public 251 | interfaces.ifTable.ifEntry.ifInOctets.1 252 | 161 253 | 254 | 0 255 | 256 | 257 | 0 258 | 259 | Apache statistics 260 | 261 | 262 | 263 | Apache: Uptime 264 | 265 | 60 266 | 30 267 | 365 268 | 0 269 | 0 270 | 271 | 0 272 | 0 273 | 1 274 | 0 275 | 276 | 277 | 0 278 | 279 | 280 | 281 | 282 | 283 | localhost 284 | public 285 | interfaces.ifTable.ifEntry.ifInOctets.1 286 | 161 287 | 288 | 0 289 | 290 | 291 | 0 292 | 293 | Apache statistics 294 | 295 | 296 | 297 | Apache: Free slots 298 | 299 | 60 300 | 30 301 | 365 302 | 0 303 | 0 304 | 305 | 0 306 | 0 307 | 0 308 | 0 309 | 310 | 311 | 0 312 | 313 | 314 | 315 | 316 | 317 | localhost 318 | 319 | 320 | 161 321 | 322 | 0 323 | 324 | 325 | 0 326 | 327 | Apache statistics 328 | 329 | 330 | 331 | 332 | 333 | 334 | 0 335 | 0 336 | 337 | 338 | 0 339 | 0 340 | 1 341 | 0.0000 342 | 100.0000 343 | 0 344 | 0 345 | 0.0000 346 | 0.0000 347 | 348 | 349 | 1 350 | 0 351 | 00cc00 352 | 0 353 | 2 354 | 0 355 | 5 356 | 357 | 358 | 1 359 | 1 360 | 0066b3 361 | 0 362 | 2 363 | 0 364 | 5 365 | 366 | 367 | 1 368 | 2 369 | ffcc00 370 | 0 371 | 2 372 | 0 373 | 5 374 | 375 | 376 | 377 | 378 | 0 379 | 0 380 | 381 | 382 | 0 383 | 0 384 | 0 385 | 0.0000 386 | 100.0000 387 | 0 388 | 0 389 | 0.0000 390 | 0.0000 391 | 392 | 393 | 0 394 | 0 395 | 00cc00 396 | 0 397 | 2 398 | 0 399 | 5 400 | 401 | 402 | 403 | 404 | 0 405 | 0 406 | 407 | 408 | 0 409 | 0 410 | 0 411 | 0.0000 412 | 100.0000 413 | 0 414 | 0 415 | 0.0000 416 | 0.0000 417 | 418 | 419 | 2 420 | 0 421 | 00cc00 422 | 0 423 | 2 424 | 0 425 | 5 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | -------------------------------------------------------------------------------- /apache/apache_status.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | if [[ "$1" = "Workers" ]]; then 3 | wget --quiet -O - http://localhost/server-status?auto | grep Score | grep -o "\." | wc -l 4 | else 5 | wget --quiet -O - http://localhost/server-status?auto | head -n 9 | grep $1 | awk -F ":" '{print $2}' 6 | fi 7 | -------------------------------------------------------------------------------- /install/Zabbix 监控vmware.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kerncai/zabbix/53cad73d345a55677c3238ca2ac4855dc8df2bfa/install/Zabbix 监控vmware.docx -------------------------------------------------------------------------------- /install/Zabbix 监控硬件.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kerncai/zabbix/53cad73d345a55677c3238ca2ac4855dc8df2bfa/install/Zabbix 监控硬件.docx -------------------------------------------------------------------------------- /install/centos7下安装mysql5.6.32文档.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kerncai/zabbix/53cad73d345a55677c3238ca2ac4855dc8df2bfa/install/centos7下安装mysql5.6.32文档.docx -------------------------------------------------------------------------------- /install/centos7下安装zabbix3.0.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kerncai/zabbix/53cad73d345a55677c3238ca2ac4855dc8df2bfa/install/centos7下安装zabbix3.0.docx -------------------------------------------------------------------------------- /io_monitor/dev-discovery.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | num=$(iostat |grep -ni device:|awk '{print $1}'|awk -F\: '{print $1 }') 4 | ((num=num+1)) 5 | ###增加lvm的监控 6 | DEVICES=$(iostat |sed -n "$num,$ p"|awk '{print $1}') 7 | COUNT=`echo "$DEVICES" | wc -l` 8 | INDEX=0 9 | echo '{"data":[' 10 | echo "$DEVICES" | while read LINE; do 11 | echo -n '{"{#DEVNAME}":"'$LINE'"}' 12 | INDEX=`expr $INDEX + 1` 13 | if [ $INDEX -lt $COUNT ]; then 14 | echo ',' 15 | fi 16 | done 17 | echo ']}' 18 | 19 | -------------------------------------------------------------------------------- /io_monitor/extra.conf: -------------------------------------------------------------------------------- 1 | ## DO NOT EDIT: This file comes with the package. 2 | 3 | # iostat 4 | UserParameter=custom.vfs.dev.discovery,/usr/local/zabbix-agent-ops/bin/dev-discovery.sh 5 | UserParameter=iostat[*],/usr/local/zabbix-agent-ops/bin/iostat-check.sh $1 $2 6 | -------------------------------------------------------------------------------- /io_monitor/iostat-check.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ################################## 3 | # Zabbix monitoring script 4 | # 5 | # iostat: 6 | # - IO 7 | # - running / blocked processes 8 | # - swap in / out 9 | # - block in / out 10 | # 11 | # Info: 12 | # - vmstat data are gathered via cron job 13 | ################################## 14 | # Contact: 15 | # vincent.viallet@gmail.com 16 | ################################## 17 | # ChangeLog: 18 | # 20100922 VV initial creation 19 | ################################## 20 | 21 | # Zabbix requested parameter 22 | ZBX_REQ_DATA="$2" 23 | ZBX_REQ_DATA_DEV="$1" 24 | 25 | # source data file 26 | SOURCE_DATA=/usr/local/zabbix-agent-ops/var/iostat-data 27 | 28 | # 29 | # Error handling: 30 | # - need to be displayable in Zabbix (avoid NOT_SUPPORTED) 31 | # - items need to be of type "float" (allow negative + float) 32 | # 33 | ERROR_NO_DATA_FILE="-0.9900" 34 | ERROR_OLD_DATA="-0.9901" 35 | ERROR_WRONG_PARAM="-0.9902" 36 | ERROR_MISSING_PARAM="-0.9903" 37 | 38 | # No data file to read from 39 | if [ ! -f "$SOURCE_DATA" ]; then 40 | echo $ERROR_NO_DATA_FILE 41 | exit 1 42 | fi 43 | 44 | # Missing device to get data from 45 | if [ -z "$ZBX_REQ_DATA_DEV" ]; then 46 | echo $ERROR_MISSING_PARAM 47 | exit 1 48 | fi 49 | 50 | # 51 | # Old data handling: 52 | # - in case the cron can not update the data file 53 | # - in case the data are too old we want to notify the system 54 | # Consider the data as non-valid if older than OLD_DATA minutes 55 | # 56 | OLD_DATA=5 57 | if [ $(stat -c "%Y" $SOURCE_DATA) -lt $(date -d "now -$OLD_DATA min" "+%s" ) ]; then 58 | echo $ERROR_OLD_DATA 59 | exit 1 60 | fi 61 | 62 | # 63 | # Grab data from SOURCE_DATA for key ZBX_REQ_DATA 64 | # 65 | # 1st check the device exists and gets data gathered by cron job 66 | device_count=$(grep -Ec "^$ZBX_REQ_DATA_DEV " $SOURCE_DATA) 67 | if [ $device_count -eq 0 ]; then 68 | echo $ERROR_WRONG_PARAM 69 | exit 1 70 | fi 71 | 72 | # 2nd grab the data from the source file 73 | case $ZBX_REQ_DATA in 74 | rrqm/s) grep -E "^$ZBX_REQ_DATA_DEV " $SOURCE_DATA | tail -1 | awk '{print $2}';; 75 | wrqm/s) grep -E "^$ZBX_REQ_DATA_DEV " $SOURCE_DATA | tail -1 | awk '{print $3}';; 76 | r/s) grep -E "^$ZBX_REQ_DATA_DEV " $SOURCE_DATA | tail -1 | awk '{print $4}';; 77 | w/s) grep -E "^$ZBX_REQ_DATA_DEV " $SOURCE_DATA | tail -1 | awk '{print $5}';; 78 | rkB/s) grep -E "^$ZBX_REQ_DATA_DEV " $SOURCE_DATA | tail -1 | awk '{print $6}';; 79 | wkB/s) grep -E "^$ZBX_REQ_DATA_DEV " $SOURCE_DATA | tail -1 | awk '{print $7}';; 80 | avgrq-sz) grep -E "^$ZBX_REQ_DATA_DEV " $SOURCE_DATA | tail -1 | awk '{print $8}';; 81 | avgqu-sz) grep -E "^$ZBX_REQ_DATA_DEV " $SOURCE_DATA | tail -1 | awk '{print $9}';; 82 | await) grep -E "^$ZBX_REQ_DATA_DEV " $SOURCE_DATA | tail -1 | awk '{print $10}';; 83 | svctm) grep -E "^$ZBX_REQ_DATA_DEV " $SOURCE_DATA | tail -1 | awk '{print $11}';; 84 | %util) grep -E "^$ZBX_REQ_DATA_DEV " $SOURCE_DATA | tail -1 | awk '{print $12}';; 85 | *) echo $ERROR_WRONG_PARAM; exit 1;; 86 | esac 87 | 88 | exit 0 89 | 90 | -------------------------------------------------------------------------------- /io_monitor/iostat-cron.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ################################## 3 | # Zabbix monitoring script 4 | # 5 | # Info: 6 | # - cron job to gather iostat data 7 | # - can not do real time as iostat data gathering will exceed 8 | # Zabbix agent timeout 9 | ################################## 10 | # Contact: 11 | # vincent.viallet@gmail.com 12 | ################################## 13 | # ChangeLog: 14 | # 20100922 VV initial creation 15 | ################################## 16 | 17 | # source data file 18 | DEST_DATA=/usr/local/zabbix-agent-ops/var/iostat-data 19 | TMP_DATA=/usr/local/zabbix-agent-ops/var/iostat-data.tmp 20 | 21 | # 22 | # gather data in temp file first, then move to final location 23 | # it avoids zabbix-agent to gather data from a half written source file 24 | # 25 | # iostat -kx 10 2 - will display 2 lines : 26 | # - 1st: statistics since boot -- useless 27 | # - 2nd: statistics over the last 10 sec 28 | # 29 | iostat -kx 10 2 > $TMP_DATA 30 | mv $TMP_DATA $DEST_DATA 31 | 32 | 33 | -------------------------------------------------------------------------------- /io_monitor/zbx_export_templates.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 2.0 4 | 2014-02-14T01:30:29Z 5 | 6 | 7 | Templates 8 | 9 | 10 | 11 | 743 | 744 | 745 | -------------------------------------------------------------------------------- /memcached/README: -------------------------------------------------------------------------------- 1 | Install perl Cache::Memcached from CPAN or your upstream distribution vendor. 2 | 3 | - perl-Cache-Memcached on redhat/fedora 4 | - libcache-memcached-perl on debian/ubuntu 5 | 6 | Generate template for desired port. For memcached listening on different address adjust template and stats collecting script accordingly. 7 | 8 | export PORT=11211; sed -e "s/#PORT#/$PORT/g" memcached_t.xml > memcached_t_$PORT.xml 9 | 10 | Add userparams into /etc/zabbix/zabbix_agentd.conf. 11 | 12 | UserParameter=memcached.stat[*],awk '/^STAT $1 / {print $$3}' /tmp/_zabbix_memcached_stat_$2 13 | UserParameter=memcached.mem[*],ps -e -orss,cmd | grep -vE '(awk|grep)' | awk '/memcached.*$1/ {print $$1}' 14 | 15 | Add cron job for runtime statistics precollection into files (crontab -e). 16 | 17 | * * * * * /usr/local/bin/memcached_stats.pl 18 | -------------------------------------------------------------------------------- /memcached/memcached_stats.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | # 2012, WTFPL. 3 | 4 | use strict; 5 | use warnings; 6 | use Cache::Memcached; 7 | 8 | my @mds; 9 | 10 | open(my $netstat, 'netstat -lnept4|'); 11 | 12 | while (<$netstat>) { 13 | if (/\s(\S*):(\d+).*memcache/) { 14 | push @mds, "$1:$2"; 15 | } 16 | } 17 | 18 | my $memc = new Cache::Memcached; 19 | $memc->set_servers(\@mds); 20 | my $stats = $memc->stats(); 21 | #print Dumper($stats); 22 | 23 | for my $host (keys %{$stats->{hosts}}) { 24 | $host =~ /:(\d+)/; 25 | my $port = $1; 26 | open (my $z, ">/tmp/_zabbix_memcached_stat_$port"); 27 | 28 | for my $key (keys %{$stats->{hosts}{$host}{misc}}) { 29 | print $z "STAT $key $stats->{hosts}{$host}{misc}{$key}\n"; 30 | } 31 | 32 | close ($z); 33 | } 34 | -------------------------------------------------------------------------------- /nginx/README.md: -------------------------------------------------------------------------------- 1 | 监控nginx也是需要在nginx配置,将nginx的状态转发出来,这边是将php-fpm的状态和nginx的状态配置文件写在一起的,详细情况查看上文的php-fpm监控的README.md 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /nginx/nginx_status: -------------------------------------------------------------------------------- 1 | UserParameter=Active,/usr/local/zabbix-agent-ops/bin/nginx_status.sh Active 2 | UserParameter=Reading,/usr/local/zabbix-agent-ops/bin/nginx_status.sh Reading 3 | UserParameter=Writing,/usr/local/zabbix-agent-ops/bin/nginx_status.sh Writing 4 | UserParameter=Waiting,/usr/local/zabbix-agent-ops/bin/nginx_status.sh Waiting 5 | -------------------------------------------------------------------------------- /nginx/nginx_status.sh: -------------------------------------------------------------------------------- 1 | ######################################################################### 2 | # File Name: nginx_status.sh 3 | # Author: kerncai 4 | # mail: kernkerncai@gmail.com 5 | # Created Time: 2013年11月13日 星期三 14时14分05秒 6 | ######################################################################### 7 | #!/bin/bash 8 | 9 | Active(){ 10 | wget --quiet -O - http://localhost:40080/nginx_status?auto |awk 'NR==1 {print$3}' 11 | } 12 | Reading(){ 13 | wget --quiet -O - http://localhost:40080/nginx_status?auto |awk 'NR==4 {print$2}' 14 | } 15 | Writing(){ 16 | wget --quiet -O - http://localhost:40080/nginx_status?auto |awk 'NR==4 {print$4}' 17 | } 18 | Waiting(){ 19 | wget --quiet -O - http://localhost:40080/nginx_status?auto |awk 'NR==4 {print$6}' 20 | } 21 | $1 22 | 23 | -------------------------------------------------------------------------------- /nginx/nginx_status.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 2.0 4 | 2013-11-13T06:24:34Z 5 | 6 | 7 | app 8 | 9 | 10 | Templates 11 | 12 | 13 | 14 | 173 | 174 | 175 | 176 | nginx_connections 177 | 900 178 | 200 179 | 0.0000 180 | 100.0000 181 | 1 182 | 1 183 | 0 184 | 1 185 | 0 186 | 0.0000 187 | 0.0000 188 | 0 189 | 0 190 | 0 191 | 0 192 | 193 | 194 | 0 195 | 0 196 | C80000 197 | 0 198 | 2 199 | 0 200 | 201 | nginx_status 202 | Active 203 | 204 | 205 | 206 | 1 207 | 0 208 | 00C800 209 | 0 210 | 2 211 | 0 212 | 213 | nginx_status 214 | Reading 215 | 216 | 217 | 218 | 2 219 | 0 220 | 0000C8 221 | 0 222 | 2 223 | 0 224 | 225 | nginx_status 226 | Waiting 227 | 228 | 229 | 230 | 3 231 | 0 232 | C800C8 233 | 0 234 | 2 235 | 0 236 | 237 | nginx_status 238 | Writing 239 | 240 | 241 | 242 | 243 | 244 | 245 | -------------------------------------------------------------------------------- /oracle/asm/asm.conf: -------------------------------------------------------------------------------- 1 | UserParameter=data.free,/usr/local/zabbix-howbuy-agent/bin/check_asm_status.sh data_free 2 | UserParameter=data.used,/usr/local/zabbix-howbuy-agent/bin/check_asm_status.sh data_used 3 | UserParameter=data.total,/usr/local/zabbix-howbuy-agent/bin/check_asm_status.sh data_total 4 | UserParameter=data.used.retio,/usr/local/zabbix-howbuy-agent/bin/check_asm_status.sh data_used_retio 5 | UserParameter=data.pfree,/usr/local/zabbix-howbuy-agent/bin/check_asm_status.sh data_pfree 6 | UserParameter=reco.free,/usr/local/zabbix-howbuy-agent/bin/check_asm_status.sh reco_free 7 | UserParameter=reco.used,/usr/local/zabbix-howbuy-agent/bin/check_asm_status.sh reco_used 8 | UserParameter=reco.total,/usr/local/zabbix-howbuy-agent/bin/check_asm_status.sh reco_total 9 | UserParameter=reco.used.retio,/usr/local/zabbix-howbuy-agent/bin/check_asm_status.sh reco_used_retio 10 | UserParameter=reco.pfree,/usr/local/zabbix-howbuy-agent/bin/check_asm_status.sh reco_pfree 11 | -------------------------------------------------------------------------------- /oracle/asm/check_asm.sh: -------------------------------------------------------------------------------- 1 | ######################################################################### 2 | # File Name: check_asm.sh 3 | # Author: kerncai 4 | # mail: kernkerncai@gmail.com 5 | # Created Time: 2014年07月16日 星期三 11时02分04秒 6 | ######################################################################### 7 | #user:oracle 8 | #!/bin/bash 9 | source /home/oracle/.bash_profile 10 | 11 | sqlplus -s / as sysdba > /usr/local/zabbix-howbuy-agent/var/asm.log < 0; 14 | exit; 15 | EOF 16 | 17 | -------------------------------------------------------------------------------- /oracle/asm/check_asm_status.sh: -------------------------------------------------------------------------------- 1 | ######################################################################### 2 | # File Name: check_asm_status.sh 3 | # Author: kerncai 4 | # mail: kernkerncai@gmail.com 5 | # Created Time: 2014年07月16日 星期三 11时03分05秒 6 | ######################################################################### 7 | #!/bin/bash 8 | data_free() { 9 | cat /usr/local/zabbix-howbuy-agent/var/asm.log|grep -i data |awk '{print$2*1024*1024}' 10 | } 11 | 12 | data_used() { 13 | cat /usr/local/zabbix-howbuy-agent/var/asm.log|grep -i data |awk '{print$4*1024*1024}' 14 | } 15 | 16 | data_total() { 17 | cat /usr/local/zabbix-howbuy-agent/var/asm.log|grep -i data |awk '{print$3*1024*1024}' 18 | } 19 | 20 | data_used_retio() { 21 | cat /usr/local/zabbix-howbuy-agent/var/asm.log |grep -i data |awk 'END{printf "%4.2f\n",$4/$3*100}' 22 | } 23 | 24 | data_pfree() { 25 | cat /usr/local/zabbix-howbuy-agent/var/asm.log |grep -i data |awk 'END{printf "%4.2f\n",$2/$3*100}' 26 | } 27 | 28 | 29 | reco_free() { 30 | cat /usr/local/zabbix-howbuy-agent/var/asm.log|grep -i reco |awk '{print$2*1024*1024}' 31 | } 32 | 33 | reco_used() { 34 | cat /usr/local/zabbix-howbuy-agent/var/asm.log|grep -i reco |awk '{print$4*1024*1024}' 35 | } 36 | 37 | reco_total() { 38 | cat /usr/local/zabbix-howbuy-agent/var/asm.log|grep -i reco |awk '{print$3*1024*1024}' 39 | } 40 | 41 | reco_used_retio() { 42 | cat /usr/local/zabbix-howbuy-agent/var/asm.log |grep -i reco |awk 'END{printf "%4.2f\n",$4/$3*100}' 43 | } 44 | 45 | reco_pfree() { 46 | cat /usr/local/zabbix-howbuy-agent/var/asm.log |grep -i reco |awk 'END{printf "%4.2f\n",$2/$3*100}' 47 | } 48 | 49 | $1 50 | -------------------------------------------------------------------------------- /oracle/asm/readme.md: -------------------------------------------------------------------------------- 1 | asm*相关为rac环境下特有 2 | check_asm.sh 为oracle用户下的crontab 每分钟 3 | check_asm_status.sh 为检测脚本 4 | -------------------------------------------------------------------------------- /oracle/tablespace/orabbix.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | zabbix监控oracle 4 | 5 | 1,Orabbix插件的下载 6 | 7 | http://www.smartmarmot.com/product/orabbix/download/ 8 | 9 | 也可以直接搜索下载,目前最新版本为1.2.3 10 | 11 | 12 | 13 | 下载插件:wget http://www.smartmarmot.com/downloads/orabbix-1.2.3.zip 14 | 15 | 16 | 17 | 2.环境配置 18 | 19 | 若是没有java 需要安装java环境 20 | 21 | 查看java环境: 22 | 23 | [root@wap ~]# whereis java 24 | java: 25 | 26 | 安装java环境: 27 | 28 | [root@wap ~]# yum install java 这里需要查看下安装的java会对系统本身造成什么更改 29 | 30 | 安装完成后查看: 31 | 32 | [root@wap ~]# whereis java 33 | java: /usr/bin/java /etc/java /usr/lib/java /usr/share/java /usr/share/man/man1/java.1.gz 34 | 35 | 2.2 创建一个目录作为orabbix的源地址: 36 | 37 | mkdir -p /usr/local/orabbix 38 | 39 | 解压缩插件: 40 | 41 | [root@wap ~]# unzip -n orabbix-1.2.3.zip -d /usr/local/orabbix/ 42 | 43 | 确认一下是否有oracle帐号 (这步可以不操作,因为本身是监控oracle,肯定会有帐号) 44 | 45 | [root@wap local]# id oracle 46 | uid=552(oracle) gid=552(oinstall) groups=552(oinstall),553(dba) 47 | 48 | 49 | 给定目录权限: 50 | 51 | 52 | 53 | [root@wap local]# chown -R oracle. orabbix/ 54 | 55 | drwxr-xr-x 7 oracle oinstall 4096 Apr 30 17:26 orabbix/ 56 | 57 | 3.更改配置文件: 58 | 59 | cd /usr/local/orabbix/ 60 | 61 | [root@wap orabbix]# cp conf/config.props.sample conf/config.props 62 | 63 | 顺带这添加下系统启动脚本: 64 | 65 | [root@wap orabbix]# cp init.d/orabbix /etc/init.d/orabbix 66 | 67 | [root@wap conf]# pwd 68 | /usr/local/orabbix/conf 69 | [root@wap conf]# vim config.props 70 | 71 | [root@wap conf]# cat config.props|grep -v "^$"|grep -v "^#" 72 | ZabbixServerList=ZabbixServer 73 | 74 | ZabbixServer.Address=10.40.40.15 75 | ZabbixServer.Port=10051 76 | 77 | 78 | OrabbixDaemon.PidFile=./logs/orabbix.pid 79 | OrabbixDaemon.Sleep=300 80 | OrabbixDaemon.MaxThreadNumber=100 81 | 82 | DatabaseList=DB_MON 83 | 84 | DatabaseList.MaxActive=10 85 | DatabaseList.MaxWait=100 86 | DatabaseList.MaxIdle=1 87 | 88 | DB_MON.Url=jdbc:oracle:thin:@10.168.109.22:1521:DB_MON 89 | DB_MON.User=zabbix 90 | DB_MON.Password=zabbix 91 | DB_MON.MaxActive=10 92 | DB_MON.MaxWait=100 93 | DB_MON.MaxIdle=1 94 | DB_MON.QueryListFile=./conf/query.props 95 | 96 | 创建zabbix用户 97 | 98 | 1,账号创建,指定数据及临时表空间profile及账号状态; 99 |   create user zabbix identified by zabbix default tablespace system temporary tablespace temp profile default account unlock; 100 | 101 | 2,给账号赋权限 102 | 103 |   grant connect,resource,dba to zabbix; 104 |   alter user zabbix default role all; 105 |   grant select any table to zabbix; 106 |   grant create session to zabbix; 107 |   grant select any dictionary to zabbix; 108 |   grant unlimited tablespace to zabbix; 109 | 110 | 完成之后,/etc/init.d/orabbix start 111 | 112 | -------------------------------------------------------------------------------- /oracle/tablespace/oracle_check.sh: -------------------------------------------------------------------------------- 1 | ######################################################################### 2 | # File Name: oracle_check.sh 3 | # Author: kerncai 4 | # mail: kernkerncai@gmail.com 5 | # Created Time: 2014年07月16日 星期三 11时07分09秒 6 | ######################################################################### 7 | #!/bin/bash 8 | EQ_DATA="$2" 9 | ZBX_REQ_DATA_TAB="$1" 10 | 11 | SOURCE_DATA=/usr/local/zabbix-howbuy-agent/var/tablespace.log 12 | 13 | ERROR_NO_DATA_FILE="-0.9900" 14 | ERROR_OLD_DATA="-0.9901" 15 | ERROR_WRONG_PARAM="-0.9902" 16 | ERROR_MISSING_PARAM="-0.9903" 17 | 18 | # No data file to read from 19 | if [ ! -f "$SOURCE_DATA" ]; then 20 | echo $ERROR_NO_DATA_FILE 21 | exit 1 22 | fi 23 | 24 | # Missing device to get data from 25 | if [ -z "$ZBX_REQ_DATA_TAB" ]; then 26 | echo $ERROR_MISSING_PARAM 27 | exit 1 28 | fi 29 | 30 | device_count=$(grep -Ec $ZBX_REQ_DATA_TAB $SOURCE_DATA) 31 | if [ $device_count -eq 0 ]; then 32 | exit 1 33 | fi 34 | 35 | case $ZBX_REQ_DATA in 36 | #case $2 in 37 | totalused) grep -E "$ZBX_REQ_DATA_TAB" $SOURCE_DATA |awk '{print $4*1024*1024}';; 38 | maxmb) grep -E "$ZBX_REQ_DATA_TAB" $SOURCE_DATA |awk '{print $3}'| awk -F '.' '{print ($1-2048)*1024*1024}';; 39 | curpercent) grep -E "$ZBX_REQ_DATA_TAB" $SOURCE_DATA |awk '{print $6}';; 40 | autopercent) grep -E "$ZBX_REQ_DATA_TAB" $SOURCE_DATA |awk '{print $7}';; 41 | *) echo $ERROR_WRONG_PARAM; exit 1;; 42 | esac 43 | 44 | exit 0 45 | -------------------------------------------------------------------------------- /oracle/tablespace/oracle_cron.sh: -------------------------------------------------------------------------------- 1 | ######################################################################### 2 | # File Name: oracle_cron.sh 3 | # Author: kerncai 4 | # mail: kernkerncai@gmail.com 5 | # Created Time: 2014年07月16日 星期三 11时05分47秒 6 | ######################################################################### 7 | #user:oracle 8 | #!/bin/bash 9 | 10 | ource /home/oracle/.bash_profile 11 | 12 | sqlplus -s / as sysdba > /usr/local/zabbix-howbuy-agent/var/tablespace.log<0 33 | and round(100*(SUM(a.bytes)/1024/1024 - round(c."Free"/1024/1024))/(SUM(decode(b.maxextend, null, A.BYTES/1024/1024, b.maxextend*8192/1024/1024)))) > 0 34 | order by round(100*(SUM(a.bytes)/1024/1024 - round(c."Free"/1024/1024))/(SUM(decode(b.maxextend, null, A.BYTES/1024/1024, b.maxextend*8192/1024/1024)))) ; 35 | exit; 36 | EOF 37 | -------------------------------------------------------------------------------- /oracle/tablespace/oracle_discovery.sh: -------------------------------------------------------------------------------- 1 | ######################################################################### 2 | # File Name: oracle_discovery.sh 3 | # Author: kerncai 4 | # mail: kernkerncai@gmail.com 5 | # Created Time: 2014年07月16日 星期三 11时05分00秒 6 | ######################################################################### 7 | #!/bin/bash 8 | 9 | PACE=`cat /usr/local/zabbix-howbuy-agent/var/tablespace.log |awk '{print$1}'|awk 'NR>3{print}'` 10 | 11 | COUNT=`echo "$TABLESPACE" |wc -l` 12 | INDEX=0 13 | echo '{"data":[' 14 | echo "$TABLESPACE" | while read LINE; do 15 | echo -n '{"{#TABLENAME}":"'$LINE'"}' 16 | INDEX=`expr $INDEX + 1` 17 | if [ $INDEX -lt $COUNT ]; then 18 | echo ',' 19 | fi 20 | done 21 | echo ']}' 22 | -------------------------------------------------------------------------------- /oracle/tablespace/readme.md: -------------------------------------------------------------------------------- 1 | oracle_cron.sh 为oracle用户下的crontab 每分钟一次,用来将表空间信息提取出来 2 | oracle_discovery.sh 将所需要的数据拼成json格式 3 | oracle_check.sh 检测信息 4 | tablespace.conf为配置文件 5 | *.xml为zabbixserver端的模板,导入即可;这个模板包含了oracle的插件orabbix,里面的一些item做了精简,配置方法见orabbix.md 6 | -------------------------------------------------------------------------------- /oracle/tablespace/tablespace.conf: -------------------------------------------------------------------------------- 1 | #oracle tablespace 2 | 3 | UserParameter=ora.tab.discovery,/usr/local/zabbix-howbuy-agent/bin/oracle_discovery.sh 4 | UserParameter=tablespace[*],/usr/local/zabbix-howbuy-agent/bin/oracle_check.sh $1 $2 5 | -------------------------------------------------------------------------------- /phpfpm/README.md: -------------------------------------------------------------------------------- 1 | 在添加脚本之前,需要将所监控php-fpm需要在nginx内配置php-fpm的状态并转发出来,nginx内配置如下 2 | 配置完成后,可以打开浏览器查看下状态,是否可以正常访问 3 | 4 | 配置完成后,将脚本放在所需要监控的机器上面,模板导入到web即可 5 | 6 | nginx配置如下: 7 | 8 | 9 | server { 10 | 11 | listen 40080; 12 | server_name _; 13 | allow 127.0.0.1; 14 | deny all; 15 | access_log off; 16 | location /php-fpm_status { 17 | fastcgi_pass unix:/tmp/php-fpm.sock; 18 | include fastcgi_params; 19 | fastcgi_param SCRIPT_FILENAME $fastcgi_script_name; 20 | 21 | } 22 | 23 | location /nginx_status { #这里配置的是nginx的状态,和php-fpm的监控一样 24 | 25 | stub_status on; 26 | 27 | } 28 | 29 | } 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /phpfpm/php-fpm_status: -------------------------------------------------------------------------------- 1 | UserParameter=idle.processe,/usr/local/zabbix-agent-ops/bin/php-fpm_status.sh idle 2 | UserParameter=total.processes,/usr/local/zabbix-agent-ops/bin/php-fpm_status.sh total 3 | UserParameter=active.processes,/usr/local/zabbix-agent-ops/bin/php-fpm_status.sh active 4 | UserParameter=max.active.processes,/usr/local/zabbix-agent-ops/bin/php-fpm_status.sh mactive 5 | UserParameter=listen.queue.len,/usr/local/zabbix-agent-ops/bin/php-fpm_status.sh listenqueuelen 6 | UserParameter=listen.queue,/usr/local/zabbix-agent-ops/bin/php-fpm_status.sh listenqueue 7 | UserParameter=start.since,/usr/local/zabbix-agent-ops/bin/php-fpm_status.sh since 8 | UserParameter=accepted.conn,/usr/local/zabbix-agent-ops/bin/php-fpm_status.sh conn 9 | -------------------------------------------------------------------------------- /phpfpm/php-fpm_status.sh: -------------------------------------------------------------------------------- 1 | ######################################################################### 2 | # File Name: php-fpm_status.sh 3 | # Author: kerncai 4 | # mail: kernkerncai@gmail.com 5 | # Created Time: 2013年11月13日 星期三 14时02分35秒 6 | ######################################################################### 7 | #!/bin/bash 8 | idle(){ 9 | wget --quiet -O - http://127.0.0.1:40080/php-fpm_status?auto |grep "idle processes" |awk '{print$3}' 10 | } 11 | 12 | total(){ 13 | wget --quiet -O - http://127.0.0.1:40080/php-fpm_status?auto |grep "total processes" |awk '{print$3}' 14 | } 15 | 16 | active(){ 17 | wget --quiet -O - http://127.0.0.1:40080/php-fpm_status?auto |grep "active" |awk '{print$3}'|grep -v "process" 18 | } 19 | 20 | mactive(){ 21 | 22 | wget --quiet -O - http://127.0.0.1:40080/php-fpm_status?auto |grep "max active processes:" |awk '{print$4}' 23 | } 24 | 25 | listenqueuelen(){ 26 | wget --quiet -O - http://127.0.0.1:40080/php-fpm_status?auto |grep "listen queue len" |awk '{print$4}' 27 | } 28 | 29 | listenqueue(){ 30 | wget --quiet -O - http://127.0.0.1:40080/php-fpm_status?auto |grep "listen queue:"|grep -vE "len|max"|awk '{print$3}' 31 | } 32 | 33 | since(){ 34 | wget --quiet -O - http://127.0.0.1:40080/php-fpm_status?auto |grep "start since: " |awk '{print$3}' 35 | } 36 | 37 | conn(){ 38 | wget --quiet -O - http://127.0.0.1:40080/php-fpm_status?auto |grep "accepted conn" |awk '{print$3}' 39 | } 40 | $1 41 | 42 | -------------------------------------------------------------------------------- /phpfpm/php-fpm_status.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 2.0 4 | 2013-11-13T06:26:56Z 5 | 6 | 7 | Templates 8 | 9 | 10 | 11 | 348 | 349 | 350 | 351 | php-fpm_status 352 | 900 353 | 200 354 | 0.0000 355 | 100.0000 356 | 1 357 | 1 358 | 0 359 | 1 360 | 0 361 | 0.0000 362 | 0.0000 363 | 0 364 | 0 365 | 0 366 | 0 367 | 368 | 369 | 0 370 | 0 371 | C800C8 372 | 0 373 | 2 374 | 0 375 | 376 | Template php-fpm 377 | active.processes 378 | 379 | 380 | 381 | 1 382 | 0 383 | 00C8C8 384 | 0 385 | 2 386 | 0 387 | 388 | Template php-fpm 389 | listen.queue 390 | 391 | 392 | 393 | 2 394 | 0 395 | C8C800 396 | 0 397 | 2 398 | 0 399 | 400 | Template php-fpm 401 | listen.queue.len 402 | 403 | 404 | 405 | 3 406 | 0 407 | C8C8C8 408 | 0 409 | 2 410 | 0 411 | 412 | Template php-fpm 413 | max.active.processes 414 | 415 | 416 | 417 | 4 418 | 0 419 | 960000 420 | 0 421 | 2 422 | 0 423 | 424 | Template php-fpm 425 | idle.processe 426 | 427 | 428 | 429 | 5 430 | 0 431 | 000096 432 | 0 433 | 2 434 | 0 435 | 436 | Template php-fpm 437 | total.processes 438 | 439 | 440 | 441 | 442 | 443 | 444 | -------------------------------------------------------------------------------- /port-discovery/port-discovery.sh: -------------------------------------------------------------------------------- 1 | ######################################################################### 2 | # File Name: port-discovery.sh 3 | # Author: kerncai 4 | # mail: kernkerncai@gmail.com 5 | # Created Time: 2014年07月16日 星期三 11时23分40秒 6 | ######################################################################### 7 | #!/bin/bash 8 | 9 | portarray=(`netstat -tnlp|egrep -i "$1"|awk {'print $4'}|awk -F':' '{if ($NF~/^[0-9]*$/) print $NF}'|sort |uniq 2>/dev/null`) 10 | length=${#portarray[@]} 11 | printf "{\n" 12 | printf '\t'"\"data\":[" 13 | for ((i=0;i<$length;i++)) 14 | do 15 | printf '\n\t\t{' 16 | printf "\"{#TCP_PORT}\":\"${portarray[$i]}\"}" 17 | if [ $i -lt $[$length-1] ];then 18 | printf ',' 19 | fi 20 | done 21 | printf "\n\t]\n" 22 | printf "}\n" 23 | -------------------------------------------------------------------------------- /port-discovery/port-discovery.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 2.0 4 | 2014-07-16T03:25:57Z 5 | 6 | 7 | Templates 8 | 9 | 10 | 11 | 117 | 118 | 119 | -------------------------------------------------------------------------------- /port-discovery/port.conf: -------------------------------------------------------------------------------- 1 | UserParameter=port[*],/usr/local/zabbix-howbuy-agent/bin/port-discovery.sh $1 2 | -------------------------------------------------------------------------------- /redis/README: -------------------------------------------------------------------------------- 1 | Usage: 2 | 3 | As root setup a cronjob: 4 | * * * * * /usr/bin/redis-cli info > /tmp/redisstat 5 | 6 | Add an user parameter to zabbix: 7 | UserParameter=redis.stat[*],cat /tmp/redisstat | grep "$1:" | cut -d":" -f2 8 | -------------------------------------------------------------------------------- /redis/redis_t.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 0 6 | 1 7 | 8 | 127.0.0.1 9 | 10050 10 | 3 11 | 0 12 | 127.0.0.1 13 | 623 14 | 0 15 | 2 16 | 17 | 18 | 19 | Templates 20 | 21 | 22 | 23 | 24 | Redis is running 25 | 26 | 60 27 | 30 28 | 365 29 | 0 30 | 0 31 | 32 | 0 33 | 0 34 | 0 35 | 0 36 | 37 | 38 | 0 39 | 40 | 41 | 42 | 43 | 44 | localhost 45 | 46 | 47 | 161 48 | 49 | 0 50 | 51 | 52 | 0 53 | 54 | Redis 55 | 56 | 57 | 58 | Blocked Clients 59 | 60 | 60 61 | 30 62 | 365 63 | 0 64 | 0 65 | 66 | 0 67 | 2 68 | 0 69 | 0 70 | 71 | 72 | 0 73 | 74 | 75 | 76 | 77 | 78 | localhost 79 | 80 | 81 | 161 82 | 83 | 0 84 | 85 | 86 | 0 87 | 88 | Redis 89 | Redis: Clients 90 | 91 | 92 | 93 | Changes Since Last Save 94 | 95 | 60 96 | 30 97 | 365 98 | 0 99 | 0 100 | 101 | 0 102 | 0 103 | 0 104 | 0 105 | 106 | 107 | 0 108 | 109 | 110 | 111 | 112 | 113 | localhost 114 | 115 | 116 | 161 117 | 118 | 0 119 | 120 | 121 | 0 122 | 123 | Redis 124 | Redis: Keys 125 | 126 | 127 | 128 | Client Biggest Input Buffer 129 | 130 | 60 131 | 30 132 | 365 133 | 0 134 | 0 135 | 136 | 0 137 | 1 138 | 0 139 | 0 140 | 141 | 142 | 0 143 | 144 | 145 | 146 | 147 | 148 | localhost 149 | 150 | 151 | 161 152 | 153 | 0 154 | 155 | 156 | 0 157 | 158 | Redis 159 | Redis: Clients 160 | 161 | 162 | 163 | Client Longest Output List 164 | 165 | 60 166 | 30 167 | 365 168 | 0 169 | 0 170 | 171 | 0 172 | 1 173 | 0 174 | 0 175 | 176 | 177 | 0 178 | 179 | 180 | 181 | 182 | 183 | localhost 184 | 185 | 186 | 161 187 | 188 | 0 189 | 190 | 191 | 0 192 | 193 | Redis 194 | Redis: Clients 195 | 196 | 197 | 198 | Connected Clients 199 | 200 | 60 201 | 30 202 | 365 203 | 0 204 | 0 205 | 206 | 0 207 | 0 208 | 0 209 | 0 210 | 211 | 212 | 0 213 | 214 | 215 | 216 | 217 | 218 | localhost 219 | 220 | 221 | 161 222 | 223 | 0 224 | 225 | 226 | 0 227 | 228 | Redis 229 | Redis: Clients 230 | 231 | 232 | 233 | Connected Slaves 234 | 235 | 60 236 | 30 237 | 365 238 | 0 239 | 0 240 | 241 | 0 242 | 0 243 | 0 244 | 0 245 | 246 | 247 | 0 248 | 249 | 250 | 251 | 252 | 253 | localhost 254 | 255 | 256 | 161 257 | 258 | 0 259 | 260 | 261 | 0 262 | 263 | Redis 264 | Redis: Clients 265 | 266 | 267 | 268 | Evicted Keys 269 | 270 | 60 271 | 30 272 | 365 273 | 0 274 | 0 275 | 276 | 0 277 | 1 278 | 0 279 | 0 280 | 281 | 282 | 0 283 | 284 | 285 | 286 | 287 | 288 | localhost 289 | 290 | 291 | 161 292 | 293 | 0 294 | 295 | 296 | 0 297 | 298 | Redis 299 | Redis: Keys 300 | 301 | 302 | 303 | Expired Keys 304 | 305 | 60 306 | 30 307 | 365 308 | 0 309 | 0 310 | 311 | 0 312 | 1 313 | 0 314 | 0 315 | 316 | 317 | 0 318 | 319 | 320 | 321 | 322 | 323 | localhost 324 | 325 | 326 | 161 327 | 328 | 0 329 | 330 | 331 | 0 332 | 333 | Redis 334 | Redis: Keys 335 | 336 | 337 | 338 | Keyspace Hits 339 | 340 | 60 341 | 30 342 | 365 343 | 0 344 | 0 345 | 346 | 0 347 | 1 348 | 0 349 | 0 350 | 351 | 352 | 0 353 | 354 | 355 | 356 | 357 | 358 | localhost 359 | 360 | 361 | 161 362 | 363 | 0 364 | 365 | 366 | 0 367 | 368 | Redis 369 | Redis: Keys 370 | 371 | 372 | 373 | Keyspace Misses 374 | 375 | 60 376 | 30 377 | 365 378 | 0 379 | 0 380 | 381 | 0 382 | 1 383 | 0 384 | 0 385 | 386 | 387 | 0 388 | 389 | 390 | 391 | 392 | 393 | localhost 394 | 395 | 396 | 161 397 | 398 | 0 399 | 400 | 401 | 0 402 | 403 | Redis 404 | Redis: Keys 405 | 406 | 407 | 408 | Memory Fragmentation Ratio 409 | 410 | 60 411 | 30 412 | 365 413 | 0 414 | 0 415 | 416 | 0 417 | 0 418 | 0 419 | 0 420 | 421 | 422 | 0 423 | 424 | 425 | 426 | 427 | 428 | localhost 429 | 430 | 431 | 161 432 | 433 | 0 434 | 435 | 436 | 0 437 | 438 | Redis 439 | Redis: Memory 440 | 441 | 442 | 443 | Commands/sec 444 | 445 | 60 446 | 30 447 | 365 448 | 0 449 | 0 450 | 451 | 0 452 | 1 453 | 0 454 | 0 455 | 456 | 457 | 0 458 | 459 | 460 | 461 | 462 | 463 | localhost 464 | 465 | 466 | 161 467 | 468 | 0 469 | 470 | 471 | 0 472 | 473 | Redis 474 | 475 | 476 | 477 | Connections/sec 478 | 479 | 60 480 | 30 481 | 365 482 | 0 483 | 0 484 | 485 | 0 486 | 1 487 | 0 488 | 0 489 | 490 | 491 | 0 492 | 493 | 494 | 495 | 496 | 497 | localhost 498 | 499 | 500 | 161 501 | 502 | 0 503 | 504 | 505 | 0 506 | 507 | Redis 508 | Redis: Clients 509 | 510 | 511 | 512 | Used CPU Sys 513 | 514 | 60 515 | 30 516 | 365 517 | 0 518 | 0 519 | 520 | 0 521 | 1 522 | 0 523 | 0 524 | 525 | 526 | 0 527 | 528 | 529 | 530 | 531 | 532 | localhost 533 | 534 | 535 | 161 536 | 537 | 0 538 | 539 | 540 | 0 541 | 542 | Redis 543 | Redis: CPU 544 | 545 | 546 | 547 | Used CPU Sys Childrens 548 | 549 | 60 550 | 30 551 | 365 552 | 0 553 | 0 554 | 555 | 0 556 | 1 557 | 0 558 | 0 559 | 560 | 561 | 0 562 | 563 | 564 | 565 | 566 | 567 | localhost 568 | 569 | 570 | 161 571 | 572 | 0 573 | 574 | 575 | 0 576 | 577 | Redis 578 | Redis: CPU 579 | 580 | 581 | 582 | Used CPU User 583 | 584 | 60 585 | 30 586 | 365 587 | 0 588 | 0 589 | 590 | 0 591 | 1 592 | 0 593 | 0 594 | 595 | 596 | 0 597 | 598 | 599 | 600 | 601 | 602 | localhost 603 | 604 | 605 | 161 606 | 607 | 0 608 | 609 | 610 | 0 611 | 612 | Redis 613 | Redis: CPU 614 | 615 | 616 | 617 | Used CPU User Childrens 618 | 619 | 60 620 | 30 621 | 365 622 | 0 623 | 0 624 | 625 | 0 626 | 1 627 | 0 628 | 0 629 | 630 | 631 | 0 632 | 633 | 634 | 635 | 636 | 637 | localhost 638 | 639 | 640 | 161 641 | 642 | 0 643 | 644 | 645 | 0 646 | 647 | Redis 648 | Redis: CPU 649 | 650 | 651 | 652 | Used memory 653 | 654 | 60 655 | 30 656 | 365 657 | 0 658 | 0 659 | B 660 | 0 661 | 0 662 | 0 663 | 0 664 | 665 | 666 | 0 667 | 668 | 669 | 670 | 671 | 672 | localhost 673 | 674 | 675 | 161 676 | 677 | 0 678 | 679 | 680 | 0 681 | 682 | Redis 683 | Redis: Memory 684 | 685 | 686 | 687 | Total Allocated memory 688 | 689 | 60 690 | 30 691 | 365 692 | 0 693 | 0 694 | B 695 | 0 696 | 0 697 | 0 698 | 0 699 | 700 | 701 | 0 702 | 703 | 704 | 705 | 706 | 707 | localhost 708 | 709 | 710 | 161 711 | 712 | 0 713 | 714 | 715 | 0 716 | 717 | Redis 718 | Redis: Memory 719 | 720 | 721 | 722 | 723 | 724 | 725 | 0 726 | 0 727 | 728 | 729 | 0 730 | 0 731 | 0 732 | 0.0000 733 | 100.0000 734 | 0 735 | 0 736 | 0.0000 737 | 0.0000 738 | 739 | 740 | 2 741 | 0 742 | 00cc00 743 | 0 744 | 2 745 | 0 746 | 5 747 | 748 | 749 | 750 | 751 | 0 752 | 0 753 | 754 | 755 | 0 756 | 0 757 | 1 758 | 0.0000 759 | 100.0000 760 | 0 761 | 0 762 | 0.0000 763 | 0.0000 764 | 765 | 766 | 0 767 | 0 768 | 00cc00 769 | 0 770 | 2 771 | 0 772 | 5 773 | 774 | 775 | 0 776 | 1 777 | 0066b3 778 | 0 779 | 2 780 | 0 781 | 5 782 | 783 | 784 | 785 | 786 | 787 | 788 | 789 | 790 | 791 | -------------------------------------------------------------------------------- /squid/README.md: -------------------------------------------------------------------------------- 1 | Please place the script on the need to monitor the machine.Then place the template to import zabbix server web. 2 | 3 | 4 | 5 | 6 | 将脚本放在需要监控的机器上,然后将squid监控的模板导入到web界面 7 | 8 | 脚本内使用的是squid的默认端口3128 9 | -------------------------------------------------------------------------------- /squid/check_squid_status.sh: -------------------------------------------------------------------------------- 1 | ######################################################################### 2 | # File Name: check_squid_status.sh 3 | # Author: kerncai 4 | # mail: kernkerncai@gmail.com 5 | # Created Time: 2013年11月12日 星期二 10时30分05秒 6 | ######################################################################### 7 | #!/bin/bash 8 | 9 | five_min(){ 10 | /usr/local/squid-2.7/bin/squidclient -h localhost -p 3128 mgr:info |grep 'Request Hit Ratios:' |awk '{print$5/100}' 11 | } 12 | 13 | six_min(){ 14 | /usr/local/squid-2.7/bin/squidclient -h localhost -p 3128 mgr:info |grep 'Request Hit Ratios:' |awk '{print$7/100}' 15 | } 16 | 17 | objects(){ 18 | /usr/local/squid-2.7/bin/squidclient -h localhost -p 3128 mgr:info |grep 'on-disk objects' |awk '{print$1}' 19 | } 20 | 21 | space(){ 22 | /usr/local/squid-2.7/bin/squidclient -h localhost -p 3128 mgr:storedir|grep 'Filesystem Space in use:'|awk -F '/' '{print$1}'|awk '{print$5}' 23 | } 24 | 25 | $1 26 | -------------------------------------------------------------------------------- /squid/squid_status.conf: -------------------------------------------------------------------------------- 1 | UserParameter=five.ratios,/usr/local/zabbix-agent-ops/bin/squid_status.sh five_ratios 2 | UserParameter=six.ratios,/usr/local/zabbix-agent-ops/bin/squid_status.sh six_ratios 3 | UserParameter=objects,/usr/local/zabbix-agent-ops/bin/squid_status.sh objects 4 | UserParameter=space,/usr/local/zabbix-agent-ops/bin/squid_status.sh space 5 | -------------------------------------------------------------------------------- /squid/zbx_squid_status.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 2.0 4 | 2013-11-13T05:23:23Z 5 | 6 | 7 | app 8 | 9 | 10 | 11 | 202 | 203 | 204 | 205 | {squid_status:net.tcp.listen[3128].last(0)}=0 206 | The squid is down on {HOST.NAME} 207 | 208 | 0 209 | 5 210 | 211 | 0 212 | 213 | 214 | 215 | 216 | 217 | squid_status:check_alive:3128 218 | 900 219 | 200 220 | 0.0000 221 | 100.0000 222 | 1 223 | 1 224 | 0 225 | 1 226 | 0 227 | 0.0000 228 | 0.0000 229 | 0 230 | 0 231 | 0 232 | 0 233 | 234 | 235 | 0 236 | 0 237 | 00DD00 238 | 0 239 | 2 240 | 0 241 | 242 | squid_status 243 | net.tcp.listen[3128] 244 | 245 | 246 | 247 | 248 | 249 | squid_status:Filesystem Space in use 250 | 900 251 | 200 252 | 0.0000 253 | 100.0000 254 | 1 255 | 1 256 | 0 257 | 1 258 | 0 259 | 0.0000 260 | 0.0000 261 | 0 262 | 0 263 | 0 264 | 0 265 | 266 | 267 | 0 268 | 1 269 | C80000 270 | 0 271 | 2 272 | 0 273 | 274 | squid_status 275 | space 276 | 277 | 278 | 279 | 280 | 281 | squid_status:Internal Data Structures on-disk objects 282 | 900 283 | 200 284 | 0.0000 285 | 100.0000 286 | 1 287 | 1 288 | 0 289 | 1 290 | 0 291 | 0.0000 292 | 0.0000 293 | 0 294 | 0 295 | 0 296 | 0 297 | 298 | 299 | 0 300 | 0 301 | 00BB00 302 | 0 303 | 2 304 | 0 305 | 306 | squid_status 307 | objects 308 | 309 | 310 | 311 | 312 | 313 | squid_status:Request Hit Ratios 314 | 900 315 | 200 316 | 0.0000 317 | 100.0000 318 | 1 319 | 1 320 | 0 321 | 1 322 | 0 323 | 0.0000 324 | 0.0000 325 | 0 326 | 0 327 | 0 328 | 0 329 | 330 | 331 | 0 332 | 0 333 | C80000 334 | 0 335 | 2 336 | 0 337 | 338 | squid_status 339 | five.ratios 340 | 341 | 342 | 343 | 1 344 | 0 345 | 00C800 346 | 0 347 | 2 348 | 0 349 | 350 | squid_status 351 | six.ratios 352 | 353 | 354 | 355 | 356 | 357 | 358 | -------------------------------------------------------------------------------- /varnish/README: -------------------------------------------------------------------------------- 1 | Usage: 2 | 3 | As root setup a cronjob: 4 | * * * * * /usr/bin/varnishstat -1 > /tmp/varnishstat 5 | 6 | Add an user parameter to zabbix: 7 | UserParameter=varnish.stat[*],cat /tmp/varnishstat | grep "$1 " | awk '{print $$2}' 8 | -------------------------------------------------------------------------------- /zabbix-agent-bi-rpm/BUILD/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /zabbix-agent-bi-rpm/RPMS/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /zabbix-agent-bi-rpm/SOURCES/1: -------------------------------------------------------------------------------- 1 | UserParameter=port[*],/usr/local/zabbix-howbuy-bi/bin/port-discovery.sh $1 2 | -------------------------------------------------------------------------------- /zabbix-agent-bi-rpm/SOURCES/cron.conf: -------------------------------------------------------------------------------- 1 | * * * * * root /usr/local/zabbix-agent-bi/bin/iostat-cron.sh 2 | -------------------------------------------------------------------------------- /zabbix-agent-bi-rpm/SOURCES/dev-discovery.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | DEVICES=`iostat | awk '{ if ($1 ~ "^([sh]d[a-z])$") { print $1 } }'` 4 | 5 | COUNT=`echo "$DEVICES" | wc -l` 6 | INDEX=0 7 | echo '{"data":[' 8 | echo "$DEVICES" | while read LINE; do 9 | echo -n '{"{#DEVNAME}":"'$LINE'"}' 10 | INDEX=`expr $INDEX + 1` 11 | if [ $INDEX -lt $COUNT ]; then 12 | echo ',' 13 | fi 14 | done 15 | echo ']}' 16 | 17 | -------------------------------------------------------------------------------- /zabbix-agent-bi-rpm/SOURCES/extra.conf: -------------------------------------------------------------------------------- 1 | ## DO NOT EDIT: This file comes with the package. 2 | 3 | # iostat 4 | UserParameter=custom.vfs.dev.discovery,/usr/local/zabbix-agent-bi/bin/dev-discovery.sh 5 | UserParameter=iostat[*],/usr/local/zabbix-agent-bi/bin/iostat-check.sh $1 $2 6 | UserParameter=port[*],/usr/local/zabbix-howbuy-bi/bin/port-discovery.sh $1 7 | -------------------------------------------------------------------------------- /zabbix-agent-bi-rpm/SOURCES/iostat-check.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ################################## 3 | # Zabbix monitoring script 4 | # 5 | # iostat: 6 | # - IO 7 | # - running / blocked processes 8 | # - swap in / out 9 | # - block in / out 10 | # 11 | # Info: 12 | # - vmstat data are gathered via cron job 13 | ################################## 14 | # Contact: 15 | # vincent.viallet@gmail.com 16 | ################################## 17 | # ChangeLog: 18 | # 20100922 VV initial creation 19 | ################################## 20 | 21 | # Zabbix requested parameter 22 | ZBX_REQ_DATA="$2" 23 | ZBX_REQ_DATA_DEV="$1" 24 | 25 | # source data file 26 | SOURCE_DATA=/usr/local/zabbix-agent-bi/var/iostat-data 27 | 28 | # 29 | # Error handling: 30 | # - need to be displayable in Zabbix (avoid NOT_SUPPORTED) 31 | # - items need to be of type "float" (allow negative + float) 32 | # 33 | ERROR_NO_DATA_FILE="-0.9900" 34 | ERROR_OLD_DATA="-0.9901" 35 | ERROR_WRONG_PARAM="-0.9902" 36 | ERROR_MISSING_PARAM="-0.9903" 37 | 38 | # No data file to read from 39 | if [ ! -f "$SOURCE_DATA" ]; then 40 | echo $ERROR_NO_DATA_FILE 41 | exit 1 42 | fi 43 | 44 | # Missing device to get data from 45 | if [ -z "$ZBX_REQ_DATA_DEV" ]; then 46 | echo $ERROR_MISSING_PARAM 47 | exit 1 48 | fi 49 | 50 | # 51 | # Old data handling: 52 | # - in case the cron can not update the data file 53 | # - in case the data are too old we want to notify the system 54 | # Consider the data as non-valid if older than OLD_DATA minutes 55 | # 56 | OLD_DATA=5 57 | if [ $(stat -c "%Y" $SOURCE_DATA) -lt $(date -d "now -$OLD_DATA min" "+%s" ) ]; then 58 | echo $ERROR_OLD_DATA 59 | exit 1 60 | fi 61 | 62 | # 63 | # Grab data from SOURCE_DATA for key ZBX_REQ_DATA 64 | # 65 | # 1st check the device exists and gets data gathered by cron job 66 | device_count=$(grep -Ec "^$ZBX_REQ_DATA_DEV " $SOURCE_DATA) 67 | if [ $device_count -eq 0 ]; then 68 | echo $ERROR_WRONG_PARAM 69 | exit 1 70 | fi 71 | 72 | # 2nd grab the data from the source file 73 | case $ZBX_REQ_DATA in 74 | rrqm/s) grep -E "^$ZBX_REQ_DATA_DEV " $SOURCE_DATA | tail -1 | awk '{print $2}';; 75 | wrqm/s) grep -E "^$ZBX_REQ_DATA_DEV " $SOURCE_DATA | tail -1 | awk '{print $3}';; 76 | r/s) grep -E "^$ZBX_REQ_DATA_DEV " $SOURCE_DATA | tail -1 | awk '{print $4}';; 77 | w/s) grep -E "^$ZBX_REQ_DATA_DEV " $SOURCE_DATA | tail -1 | awk '{print $5}';; 78 | rkB/s) grep -E "^$ZBX_REQ_DATA_DEV " $SOURCE_DATA | tail -1 | awk '{print $6}';; 79 | wkB/s) grep -E "^$ZBX_REQ_DATA_DEV " $SOURCE_DATA | tail -1 | awk '{print $7}';; 80 | avgrq-sz) grep -E "^$ZBX_REQ_DATA_DEV " $SOURCE_DATA | tail -1 | awk '{print $8}';; 81 | avgqu-sz) grep -E "^$ZBX_REQ_DATA_DEV " $SOURCE_DATA | tail -1 | awk '{print $9}';; 82 | await) grep -E "^$ZBX_REQ_DATA_DEV " $SOURCE_DATA | tail -1 | awk '{print $10}';; 83 | svctm) grep -E "^$ZBX_REQ_DATA_DEV " $SOURCE_DATA | tail -1 | awk '{print $11}';; 84 | %util) grep -E "^$ZBX_REQ_DATA_DEV " $SOURCE_DATA | tail -1 | awk '{print $12}';; 85 | *) echo $ERROR_WRONG_PARAM; exit 1;; 86 | esac 87 | 88 | exit 0 89 | 90 | -------------------------------------------------------------------------------- /zabbix-agent-bi-rpm/SOURCES/iostat-cron.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ################################## 3 | # Zabbix monitoring script 4 | # 5 | # Info: 6 | # - cron job to gather iostat data 7 | # - can not do real time as iostat data gathering will exceed 8 | # Zabbix agent timeout 9 | ################################## 10 | # Contact: 11 | # vincent.viallet@gmail.com 12 | ################################## 13 | # ChangeLog: 14 | # 20100922 VV initial creation 15 | ################################## 16 | 17 | # source data file 18 | DEST_DATA=/usr/local/zabbix-agent-bi/var/iostat-data 19 | TMP_DATA=/usr/local/zabbix-agent-bi/var/iostat-data.tmp 20 | 21 | # 22 | # gather data in temp file first, then move to final location 23 | # it avoids zabbix-agent to gather data from a half written source file 24 | # 25 | # iostat -kx 10 2 - will display 2 lines : 26 | # - 1st: statistics since boot -- useless 27 | # - 2nd: statistics over the last 10 sec 28 | # 29 | iostat -kx 10 2 > $TMP_DATA 30 | mv $TMP_DATA $DEST_DATA 31 | 32 | 33 | -------------------------------------------------------------------------------- /zabbix-agent-bi-rpm/SOURCES/path.patch: -------------------------------------------------------------------------------- 1 | diff -ru zabbix-2.2.5/conf/zabbix_agentd.conf zabbix-2.2.5-patched/conf/zabbix_agentd.conf 2 | --- zabbix-2.2.5/conf/zabbix_agentd.conf 2014-03-12 19:27:22.000000000 +0800 3 | +++ zabbix-2.2.5-patched/conf/zabbix_agentd.conf 2014-09-15 12:12:14.340196886 +0800 4 | @@ -9,6 +9,7 @@ 5 | # Mandatory: no 6 | # Default: 7 | # PidFile=/tmp/zabbix_agentd.pid 8 | +PidFile=/usr/local/zabbix-agent-bi/var/zabbix_agentd.pid 9 | 10 | ### Option: LogFile 11 | # Name of log file. 12 | @@ -18,7 +19,7 @@ 13 | # Default: 14 | # LogFile= 15 | 16 | -LogFile=/tmp/zabbix_agentd.log 17 | +LogFile=/usr/local/zabbix-agent-bi/var/zabbix_agentd.log 18 | 19 | ### Option: LogFileSize 20 | # Maximum size of log file in MB. 21 | @@ -131,7 +132,6 @@ 22 | # Default: 23 | # Hostname= 24 | 25 | -Hostname=Zabbix server 26 | 27 | ### Option: HostnameItem 28 | # Item used for generating Hostname if it is undefined. 29 | @@ -213,7 +213,8 @@ 30 | # Include= 31 | 32 | # Include=/usr/local/etc/zabbix_agentd.userparams.conf 33 | -# Include=/usr/local/etc/zabbix_agentd.conf.d/ 34 | +Include=/usr/local/zabbix-agent-bi/etc/extra.conf 35 | +Include=/usr/local/zabbix-agent-bi/etc/zabbix_agentd.conf.d/ 36 | 37 | ####### USER-DEFINED MONITORED PARAMETERS ####### 38 | 39 | diff -ru zabbix-2.2.5/misc/init.d/fedora/core5/zabbix_agentd zabbix-2.2.5-patched/misc/init.d/fedora/core5/zabbix_agentd 40 | --- zabbix-2.2.5/misc/init.d/fedora/core5/zabbix_agentd 2014-03-12 19:27:23.000000000 +0800 41 | +++ zabbix-2.2.5-patched/misc/init.d/fedora/core5/zabbix_agentd 2014-09-15 12:09:51.715205850 +0800 42 | @@ -18,7 +18,7 @@ 43 | 44 | RETVAL=0 45 | prog="Zabbix Agent" 46 | -ZABBIX_BIN="/usr/local/sbin/zabbix_agentd" 47 | +ZABBIX_BIN="/usr/local/zabbix-agent-bi/sbin/zabbix_agentd" 48 | 49 | if [ ! -x ${ZABBIX_BIN} ] ; then 50 | echo -n "${ZABBIX_BIN} not installed! " 51 | -------------------------------------------------------------------------------- /zabbix-agent-bi-rpm/SOURCES/port-discovery.sh: -------------------------------------------------------------------------------- 1 | ######################################################################### 2 | # File Name: port-discovery.sh 3 | # Author: kerncai 4 | # mail: kernkerncai@gmail.com 5 | # Created Time: 2014年07月16日 星期三 11时23分40秒 6 | ######################################################################### 7 | #!/bin/bash 8 | 9 | portarray=(`netstat -tnlp|egrep -i "$1"|awk {'print $4'}|awk -F':' '{if ($NF~/^[0-9]*$/) print $NF}'|sort |uniq 2>/dev/null`) 10 | length=${#portarray[@]} 11 | printf "{\n" 12 | printf '\t'"\"data\":[" 13 | for ((i=0;i<$length;i++)) 14 | do 15 | printf '\n\t\t{' 16 | printf "\"{#TCP_PORT}\":\"${portarray[$i]}\"}" 17 | if [ $i -lt $[$length-1] ];then 18 | printf ',' 19 | fi 20 | done 21 | printf "\n\t]\n" 22 | printf "}\n" 23 | -------------------------------------------------------------------------------- /zabbix-agent-bi-rpm/SOURCES/zabbix-2.2.5.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kerncai/zabbix/53cad73d345a55677c3238ca2ac4855dc8df2bfa/zabbix-agent-bi-rpm/SOURCES/zabbix-2.2.5.tar.gz -------------------------------------------------------------------------------- /zabbix-agent-bi-rpm/SPECS/zabbix-agent.spec: -------------------------------------------------------------------------------- 1 | Summary: Zabbix Agent 2 | Name: zabbix-agent-bi 3 | Version: 2.2.5 4 | Release: 4 5 | Group: Networking/Admin 6 | Source: zabbix-2.2.5.tar.gz 7 | Packager: kerncai 8 | License: GPLv2 9 | BuildRoot: %{_tmppath}/%{name}-%{version}-root 10 | 11 | %define prefix /usr/local/zabbix-agent-bi 12 | 13 | %description 14 | Zabbix Agent 15 | 16 | %prep 17 | cd $RPM_BUILD_DIR 18 | rm -fr zabbix-2.2.5 19 | tar zxf $RPM_SOURCE_DIR/zabbix-2.2.5.tar.gz 20 | patch -p0 < $RPM_SOURCE_DIR/path.patch 21 | 22 | %build 23 | cd $RPM_BUILD_DIR/zabbix-2.2.5 24 | ./configure --prefix=%{prefix} --enable-agent 25 | 26 | %install 27 | cd $RPM_BUILD_DIR/zabbix-2.2.5 28 | make install DESTDIR=$RPM_BUILD_ROOT 29 | 30 | # extra.conf 31 | install -D -m0644 $RPM_SOURCE_DIR/extra.conf $RPM_BUILD_ROOT%{prefix}/etc/extra.conf 32 | 33 | # var 34 | mkdir -p $RPM_BUILD_ROOT%{prefix}/var 35 | 36 | # service 37 | install -D -m0755 $RPM_BUILD_DIR/zabbix-2.2.5/misc/init.d/fedora/core5/zabbix_agentd $RPM_BUILD_ROOT/etc/init.d/%{name} 38 | 39 | # cron 40 | install -D -m0644 $RPM_SOURCE_DIR/cron.conf $RPM_BUILD_ROOT/etc/cron.d/%{name} 41 | 42 | # iostat 43 | install -D -m0755 $RPM_SOURCE_DIR/dev-discovery.sh $RPM_BUILD_ROOT%{prefix}/bin/dev-discovery.sh 44 | install -D -m0755 $RPM_SOURCE_DIR/iostat-cron.sh $RPM_BUILD_ROOT%{prefix}/bin/iostat-cron.sh 45 | install -D -m0755 $RPM_SOURCE_DIR/iostat-check.sh $RPM_BUILD_ROOT%{prefix}/bin/iostat-check.sh 46 | 47 | #port-discovery 48 | install -D -m0755 $RPM_SOURCE_DIR/port-discovery.sh $RPM_BUILD_ROOT%{prefix}/bin/port-discovery.sh 49 | 50 | %clean 51 | rm -fr $RPM_BUILD_ROOT 52 | 53 | %files 54 | %dir %{prefix} 55 | %{prefix}/bin 56 | %{prefix}/sbin 57 | %{prefix}/share 58 | 59 | %dir %{prefix}/etc 60 | %{prefix}/etc/extra.conf 61 | %config(noreplace) %{prefix}/etc/zabbix_agentd.conf 62 | %config(noreplace) %{prefix}/etc/zabbix_agentd.conf.d 63 | %config(noreplace) %{prefix}/etc/zabbix_agent.conf 64 | %config(noreplace) %{prefix}/etc/zabbix_agent.conf.d 65 | 66 | %attr(-,zabbix,zabbix) %{prefix}/var 67 | 68 | /etc/init.d/%{name} 69 | /etc/cron.d/%{name} 70 | 71 | %pre 72 | if [ $1 -eq 1 ]; then 73 | user_check="`grep zabbix /etc/passwd | wc -l`" 74 | group_check="`grep zabbix /etc/group | wc -l`" 75 | 76 | if [[ $user_check -eq 0 ]]; 77 | then 78 | groupadd zabbix 79 | fi 80 | 81 | if [[ $group_check -eq 0 ]]; 82 | then 83 | useradd -M -d %{prefix}/var -s /sbin/nologin -g zabbix zabbix 84 | fi 85 | fi 86 | 87 | %post 88 | if [ $1 -eq 1 ]; then 89 | chkconfig --add %{name} 90 | chkconfig --level 345 %{name} on 91 | service %{name} start 92 | fi 93 | 94 | %preun 95 | if [ $1 -eq 0 ]; then 96 | service %{name} stop 97 | chkconfig --del %{name} 98 | fi 99 | 100 | %postun 101 | if [ $1 -ge 1 ]; then 102 | service %{name} condrestart 103 | fi 104 | 105 | -------------------------------------------------------------------------------- /zabbix-agent-bi-rpm/SRPMS/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /zabbix-agent-bi-rpm/rpmbuild/BUILD/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /zabbix-agent-bi-rpm/rpmbuild/RPMS/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /zabbix-agent-bi-rpm/rpmbuild/SOURCES/cron.conf: -------------------------------------------------------------------------------- 1 | * * * * * root /usr/local/zabbix-agent-bi/bin/iostat-cron.sh 2 | -------------------------------------------------------------------------------- /zabbix-agent-bi-rpm/rpmbuild/SOURCES/dev-discovery.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | DEVICES=`iostat | awk '{ if ($1 ~ "^([sh]d[a-z])$") { print $1 } }'` 4 | 5 | COUNT=`echo "$DEVICES" | wc -l` 6 | INDEX=0 7 | echo '{"data":[' 8 | echo "$DEVICES" | while read LINE; do 9 | echo -n '{"{#DEVNAME}":"'$LINE'"}' 10 | INDEX=`expr $INDEX + 1` 11 | if [ $INDEX -lt $COUNT ]; then 12 | echo ',' 13 | fi 14 | done 15 | echo ']}' 16 | 17 | -------------------------------------------------------------------------------- /zabbix-agent-bi-rpm/rpmbuild/SOURCES/extra.conf: -------------------------------------------------------------------------------- 1 | ## DO NOT EDIT: This file comes with the package. 2 | 3 | # iostat 4 | UserParameter=custom.vfs.dev.discovery,/usr/local/zabbix-agent-bi/bin/dev-discovery.sh 5 | UserParameter=iostat[*],/usr/local/zabbix-agent-bi/bin/iostat-check.sh $1 $2 6 | UserParameter=port[*],/usr/local/zabbix-agent-bi/bin/port-discovery.sh $1 7 | -------------------------------------------------------------------------------- /zabbix-agent-bi-rpm/rpmbuild/SOURCES/iostat-check.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ################################## 3 | # Zabbix monitoring script 4 | # 5 | # iostat: 6 | # - IO 7 | # - running / blocked processes 8 | # - swap in / out 9 | # - block in / out 10 | # 11 | # Info: 12 | # - vmstat data are gathered via cron job 13 | ################################## 14 | # Contact: 15 | # vincent.viallet@gmail.com 16 | ################################## 17 | # ChangeLog: 18 | # 20100922 VV initial creation 19 | ################################## 20 | 21 | # Zabbix requested parameter 22 | ZBX_REQ_DATA="$2" 23 | ZBX_REQ_DATA_DEV="$1" 24 | 25 | # source data file 26 | SOURCE_DATA=/usr/local/zabbix-agent-bi/var/iostat-data 27 | 28 | # 29 | # Error handling: 30 | # - need to be displayable in Zabbix (avoid NOT_SUPPORTED) 31 | # - items need to be of type "float" (allow negative + float) 32 | # 33 | ERROR_NO_DATA_FILE="-0.9900" 34 | ERROR_OLD_DATA="-0.9901" 35 | ERROR_WRONG_PARAM="-0.9902" 36 | ERROR_MISSING_PARAM="-0.9903" 37 | 38 | # No data file to read from 39 | if [ ! -f "$SOURCE_DATA" ]; then 40 | echo $ERROR_NO_DATA_FILE 41 | exit 1 42 | fi 43 | 44 | # Missing device to get data from 45 | if [ -z "$ZBX_REQ_DATA_DEV" ]; then 46 | echo $ERROR_MISSING_PARAM 47 | exit 1 48 | fi 49 | 50 | # 51 | # Old data handling: 52 | # - in case the cron can not update the data file 53 | # - in case the data are too old we want to notify the system 54 | # Consider the data as non-valid if older than OLD_DATA minutes 55 | # 56 | OLD_DATA=5 57 | if [ $(stat -c "%Y" $SOURCE_DATA) -lt $(date -d "now -$OLD_DATA min" "+%s" ) ]; then 58 | echo $ERROR_OLD_DATA 59 | exit 1 60 | fi 61 | 62 | # 63 | # Grab data from SOURCE_DATA for key ZBX_REQ_DATA 64 | # 65 | # 1st check the device exists and gets data gathered by cron job 66 | device_count=$(grep -Ec "^$ZBX_REQ_DATA_DEV " $SOURCE_DATA) 67 | if [ $device_count -eq 0 ]; then 68 | echo $ERROR_WRONG_PARAM 69 | exit 1 70 | fi 71 | 72 | # 2nd grab the data from the source file 73 | case $ZBX_REQ_DATA in 74 | rrqm/s) grep -E "^$ZBX_REQ_DATA_DEV " $SOURCE_DATA | tail -1 | awk '{print $2}';; 75 | wrqm/s) grep -E "^$ZBX_REQ_DATA_DEV " $SOURCE_DATA | tail -1 | awk '{print $3}';; 76 | r/s) grep -E "^$ZBX_REQ_DATA_DEV " $SOURCE_DATA | tail -1 | awk '{print $4}';; 77 | w/s) grep -E "^$ZBX_REQ_DATA_DEV " $SOURCE_DATA | tail -1 | awk '{print $5}';; 78 | rkB/s) grep -E "^$ZBX_REQ_DATA_DEV " $SOURCE_DATA | tail -1 | awk '{print $6}';; 79 | wkB/s) grep -E "^$ZBX_REQ_DATA_DEV " $SOURCE_DATA | tail -1 | awk '{print $7}';; 80 | avgrq-sz) grep -E "^$ZBX_REQ_DATA_DEV " $SOURCE_DATA | tail -1 | awk '{print $8}';; 81 | avgqu-sz) grep -E "^$ZBX_REQ_DATA_DEV " $SOURCE_DATA | tail -1 | awk '{print $9}';; 82 | await) grep -E "^$ZBX_REQ_DATA_DEV " $SOURCE_DATA | tail -1 | awk '{print $10}';; 83 | svctm) grep -E "^$ZBX_REQ_DATA_DEV " $SOURCE_DATA | tail -1 | awk '{print $11}';; 84 | %util) grep -E "^$ZBX_REQ_DATA_DEV " $SOURCE_DATA | tail -1 | awk '{print $12}';; 85 | *) echo $ERROR_WRONG_PARAM; exit 1;; 86 | esac 87 | 88 | exit 0 89 | 90 | -------------------------------------------------------------------------------- /zabbix-agent-bi-rpm/rpmbuild/SOURCES/iostat-cron.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ################################## 3 | # Zabbix monitoring script 4 | # 5 | # Info: 6 | # - cron job to gather iostat data 7 | # - can not do real time as iostat data gathering will exceed 8 | # Zabbix agent timeout 9 | ################################## 10 | # Contact: 11 | # vincent.viallet@gmail.com 12 | ################################## 13 | # ChangeLog: 14 | # 20100922 VV initial creation 15 | ################################## 16 | 17 | # source data file 18 | DEST_DATA=/usr/local/zabbix-agent-bi/var/iostat-data 19 | TMP_DATA=/usr/local/zabbix-agent-bi/var/iostat-data.tmp 20 | 21 | # 22 | # gather data in temp file first, then move to final location 23 | # it avoids zabbix-agent to gather data from a half written source file 24 | # 25 | # iostat -kx 10 2 - will display 2 lines : 26 | # - 1st: statistics since boot -- useless 27 | # - 2nd: statistics over the last 10 sec 28 | # 29 | iostat -kx 10 2 > $TMP_DATA 30 | mv $TMP_DATA $DEST_DATA 31 | 32 | 33 | -------------------------------------------------------------------------------- /zabbix-agent-bi-rpm/rpmbuild/SOURCES/path.patch: -------------------------------------------------------------------------------- 1 | diff -ru zabbix-2.2.5/conf/zabbix_agentd.conf zabbix-2.2.5-patched/conf/zabbix_agentd.conf 2 | --- zabbix-2.2.5/conf/zabbix_agentd.conf 2014-03-12 19:27:22.000000000 +0800 3 | +++ zabbix-2.2.5-patched/conf/zabbix_agentd.conf 2014-09-15 12:12:14.340196886 +0800 4 | @@ -9,6 +9,7 @@ 5 | # Mandatory: no 6 | # Default: 7 | # PidFile=/tmp/zabbix_agentd.pid 8 | +PidFile=/usr/local/zabbix-agent-bi/var/zabbix_agentd.pid 9 | 10 | ### Option: LogFile 11 | # Name of log file. 12 | @@ -18,7 +19,7 @@ 13 | # Default: 14 | # LogFile= 15 | 16 | -LogFile=/tmp/zabbix_agentd.log 17 | +LogFile=/usr/local/zabbix-agent-bi/var/zabbix_agentd.log 18 | 19 | ### Option: LogFileSize 20 | # Maximum size of log file in MB. 21 | @@ -131,7 +132,6 @@ 22 | # Default: 23 | # Hostname= 24 | 25 | -Hostname=Zabbix server 26 | 27 | ### Option: HostnameItem 28 | # Item used for generating Hostname if it is undefined. 29 | @@ -213,7 +213,8 @@ 30 | # Include= 31 | 32 | # Include=/usr/local/etc/zabbix_agentd.userparams.conf 33 | -# Include=/usr/local/etc/zabbix_agentd.conf.d/ 34 | +Include=/usr/local/zabbix-agent-bi/etc/extra.conf 35 | +Include=/usr/local/zabbix-agent-bi/etc/zabbix_agentd.conf.d/ 36 | 37 | ####### USER-DEFINED MONITORED PARAMETERS ####### 38 | 39 | diff -ru zabbix-2.2.5/misc/init.d/fedora/core5/zabbix_agentd zabbix-2.2.5-patched/misc/init.d/fedora/core5/zabbix_agentd 40 | --- zabbix-2.2.5/misc/init.d/fedora/core5/zabbix_agentd 2014-03-12 19:27:23.000000000 +0800 41 | +++ zabbix-2.2.5-patched/misc/init.d/fedora/core5/zabbix_agentd 2014-09-15 12:09:51.715205850 +0800 42 | @@ -18,7 +18,7 @@ 43 | 44 | RETVAL=0 45 | prog="Zabbix Agent" 46 | -ZABBIX_BIN="/usr/local/sbin/zabbix_agentd" 47 | +ZABBIX_BIN="/usr/local/zabbix-agent-bi/sbin/zabbix_agentd" 48 | 49 | if [ ! -x ${ZABBIX_BIN} ] ; then 50 | echo -n "${ZABBIX_BIN} not installed! " 51 | -------------------------------------------------------------------------------- /zabbix-agent-bi-rpm/rpmbuild/SOURCES/port-discovery.sh: -------------------------------------------------------------------------------- 1 | ######################################################################### 2 | # File Name: port-discovery.sh 3 | # Author: kerncai 4 | # mail: kernkerncai@gmail.com 5 | # Created Time: 2014年07月16日 星期三 11时23分40秒 6 | ######################################################################### 7 | #!/bin/bash 8 | 9 | portarray=(`netstat -tnla|egrep -i "$1"|awk {'print $4'}|awk -F':' '{if ($NF~/^[0-9]*$/) print $NF}'|sort |uniq 2>/dev/null`) 10 | length=${#portarray[@]} 11 | printf "{\n" 12 | printf '\t'"\"data\":[" 13 | for ((i=0;i<$length;i++)) 14 | do 15 | printf '\n\t\t{' 16 | printf "\"{#TCP_PORT}\":\"${portarray[$i]}\"}" 17 | if [ $i -lt $[$length-1] ];then 18 | printf ',' 19 | fi 20 | done 21 | printf "\n\t]\n" 22 | printf "}\n" 23 | -------------------------------------------------------------------------------- /zabbix-agent-bi-rpm/rpmbuild/SOURCES/zabbix-2.2.5.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kerncai/zabbix/53cad73d345a55677c3238ca2ac4855dc8df2bfa/zabbix-agent-bi-rpm/rpmbuild/SOURCES/zabbix-2.2.5.tar.gz -------------------------------------------------------------------------------- /zabbix-agent-bi-rpm/rpmbuild/SPECS/zabbix-agent.spec: -------------------------------------------------------------------------------- 1 | Summary: Zabbix Agent 2 | Name: zabbix-agent-bi 3 | Version: 2.2.5 4 | Release: 4 5 | Group: Networking/Admin 6 | Source: zabbix-2.2.5.tar.gz 7 | Packager: kerncai 8 | License: GPLv2 9 | BuildRoot: %{_tmppath}/%{name}-%{version}-root 10 | 11 | %define prefix /usr/local/zabbix-agent-bi 12 | 13 | %description 14 | Zabbix Agent 15 | 16 | %prep 17 | cd $RPM_BUILD_DIR 18 | rm -fr zabbix-2.2.5 19 | tar zxf $RPM_SOURCE_DIR/zabbix-2.2.5.tar.gz 20 | patch -p0 < $RPM_SOURCE_DIR/path.patch 21 | 22 | %build 23 | cd $RPM_BUILD_DIR/zabbix-2.2.5 24 | ./configure --prefix=%{prefix} --enable-agent 25 | 26 | %install 27 | cd $RPM_BUILD_DIR/zabbix-2.2.5 28 | make install DESTDIR=$RPM_BUILD_ROOT 29 | 30 | # extra.conf 31 | install -D -m0644 $RPM_SOURCE_DIR/extra.conf $RPM_BUILD_ROOT%{prefix}/etc/extra.conf 32 | 33 | # var 34 | mkdir -p $RPM_BUILD_ROOT%{prefix}/var 35 | 36 | # service 37 | install -D -m0755 $RPM_BUILD_DIR/zabbix-2.2.5/misc/init.d/fedora/core5/zabbix_agentd $RPM_BUILD_ROOT/etc/init.d/%{name} 38 | 39 | # cron 40 | install -D -m0644 $RPM_SOURCE_DIR/cron.conf $RPM_BUILD_ROOT/etc/cron.d/%{name} 41 | 42 | # iostat 43 | install -D -m0755 $RPM_SOURCE_DIR/dev-discovery.sh $RPM_BUILD_ROOT%{prefix}/bin/dev-discovery.sh 44 | install -D -m0755 $RPM_SOURCE_DIR/iostat-cron.sh $RPM_BUILD_ROOT%{prefix}/bin/iostat-cron.sh 45 | install -D -m0755 $RPM_SOURCE_DIR/iostat-check.sh $RPM_BUILD_ROOT%{prefix}/bin/iostat-check.sh 46 | 47 | #port-discovery 48 | install -D -m0755 $RPM_SOURCE_DIR/port-discovery.sh $RPM_BUILD_ROOT%{prefix}/bin/port-discovery.sh 49 | 50 | %clean 51 | rm -fr $RPM_BUILD_ROOT 52 | 53 | %files 54 | %dir %{prefix} 55 | %{prefix}/bin 56 | %{prefix}/sbin 57 | %{prefix}/share 58 | 59 | %dir %{prefix}/etc 60 | %{prefix}/etc/extra.conf 61 | %config(noreplace) %{prefix}/etc/zabbix_agentd.conf 62 | %config(noreplace) %{prefix}/etc/zabbix_agentd.conf.d 63 | %config(noreplace) %{prefix}/etc/zabbix_agent.conf 64 | %config(noreplace) %{prefix}/etc/zabbix_agent.conf.d 65 | 66 | %attr(-,zabbix,zabbix) %{prefix}/var 67 | 68 | /etc/init.d/%{name} 69 | /etc/cron.d/%{name} 70 | 71 | %pre 72 | if [ $1 -eq 1 ]; then 73 | user_check="`grep zabbix /etc/passwd | wc -l`" 74 | group_check="`grep zabbix /etc/group | wc -l`" 75 | 76 | if [[ $user_check -eq 0 ]]; 77 | then 78 | groupadd zabbix 79 | fi 80 | 81 | if [[ $group_check -eq 0 ]]; 82 | then 83 | useradd -M -d %{prefix}/var -s /sbin/nologin -g zabbix zabbix 84 | fi 85 | fi 86 | 87 | %post 88 | if [ $1 -eq 1 ]; then 89 | chkconfig --add %{name} 90 | chkconfig --level 345 %{name} on 91 | service %{name} start 92 | fi 93 | 94 | %preun 95 | if [ $1 -eq 0 ]; then 96 | service %{name} stop 97 | chkconfig --del %{name} 98 | fi 99 | 100 | %postun 101 | if [ $1 -ge 1 ]; then 102 | service %{name} condrestart 103 | fi 104 | 105 | -------------------------------------------------------------------------------- /zabbix-agent-bi-rpm/rpmbuild/SRPMS/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /zabbix_send_alarm/action.xml: -------------------------------------------------------------------------------- 1 | 2 | 故障通知
3 | 所属业务:华翔
4 | 触发器: {TRIGGER.NAME}
5 | 主机名:{HOST.NAME}({IPADDRESS})
6 | 状态: {TRIGGER.STATUS}
7 | 告警项目:
8 | {ITEM.NAME1} ({HOST.NAME1}:{ITEM.KEY1}): {ITEM.VALUE1}
9 | 告警快照:
10 |
11 | 12 |
13 | ItemID:{ITEM.ID}
14 | EventID: {EVENT.ID}
15 | 告警时间:{EVENT.DATE} {EVENT.TIME}
16 |
17 | 详细信息:登录查看
18 | 19 | -------------------------------------------------------------------------------- /zabbix_send_alarm/readme.md: -------------------------------------------------------------------------------- 1 | ##################################### 2 | 3 | zabbix_send_image.py 用途: 4 | 5 | 可实现告警触发的同时,将该告警时间点,往前推3600秒,获取改item的数据曲线图, 6 | 以方便排错 7 | 8 | action.xml 需要在action内,创建动作,默认信息需要填action.xml的内容,将zabbix的url换成 9 | 当前正在使用的即可。 10 | -------------------------------------------------------------------------------- /zabbix_send_alarm/send_mail_image.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | #encoding:utf-8 3 | #owner:kerncai 4 | 5 | import os 6 | import re 7 | import sys 8 | import time,datetime 9 | import smtplib 10 | import urllib2,cookielib,urllib 11 | from email.mime.text import MIMEText 12 | from email.mime.image import MIMEImage 13 | from email.mime.multipart import MIMEMultipart 14 | 15 | class mail: 16 | def __init__(self): 17 | self.login_url = 'http://zabbix.test/zabbix/index.php' 18 | self.zab_user = 'Admin' 19 | self.zab_passwd = 'passwd' 20 | 21 | def GetItemID(self,body): 22 | try: 23 | ItemID = re.match(r'.*ItemID:(\d+)[^\d]+.*',body.replace('\n',''),re.S).group(1) 24 | except: 25 | pass 26 | return ItemID 27 | 28 | def GetTime(self): 29 | itemtime = (datetime.datetime.now() - datetime.timedelta(hours=1)).strftime("%Y%m%d%H%M%S") 30 | return itemtime 31 | 32 | def GetImage(self,body): 33 | login_data = urllib.urlencode({ 34 | "name": self.zab_user, 35 | "password": self.zab_passwd, 36 | "autologin": 1, 37 | "enter": "Sign in"}) 38 | cj = cookielib.CookieJar() 39 | opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) 40 | urllib2.install_opener(opener) 41 | r = opener.open(self.login_url,login_data).read() 42 | zab_img_url = 'http://zabbix.test/zabbix/chart.php?period=3600&stime=%s&itemids[0]=%s&type=0&updateProfile=1&profileIdx=web.item.graph&profileIdx2=%s&width=1138' %(self.GetTime(),self.GetItemID(body),self.GetItemID(body)) 43 | s = opener.open(zab_img_url) 44 | image_data = s.read() 45 | s.close() 46 | if s.info().get('Content-Type') == "image/png": 47 | image_file = open('/usr/lib/zabbix/alertscripts/imgs/%s.png' %self.GetItemID(body),'wb') 48 | image_file.write(image_data) 49 | image_file.close() 50 | 51 | def sendmail(self,receiver,title,body): 52 | logfile = open('/usr/lib/zabbix/alertscripts/logs/alarm_mail.log','a') 53 | host = 'smtp.test.com' 54 | port = 25 55 | sender = 'zabbix@test.com' 56 | pwd = 'passwd' 57 | 58 | msg = MIMEMultipart('related') 59 | msg['subject'] = title 60 | msg['from'] = sender 61 | msg['To'] = ','.join(receiver) 62 | con_txt = MIMEText(body, 'html','utf-8') 63 | msg.attach(con_txt) 64 | img_path = '/usr/lib/zabbix/alertscripts/imgs/%s.png' %self.GetItemID(body) 65 | if os.path.exists(img_path): 66 | a = open(img_path,'r') 67 | img = a.read() 68 | a.close() 69 | else: 70 | a = open('/usr/lib/zabbix/alertscripts/imgs/404.jpg','r') 71 | img = a.read() 72 | a.close() 73 | con_img = MIMEImage(img) 74 | con_img.add_header('Content-ID','') 75 | msg.attach(con_img) 76 | try: 77 | s = smtplib.SMTP(host, port) 78 | s.login(sender, pwd) 79 | s.sendmail(sender, receiver, msg.as_string()) 80 | print 'The mail named %s to %s is sended successly.' % (title, receiver) 81 | log = '%s, OK,%s,%s\n' %(time.ctime(),title,receiver) 82 | except Exception,e: 83 | print "失败:"+str(e) 84 | log = '%s, Fail,%s,%s,%s\n' %(time.ctime(),title,receiver,str(e)) 85 | logfile.write(log) 86 | logfile.close() 87 | 88 | if __name__=='__main__': 89 | run = mail() 90 | receiver = [] 91 | receiver.append(sys.argv[1]) 92 | title = sys.argv[2] 93 | body = sys.argv[3] 94 | run.GetItemID(body) 95 | old_img = '/usr/lib/zabbix/alertscripts/imgs/%s.png' %run.GetItemID(body) 96 | rm_cmd = 'rm -fv %s' %old_img 97 | os.system(rm_cmd) 98 | run.GetImage(body) 99 | run.sendmail(receiver,title,body) 100 | del run 101 | --------------------------------------------------------------------------------