├── README.md ├── aerospike ├── aerospike.conf ├── aerospike.sh └── aerospike.xml ├── check_backups ├── buckets.zabbix ├── check_backups.conf ├── check_backups.sh └── check_backups.xml ├── iostat ├── iostat-collect.sh ├── iostat-parse.sh ├── iostat.conf └── iostat.xml ├── linux-sockets ├── linux-sockets.xml ├── sockets.conf ├── sockets.sh └── sockets.xml ├── mongodb ├── mongodb.conf ├── mongodb.py └── mongodb.sh ├── mysql └── userparameter_mysql.conf ├── netstat ├── netstat.sh ├── netstat.xml ├── sockets.conf └── sockets.sh ├── nginx-background ├── nginx-background.conf ├── nginx-background.sh └── nginx-background.xml ├── nginx ├── nginx.conf ├── nginx.sh └── nginx.xml ├── php-fpm-multiple-pools ├── fpm-multiple-pools.xml ├── fpm-pool.conf └── fpm-pool.sh ├── php-fpm ├── fpm.conf ├── fpm.sh └── fpm.xml ├── redis ├── redis.conf ├── redis.sh └── redis.xml └── ssl-checks ├── ssl-checks.xml ├── ssl.conf ├── ssl.pl └── zabbix-external-check-scripts └── ssl /README.md: -------------------------------------------------------------------------------- 1 | zabbix-templates 2 | ================ 3 | 4 | Zabbix templates for various services and applications. 5 | 6 | -------------------------------------------------------------------------------- /aerospike/aerospike.conf: -------------------------------------------------------------------------------- 1 | UserParameter=aerospike[*],/etc/zabbix/scripts/aerospike.sh $1 $2 $3 $4 2 | -------------------------------------------------------------------------------- /aerospike/aerospike.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | DEFAULT_HOST=127.0.0.1 5 | DEFAULT_PORT=3000 6 | DEFAULT_KEY=objects 7 | 8 | 9 | if [ "$1" != "" ] ; then 10 | DEFAULT_KEY=$1 11 | fi 12 | 13 | if [ "$2" != "" ] ; then 14 | DEFAULT_HOST=$2 15 | fi 16 | 17 | if [ "$3" != "" ] ; then 18 | OPT1=$3 19 | fi 20 | 21 | if [ "$4" != "" ] ; then 22 | OPT2=$4 23 | fi 24 | 25 | down=`asinfo -h $DEFAULT_HOST -p $DEFAULT_PORT -v version | grep error | wc -l` 26 | 27 | if [ "$down" = "1" ] ; then 28 | echo "-1" 29 | exit 30 | fi 31 | 32 | 33 | case "$DEFAULT_KEY" in 34 | sets) 35 | if [ "$OPT1" != "" ] ; then 36 | if [ "$OPT2" = "" ] ;then 37 | OPT2="n_objects" 38 | fi 39 | asinfo -h $DEFAULT_HOST -p $DEFAULT_PORT -v sets -l | grep "set_name=$OPT1:" | grep -oe "$OPT2=[^:]\+" | awk -F= '{print $2}' 40 | else 41 | sets=`asinfo -h $DEFAULT_HOST -p $DEFAULT_PORT -v sets -l | grep -oe 'set_name=[^:]\+' | awk -F= '{print $2}'` 42 | for x in $sets ; do 43 | if [ "$res" != "" ] ; then 44 | res=$res',' 45 | fi 46 | res=$res'{"{#SET}":"'$x'"}' 47 | done 48 | echo '{"data":['$res']}' 49 | fi 50 | ;; 51 | keys) 52 | /usr/bin/asinfo -h $DEFAULT_HOST -p $DEFAULT_PORT | head -n 4 | tail -n 1 | tr ';' '\n' | awk -F '=' '{print $1;}' | xargs 53 | ;; 54 | latency) 55 | case $OPT1 in 56 | 8) OPT1='$5' ;; 57 | 64) OPT1='$6' ;; 58 | *) OPT1='$4' ;; 59 | esac 60 | /usr/bin/asmonitor -d /var/lib/zabbix/.asmonitor -e "latency -v reads -h $DEFAULT_HOST -p $DEFAULT_PORT " | grep ":$DEFAULT_PORT" | awk "{print $OPT1}" 61 | ;; 62 | stat_read_latency_gt100 | stat_read_latency_gt250 | stat_read_latency_gt50 | stat_write_latency_gt100 | stat_write_latency_gt250 | stat_write_latency_gt50 ) 63 | /usr/bin/asmonitor -h $DEFAULT_HOST -p $DEFAULT_PORT -d /var/lib/zabbix/.asmonitor -e 'stat' | grep "$DEFAULT_KEY" | awk '{print $2}' 64 | ;; 65 | *) 66 | res=`/usr/bin/asinfo -h $DEFAULT_HOST -p $DEFAULT_PORT | head -n 4 | tail -n 1 | tr ';' '\n' | tr -d ' ' | grep "^$DEFAULT_KEY=" | awk -F '=' '{print $2;}'` 67 | if [[ "$res" == "" ]] ; then 68 | res='0' 69 | fi 70 | echo $res 71 | ;; 72 | esac 73 | -------------------------------------------------------------------------------- /check_backups/buckets.zabbix: -------------------------------------------------------------------------------- 1 | /backups/server1 2 | /backups/server2 3 | -------------------------------------------------------------------------------- /check_backups/check_backups.conf: -------------------------------------------------------------------------------- 1 | UserParameter=backups[*],/etc/zabbix/scripts/check_backups.sh $1 2 | UserParameter=backups.discovery,/etc/zabbix/scripts/check_backups.sh discovery 3 | -------------------------------------------------------------------------------- /check_backups/check_backups.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | backup_config=/backups/buckets.zabbix 5 | DIR=. 6 | 7 | if [[ "$1" != "" ]] ; then 8 | DIR=$1 9 | if [[ "$DIR" == "discovery" ]] ; then 10 | for bucket in `cat ` ; do 11 | if [[ "$buckets" != "$backup_config" ]] ; then 12 | buckets=$buckets',' 13 | fi 14 | buckets=$buckets'{"{#BUCKET}":"'$bucket'"}' 15 | done 16 | echo '{"data":['$buckets']}' 17 | 18 | exit 19 | fi 20 | fi 21 | 22 | #checks if there are fresh files and each of them is not empty 23 | 24 | last_files=`find $DIR -mtime -2 -exec echo {} \; | grep -ve "^$DIR$"` 25 | 26 | if [[ "$last_files" == "" ]] ; then 27 | echo 1 28 | exit 29 | fi 30 | 31 | for file in $last_files ; do 32 | size=`stat -c%s $file` 33 | if [[ "$size" == "0" ]] ; then 34 | echo 2 35 | exit 36 | fi 37 | done 38 | 39 | echo 0 40 | -------------------------------------------------------------------------------- /check_backups/check_backups.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 2.0 4 | 2014-06-30T14:17:44Z 5 | 6 | 7 | Linux servers 8 | 9 | 10 | 11 | 112 | 113 | 114 | -------------------------------------------------------------------------------- /iostat/iostat-collect.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | SECONDS=$2 4 | TOFILE=$1 5 | IOSTAT="/usr/bin/iostat" 6 | 7 | [[ $# -lt 2 ]] && { echo "FATAL: some parameters not specified"; exit 1; } 8 | 9 | DISK=$($IOSTAT -x 1 $SECONDS | awk 'BEGIN {check=0;} {if(check==1 && $1=="avg-cpu:"){check=0}if(check==1 && $1!=""){print $0}if($1=="Device:"){check=1}}' | tr '\n' '|') 10 | echo $DISK | sed 's/|/\n/g' > $TOFILE 11 | echo 0 12 | -------------------------------------------------------------------------------- /iostat/iostat-parse.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | NUMBER=0 4 | FROMFILE=$1 5 | DISK=$2 6 | METRIC=$3 7 | 8 | [[ $# -lt 3 ]] && { echo "FATAL: some parameters not specified"; exit 1; } 9 | [[ -f "$FROMFILE" ]] || { echo "FATAL: datafile not found"; exit 1; } 10 | 11 | case "$3" in 12 | "rrqm/s") 13 | NUMBER=2 14 | ;; 15 | "wrqm/s") 16 | NUMBER=3 17 | ;; 18 | "r/s") 19 | NUMBER=4 20 | ;; 21 | "w/s") 22 | NUMBER=5 23 | ;; 24 | "rkb/s") 25 | NUMBER=6 26 | ;; 27 | "wkb/s") 28 | NUMBER=7 29 | ;; 30 | "avgrq-sz") 31 | NUMBER=8 32 | ;; 33 | "avgqu-sz") 34 | NUMBER=9 35 | ;; 36 | "await") 37 | NUMBER=10 38 | ;; 39 | "r_await") 40 | NUMBER=11 41 | ;; 42 | "w_await") 43 | NUMBER=12 44 | ;; 45 | "svctm") 46 | NUMBER=13 47 | ;; 48 | "util") 49 | NUMBER=14 50 | ;; 51 | *) echo ZBX_NOTSUPPORTED; exit 1 ;; 52 | esac 53 | 54 | grep -w $DISK $FROMFILE | tail -n +2 | tr -s ' ' |awk -v N=$NUMBER 'BEGIN {sum=0.0;count=0;} {sum=sum+$N;count=count+1;} END {printf("%.2f\n", sum/count);}' 55 | -------------------------------------------------------------------------------- /iostat/iostat.conf: -------------------------------------------------------------------------------- 1 | # Disk statistics via iostat (sysstat) 2 | # Attention: Second parameter in iostat.collect must be less than Timeout option in zabbix_agentd.conf 3 | UserParameter=iostat.discovery, iostat -d | awk 'BEGIN {check=0;count=0;array[0]=0;} {if(check==1 && $1 != ""){array[count]=$1;count=count+1;}if($1=="Device:"){check=1;}} END {printf("{\n\t\"data\":[\n");for(i=0;i 2 | 3 | 2.0 4 | 2015-10-12T08:43:54Z 5 | 6 | 7 | Templates 8 | 9 | 10 | 11 | 882 | 883 | 884 | 885 | {Template Iostat-Disk-Utilization:iostat.collect.last(0)}=1 886 | Iostat statistics not collected on {HOSTNAME} 887 | 888 | 0 889 | 2 890 | 891 | 0 892 | 893 | 894 | 895 | 896 | -------------------------------------------------------------------------------- /linux-sockets/linux-sockets.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 2.0 4 | 2014-12-03T15:48:12Z 5 | 6 | 7 | Templates 8 | 9 | 10 | 11 | 426 | 427 | 428 | 429 | Unix sockets states 430 | 900 431 | 200 432 | 0.0000 433 | 100.0000 434 | 1 435 | 1 436 | 0 437 | 1 438 | 0 439 | 0.0000 440 | 0.0000 441 | 0 442 | 0 443 | 0 444 | 0 445 | 446 | 447 | 0 448 | 0 449 | 009600 450 | 0 451 | 2 452 | 0 453 | 454 | Template Unix sockets status 455 | sockets[CLOSE-WAIT,{$SOCKET_ADDRESS}] 456 | 457 | 458 | 459 | 1 460 | 0 461 | 000096 462 | 0 463 | 2 464 | 0 465 | 466 | Template Unix sockets status 467 | sockets[CLOSING,{$SOCKET_ADDRESS}] 468 | 469 | 470 | 471 | 2 472 | 0 473 | 960096 474 | 0 475 | 2 476 | 0 477 | 478 | Template Unix sockets status 479 | sockets[FIN-WAIT-1,{$SOCKET_ADDRESS}] 480 | 481 | 482 | 483 | 3 484 | 0 485 | 009696 486 | 0 487 | 2 488 | 0 489 | 490 | Template Unix sockets status 491 | sockets[FIN-WAIT-2,{$SOCKET_ADDRESS}] 492 | 493 | 494 | 495 | 4 496 | 0 497 | 969600 498 | 0 499 | 2 500 | 0 501 | 502 | Template Unix sockets status 503 | sockets[LAST-ACK,{$SOCKET_ADDRESS}] 504 | 505 | 506 | 507 | 5 508 | 0 509 | 969696 510 | 0 511 | 2 512 | 0 513 | 514 | Template Unix sockets status 515 | sockets[LISTEN,{$SOCKET_ADDRESS}] 516 | 517 | 518 | 519 | 6 520 | 0 521 | FF0000 522 | 0 523 | 2 524 | 0 525 | 526 | Template Unix sockets status 527 | sockets[SYN-RECV,{$SOCKET_ADDRESS}] 528 | 529 | 530 | 531 | 7 532 | 0 533 | 00FF00 534 | 0 535 | 2 536 | 0 537 | 538 | Template Unix sockets status 539 | sockets[SYN-SENT,{$SOCKET_ADDRESS}] 540 | 541 | 542 | 543 | 8 544 | 0 545 | 0000FF 546 | 0 547 | 2 548 | 0 549 | 550 | Template Unix sockets status 551 | sockets[TIME-WAIT,{$SOCKET_ADDRESS}] 552 | 553 | 554 | 555 | 9 556 | 0 557 | FF00FF 558 | 0 559 | 2 560 | 0 561 | 562 | Template Unix sockets status 563 | sockets[ESTAB,{$SOCKET_ADDRESS}] 564 | 565 | 566 | 567 | 568 | 569 | 570 | -------------------------------------------------------------------------------- /linux-sockets/sockets.conf: -------------------------------------------------------------------------------- 1 | UserParameter=sockets[*],/etc/zabbix/scripts/sockets.sh "$1" "$2" 2 | -------------------------------------------------------------------------------- /linux-sockets/sockets.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | PORT="$2" 4 | 5 | CACHETTL="55" # Время действия кеша в секундах (чуть меньше чем период опроса элементов) 6 | CACHE="/tmp/zabbix-sockets-status.$PORT.cache" 7 | 8 | if [ -s "$CACHE" ]; then 9 | TIMECACHE=`stat -c"%Z" "$CACHE"` 10 | else 11 | TIMECACHE=0 12 | fi 13 | 14 | TIMENOW=`date '+%s'` 15 | 16 | if [ "$(($TIMENOW - $TIMECACHE))" -gt "$CACHETTL" ]; then 17 | if [[ $PORT == "" ]] ; then 18 | ss -na | grep -v State | awk '{print $1;}' | sort | uniq -c > $CACHE 19 | else 20 | ss -na src $PORT | grep -v State | awk '{print $1;}' | sort | uniq -c > $CACHE 21 | fi 22 | fi 23 | 24 | res=`grep "$1" $CACHE | awk '{print $1;}'` 25 | if [[ "$res" == "" ]] ; then 26 | echo 0 27 | else 28 | echo $res 29 | fi 30 | -------------------------------------------------------------------------------- /mongodb/mongodb.conf: -------------------------------------------------------------------------------- 1 | # mongodb stats 2 | UserParameter=mongodb.zabbix.sender,/etc/zabbix/scripts/mongodb.sh 3 | -------------------------------------------------------------------------------- /mongodb/mongodb.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | Date: 03/01/2017 4 | Author: Long Chen 5 | Description: A script to get MongoDB metrics 6 | Requires: MongoClient in python 7 | """ 8 | 9 | from calendar import timegm 10 | from time import gmtime 11 | 12 | from pymongo import MongoClient, errors 13 | from sys import exit 14 | 15 | import json 16 | 17 | class MongoDB(object): 18 | """main script class""" 19 | # pylint: disable=too-many-instance-attributes 20 | def __init__(self): 21 | self.mongo_host = "mongo" 22 | self.mongo_port = 27017 23 | self.mongo_db = ["admin", ] 24 | self.mongo_user = None 25 | self.mongo_password = None 26 | self.__conn = None 27 | self.__dbnames = None 28 | self.__metrics = [] 29 | 30 | def connect(self): 31 | """Connect to MongoDB""" 32 | if self.__conn is None: 33 | if self.mongo_user is None: 34 | try: 35 | self.__conn = MongoClient('mongodb://%s:%s' % 36 | (self.mongo_host, 37 | self.mongo_port)) 38 | except errors.PyMongoError as py_mongo_error: 39 | print('Error in MongoDB connection: %s' % 40 | str(py_mongo_error)) 41 | else: 42 | try: 43 | self.__conn = MongoClient('mongodb://%s:%s@%s:%s' % 44 | (self.mongo_user, 45 | self.mongo_password, 46 | self.mongo_host, 47 | self.mongo_port)) 48 | except errors.PyMongoError as py_mongo_error: 49 | print('Error in MongoDB connection: %s' % 50 | str(py_mongo_error)) 51 | 52 | def add_metrics(self, k, v): 53 | """add each metric to the metrics list""" 54 | dict_metrics = {} 55 | dict_metrics['key'] = k 56 | dict_metrics['value'] = v 57 | self.__metrics.append(dict_metrics) 58 | 59 | def print_metrics(self): 60 | """print out all metrics""" 61 | metrics = self.__metrics 62 | for metric in metrics: 63 | zabbix_item_key = str(metric['key']) 64 | zabbix_item_value = str(metric['value']) 65 | print('- ' + zabbix_item_key + ' ' + zabbix_item_value) 66 | 67 | def get_db_names(self): 68 | """get a list of DB names""" 69 | if self.__conn is None: 70 | self.connect() 71 | db_handler = self.__conn[self.mongo_db[0]] 72 | 73 | master = db_handler.command('isMaster')['ismaster'] 74 | dict_metrics = {} 75 | dict_metrics['key'] = 'mongodb.ismaster' 76 | if master: 77 | dict_metrics['value'] = 1 78 | db_names = self.__conn.database_names() 79 | self.__dbnames = db_names 80 | else: 81 | dict_metrics['value'] = 0 82 | self.__metrics.append(dict_metrics) 83 | 84 | def get_mongo_db_lld(self): 85 | """print DB list in json format, to be used for 86 | mongo db discovery in zabbix""" 87 | if self.__dbnames is None: 88 | db_names = self.get_db_names() 89 | else: 90 | db_names = self.__dbnames 91 | dict_metrics = {} 92 | db_list = [] 93 | dict_metrics['key'] = 'mongodb.discovery' 94 | dict_metrics['value'] = {"data": db_list} 95 | if db_names is not None: 96 | for db_name in db_names: 97 | dict_lld_metric = {} 98 | dict_lld_metric['{#MONGODBNAME}'] = db_name 99 | db_list.append(dict_lld_metric) 100 | dict_metrics['value'] = '{"data": ' + json.dumps(db_list) + '}' 101 | self.__metrics.insert(0, dict_metrics) 102 | 103 | def get_oplog(self): 104 | """get replica set oplog information""" 105 | if self.__conn is None: 106 | self.connect() 107 | db_handler = self.__conn['local'] 108 | 109 | coll = db_handler.oplog.rs 110 | 111 | op_first = (coll.find().sort('$natural', 1).limit(1)) 112 | op_last = (coll.find().sort('$natural', -1).limit(1)) 113 | 114 | # if host is not a member of replica set, without this check we will 115 | # raise StopIteration as guided in 116 | # http://api.mongodb.com/python/current/api/pymongo/cursor.html 117 | 118 | if op_first.count() > 0 and op_last.count() > 0: 119 | op_fst = (op_first.next())['ts'].time 120 | op_last_st = op_last[0]['ts'] 121 | op_lst = (op_last.next())['ts'].time 122 | 123 | status = round(float(op_lst - op_fst), 1) 124 | self.add_metrics('mongodb.oplog', status) 125 | 126 | current_time = timegm(gmtime()) 127 | oplog = int(((str(op_last_st).split('('))[1].split(','))[0]) 128 | self.add_metrics('mongodb.oplog-sync', (current_time - oplog)) 129 | 130 | 131 | def get_maintenance(self): 132 | """get replica set maintenance info""" 133 | if self.__conn is None: 134 | self.connect() 135 | db_handler = self.__conn 136 | 137 | fsync_locked = int(db_handler.is_locked) 138 | self.add_metrics('mongodb.fsync-locked', fsync_locked) 139 | 140 | try: 141 | config = db_handler.admin.command("replSetGetConfig", 1) 142 | connstring = (self.mongo_host + ':' + str(self.mongo_port)) 143 | connstrings = list() 144 | 145 | for i in range(0, len(config['config']['members'])): 146 | host = config['config']['members'][i]['host'] 147 | connstrings.append(host) 148 | 149 | if connstring in host: 150 | priority = config['config']['members'][i]['priority'] 151 | hidden = int(config['config']['members'][i]['hidden']) 152 | 153 | self.add_metrics('mongodb.priority', priority) 154 | self.add_metrics('mongodb.hidden', hidden) 155 | except errors.PyMongoError: 156 | print ('Error while fetching replica set configuration.' 157 | 'Not a member of replica set?') 158 | except UnboundLocalError: 159 | print ('Cannot use this mongo host: must be one of ' + ','.join(connstrings)) 160 | exit(1) 161 | 162 | def get_server_status_metrics(self): 163 | """get server status""" 164 | if self.__conn is None: 165 | self.connect() 166 | db_handler = self.__conn[self.mongo_db[0]] 167 | ss = db_handler.command('serverStatus') 168 | 169 | # db info 170 | self.add_metrics('mongodb.version', ss['version']) 171 | self.add_metrics('mongodb.storageEngine', ss['storageEngine']['name']) 172 | self.add_metrics('mongodb.uptime', int(ss['uptime'])) 173 | self.add_metrics('mongodb.okstatus', int(ss['ok'])) 174 | 175 | # asserts 176 | for k, v in ss['asserts'].items(): 177 | self.add_metrics('mongodb.asserts.' + k, v) 178 | 179 | # operations 180 | for k, v in ss['opcounters'].items(): 181 | self.add_metrics('mongodb.operation.' + k, v) 182 | 183 | # memory 184 | for k in ['resident', 'virtual', 'mapped', 'mappedWithJournal']: 185 | self.add_metrics('mongodb.memory.' + k, ss['mem'][k]) 186 | 187 | # connections 188 | for k, v in ss['connections'].items(): 189 | self.add_metrics('mongodb.connection.' + k, v) 190 | 191 | # network 192 | for k, v in ss['network'].items(): 193 | self.add_metrics('mongodb.network.' + k, v) 194 | 195 | # extra info 196 | self.add_metrics('mongodb.page.faults', 197 | ss['extra_info']['page_faults']) 198 | 199 | #wired tiger 200 | if ss['storageEngine']['name'] == 'wiredTiger': 201 | self.add_metrics('mongodb.used-cache', 202 | ss['wiredTiger']['cache'] 203 | ["bytes currently in the cache"]) 204 | self.add_metrics('mongodb.total-cache', 205 | ss['wiredTiger']['cache'] 206 | ["maximum bytes configured"]) 207 | self.add_metrics('mongodb.dirty-cache', 208 | ss['wiredTiger']['cache'] 209 | ["tracked dirty bytes in the cache"]) 210 | 211 | # global lock 212 | lock_total_time = ss['globalLock']['totalTime'] 213 | self.add_metrics('mongodb.globalLock.totalTime', lock_total_time) 214 | for k, v in ss['globalLock']['currentQueue'].items(): 215 | self.add_metrics('mongodb.globalLock.currentQueue.' + k, v) 216 | for k, v in ss['globalLock']['activeClients'].items(): 217 | self.add_metrics('mongodb.globalLock.activeClients.' + k, v) 218 | 219 | def get_db_stats_metrics(self): 220 | """get DB stats for each DB""" 221 | if self.__conn is None: 222 | self.connect() 223 | if self.__dbnames is None: 224 | self.get_db_names() 225 | if self.__dbnames is not None: 226 | for mongo_db in self.__dbnames: 227 | db_handler = self.__conn[mongo_db] 228 | dbs = db_handler.command('dbstats') 229 | for k, v in dbs.items(): 230 | if k in ['storageSize', 'ok', 'avgObjSize', 'indexes', 231 | 'objects', 'collections', 'fileSize', 232 | 'numExtents', 'dataSize', 'indexSize', 233 | 'nsSizeMB']: 234 | self.add_metrics('mongodb.stats.' + k + 235 | '[' + mongo_db + ']', int(v)) 236 | def close(self): 237 | """close connection to mongo""" 238 | if self.__conn is not None: 239 | self.__conn.close() 240 | 241 | if __name__ == '__main__': 242 | mongodb = MongoDB() 243 | mongodb.get_db_names() 244 | mongodb.get_mongo_db_lld() 245 | mongodb.get_oplog() 246 | mongodb.get_maintenance() 247 | mongodb.get_server_status_metrics() 248 | mongodb.get_db_stats_metrics() 249 | mongodb.print_metrics() 250 | mongodb.close() 251 | -------------------------------------------------------------------------------- /mongodb/mongodb.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Date: 22/01/2017 4 | # Author: Long Chen 5 | # Description: A script to send MongoDB stats to zabbix server by using zabbix sender 6 | # Requires: Zabbix Sender, zabbix-mongodb.py 7 | 8 | get_MongoDB_metrics(){ 9 | python /etc/zabbix/scripts/mongodb.py 10 | } 11 | 12 | # Send the results to zabbix server by using zabbix sender 13 | result=$(get_MongoDB_metrics | /usr/bin/zabbix_sender -c /etc/zabbix/zabbix_agentd.conf -i - 2>&1) 14 | response=$(echo "$result" | awk -F ';' '$1 ~ /^info/ && match($1,/[0-9].*$/) {sum+=substr($1,RSTART,RLENGTH)} END {print sum}') 15 | if [ -n "$response" ]; then 16 | echo "$response" 17 | else 18 | echo "$result" 19 | fi 20 | -------------------------------------------------------------------------------- /mysql/userparameter_mysql.conf: -------------------------------------------------------------------------------- 1 | # For all the following commands HOME should be set to the directory that has .my.cnf file with password information. 2 | 3 | # Flexible parameter to grab global variables. On the frontend side, use keys like mysql.status[Com_insert]. 4 | # Key syntax is mysql.status[variable]. 5 | UserParameter=mysql.status[*],echo "show global status where Variable_name='$1';" | HOME=/var/lib/zabbix mysql -uzabbix-agent -p7yNPKc9nLCXsv8R8 -N | awk '{print $$2}' 6 | 7 | # Flexible parameter to determine database or table size. On the frontend side, use keys like mysql.size[zabbix,history,data]. 8 | # Key syntax is mysql.size[,,]. 9 | # Database may be a database name or "all". Default is "all". 10 | # Table may be a table name or "all". Default is "all". 11 | # Type may be "data", "index", "free" or "both". Both is a sum of data and index. Default is "both". 12 | # Database is mandatory if a table is specified. Type may be specified always. 13 | # Returns value in bytes. 14 | # 'sum' on data_length or index_length alone needed when we are getting this information for whole database instead of a single table 15 | UserParameter=mysql.size[*],echo "select sum($(case "$3" in both|"") echo "data_length+index_length";; data|index) echo "$3_length";; free) echo "data_free";; esac)) from information_schema.tables$([[ "$1" = "all" || ! "$1" ]] || echo " where table_schema='$1'")$([[ "$2" = "all" || ! "$2" ]] || echo "and table_name='$2'");" | HOME=/var/lib/zabbix mysql -N 16 | 17 | UserParameter=mysql.ping,HOME=/var/lib/zabbix mysqladmin -uzabbix-agent -pPASSWORD_HERE ping | grep -c alive 18 | UserParameter=mysql.version,mysql -V 19 | -------------------------------------------------------------------------------- /netstat/netstat.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | CACHETTL="55" # Время действия кеша в секундах (чуть меньше чем период опроса элементов) 5 | CACHE="/tmp/zabbix-netstat-status.cache" 6 | 7 | if [ -s "$CACHE" ]; then 8 | TIMECACHE=`stat -c"%Z" "$CACHE"` 9 | else 10 | TIMECACHE=0 11 | fi 12 | 13 | TIMENOW=`date '+%s'` 14 | 15 | if [ "$(($TIMENOW - $TIMECACHE))" -gt "$CACHETTL" ]; then 16 | netstat -s > $CACHE 17 | fi 18 | 19 | if [[ "$1" == "" ]] ; then 20 | grep -e '[0-9]' $CACHE | sed 's/[0-9][0-9]*//g' | sed 's/\s\+/ /g' | sed 's/^ //' | grep -v : 21 | exit 22 | fi 23 | 24 | res=`grep "$1" $CACHE | sed 's/[^0-9]*[^0-9-]\(-\?[0-9]\+\).*/\1/g' | head -n 1` 25 | if [[ "$res" == "" ]] ; then 26 | echo 0 27 | else 28 | echo $res 29 | fi 30 | 31 | -------------------------------------------------------------------------------- /netstat/sockets.conf: -------------------------------------------------------------------------------- 1 | UserParameter=sockets[*],/etc/zabbix/scripts/sockets.sh "$1" "$2" 2 | UserParameter=netstat[*],/etc/zabbix/scripts/netstat.sh "$1" 3 | -------------------------------------------------------------------------------- /netstat/sockets.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | PORT="$2" 4 | 5 | CACHETTL="55" # Время действия кеша в секундах (чуть меньше чем период опроса элементов) 6 | CACHE="/tmp/zabbix-sockets-status.$PORT.cache" 7 | 8 | if [ -s "$CACHE" ]; then 9 | TIMECACHE=`stat -c"%Z" "$CACHE"` 10 | else 11 | TIMECACHE=0 12 | fi 13 | 14 | TIMENOW=`date '+%s'` 15 | 16 | if [ "$(($TIMENOW - $TIMECACHE))" -gt "$CACHETTL" ]; then 17 | if [[ $PORT == "" ]] ; then 18 | ss -na | grep -v State | grep -v LISTEN | awk '{print $1;}' | sort | uniq -c > $CACHE 19 | else 20 | ss -na src $PORT | grep -v State | awk '{print $1;}' | sort | uniq -c > $CACHE 21 | fi 22 | fi 23 | 24 | res=`grep "$1" $CACHE | awk '{print $1;}'` 25 | if [[ "$res" == "" ]] ; then 26 | echo 0 27 | else 28 | echo $res 29 | fi 30 | -------------------------------------------------------------------------------- /nginx-background/nginx-background.conf: -------------------------------------------------------------------------------- 1 | UserParameter=nginx-background[*],/etc/zabbix/scripts/nginx-background.sh "$1" "$2" 2 | -------------------------------------------------------------------------------- /nginx-background/nginx-background.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ################################## 3 | # Zabbix monitoring script 4 | # 5 | # nginx: 6 | # - anything available via nginx stub-status module 7 | # 8 | ################################## 9 | # Contact: 10 | # vincent.viallet@gmail.com 11 | ################################## 12 | # ChangeLog: 13 | # 20100922 VV initial creation 14 | ################################## 15 | 16 | # Zabbix requested parameter 17 | ZBX_REQ_DATA="$1" 18 | ZBX_REQ_DATA_URL="$2" 19 | 20 | # Nginx defaults 21 | NGINX_STATUS_DEFAULT_URL="http://localhost:80/fpm/inner_nginx1" 22 | WGET_BIN="/usr/bin/wget" 23 | 24 | # 25 | # Error handling: 26 | # - need to be displayable in Zabbix (avoid NOT_SUPPORTED) 27 | # - items need to be of type "float" (allow negative + float) 28 | # 29 | ERROR_NO_ACCESS_FILE="-0.9900" 30 | ERROR_NO_ACCESS="-0.9901" 31 | ERROR_WRONG_PARAM="-0.9902" 32 | ERROR_DATA="-0.9903" # either can not connect / bad host / bad port 33 | 34 | # Handle host and port if non-default 35 | if [ ! -z "$ZBX_REQ_DATA_URL" ]; then 36 | URL="$ZBX_REQ_DATA_URL" 37 | else 38 | URL="$NGINX_STATUS_DEFAULT_URL" 39 | fi 40 | 41 | # save the nginx stats in a variable for future parsing 42 | NGINX_STATS=$($WGET_BIN -q $URL -O - 2> /dev/null) 43 | 44 | # error during retrieve 45 | if [ $? -ne 0 -o -z "$NGINX_STATS" ]; then 46 | echo $ERROR_DATA 47 | exit 1 48 | fi 49 | 50 | # 51 | # Extract data from nginx stats 52 | # 53 | case $ZBX_REQ_DATA in 54 | active_connections) echo "$NGINX_STATS" | head -1 | cut -f3 -d' ';; 55 | accepted_connections) echo "$NGINX_STATS" | grep -Ev '[a-zA-Z]' | cut -f2 -d' ';; 56 | handled_connections) echo "$NGINX_STATS" | grep -Ev '[a-zA-Z]' | cut -f3 -d' ';; 57 | handled_requests) echo "$NGINX_STATS" | grep -Ev '[a-zA-Z]' | cut -f4 -d' ';; 58 | reading) echo "$NGINX_STATS" | tail -1 | cut -f2 -d' ';; 59 | writing) echo "$NGINX_STATS" | tail -1 | cut -f4 -d' ';; 60 | waiting) echo "$NGINX_STATS" | tail -1 | cut -f6 -d' ';; 61 | failed_connections) 62 | one=`echo "$NGINX_STATS" | grep -Ev '[a-zA-Z]' | cut -f2 -d' '` 63 | two=`echo "$NGINX_STATS" | grep -Ev '[a-zA-Z]' | cut -f3 -d' '` 64 | let a=$one-$two 65 | echo $a 66 | ;; 67 | *) echo $ERROR_WRONG_PARAM; exit 1;; 68 | esac 69 | 70 | exit 0 71 | -------------------------------------------------------------------------------- /nginx-background/nginx-background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 2.0 4 | 2015-10-12T08:45:56Z 5 | 6 | 7 | Templates 8 | 9 | 10 | 11 | 381 | 382 | 383 | 384 | {Template Nginx-Background:nginx-background[failed_connections,{$NGINX_BACKGROUND_STATUS_URL}].last(0)}>0 385 | Not enough NGINX {HOSTNAME} workers 386 | 387 | 0 388 | 3 389 | 390 | 0 391 | 392 | 393 | 394 | 395 | 396 | Nginx-Background - Connections and Requests status 397 | 900 398 | 200 399 | 0.0000 400 | 100.0000 401 | 0 402 | 0 403 | 0 404 | 1 405 | 0 406 | 0.0000 407 | 0.0000 408 | 1 409 | 0 410 | 0 411 | 0 412 | 413 | 414 | 0 415 | 1 416 | FF9999 417 | 0 418 | 4 419 | 0 420 | 421 | Template Nginx-Background 422 | nginx-background[accepted_connections,{$NGINX_BACKGROUND_STATUS_URL}] 423 | 424 | 425 | 426 | 1 427 | 2 428 | 990000 429 | 0 430 | 4 431 | 0 432 | 433 | Template Nginx-Background 434 | nginx-background[handled_connections,{$NGINX_BACKGROUND_STATUS_URL}] 435 | 436 | 437 | 438 | 2 439 | 0 440 | 009900 441 | 0 442 | 4 443 | 0 444 | 445 | Template Nginx-Background 446 | nginx-background[handled_requests,{$NGINX_BACKGROUND_STATUS_URL}] 447 | 448 | 449 | 450 | 451 | 452 | Nginx-Background - Threads status 453 | 900 454 | 200 455 | 0.0000 456 | 100.0000 457 | 0 458 | 0 459 | 1 460 | 1 461 | 0 462 | 0.0000 463 | 0.0000 464 | 1 465 | 0 466 | 0 467 | 0 468 | 469 | 470 | 0 471 | 5 472 | 990000 473 | 0 474 | 4 475 | 0 476 | 477 | Template Nginx-Background 478 | nginx-background[writing,{$NGINX_BACKGROUND_STATUS_URL}] 479 | 480 | 481 | 482 | 1 483 | 5 484 | 999900 485 | 0 486 | 4 487 | 0 488 | 489 | Template Nginx-Background 490 | nginx-background[reading,{$NGINX_BACKGROUND_STATUS_URL}] 491 | 492 | 493 | 494 | 2 495 | 5 496 | 009900 497 | 0 498 | 4 499 | 0 500 | 501 | Template Nginx-Background 502 | nginx-background[waiting,{$NGINX_BACKGROUND_STATUS_URL}] 503 | 504 | 505 | 506 | 507 | 508 | 509 | -------------------------------------------------------------------------------- /nginx/nginx.conf: -------------------------------------------------------------------------------- 1 | UserParameter=nginx[*],/etc/zabbix/scripts/nginx.sh "$1" "$2" 2 | -------------------------------------------------------------------------------- /nginx/nginx.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ################################## 3 | # Zabbix monitoring script 4 | # 5 | # nginx: 6 | # - anything available via nginx stub-status module 7 | # 8 | ################################## 9 | # Contact: 10 | # vincent.viallet@gmail.com 11 | ################################## 12 | # ChangeLog: 13 | # 20100922 VV initial creation 14 | ################################## 15 | 16 | # Zabbix requested parameter 17 | ZBX_REQ_DATA="$1" 18 | ZBX_REQ_DATA_URL="$2" 19 | 20 | # Nginx defaults 21 | NGINX_STATUS_DEFAULT_URL="http://127.0.0.1/status" 22 | WGET_BIN="/usr/bin/wget" 23 | 24 | # 25 | # Error handling: 26 | # - need to be displayable in Zabbix (avoid NOT_SUPPORTED) 27 | # - items need to be of type "float" (allow negative + float) 28 | # 29 | ERROR_NO_ACCESS_FILE="-0.9" 30 | ERROR_NO_ACCESS="-0.91" 31 | ERROR_WRONG_PARAM="-0.92" 32 | ERROR_DATA="-0.93" # either can not connect / bad host / bad port 33 | 34 | # Handle host and port if non-default 35 | if [ ! -z "$ZBX_REQ_DATA_URL" ]; then 36 | URL="$ZBX_REQ_DATA_URL" 37 | else 38 | URL="$NGINX_STATUS_DEFAULT_URL" 39 | fi 40 | 41 | # save the nginx stats in a variable for future parsing 42 | NGINX_STATS=$($WGET_BIN -q $URL -O - 2> /dev/null) 43 | 44 | # error during retrieve 45 | if [ $? -ne 0 -o -z "$NGINX_STATS" ]; then 46 | echo $ERROR_DATA 47 | exit 1 48 | fi 49 | 50 | # 51 | # Extract data from nginx stats 52 | # 53 | case $ZBX_REQ_DATA in 54 | active_connections) echo "$NGINX_STATS" | head -1 | cut -f3 -d' ';; 55 | accepted_connections) echo "$NGINX_STATS" | grep -Ev '[a-zA-Z]' | cut -f2 -d' ';; 56 | handled_connections) echo "$NGINX_STATS" | grep -Ev '[a-zA-Z]' | cut -f3 -d' ';; 57 | handled_requests) echo "$NGINX_STATS" | grep -Ev '[a-zA-Z]' | cut -f4 -d' ';; 58 | reading) echo "$NGINX_STATS" | tail -1 | cut -f2 -d' ';; 59 | writing) echo "$NGINX_STATS" | tail -1 | cut -f4 -d' ';; 60 | waiting) echo "$NGINX_STATS" | tail -1 | cut -f6 -d' ';; 61 | failed_connections) 62 | one=`echo "$NGINX_STATS" | grep -Ev '[a-zA-Z]' | cut -f2 -d' '` 63 | two=`echo "$NGINX_STATS" | grep -Ev '[a-zA-Z]' | cut -f3 -d' '` 64 | let a=$one-$two 65 | echo $a 66 | ;; 67 | *) echo $ERROR_WRONG_PARAM; exit 1;; 68 | esac 69 | 70 | exit 0 71 | -------------------------------------------------------------------------------- /nginx/nginx.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 2.0 4 | 2014-04-07T13:19:36Z 5 | 6 | 7 | Templates 8 | 9 | 10 | 11 | 387 | 388 | 389 | 390 | {Template Nginx:proc.num[nginx].last(0)}=0 391 | Nginx is not running on {HOSTNAME} 392 | 393 | 0 394 | 5 395 | Nginx is not running. 396 | 397 | It has been stopped / shutdown or has crashed. 398 | Check on the server for more details: 399 | - w / last 400 | - dmesg logs 401 | - /var/log/messages 402 | - nginx error logs 403 | 0 404 | 405 | 406 | 407 | {Template Nginx:nginx[failed_connections,{$NGINX_STATUS_URL}].last(0)}>0 408 | Not enough NGINX {HOSTNAME} workers 409 | 410 | 0 411 | 3 412 | 413 | 0 414 | 415 | 416 | 417 | 418 | 419 | Nginx - Connections and Requests status 420 | 900 421 | 200 422 | 0.0000 423 | 100.0000 424 | 0 425 | 0 426 | 0 427 | 1 428 | 0 429 | 0.0000 430 | 0.0000 431 | 1 432 | 0 433 | 0 434 | 0 435 | 436 | 437 | 0 438 | 1 439 | FF9999 440 | 0 441 | 4 442 | 0 443 | 444 | Template Nginx 445 | nginx[accepted_connections,{$NGINX_STATUS_URL}] 446 | 447 | 448 | 449 | 1 450 | 2 451 | 990000 452 | 0 453 | 4 454 | 0 455 | 456 | Template Nginx 457 | nginx[handled_connections,{$NGINX_STATUS_URL}] 458 | 459 | 460 | 461 | 2 462 | 0 463 | 009900 464 | 0 465 | 4 466 | 0 467 | 468 | Template Nginx 469 | nginx[handled_requests,{$NGINX_STATUS_URL}] 470 | 471 | 472 | 473 | 474 | 475 | Nginx - Threads status 476 | 900 477 | 200 478 | 0.0000 479 | 100.0000 480 | 0 481 | 0 482 | 1 483 | 1 484 | 0 485 | 0.0000 486 | 0.0000 487 | 1 488 | 0 489 | 0 490 | 0 491 | 492 | 493 | 0 494 | 1 495 | 990000 496 | 0 497 | 4 498 | 0 499 | 500 | Template Nginx 501 | nginx[writing,{$NGINX_STATUS_URL}] 502 | 503 | 504 | 505 | 1 506 | 1 507 | 999900 508 | 0 509 | 4 510 | 0 511 | 512 | Template Nginx 513 | nginx[reading,{$NGINX_STATUS_URL}] 514 | 515 | 516 | 517 | 2 518 | 1 519 | 009900 520 | 0 521 | 4 522 | 0 523 | 524 | Template Nginx 525 | nginx[waiting,{$NGINX_STATUS_URL}] 526 | 527 | 528 | 529 | 530 | 531 | 532 | -------------------------------------------------------------------------------- /php-fpm-multiple-pools/fpm-multiple-pools.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 3.4 4 | 2018-12-20T12:56:52Z 5 | 6 | 7 | Templates 8 | 9 | 10 | 11 | 662 | 663 | 664 | -------------------------------------------------------------------------------- /php-fpm-multiple-pools/fpm-pool.conf: -------------------------------------------------------------------------------- 1 | UserParameter=php-fpm-pool[*],/etc/zabbix/scripts/fpm-pool.sh "$1" "$2" 2 | -------------------------------------------------------------------------------- /php-fpm-multiple-pools/fpm-pool.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ################################## 3 | # Zabbix monitoring script 4 | # 5 | # php-fpm: 6 | # - anything available via FPM status page 7 | # 8 | ################################## 9 | 10 | 11 | if [[ "$1" == "discovery" ]] ; then 12 | echo '{"data":[' 13 | for file in `find /etc/php5/fpm/pool.d/ /etc/php/*/fpm/pool.d/ -name '*.conf' 2>/dev/null` ; do 14 | poolname=`grep -e '^\s*\[[a-zA-Z-]*\]\s*$' $file | sed -e 's/.*\[\(.*\)\].*/\1/'` 15 | status_path=`grep -e '^\s*pm\.status_path\s*=\s*' $file | awk -F '=' '{print $2;}' | sed -e 's/^\s*\([^ ;]*\)\s*;\?.*/\1/'` 16 | if [[ "$comma" == 1 ]] ; then 17 | echo ',' 18 | fi 19 | echo ' {' 20 | echo ' "{#POOL}":"'$poolname'",' 21 | echo ' "{#STATUS}":"'$status_path'"' 22 | echo -n ' }' 23 | comma=1 24 | done 25 | echo ']}' 26 | exit 27 | fi 28 | 29 | 30 | # Zabbix requested parameter 31 | ZBX_REQ_DATA="$1" 32 | ZBX_REQ_DATA_URL="$2" 33 | 34 | # Nginx defaults 35 | STATUS_HOST="http://127.0.0.1" 36 | NGINX_STATUS_DEFAULT_URL="/status" 37 | 38 | WGET_BIN="/usr/bin/wget" 39 | 40 | # 41 | # Error handling: 42 | # - need to be displayable in Zabbix (avoid NOT_SUPPORTED) 43 | # - items need to be of type "float" (allow negative + float) 44 | # 45 | ERROR_NO_ACCESS_FILE="-0.9900" 46 | ERROR_NO_ACCESS="-0.9901" 47 | ERROR_WRONG_PARAM="-0.9902" 48 | ERROR_DATA="-0.9903" # either can not connect / bad host / bad port 49 | 50 | # Handle host and port if non-default 51 | if [ ! -z "$ZBX_REQ_DATA_URL" ]; then 52 | URL="$ZBX_REQ_DATA_URL" 53 | else 54 | URL="$NGINX_STATUS_DEFAULT_URL" 55 | fi 56 | 57 | URL=${STATUS_HOST}${URL} 58 | 59 | # save the nginx stats in a variable for future parsing 60 | NGINX_STATS=$($WGET_BIN -q $URL -O - 2> /dev/null) 61 | 62 | # error during retrieve 63 | if [ $? -ne 0 -o -z "$NGINX_STATS" ]; then 64 | echo $ERROR_DATA 65 | exit 1 66 | fi 67 | 68 | # 69 | # Extract data from nginx stats 70 | # 71 | #RESULT=$(echo "$NGINX_STATS" | awk 'print $0;match($0, "^'"$ZBX_REQ_DATA"':[[:space:]]+(.*)", a) { print a[1] }') 72 | #RESULT=$(echo "$NGINX_STATS" | grep "$ZBX_REQ_DATA" | awk -F : '{print $2}') 73 | RESULT=$(echo "$NGINX_STATS" | awk -F : "{if(\$1==\"$ZBX_REQ_DATA\") print \$2}") 74 | if [ $? -ne 0 -o -z "$RESULT" ]; then 75 | echo $ERROR_WRONG_PARAM 76 | exit 1 77 | fi 78 | 79 | echo $RESULT 80 | 81 | exit 0 82 | -------------------------------------------------------------------------------- /php-fpm/fpm.conf: -------------------------------------------------------------------------------- 1 | UserParameter=php-fpm[*],/etc/zabbix/scripts/fpm.sh "$1" "$2" 2 | -------------------------------------------------------------------------------- /php-fpm/fpm.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ################################## 3 | # Zabbix monitoring script 4 | # 5 | # php-fpm: 6 | # - anything available via FPM status page 7 | # 8 | ################################## 9 | # Contact: 10 | # vincent.viallet@gmail.com 11 | ################################## 12 | # ChangeLog: 13 | # 20100922 VV initial creation 14 | ################################## 15 | 16 | # Zabbix requested parameter 17 | ZBX_REQ_DATA="$1" 18 | ZBX_REQ_DATA_URL="$2" 19 | 20 | # Nginx defaults 21 | NGINX_STATUS_DEFAULT_URL="http://localhost/fpm/status" 22 | WGET_BIN="/usr/bin/wget" 23 | 24 | # 25 | # Error handling: 26 | # - need to be displayable in Zabbix (avoid NOT_SUPPORTED) 27 | # - items need to be of type "float" (allow negative + float) 28 | # 29 | ERROR_NO_ACCESS_FILE="-0.91" 30 | ERROR_NO_ACCESS="-0.92" 31 | ERROR_WRONG_PARAM="-0.93" 32 | ERROR_DATA="-0.94" # either can not connect / bad host / bad port 33 | 34 | # Handle host and port if non-default 35 | if [ ! -z "$ZBX_REQ_DATA_URL" ]; then 36 | URL="$ZBX_REQ_DATA_URL" 37 | else 38 | URL="$NGINX_STATUS_DEFAULT_URL" 39 | fi 40 | 41 | # save the nginx stats in a variable for future parsing 42 | NGINX_STATS=$($WGET_BIN -q $URL -O - 2>/dev/null) 43 | 44 | # error during retrieve 45 | if [ $? -ne 0 -o -z "$NGINX_STATS" ]; then 46 | echo $ERROR_DATA 47 | exit 1 48 | fi 49 | 50 | # 51 | # Extract data from nginx stats 52 | # 53 | #RESULT=$(echo "$NGINX_STATS" | awk 'print $0;match($0, "^'"$ZBX_REQ_DATA"':[[:space:]]+(.*)", a) { print a[1] }') 54 | #RESULT=$(echo "$NGINX_STATS" | grep "$ZBX_REQ_DATA" | awk -F : '{print $2}') 55 | RESULT=$(echo "$NGINX_STATS" | awk -F : "{if(\$1==\"$ZBX_REQ_DATA\") print \$2}") 56 | if [ $? -ne 0 -o -z "$RESULT" ]; then 57 | echo $ERROR_WRONG_PARAM 58 | exit 1 59 | fi 60 | 61 | echo $RESULT 62 | 63 | exit 0 64 | -------------------------------------------------------------------------------- /php-fpm/fpm.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 2.0 4 | 2015-10-12T08:46:18Z 5 | 6 | 7 | Templates 8 | 9 | 10 | 11 | 338 | 339 | 340 | 341 | {Template php-fpm:php-fpm["active processes",{$PHP_FPM_STATUS_URL}].nodata(220)}=1 or {Template php-fpm:php-fpm["active processes",{$PHP_FPM_STATUS_URL}].last(0)}<0 342 | PHP-fpm of {HOSTNAME} is down 343 | 344 | 0 345 | 5 346 | 347 | 0 348 | 349 | 350 | Zabbix agent on {HOST.NAME} is unreachable for 5 minutes 351 | {Template OS Linux:agent.ping.nodata(5m)}=1 352 | 353 | 354 | 355 | 356 | 357 | 358 | php-fpm Accepted Connections / sec 359 | 900 360 | 200 361 | 0.0000 362 | 100.0000 363 | 1 364 | 1 365 | 0 366 | 1 367 | 0 368 | 0.0000 369 | 0.0000 370 | 0 371 | 0 372 | 0 373 | 0 374 | 375 | 376 | 0 377 | 0 378 | C80000 379 | 0 380 | 2 381 | 0 382 | 383 | Template php-fpm 384 | php-fpm["accepted conn",{$PHP_FPM_STATUS_URL}] 385 | 386 | 387 | 388 | 389 | 390 | php-fpm Listen Queue 391 | 900 392 | 200 393 | 0.0000 394 | 100.0000 395 | 1 396 | 1 397 | 0 398 | 1 399 | 0 400 | 0.0000 401 | 0.0000 402 | 0 403 | 0 404 | 0 405 | 0 406 | 407 | 408 | 0 409 | 0 410 | EE0000 411 | 0 412 | 2 413 | 0 414 | 415 | Template php-fpm 416 | php-fpm["listen queue len",{$PHP_FPM_STATUS_URL}] 417 | 418 | 419 | 420 | 1 421 | 0 422 | 00EE00 423 | 0 424 | 2 425 | 0 426 | 427 | Template php-fpm 428 | php-fpm["listen queue",{$PHP_FPM_STATUS_URL}] 429 | 430 | 431 | 432 | 433 | 434 | php-fpm Processes 435 | 900 436 | 200 437 | 0.0000 438 | 100.0000 439 | 1 440 | 1 441 | 1 442 | 1 443 | 0 444 | 0.0000 445 | 0.0000 446 | 0 447 | 0 448 | 0 449 | 0 450 | 451 | 452 | 0 453 | 0 454 | EE0000 455 | 0 456 | 4 457 | 0 458 | 459 | Template php-fpm 460 | php-fpm["active processes",{$PHP_FPM_STATUS_URL}] 461 | 462 | 463 | 464 | 1 465 | 0 466 | 00EE00 467 | 0 468 | 1 469 | 0 470 | 471 | Template php-fpm 472 | php-fpm["idle processes",{$PHP_FPM_STATUS_URL}] 473 | 474 | 475 | 476 | 477 | 478 | php-fpm Slow Requests / sec 479 | 900 480 | 200 481 | 0.0000 482 | 100.0000 483 | 1 484 | 1 485 | 0 486 | 1 487 | 0 488 | 0.0000 489 | 0.0000 490 | 0 491 | 0 492 | 0 493 | 0 494 | 495 | 496 | 0 497 | 0 498 | C80000 499 | 0 500 | 2 501 | 0 502 | 503 | Template php-fpm 504 | php-fpm["slow requests",{$PHP_FPM_STATUS_URL}] 505 | 506 | 507 | 508 | 509 | 510 | 511 | -------------------------------------------------------------------------------- /redis/redis.conf: -------------------------------------------------------------------------------- 1 | UserParameter=redis.discovery,/etc/zabbix/scripts/redis.sh localhost list_key_space_db 2 | UserParameter=redis[*],/etc/zabbix/scripts/redis.sh $1 $2 $3 3 | -------------------------------------------------------------------------------- /redis/redis.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #Redis status 4 | 5 | METRIC="$2" 6 | SERV="$1" 7 | DB="$3" 8 | 9 | PORT="6379" 10 | 11 | if [[ -z "$1" ]]; then 12 | #echo "Please set server" 13 | #exit 1 14 | SERV=127.0.0.1 15 | fi 16 | 17 | CACHETTL="55" # Время действия кеша в секундах (чуть меньше чем период опроса элементов) 18 | CACHE="/tmp/redis-status-`echo $SERV | md5sum | cut -d" " -f1`.cache" 19 | 20 | if [ -s "$CACHE" ]; then 21 | TIMECACHE=`stat -c"%Z" "$CACHE"` 22 | else 23 | TIMECACHE=0 24 | fi 25 | 26 | TIMENOW=`date '+%s'` 27 | 28 | if [ "$(($TIMENOW - $TIMECACHE))" -gt "$CACHETTL" ]; then 29 | redis-cli -h $SERV -p $PORT info > $CACHE 30 | #(echo -en "INFO\r\n"; sleep 1;) | nc $SERV $PORT > $CACHE || exit 1 31 | fi 32 | 33 | FIRST_ELEMENT=1 34 | function json_head { 35 | printf "{"; 36 | printf "\"data\":["; 37 | } 38 | 39 | function json_end { 40 | printf "]"; 41 | printf "}"; 42 | } 43 | 44 | function check_first_element { 45 | if [[ $FIRST_ELEMENT -ne 1 ]]; then 46 | printf "," 47 | fi 48 | FIRST_ELEMENT=0 49 | } 50 | 51 | function databse_detect { 52 | json_head 53 | for dbname in $LIST_DATABSE 54 | do 55 | local dbname_t=$(echo $dbname| sed 's!\n!!g') 56 | check_first_element 57 | printf "{" 58 | printf "\"{#DBNAME}\":\"$dbname_t\"" 59 | printf "}" 60 | done 61 | json_end 62 | } 63 | 64 | case $METRIC in 65 | 'redis_version') 66 | cat $CACHE | grep "redis_version:" | cut -d':' -f2 67 | ;; 68 | 'redis_git_sha1') 69 | cat $CACHE | grep "redis_git_sha1:" | cut -d':' -f2 70 | ;; 71 | 'redis_git_dirty') 72 | cat $CACHE | grep "redis_git_dirty:" | cut -d':' -f2 73 | ;; 74 | 'redis_mode') 75 | cat $CACHE | grep "redis_mode:" | cut -d':' -f2 76 | ;; 77 | 'arch_bits') 78 | cat $CACHE | grep "arch_bits:" | cut -d':' -f2 79 | ;; 80 | 'multiplexing_api') 81 | cat $CACHE | grep "multiplexing_api:" | cut -d':' -f2 82 | ;; 83 | 'gcc_version') 84 | cat $CACHE | grep "gcc_version:" | cut -d':' -f2 85 | ;; 86 | 'uptime_in_seconds') 87 | cat $CACHE | grep "uptime_in_seconds:" | cut -d':' -f2 88 | ;; 89 | 'lru_clock') 90 | cat $CACHE | grep "lru_clock:" | cut -d':' -f2 91 | ;; 92 | 'connected_clients') 93 | cat $CACHE | grep "connected_clients:" | cut -d':' -f2 94 | ;; 95 | 'client_longest_output_list') 96 | cat $CACHE | grep "client_longest_output_list:" | cut -d':' -f2 97 | ;; 98 | 'client_biggest_input_buf') 99 | cat $CACHE | grep "client_biggest_input_buf:" | cut -d':' -f2 100 | ;; 101 | 'used_memory') 102 | cat $CACHE | grep "used_memory:" | cut -d':' -f2 103 | ;; 104 | 'used_memory_peak') 105 | cat $CACHE | grep "used_memory_peak:" | cut -d':' -f2 106 | ;; 107 | 'mem_fragmentation_ratio') 108 | cat $CACHE | grep "mem_fragmentation_ratio:" | cut -d':' -f2 109 | ;; 110 | 'loading') 111 | cat $CACHE | grep "loading:" | cut -d':' -f2 112 | ;; 113 | 'rdb_changes_since_last_save') 114 | cat $CACHE | grep "rdb_changes_since_last_save:" | cut -d':' -f2 115 | ;; 116 | 'rdb_bgsave_in_progress') 117 | cat $CACHE | grep "rdb_bgsave_in_progress:" | cut -d':' -f2 118 | ;; 119 | 'aof_rewrite_in_progress') 120 | cat $CACHE | grep "aof_rewrite_in_progress:" | cut -d':' -f2 121 | ;; 122 | 'aof_enabled') 123 | cat $CACHE | grep "aof_enabled:" | cut -d':' -f2 124 | ;; 125 | 'aof_rewrite_scheduled') 126 | cat $CACHE | grep "aof_rewrite_scheduled:" | cut -d':' -f2 127 | ;; 128 | 'total_connections_received') 129 | cat $CACHE | grep "total_connections_received:" | cut -d':' -f2 130 | ;; 131 | 'total_commands_processed') 132 | cat $CACHE | grep "total_commands_processed:" | cut -d':' -f2 133 | ;; 134 | 'instantaneous_ops_per_sec') 135 | cat $CACHE | grep "instantaneous_ops_per_sec:" | cut -d':' -f2 136 | ;; 137 | 'rejected_connections') 138 | cat $CACHE | grep "rejected_connections:" | cut -d':' -f2 139 | ;; 140 | 'expired_keys') 141 | cat $CACHE | grep "expired_keys:" | cut -d':' -f2 142 | ;; 143 | 'evicted_keys') 144 | cat $CACHE | grep "evicted_keys:" | cut -d':' -f2 145 | ;; 146 | 'keyspace_hits') 147 | cat $CACHE | grep "keyspace_hits:" | cut -d':' -f2 148 | ;; 149 | 'keyspace_misses') 150 | cat $CACHE | grep "keyspace_misses:" | cut -d':' -f2 151 | ;; 152 | 'pubsub_channels') 153 | cat $CACHE | grep "pubsub_channels:" | cut -d':' -f2 154 | ;; 155 | 'pubsub_patterns') 156 | cat $CACHE | grep "pubsub_patterns:" | cut -d':' -f2 157 | ;; 158 | 'latest_fork_usec') 159 | cat $CACHE | grep "latest_fork_usec:" | cut -d':' -f2 160 | ;; 161 | 'role') 162 | cat $CACHE | grep "role:" | cut -d':' -f2 163 | ;; 164 | 'connected_slaves') 165 | cat $CACHE | grep "connected_slaves:" | cut -d':' -f2 166 | ;; 167 | 'used_cpu_sys') 168 | cat $CACHE | grep "used_cpu_sys:" | cut -d':' -f2 169 | ;; 170 | 'used_cpu_user') 171 | cat $CACHE | grep "used_cpu_user:" | cut -d':' -f2 172 | ;; 173 | 'used_cpu_sys_children') 174 | cat $CACHE | grep "used_cpu_sys_children:" | cut -d':' -f2 175 | ;; 176 | 'used_cpu_user_children') 177 | cat $CACHE | grep "used_cpu_user_children:" | cut -d':' -f2 178 | ;; 179 | 'key_space_db_keys') 180 | cat $CACHE | grep $DB:|cut -d':' -f2|awk -F, '{print $1}'|cut -d'=' -f2 181 | ;; 182 | 'key_space_db_expires') 183 | cat $CACHE | grep $DB:|cut -d':' -f2|awk -F, '{print $2}'|cut -d'=' -f2 184 | ;; 185 | 'list_key_space_db') 186 | LIST_DATABSE=`cat $CACHE | grep '^db[0-9]\+:'|cut -d: -f1` 187 | databse_detect 188 | ;; 189 | *) 190 | echo "Not selected metric" 191 | exit 0 192 | ;; 193 | esac 194 | -------------------------------------------------------------------------------- /ssl-checks/ssl-checks.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 3.4 4 | 2018-12-14T12:07:07Z 5 | 6 | 7 | Templates 8 | 9 | 10 | 11 | 201 | 202 | 203 | -------------------------------------------------------------------------------- /ssl-checks/ssl.conf: -------------------------------------------------------------------------------- 1 | UserParameter=ssl.discovery[*],/etc/zabbix/scripts/ssl.pl "$1" "$2" 2 | -------------------------------------------------------------------------------- /ssl-checks/ssl.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | $nginxConfigPath = "/etc/nginx/"; 4 | $mainConfigName = "nginx.conf"; 5 | 6 | 7 | $ignoredDomainsRaw = $ARGV[0]; 8 | @ignoredDomains = split /[\s,;|]+/g, $ignoredDomainsRaw; 9 | %ignoredDomainsHash = (); 10 | foreach $domain (@ignoredDomains) { 11 | $ignoredDomainsHash{$domain} = 1; 12 | } 13 | 14 | sub readFile { 15 | my ($filename) = @_; 16 | 17 | if(!($filename =~ /^\//)) { 18 | $filename = $nginxConfigPath . $filename; 19 | } 20 | 21 | open(my $handle, '<', $filename) 22 | or die('Error openning file '.$filename); 23 | $contents = ''; 24 | while (<$handle>) { 25 | $contents .= $_; 26 | } 27 | close($handle); 28 | $contents =~ s/\#[^\n]*//g; 29 | return $contents; 30 | } 31 | 32 | 33 | #Join separate config files to one config 34 | $mainConfig = readFile($mainConfigName); 35 | while ($mainConfig =~ /(include\s+([^\n;]+);\s*)\n/) { 36 | $includeFilenameTemplate = $2; 37 | $includeCommand = quotemeta $1; 38 | 39 | if (!($includeFilenameTemplate=~/^\//)) { 40 | $includeFilenameTemplate = $nginxConfigPath . $includeFilenameTemplate; 41 | } 42 | 43 | if ($includeFilenameTemplate=~/\*/) { 44 | $filelist = `ls -1 $includeFilenameTemplate 2>/dev/null`; 45 | @filelist = split /\n/,$filelist; 46 | $concatenatedFiles = ''; 47 | foreach $filename (@filelist) { 48 | $concatenatedFiles .= readFile($filename); 49 | } 50 | $mainConfig =~ s/$includeCommand/$concatenatedFiles/g; 51 | } else { 52 | $mainConfig =~ s/$includeCommand/$files{$includeFilename}/g; 53 | } 54 | } 55 | 56 | @servers = split /\s*server\s*\{/i, $mainConfig; 57 | %allServerNames = (); 58 | shift @servers; 59 | 60 | foreach $config (@servers) { 61 | if($config =~ /listen [^;]*(ssl|http2)/ || $config =~ /\sssl\s+on\s*;/) { 62 | $config =~ /server_name\s+([^;]+);/; 63 | $serverNamesRaw = $1; 64 | @configServerNames = split /\s+/, $serverNamesRaw; 65 | foreach $serverName (@configServerNames) { 66 | if(!($serverName =~ /^(_|localhost)?$/) && !exists($ignoredDomainsHash{$serverName})) { 67 | $allServerNames{$serverName} = 1; 68 | } 69 | } 70 | } 71 | } 72 | 73 | print '{"data":['."\n"; 74 | $firstRow=1; 75 | foreach $serverName (keys %allServerNames) { 76 | if(!$firstRow) { 77 | print ",\n"; 78 | } 79 | $firstRow=0; 80 | print '{"{#DOMAIN}":"'.$serverName.'"}'; 81 | } 82 | print "\n]}"; 83 | -------------------------------------------------------------------------------- /ssl-checks/zabbix-external-check-scripts/ssl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | use POSIX; 4 | 5 | $action=$ARGV[0]; 6 | $domain=$ARGV[1]; 7 | 8 | if($action eq 'daysBeforeExpiration') { 9 | $notAfterDate=`echo | openssl s_client -servername $domain -connect $domain:443 2>/dev/null | openssl x509 -noout -dates | grep notAfter | awk -F'=' '{print \$2;}' 2>/dev/null`; 10 | $expirationTimestamp=`date --date="$notAfterDate" +%s`; 11 | $currentTimestamp=`date +%s`; 12 | print floor(($expirationTimestamp-$currentTimestamp)/3600/24); 13 | } elsif($action eq 'isDomainValid') { 14 | $mainDomain=`echo | openssl s_client -servername $domain -connect $domain:443 2>/dev/null | openssl x509 -noout -subject | awk -F'=' '{print \$3;}'`; 15 | $additionalDomains=`echo | openssl s_client -servername $domain -connect $domain:443 2>/dev/null | openssl x509 -noout -text | grep DNS:`; 16 | 17 | @additionalDomains = split /,?[\n\s]*DNS:[\s\n]*/g, $additionalDomains; 18 | 19 | @domains = ($mainDomain, @additionalDomains); 20 | %validDomains = (); 21 | 22 | foreach $domain (@domains) { 23 | $domain =~ s/[\s\n]*//g; 24 | if(! ($domain eq '')) { 25 | $validDomains{$domain} = 1; 26 | } 27 | } 28 | 29 | print exists($validDomains{$domain}) ? 1 : 0; 30 | } else { 31 | print "Invalid action\n"; 32 | exit 1; 33 | } 34 | 35 | print "\n"; 36 | --------------------------------------------------------------------------------