├── zabbix-DiskIO ├── Template_Linux_Disk_IO_Stats.xml ├── discover_disk.pl └── zabbix_io_stats ├── zabbix-Hardware ├── Hardware-Check(2.4.6).xml └── Hardware-Check(3.0.4).xml ├── zabbix-Screens ├── zabbix_screen_group.py └── zabbix_screen_host.py ├── zabbix-Win └── zabbix │ ├── bin │ ├── win32 │ │ ├── dev │ │ │ ├── zabbix_sender.dll │ │ │ └── zabbix_sender.lib │ │ ├── zabbix_agentd.exe │ │ ├── zabbix_get.exe │ │ └── zabbix_sender.exe │ └── win64 │ │ ├── dev │ │ ├── zabbix_sender.dll │ │ └── zabbix_sender.lib │ │ ├── zabbix_agentd.exe │ │ ├── zabbix_get.exe │ │ └── zabbix_sender.exe │ ├── conf │ └── zabbix_agentd.win.conf │ └── 监控安装.bat ├── zabbix-disk ├── disk.conf ├── disk_health_check.py └── zbx_disk_templates.xml ├── zabbix-iptables ├── Template-iptables.xml ├── iptables.conf └── iptables.sh ├── zabbix-police ├── allpolice.py ├── dbread.py ├── operation.py └── weixin.py └── zabbix-weixin └── weixinnew.py /zabbix-DiskIO/Template_Linux_Disk_IO_Stats.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 3.0 4 | 2016-12-20T02:56:56Z 5 | 6 | 7 | Template-Hardware 8 | 9 | 10 | 11 | 474 | 475 | 476 | -------------------------------------------------------------------------------- /zabbix-DiskIO/discover_disk.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | sub get_vmname_by_id 4 | { 5 | $vmname=`cat /etc/qemu-server/$_[0].conf | grep name | cut -d \: -f 2`; 6 | $vmname =~ s/^\s+//; #remove leading spaces 7 | $vmname =~ s/\s+$//; #remove trailing spaces 8 | return $vmname 9 | } 10 | 11 | $first = 1; 12 | print "{\n"; 13 | print "\t\"data\":[\n\n"; 14 | 15 | for (`cat /proc/diskstats`) 16 | { 17 | ($major,$minor,$disk) = m/^\s*([0-9]+)\s+([0-9]+)\s+(\S+)\s.*$/; 18 | $dmnamefile = "/sys/dev/block/$major:$minor/dm/name"; 19 | $vmid= ""; 20 | $vmname = ""; 21 | $dmname = $disk; 22 | $diskdev = "/dev/$disk"; 23 | # DM name 24 | if (-e $dmnamefile) { 25 | $dmname = `cat $dmnamefile`; 26 | $dmname =~ s/\n$//; #remove trailing \n 27 | $diskdev = "/dev/mapper/$dmname"; 28 | # VM name and ID 29 | if ($dmname =~ m/^.*--([0-9]+)--.*$/) { 30 | $vmid = $1; 31 | #$vmname = get_vmname_by_id($vmid); 32 | } 33 | } 34 | #print("$major $minor $disk $diskdev $dmname $vmid $vmname \n"); 35 | 36 | print "\t,\n" if not $first; 37 | $first = 0; 38 | 39 | print "\t{\n"; 40 | print "\t\t\"{#DISK}\":\"$disk\",\n"; 41 | print "\t\t\"{#DISKDEV}\":\"$diskdev\",\n"; 42 | print "\t\t\"{#DMNAME}\":\"$dmname\",\n"; 43 | print "\t\t\"{#VMNAME}\":\"$vmname\",\n"; 44 | print "\t\t\"{#VMID}\":\"$vmid\"\n"; 45 | print "\t}\n"; 46 | } 47 | 48 | print "\n\t]\n"; 49 | print "}\n"; 50 | 51 | 52 | -------------------------------------------------------------------------------- /zabbix-DiskIO/zabbix_io_stats: -------------------------------------------------------------------------------- 1 | # diskio discovery 2 | UserParameter=discovery.disks.iostats,/usr/local/zabbix/scripts/discover_disk.pl 3 | #读扇区的次数 4 | UserParameter=custom.vfs.dev.read.sectors[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$6}' 5 | #写扇区次数 6 | UserParameter=custom.vfs.dev.write.sectors[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$10}' 7 | #合并读完成次数 8 | UserParameter=custom.vfs.dev.read.ops[*],cat /proc/diskstats | grep $1 | head -1 |awk '{print $$4}' 9 | #合并写完成次数 10 | UserParameter=custom.vfs.dev.write.ops[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$8}' 11 | #读花费的毫秒数 12 | UserParameter=custom.vfs.dev.read.ms[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$7}' 13 | #写操作花费的毫秒数 14 | UserParameter=custom.vfs.dev.write.ms[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$11}' -------------------------------------------------------------------------------- /zabbix-Hardware/Hardware-Check(2.4.6).xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 2.0 4 | 2016-12-19T07:36:19Z 5 | 6 | 7 | Template-Hardware 8 | 9 | 10 | 11 | 247 | 248 | 249 | 250 | 服务器硬件状态监控(0-不正常,1-正常) 251 | 900 252 | 200 253 | 0.0000 254 | 100.0000 255 | 1 256 | 1 257 | 0 258 | 1 259 | 0 260 | 0.0000 261 | 0.0000 262 | 0 263 | 0 264 | 0 265 | 0 266 | 267 | 268 | 0 269 | 0 270 | 00C800 271 | 0 272 | 2 273 | 0 274 | 275 | Hardware-Check 276 | hardware_cpu 277 | 278 | 279 | 280 | 1 281 | 0 282 | C80000 283 | 0 284 | 2 285 | 0 286 | 287 | Hardware-Check 288 | hardware_virtual_health 289 | 290 | 291 | 292 | 3 293 | 0 294 | C800C8 295 | 0 296 | 2 297 | 0 298 | 299 | Hardware-Check 300 | hardware_memory_health 301 | 302 | 303 | 304 | 5 305 | 0 306 | C8C800 307 | 0 308 | 2 309 | 0 310 | 311 | Hardware-Check 312 | hardware_physics_health 313 | 314 | 315 | 316 | 7 317 | 0 318 | 009600 319 | 0 320 | 2 321 | 0 322 | 323 | Hardware-Check 324 | hardware_nic_health 325 | 326 | 327 | 328 | 329 | 330 | 331 | -------------------------------------------------------------------------------- /zabbix-Hardware/Hardware-Check(3.0.4).xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 3.0 4 | 2016-12-19T07:33:47Z 5 | 6 | 7 | Template-Hardware 8 | 9 | 10 | 11 | 247 | 248 | 249 | 250 | 服务器硬件状态监控(0-不正常,1-正常) 251 | 900 252 | 200 253 | 0.0000 254 | 100.0000 255 | 1 256 | 1 257 | 0 258 | 1 259 | 0 260 | 0.0000 261 | 0.0000 262 | 0 263 | 0 264 | 0 265 | 0 266 | 267 | 268 | 0 269 | 0 270 | 00C800 271 | 0 272 | 2 273 | 0 274 | 275 | Hardware-Check 276 | hardware_cpu 277 | 278 | 279 | 280 | 1 281 | 0 282 | C80000 283 | 0 284 | 2 285 | 0 286 | 287 | Hardware-Check 288 | hardware_virtual_health 289 | 290 | 291 | 292 | 3 293 | 0 294 | C800C8 295 | 0 296 | 2 297 | 0 298 | 299 | Hardware-Check 300 | hardware_memory_health 301 | 302 | 303 | 304 | 5 305 | 0 306 | C8C800 307 | 0 308 | 2 309 | 0 310 | 311 | Hardware-Check 312 | hardware_physics_health 313 | 314 | 315 | 316 | 7 317 | 0 318 | 009600 319 | 0 320 | 2 321 | 0 322 | 323 | Hardware-Check 324 | hardware_nic_health 325 | 326 | 327 | 328 | 329 | 330 | 331 | -------------------------------------------------------------------------------- /zabbix-Screens/zabbix_screen_group.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import urllib2 3 | import sys 4 | import json 5 | import argparse 6 | 7 | #定义通过HTTP方式访问API地址的函数,后面每次请求API的各个方法都会调用这个函数 8 | def requestJson(url,values): 9 | data = json.dumps(values) 10 | req = urllib2.Request(url, data, {'Content-Type': 'application/json-rpc'}) 11 | response = urllib2.urlopen(req, data) 12 | output = json.loads(response.read()) 13 | # print output 14 | try: 15 | message = output['result'] 16 | except: 17 | message = output['error']['data'] 18 | print message 19 | quit() 20 | 21 | return output['result'] 22 | 23 | #API接口认证的函数,登录成功会返回一个Token 24 | def authenticate(url, username, password): 25 | values = {'jsonrpc': '2.0', 26 | 'method': 'user.login', 27 | 'params': { 28 | 'user': username, 29 | 'password': password 30 | }, 31 | 'id': '0' 32 | } 33 | idvalue = requestJson(url,values) 34 | return idvalue 35 | 36 | #定义更加主机分组名称获取各个hostid的函数 37 | def getHosts(groupname,url,auth): 38 | host_list = [] 39 | values = {'jsonrpc': '2.0', 40 | 'method': 'hostgroup.get', 41 | 'params': { 42 | 'output': 'extend', 43 | 'filter': { 44 | 'name': groupname 45 | }, 46 | 47 | 'selectHosts' : ['hostid','host'], 48 | }, 49 | 'auth': auth, 50 | 'id': '2' 51 | } 52 | output = requestJson(url,values) 53 | for host in output[0]['hosts']: 54 | host_list.append(host['hostid']) 55 | return host_list 56 | 57 | #定义获取graphid的函数 58 | def getGraphs(host_list,name_list, url, auth, columns, graphtype=0 ,dynamic=0): 59 | if (graphtype == 0): 60 | selecttype = ['graphid'] 61 | select = 'selectGraphs' 62 | if (graphtype == 1): 63 | selecttype = ['itemid', 'value_type'] 64 | select = 'selectItems' 65 | values=({'jsonrpc' : '2.0', 66 | 'method' : 'graph.get', 67 | 'params' : { 68 | 'output' : ['graphid','name'], 69 | select : [selecttype,'name'], 70 | 'hostids' : host_list, 71 | 'sortfield' : 'name', 72 | 'filter' : { 73 | 'name' : name_list, 74 | 75 | }, 76 | }, 77 | 'auth' : auth, 78 | 'id' : 3 79 | }) 80 | output = requestJson(url,values) 81 | bb = sorted(output,key = lambda x:x['graphid']) 82 | graphs = [] 83 | if (graphtype == 0): 84 | for i in bb: 85 | print i 86 | graphs.append(i['graphid']) 87 | if (graphtype == 1): 88 | for i in bb: 89 | if int(i['value_type']) in (0, 3): 90 | graphs.append(i['itemid']) 91 | 92 | graph_list = [] 93 | x = 0 94 | y = 0 95 | for graph in graphs: 96 | print "x is " + str(x) 97 | print "y is " + str(y) 98 | graph_list.append({ 99 | "resourcetype": graphtype, 100 | "resourceid": graph, 101 | "width": "500", 102 | "height": "100", 103 | "x": str(x), 104 | "y": str(y), 105 | "colspan": "1", 106 | "rowspan": "1", 107 | "elements": "0", 108 | "valign": "0", 109 | "halign": "0", 110 | "style": "0", 111 | "url": "", 112 | "dynamic": str(dynamic) 113 | }) 114 | x += 1 115 | # print type(x) 116 | # print type(columns) 117 | if x == int(columns): 118 | x = 0 119 | y += 1 120 | # print graph_list 121 | return graph_list 122 | 123 | #定义创建screen的函数 124 | def screenCreate(url, auth, screen_name, graphids, columns): 125 | columns = int(columns) 126 | if len(graphids) % columns == 0: 127 | vsize = len(graphids) / columns 128 | else: 129 | vsize = (len(graphids) / columns) + 1 130 | 131 | #先使用screen.get判断给定的screen name是否存在 132 | values0 = { 133 | "jsonrpc" : "2.0", 134 | "method" : "screen.get", 135 | "params" : { 136 | "output" : "extend", 137 | "filter" : { 138 | "name" : screen_name, 139 | } 140 | }, 141 | "auth" : auth, 142 | "id" : 2 143 | } 144 | values = { 145 | "jsonrpc": "2.0", 146 | "method": "screen.create", 147 | "params": { 148 | "name": screen_name, 149 | "hsize": columns, 150 | "vsize": vsize, 151 | "screenitems": [] 152 | }, 153 | "auth": auth, 154 | "id": 2 155 | } 156 | output0 = requestJson(url,values0) 157 | print output0 158 | 159 | #如果给定的screen name不存在则直接创建screen 160 | if output0 == []: 161 | print "The Given Screen Name Not Exists" 162 | print "Creating Screen %s" %screen_name 163 | for i in graphids: 164 | values['params']['screenitems'].append(i) 165 | output = requestJson(url,values) 166 | else: 167 | 168 | 169 | #如果给定的screen name已经存在,直接创建screen是不行的, 170 | #要么先使用screen.delete把原来的screen删除掉,然后再创建, 171 | #要么直接使用screen.update更新原来那个screen, 172 | #使用screen.delete会产生新的screenid, 173 | #使用screen.update比较合理一点。 174 | print "The Given Screen Name Already Exists" 175 | update_screenid=output0[0]["screenid"] 176 | print update_screenid 177 | print "Updating Screen Name %s Screen ID %s" %(screen_name,update_screenid) 178 | values1 = { 179 | "jsonrpc" : "2.0", 180 | "method" : "screen.update", 181 | "params" : { 182 | "screenid" : update_screenid, 183 | "screenitems": [] 184 | }, 185 | "auth" : auth, 186 | "id" : 2 187 | } 188 | output1 = requestJson(url,values1) 189 | print output1 190 | print "Updating Screen Name %s" %screen_name 191 | for i in graphids: 192 | values1['params']['screenitems'].append(i) 193 | output = requestJson(url,values1) 194 | 195 | def main(): 196 | url = 'http://zabbixip/zabbix/api_jsonrpc.php' 197 | username = '****' 198 | password = '****' 199 | auth = authenticate(url, username, password) 200 | host_list = getHosts(groupname,url,auth) 201 | print host_list 202 | graph_ids = getGraphs(host_list,graphname, url, auth, columns) 203 | screenCreate(url, auth, screenname, graph_ids, columns) 204 | if __name__ == '__main__': 205 | parser = argparse.ArgumentParser(description='Create Zabbix screen from all of a host Items or Graphs.') 206 | parser.add_argument('-G', dest='graphname', nargs='+',metavar=('grah name'), 207 | help='Zabbix Host Graph to create screen from') 208 | parser.add_argument('-H', dest='hostname', nargs='+',metavar=('10.19.111.145'), 209 | help='Zabbix Host to create screen from') 210 | parser.add_argument('-g', dest='groupname', nargs='+',metavar=('linux server'), 211 | help='Zabbix Group to create screen from') 212 | parser.add_argument('-n', dest='screenname', type=str, 213 | help='Screen name in Zabbix. Put quotes around it if you want spaces in the name.') 214 | parser.add_argument('-c', dest='columns', type=int, 215 | help='number of columns in the screen') 216 | args = parser.parse_args() 217 | print args 218 | hostname = args.hostname 219 | groupname = args.groupname 220 | screenname = args.screenname 221 | columns = args.columns 222 | graphname = args.graphname 223 | if columns is None: 224 | columns = len(graphname) 225 | # print columns 226 | main() -------------------------------------------------------------------------------- /zabbix-Screens/zabbix_screen_host.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | #zabbix_screen_host.py 3 | import urllib2 4 | import json 5 | import argparse 6 | def authenticate(url, username, password): 7 | values = {'jsonrpc': '2.0', 8 | 'method': 'user.login', 9 | 'params': { 10 | 'user': username, 11 | 'password': password 12 | }, 13 | 'id': '0' 14 | } 15 | data = json.dumps(values) 16 | req = urllib2.Request(url, data, {'Content-Type': 'application/json-rpc'}) 17 | response = urllib2.urlopen(req, data) 18 | output = json.loads(response.read()) 19 | try: 20 | message = output['result'] 21 | except: 22 | message = output['error']['data'] 23 | print message 24 | quit() 25 | return output['result'] 26 | def getGraph(hostname, url, auth, graphtype, dynamic, columns): 27 | if (graphtype == 0): 28 | selecttype = ['graphid'] 29 | select = 'selectGraphs' 30 | if (graphtype == 1): 31 | selecttype = ['itemid', 'value_type'] 32 | select = 'selectItems' 33 | values = {'jsonrpc': '2.0', 34 | 'method': 'host.get', 35 | 'params': { 36 | select: selecttype, 37 | 'output': ['hostid', 'host'], 38 | 'searchByAny': 1, 39 | 'filter': { 40 | 'host': hostname 41 | } 42 | }, 43 | 'auth': auth, 44 | 'id': '2' 45 | } 46 | data = json.dumps(values) 47 | req = urllib2.Request(url, data, {'Content-Type': 'application/json-rpc'}) 48 | response = urllib2.urlopen(req, data) 49 | host_get = response.read() 50 | output = json.loads(host_get) 51 | # print json.dumps(output) 52 | graphs = [] 53 | if (graphtype == 0): 54 | for i in output['result'][0]['graphs']: 55 | graphs.append(i['graphid']) 56 | if (graphtype == 1): 57 | for i in output['result'][0]['items']: 58 | if int(i['value_type']) in (0, 3): 59 | graphs.append(i['itemid']) 60 | graph_list = [] 61 | x = 0 62 | y = 0 63 | for graph in graphs: 64 | graph_list.append({ 65 | "resourcetype": graphtype, 66 | "resourceid": graph, 67 | "width": "500", 68 | "height": "100", 69 | "x": str(x), 70 | "y": str(y), 71 | "colspan": "1", 72 | "rowspan": "1", 73 | "elements": "0", 74 | "valign": "0", 75 | "halign": "0", 76 | "style": "0", 77 | "url": "", 78 | "dynamic": str(dynamic) 79 | }) 80 | x += 1 81 | if x == columns: 82 | x = 0 83 | y += 1 84 | return graph_list 85 | def screenCreate(url, auth, screen_name, graphids, columns): 86 | # print graphids 87 | if len(graphids) % columns == 0: 88 | vsize = len(graphids) / columns 89 | else: 90 | vsize = (len(graphids) / columns) + 1 91 | values = {"jsonrpc": "2.0", 92 | "method": "screen.create", 93 | "params": [{ 94 | "name": screen_name, 95 | "hsize": columns, 96 | "vsize": vsize, 97 | "screenitems": [] 98 | }], 99 | "auth": auth, 100 | "id": 2 101 | } 102 | for i in graphids: 103 | values['params'][0]['screenitems'].append(i) 104 | data = json.dumps(values) 105 | req = urllib2.Request(url, data, {'Content-Type': 'application/json-rpc'}) 106 | response = urllib2.urlopen(req, data) 107 | host_get = response.read() 108 | output = json.loads(host_get) 109 | try: 110 | message = output['result'] 111 | except: 112 | message = output['error']['data'] 113 | print json.dumps(message) 114 | 115 | def main(): 116 | url = 'http://zabbixip/zabbix/api_jsonrpc.php' 117 | username = "***" 118 | password = "***" 119 | parser = argparse.ArgumentParser(description='Create Zabbix screen from all of a host Items or Graphs.') 120 | parser.add_argument('hostname', metavar='H', type=str, 121 | help='Zabbix Host to create screen from') 122 | parser.add_argument('screenname', metavar='N', type=str, 123 | help='Screen name in Zabbix. Put quotes around it if you want spaces in the name.') 124 | parser.add_argument('-c', dest='columns', type=int, default=3, 125 | help='number of columns in the screen (default: 3)') 126 | parser.add_argument('-d', dest='dynamic', action='store_true', 127 | help='enable for dynamic screen items (default: disabled)') 128 | parser.add_argument('-t', dest='screentype', action='store_true', 129 | help='set to 1 if you want item simple graphs created (default: 0, regular graphs)') 130 | args = parser.parse_args() 131 | hostname = args.hostname 132 | screen_name = args.screenname 133 | columns = args.columns 134 | dynamic = (1 if args.dynamic else 0) 135 | screentype = (1 if args.screentype else 0) 136 | auth = authenticate(url, username, password) 137 | graphids = getGraph(hostname, url, auth, screentype, dynamic, columns) 138 | print "Screen Name: " + screen_name 139 | print "Total Number of Graphs: " + str(len(graphids)) 140 | screenCreate(url, auth, screen_name, graphids, columns) 141 | if __name__ == '__main__': 142 | main() -------------------------------------------------------------------------------- /zabbix-Win/zabbix/bin/win32/dev/zabbix_sender.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JPOPS/Monitor/6bf1623919e0d84edd1dbe799b5d36e9cbf70a24/zabbix-Win/zabbix/bin/win32/dev/zabbix_sender.dll -------------------------------------------------------------------------------- /zabbix-Win/zabbix/bin/win32/dev/zabbix_sender.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JPOPS/Monitor/6bf1623919e0d84edd1dbe799b5d36e9cbf70a24/zabbix-Win/zabbix/bin/win32/dev/zabbix_sender.lib -------------------------------------------------------------------------------- /zabbix-Win/zabbix/bin/win32/zabbix_agentd.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JPOPS/Monitor/6bf1623919e0d84edd1dbe799b5d36e9cbf70a24/zabbix-Win/zabbix/bin/win32/zabbix_agentd.exe -------------------------------------------------------------------------------- /zabbix-Win/zabbix/bin/win32/zabbix_get.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JPOPS/Monitor/6bf1623919e0d84edd1dbe799b5d36e9cbf70a24/zabbix-Win/zabbix/bin/win32/zabbix_get.exe -------------------------------------------------------------------------------- /zabbix-Win/zabbix/bin/win32/zabbix_sender.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JPOPS/Monitor/6bf1623919e0d84edd1dbe799b5d36e9cbf70a24/zabbix-Win/zabbix/bin/win32/zabbix_sender.exe -------------------------------------------------------------------------------- /zabbix-Win/zabbix/bin/win64/dev/zabbix_sender.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JPOPS/Monitor/6bf1623919e0d84edd1dbe799b5d36e9cbf70a24/zabbix-Win/zabbix/bin/win64/dev/zabbix_sender.dll -------------------------------------------------------------------------------- /zabbix-Win/zabbix/bin/win64/dev/zabbix_sender.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JPOPS/Monitor/6bf1623919e0d84edd1dbe799b5d36e9cbf70a24/zabbix-Win/zabbix/bin/win64/dev/zabbix_sender.lib -------------------------------------------------------------------------------- /zabbix-Win/zabbix/bin/win64/zabbix_agentd.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JPOPS/Monitor/6bf1623919e0d84edd1dbe799b5d36e9cbf70a24/zabbix-Win/zabbix/bin/win64/zabbix_agentd.exe -------------------------------------------------------------------------------- /zabbix-Win/zabbix/bin/win64/zabbix_get.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JPOPS/Monitor/6bf1623919e0d84edd1dbe799b5d36e9cbf70a24/zabbix-Win/zabbix/bin/win64/zabbix_get.exe -------------------------------------------------------------------------------- /zabbix-Win/zabbix/bin/win64/zabbix_sender.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JPOPS/Monitor/6bf1623919e0d84edd1dbe799b5d36e9cbf70a24/zabbix-Win/zabbix/bin/win64/zabbix_sender.exe -------------------------------------------------------------------------------- /zabbix-Win/zabbix/conf/zabbix_agentd.win.conf: -------------------------------------------------------------------------------- 1 | LogFile=c:\zabbix\zabbix_agentd.log 2 | Server=****** 3 | Hostname=Windows host -------------------------------------------------------------------------------- /zabbix-Win/zabbix/监控安装.bat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JPOPS/Monitor/6bf1623919e0d84edd1dbe799b5d36e9cbf70a24/zabbix-Win/zabbix/监控安装.bat -------------------------------------------------------------------------------- /zabbix-disk/disk.conf: -------------------------------------------------------------------------------- 1 | UserParameter=disk.health.check,/usr/bin/python /usr/local/zabbix/scripts/disk_health_check.py -------------------------------------------------------------------------------- /zabbix-disk/disk_health_check.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | #磁盘只读检测脚本正常0,异常1 3 | #jipeng 2016/3/26 4 | import time 5 | try: 6 | fileDisk = open ( '/usr/local/zabbix/scripts/disk_health_check.log', 'w' ) 7 | old = str(time.time()) 8 | fileDisk.write(old) 9 | fileDisk = open ( '/usr/local/zabbix/scripts/disk_health_check.log' ) 10 | new=fileDisk.read() 11 | if (old==new): 12 | print '0' 13 | else: 14 | print '1' 15 | fileDisk.close() 16 | except: 17 | print '1' -------------------------------------------------------------------------------- /zabbix-disk/zbx_disk_templates.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 3.0 4 | 2016-11-18T05:15:07Z 5 | 6 | 7 | Template-Hardware 8 | 9 | 10 | 11 | 75 | 76 | 77 | 78 | {DiskHealth-Check:disk.health.check.count(#2,1,"eq")}>1 79 | DiskHealthCheck 80 | 81 | 0 82 | 2 83 | 2次内触发器等于1的次数大于1(等于2)次就会告警 84 | 判断两次都异常即告警 85 | 0 86 | 87 | 88 | 89 | 90 | 91 | 磁盘健康检查 92 | 900 93 | 200 94 | 0.0000 95 | 100.0000 96 | 1 97 | 1 98 | 0 99 | 1 100 | 0 101 | 0.0000 102 | 0.0000 103 | 0 104 | 0 105 | 0 106 | 0 107 | 108 | 109 | 0 110 | 3 111 | 00C800 112 | 0 113 | 7 114 | 0 115 | 116 | DiskHealth-Check 117 | disk.health.check 118 | 119 | 120 | 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /zabbix-iptables/Template-iptables.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 3.0 4 | 2016-11-18T09:27:03Z 5 | 6 | 7 | Template-Security 8 | 9 | 10 | 11 | 376 | 377 | 378 | 379 | {Template-iptables:iptstate[all].last()}<3 380 | iptables not running 381 | 382 | 0 383 | 2 384 | iptstates条目小于3认为关闭或者异常状态 385 | 0 386 | 387 | 388 | 389 | 390 | 391 | iptstate 392 | 900 393 | 200 394 | 0.0000 395 | 100.0000 396 | 1 397 | 1 398 | 0 399 | 1 400 | 0 401 | 0.0000 402 | 0.0000 403 | 0 404 | 0 405 | 0 406 | 0 407 | 408 | 409 | 0 410 | 0 411 | 00C800 412 | 0 413 | 2 414 | 0 415 | 416 | Template-iptables 417 | iptstate[tcp-close] 418 | 419 | 420 | 421 | 1 422 | 0 423 | C80000 424 | 0 425 | 2 426 | 0 427 | 428 | Template-iptables 429 | iptstate[tcp-established] 430 | 431 | 432 | 433 | 2 434 | 0 435 | 0000C8 436 | 0 437 | 2 438 | 0 439 | 440 | Template-iptables 441 | iptstate[tcp-syn] 442 | 443 | 444 | 445 | 3 446 | 0 447 | C800C8 448 | 0 449 | 2 450 | 0 451 | 452 | Template-iptables 453 | iptstate[tcp-timewait] 454 | 455 | 456 | 457 | 4 458 | 0 459 | 00C8C8 460 | 0 461 | 2 462 | 0 463 | 464 | Template-iptables 465 | iptstate[all] 466 | 467 | 468 | 469 | 5 470 | 0 471 | C8C800 472 | 0 473 | 2 474 | 0 475 | 476 | Template-iptables 477 | iptstate[icmp] 478 | 479 | 480 | 481 | 6 482 | 0 483 | C8C8C8 484 | 0 485 | 2 486 | 0 487 | 488 | Template-iptables 489 | iptstate[tcp] 490 | 491 | 492 | 493 | 7 494 | 0 495 | 009600 496 | 0 497 | 2 498 | 0 499 | 500 | Template-iptables 501 | iptstate[udp] 502 | 503 | 504 | 505 | 506 | 507 | 508 | -------------------------------------------------------------------------------- /zabbix-iptables/iptables.conf: -------------------------------------------------------------------------------- 1 | UserParameter=iptstate[*],/usr/local/zabbix/scripts/iptables.sh $1 2 | -------------------------------------------------------------------------------- /zabbix-iptables/iptables.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #iptables 监控脚本 3 | #2017-03-30 4 | function tcp { 5 | sudo iptstate --single | grep tcp | wc -l 6 | } 7 | function tcp-syn { 8 | sudo iptstate --single | grep SYN | wc -l 9 | } 10 | function tcp-timewait { 11 | sudo iptstate --single | grep TIME_WAIT | wc -l 12 | } 13 | function tcp-established { 14 | sudo iptstate --single | grep ESTABLISHED | wc -l 15 | } 16 | function tcp-close { 17 | sudo iptstate --single | grep CLOSE | wc -l 18 | } 19 | function udp { 20 | sudo iptstate --single | grep udp | wc -l 21 | } 22 | function icmp { 23 | sudo iptstate --single | grep icmp | wc -l 24 | } 25 | function all { 26 | sudo iptstate --single | wc -l 27 | } 28 | $1 29 | -------------------------------------------------------------------------------- /zabbix-police/allpolice.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | #coding:utf-8 3 | import MySQLdb 4 | import redis 5 | import sys 6 | from dbread import * 7 | from operation import * 8 | from weixin import * 9 | import datetime,time 10 | sendtime=time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(time.time())) 11 | accesstoken = gettoken() 12 | #发送微信给运维人员 13 | users=['*****'] 14 | #在zabbix 可以找到告警收敛的动作ID(actionid) 15 | actionid=***** 16 | #连接redis,并读取所有事件id 17 | r = redis.StrictRedis(host='*****', port=6379) 18 | 19 | 20 | subjectlist=r.keys() 21 | for i in subjectlist: 22 | r.delete(i) 23 | #r.flushdb() 24 | #获取原始数据并存入数据库 25 | originallist=[] 26 | for subject in subjectlist: 27 | a=alerts_eventid(str(actionid),subject) 28 | originallist.append(a) 29 | problem=mergeproblem(originallist) 30 | normal=mergenormal(originallist) 31 | #发送告警信息 32 | messagelist=compressproblem(problem) 33 | if len(messagelist) != 0: 34 | for content in messagelist: 35 | print sendtime 36 | for user in users: 37 | senddata(accesstoken,user,content) 38 | #发送恢复信息 39 | messagelist=compressnormal(normal) 40 | if len(messagelist) != 0: 41 | for content in messagelist: 42 | print sendtime 43 | for user in users: 44 | senddata(accesstoken,user,content) -------------------------------------------------------------------------------- /zabbix-police/dbread.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | #coding:utf-8 3 | #脚本中*****需要修改的地方 4 | import MySQLdb 5 | import datetime,time 6 | import sys 7 | #定义通过actionid和subject获取数据库告警具体信息,并以字典形式返回 8 | def alerts_eventid(actionid,subject): 9 | try: 10 | conn=MySQLdb.connect(host='*****',user=*****',passwd='******',db='*****',port=3306) 11 | #host:zabbix数据库ip 12 | #user:zabbix数据库用户 13 | #passwd:zabbix数据库密码 14 | #db:zabbix数据库名称 15 | cursor = conn.cursor() 16 | cursor.execute("SET NAMES utf8"); 17 | sql = "SELECT * FROM alerts where actionid = '%s' and subject = '%s' ;" % (actionid,subject) 18 | cursor.execute(sql) 19 | data = cursor.fetchall() 20 | cursor.close() 21 | conn.close() 22 | event=data[0] 23 | messagelist=[] 24 | message=event[8] 25 | messageone=message.split('#') 26 | for i in messageone: 27 | messagelist.append(i.split('|')) 28 | print messagelist 29 | messagedict=dict(messagelist) 30 | return messagedict 31 | except MySQLdb.Error,e: 32 | print "Mysql Error %d: %s" % (e.args[0], e.args[1]) -------------------------------------------------------------------------------- /zabbix-police/operation.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | #coding:utf-8 3 | import datetime,time 4 | #告警合并 5 | def mergeproblem(originallist): 6 | problemlist=[] 7 | normalist=[] 8 | Unknown=[] 9 | triggerkeylist=[] 10 | sorts=[] 11 | alarminfo=[] 12 | #告警or恢复 13 | for origina in originallist: 14 | 15 | if origina['triggervalue']=='1' : 16 | problemlist.append(origina) 17 | if origina['triggerkey'] not in triggerkeylist: 18 | triggerkeylist.append(origina['triggerkey']) 19 | else : 20 | Unknown.append(origina) 21 | 22 | for triggerkey in triggerkeylist: 23 | for problem in problemlist: 24 | if problem['triggerkey']==triggerkey: 25 | sorts.append(problem) 26 | alarminfo.append(sorts) 27 | sorts=[] 28 | return alarminfo 29 | #恢复合并 30 | def mergenormal(originallist): 31 | normallist=[] 32 | Unknown=[] 33 | triggerkeylist=[] 34 | sorts=[] 35 | alarminfo=[] 36 | #告警or恢复 37 | for origina in originallist: 38 | 39 | if origina['triggervalue']=='0' : 40 | normallist.append(origina) 41 | if origina['triggerkey'] not in triggerkeylist: 42 | triggerkeylist.append(origina['triggerkey']) 43 | else : 44 | Unknown.append(origina) 45 | 46 | for triggerkey in triggerkeylist: 47 | for normal in normallist: 48 | if normal['triggerkey']==triggerkey: 49 | sorts.append(normal) 50 | alarminfo.append(sorts) 51 | sorts=[] 52 | return alarminfo 53 | 54 | #告警压缩 55 | def compressproblem(alarminfo): 56 | currenttime=time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(time.time())) 57 | messagelist=[] 58 | for info in alarminfo: 59 | hostlist='' 60 | hostgroup='' 61 | infonum=len(info) 62 | for host in info: 63 | triggername=host['triggername'] 64 | hostinfo=host['hostname']+':'+host['ipaddress']+'\n' 65 | if host['hostgroup'] not in hostgroup: 66 | hostgroup+=host['hostgroup']+'\n' 67 | hostlist+=hostinfo 68 | if infonum >= 3 and infonum <= 6: 69 | message='告警◕﹏◕\n'+'告警主机:'+str(infonum)+'台\n'+hostlist+'涉及主机组:\n'+hostgroup+'告警项目:\n'+triggername+'\n'+'分析时间:\n'+currenttime 70 | messagelist.append(message) 71 | elif infonum > 6: 72 | message='告警◕﹏◕\n'+'当前存在大量相同告警项,可能发生网络故障!\n详情请查看云警系统!\n'+'告警主机:'+str(infonum)+'台\n'+'告警项目:\n'+triggername+'\n'+'分析时间:\n'+currenttime 73 | messagelist.append(message) 74 | return messagelist 75 | 76 | 77 | #恢复压缩 78 | def compressnormal(alarminfo): 79 | currenttime=time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(time.time())) 80 | messagelist=[] 81 | for info in alarminfo: 82 | hostlist='' 83 | hostgroup='' 84 | infonum=len(info) 85 | for host in info: 86 | triggername=host['triggername'] 87 | hostinfo=host['hostname']+':'+host['ipaddress']+'\n' 88 | if host['hostgroup'] not in hostgroup: 89 | hostgroup+=host['hostgroup']+'\n' 90 | hostlist+=hostinfo 91 | if infonum >= 3 and infonum <= 6: 92 | message='恢复◕‿◕\n'+'恢复主机:'+str(infonum)+'台\n'+hostlist+'涉及主机组:\n'+hostgroup+'恢复项目:\n'+triggername+'\n'+'分析时间:\n'+currenttime 93 | messagelist.append(message) 94 | elif infonum > 6: 95 | message='恢复◕‿◕\n'+'大量主机已经恢复!\n详情请查看监控系统!\n'+'恢复主机:'+str(infonum)+'台\n'+'恢复项目:\n'+triggername+'\n'+'分析时间:\n'+currenttime 96 | messagelist.append(message) 97 | return messagelist -------------------------------------------------------------------------------- /zabbix-police/weixin.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # coding: utf-8 3 | #jipeng 2016.8.11 4 | #python2将zabbix报警信息发送到微信。 5 | #脚本中*****需要修改的地方 6 | import urllib,urllib2 7 | import json 8 | import sys 9 | def gettoken(): 10 | CropID='*****' 11 | Secret='*****' 12 | GURL="https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid="+CropID+"&corpsecret="+Secret 13 | token_file = urllib2.urlopen(GURL) 14 | token_data = token_file.read().decode('utf-8') 15 | token_json = json.loads(token_data) 16 | token_json.keys() 17 | token = token_json['access_token'] 18 | return token 19 | def senddata(access_token,user,content): 20 | PURL="https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token="+access_token 21 | send_values = { 22 | "touser":user, #企业号中的用户帐号,在zabbix用户Media中配置,如果配置不正常,将按部门发送。 23 | #"toparty":"2", #企业号中的部门id 24 | "msgtype":"text", #消息类型 25 | "agentid":"*****", #填写企业号中的应用id, 26 | "text":{ 27 | "content":content 28 | }, 29 | "safe":"0" 30 | } 31 | send_data = json.dumps(send_values, ensure_ascii=False) 32 | send_request = urllib2.Request(PURL, send_data) 33 | response = json.loads(urllib2.urlopen(send_request).read()) 34 | print str(response) 35 | 36 | if __name__ == '__main__': 37 | user = str(sys.argv[1]) #zabbix传过来的第一个参数 38 | content = str(sys.argv[3]) #zabbix传过来的第三个参数 39 | accesstoken = gettoken() 40 | senddata(accesstoken,user,content) -------------------------------------------------------------------------------- /zabbix-weixin/weixinnew.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # coding: utf-8 3 | #jipeng 2017.3.15 4 | #python2将zabbix报警信息发送到微信。 5 | import urllib,urllib2 6 | import json 7 | import sys 8 | import datetime,time 9 | import os 10 | import argparse 11 | import requests 12 | import re 13 | default_encoding = 'utf-8' 14 | if sys.getdefaultencoding() != default_encoding: 15 | reload(sys) 16 | sys.setdefaultencoding(default_encoding) 17 | ###################################### 18 | #可以访问到zabbix页面的URL 19 | URL = 'http://**.**.**.**/zabbix/api_jsonrpc.php' 20 | ZABBIX_URL='http://**.**.**.**/zabbix/index.php' 21 | CHART_URL='http://**.**.**.**/zabbix/chart.php' 22 | #登录zabbix的账号密码 23 | USERNAME='*****' 24 | PASSWORD='*****' 25 | #放cookie的路径 26 | COOKIEURL='*****/cookie' 27 | #方式图片的路径 28 | PIC_PATH ='/*****/image/' 29 | 30 | #微信企业号 31 | corpsecret ="*****" 32 | corpid = "*****" 33 | #配置应用id 34 | appid='*' 35 | ###################################### 36 | 37 | 38 | #获取上传图片至微信服务器返回的id 39 | def getMediaId(ip,key,auth,USERNAME,PASSWORD,COOKIEURL,ZABBIX_URL,PIC_PATH,CHART_URL,corpsecret,corpid): 40 | 41 | ###写入cookie文件 42 | curlcookie='curl -c %s -b %s -d "name=%s&password=%s&autologin=1&enter=Sign+in" %s '% (COOKIEURL,COOKIEURL,USERNAME,PASSWORD,ZABBIX_URL) 43 | a=os.system(curlcookie) 44 | #通过ip获取hostid+graphname进而获取graphids 45 | hostids=ipgetHostsid(ip,URL,auth) 46 | hostid=int(hostids[0]['hostid']) 47 | itemids=getitemid(hostid,key,URL,auth) 48 | itemid=itemids[0]["itemid"] 49 | 50 | ###获取一小时前时间 51 | timedata=datetime.datetime.now()-datetime.timedelta(hours=1) 52 | stime=timedata.strftime("%Y%m%d%H%M%S") 53 | 54 | ##保存图片文件 55 | PIC_URL = "%sgraph.%s.png" % (PIC_PATH,stime) 56 | curlgraph='curl -b %s -d "itemids=%s&period=3600&time=%s&width=800" %s >%s'% (COOKIEURL,itemid,stime,CHART_URL,PIC_URL) 57 | b=os.system(curlgraph) 58 | 59 | ##上传图片 60 | tokenURL="https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=%s&corpsecret=%s" % (corpid,corpsecret) 61 | response = urllib2.urlopen(tokenURL) 62 | html = response.read() 63 | tokeninfo = json.loads(html) 64 | token = tokeninfo['access_token'] 65 | #获取id 66 | M_URL="https://qyapi.weixin.qq.com/cgi-bin/media/upload?access_token=%s&type=image" % token 67 | files={'image': open(PIC_URL, 'rb')} 68 | r =requests.post(M_URL, files=files) 69 | media_id=json.loads(r.content) 70 | return media_id["media_id"] 71 | 72 | #获取微信token 73 | def gettoken(corpsecret,corpid): 74 | tokenURL="https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=%s&corpsecret=%s" % (corpid,corpsecret) 75 | token_file = urllib2.urlopen(tokenURL) 76 | token_data = token_file.read().decode('utf-8') 77 | token_json = json.loads(token_data) 78 | token_json.keys() 79 | token = token_json['access_token'] 80 | return token 81 | 82 | #发送图文信息 83 | def senddata(access_token,user,appid,title,content,MEDIA_ID): 84 | PURL="https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token="+access_token 85 | send_values = { 86 | "touser":user, #接收人 87 | "msgtype":"mpnews", #消息类型图文。 88 | "agentid":appid, #微信企业应用id 89 | "mpnews": { 90 | "articles":[ 91 | { 92 | "title": title, 93 | "thumb_media_id": MEDIA_ID, 94 | "author": "zabbix", 95 | "content_source_url": "URL", 96 | "content":content, 97 | "digest": content, 98 | "show_cover_pic": "1" 99 | }, 100 | ] 101 | }, 102 | "safe":1 103 | } 104 | send_data = json.dumps(send_values, ensure_ascii=False) 105 | send_request = urllib2.Request(PURL, send_data) 106 | response = json.loads(urllib2.urlopen(send_request).read()) 107 | print str(response) 108 | 109 | #定义通过HTTP方式访问API地址的函数,后面每次请求API的各个方法都会调用这个函数 110 | def requestJson(URL,values): 111 | data = json.dumps(values) 112 | req = urllib2.Request(URL, data, {'Content-Type': 'application/json-rpc'}) 113 | response = urllib2.urlopen(req, data) 114 | output = json.loads(response.read()) 115 | try: 116 | message = output['result'] 117 | except: 118 | message = output['error']['data'] 119 | print message 120 | quit() 121 | 122 | return output['result'] 123 | 124 | #API接口认证的函数,登录成功会返回一个Token 125 | def authenticate(URL, USERNAME, PASSWORD): 126 | values = {'jsonrpc': '2.0', 127 | 'method': 'user.login', 128 | 'params': { 129 | 'user': USERNAME, 130 | 'password': PASSWORD 131 | }, 132 | 'id': '0' 133 | } 134 | idvalue = requestJson(URL,values) 135 | return idvalue 136 | 137 | #zabbix api通过ip获取主机id 138 | def ipgetHostsid(ip,URL,auth): 139 | values = {'jsonrpc': '2.0', 140 | 'method': 'host.get', 141 | 'params': { 142 | 'output': [ "host" ], 143 | 'filter': { 144 | 'ip': ip 145 | }, 146 | }, 147 | 'auth': auth, 148 | 'id': '3' 149 | } 150 | output = requestJson(URL,values) 151 | return output 152 | 153 | #zabbix api 通过hostid获取itemid的函数 154 | def getitemid(hostid,key,URL,auth): 155 | values = {'jsonrpc': '2.0', 156 | 'method': 'item.get', 157 | 'params': { 158 | "output": "itemid", 159 | "hostids": hostid, 160 | "search": { 161 | "key_": key 162 | }, 163 | "sortfield": "name", 164 | }, 165 | 'auth': auth, 166 | 'id': '21' 167 | } 168 | output = requestJson(URL,values) 169 | return output 170 | 171 | if __name__ == '__main__': 172 | auth = authenticate(URL, USERNAME, PASSWORD) 173 | user = 'jipeng' #微信企业号账号标识 174 | title = str(sys.argv[1]) #zabbix传过来的第一个参数-标题 175 | content = str(sys.argv[2]) #zabbix传过来的第二个参数-内容 176 | ip=re.findall(r"主机IP:(.+?)
",content)[0]#截取ip地址 177 | key=re.findall(r"告警项目:(.+?)
",content)[0]#截取zabbix key 178 | #获取图片id 179 | MEDIA_ID=getMediaId(ip,key,auth,USERNAME,PASSWORD,COOKIEURL,ZABBIX_URL,PIC_PATH,CHART_URL,corpsecret,corpid) 180 | #获取token 181 | accesstoken = gettoken(corpsecret,corpid) 182 | #发送图文 183 | senddata(accesstoken,user,appid,title,content,MEDIA_ID) 184 | 185 | --------------------------------------------------------------------------------