zabbix 监控ssl证书是否过期

简介:

cd /usr/lib/zabbix/externalscripts

#cat check_ssl

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#/bin/bash
host=$1
port=$2
end_date=`openssl s_client -host $host -port $port -showcerts </dev/ null  2>/dev/ null  |
           sed -n  '/BEGIN CERTIFICATE/,/END CERT/p'  |
       openssl x509 -text 2>/dev/ null  |
       sed -n  's/ *Not After : *//p' `
if  [ -n  "$end_date"  ]
then
     end_date_seconds=`date  '+%s'  --date  "$end_date" `
# date指令format字符串时间。
     now_seconds=`date  '+%s' `
     echo  "($end_date_seconds-$now_seconds)/24/3600"  | bc
fi

zabbix 界面配置如下

wKiom1nAjRfhHRFmAAPNQptYbCc027.png

check_rabbitmq_stats

cat check_rabbitmq_stats

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#/bin/bash
host=$1
port=$2
end_date=`openssl s_client -host $host -port $port -showcerts </dev/ null  2>/dev/ null  |
           sed -n  '/BEGIN CERTIFICATE/,/END CERT/p'  |
       openssl x509 -text 2>/dev/ null  |
       sed -n  's/ *Not After : *//p' `
if  [ -n  "$end_date"  ]
then
     end_date_seconds=`date  '+%s'  --date  "$end_date" `
# date指令format字符串时间。
     now_seconds=`date  '+%s' `
     echo  "($end_date_seconds-$now_seconds)/24/3600"  | bc
fi
[root@it-zabbix03 externalscripts]#
[root@it-zabbix03 externalscripts]#
[root@it-zabbix03 externalscripts]#
[root@it-zabbix03 externalscripts]#
[root@it-zabbix03 externalscripts]#ls
check_rabbitmq_stats  check_ssl  digium_active_calls  digium_active_ports  mikoomi-mongodb-plugin.php  mikoomi-mongodb-plugin.sh  rbl.check  rblwatch.py  rblwatch.pyc  ronglianyun.php  ronglianyun.sh
[root@it-zabbix03 externalscripts]#cat check_rabbitmq_stats
#!/usr/bin/python
 
import sys
import socket
import re
import ZabbixSender
#from ZabbixSender.ZabbixSender import ZabbixSender
 
import json
import socket
import urllib2
import requests
from  collections import defaultdict
 
class  RabbitMQAPI( object ):
     '' 'Class for RabbitMQ Management API' ''
 
     def __init__(self, username= 'guest' , password= 'guest' , hostname= '' ,
                  port=15672, interval=60):
         self.username = username
         self.password = password
         self.hostname = hostname or socket.gethostname()
         self.port = port
         self.stat_interval = interval
 
     def call_api(self, path):
         '' 'Call the REST API and convert the results into JSON.' ''
         url =  'http://{0}:{1}/api/{2}' .format(self.hostname, self.port, path)
         response = requests. get (url, auth=(self.username, self.password))
         '' '
         password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
         password_mgr.add_password(None, url, self.username, self.password)
         handler = urllib2.HTTPBasicAuthHandler(password_mgr)
         '' '
         return  json.loads(response.content)
 
     def get_message_details(self):
         '' 'get messages overview' ''
         messages = {}
         cluster = self.call_api( 'overview' )
         messages[ 'cluster.messages_ready' ] = cluster. get ( 'queue_totals' , {}). get ( 'messages_ready' ,0)
         messages[ 'cluster.messages_unacknowledged' ] = cluster. get (
             'queue_totals' , {}). get ( 'messages_unacknowledged' , 0)
         messages[ 'cluster.messages_deliver_get' ] =  float (format(cluster. get ( 'message_stats' , {}). get (
             'deliver_get_details' ,{}). get ( 'rate' ,0), '.2f' ))
         messages[ 'cluster.messages_publish' ] =  float (format(cluster. get ( 'message_stats' , {}). get (
             'publish_details' ,{}). get ( 'rate' , 0),  '.2f' ))
         messages[ 'cluster.messages_redeliver' ] =  float (format(cluster. get ( 'message_stats' , {}). get (
             'redeliver_details' ,{}). get ( 'rate' , 0),  '.2f' ))
         messages[ 'cluster.messages_ack' ] =  float (format(cluster. get ( 'message_stats' ,{}). get (
             'ack_details' ,{}). get ( 'rate' ,0),  '.2f' ))
         return  messages
 
     def get_nodes_details(self):
         detail = defaultdict( float )
         for  node  in  self.call_api( 'nodes' ):
             name = node[ 'name' ].split( '@' )[1]
             if  name == self.hostname.split( '.' )[0]:
                 detail[ 'nodes.proc_used' ] = node[ 'proc_used' ]
                 detail[ 'nodes.proc_total' ] = node[ 'proc_total' ]
                 detail[ 'nodes.proc_used_ratio' ] =format(
                     node[ 'proc_used' ]/ float (node[ 'proc_total' ]) * 100,  '.2f' )
                 detail[ 'nodes.fd_used' ] = node[ 'fd_used' ]
                 detail[ 'nodes.fd_total' ] = node[ 'fd_total' ]
                 detail[ 'nodes.fd_used_ratio' ] = format(
                     node[ 'fd_used' ]/ float (node[ 'fd_total' ]) * 100,  '.2f' )
                 detail[ 'nodes.sockets_used' ] = node[ 'sockets_used' ]
                 detail[ 'nodes.sockets_total' ] = node[ 'sockets_total' ]
                 detail[ 'nodes.sockets_used_ratio' ] = format(
                     node[ 'sockets_used' ]/ float (node[ 'sockets_total' ]) * 100,  '.2f' )
                 detail[ 'nodes.mem_used' ] = format(
                     node[ 'mem_used' ]/1024.0/1024.0, '.2f' )
                 detail[ 'nodes.mem_limit' ] = format(
                     node[ 'mem_limit' ]/1024.0/1024.0, '.2f' )
                 detail[ 'nodes.mem_used_ratio' ] = format(
                     node[ 'mem_used' ]/ float (node[ 'mem_limit' ]) * 100,  '.2f' )
                 detail[ 'nodes.disk_free' ] = format(
                     node[ 'disk_free' ]/1024.0/1024.0/1024.0, '.2f' )
                 detail[ 'nodes.disk_free_limit' ] = format(
                     node[ 'disk_free_limit' ]/1024.0/1024.0/1024.0, '.2f' )
                 detail[ 'nodes.disk_free_ratio' ] = format(
                     node[ 'disk_free' ]/ float (node[ 'disk_free_limit' ]),  '.2f' )
         return  detail
 
     def get_channels_details(self):
         channels = defaultdict( float )
         for  channel  in  self.call_api( 'channels' ):
             channels[ 'cluster.channels' ] += 1
             name = channel[ 'node' ].split( '@' )[1]
             if  name == self.hostname.split( '.' )[0]:
                 channels[ 'nodes.channels' ] += 1
                 if  'nodes.channels_blocked'  not  in  channels:
                     channels[ 'nodes.channels_blocked' ] = 0
                 if  'client_flow_blocked'  in  channel and channel[ 'client_flow_blocked' ]:
                     channels[ 'nodes.channels_blocked' ] += 1
                 else :
                     channels[ 'nodes.channels_blocked' ] += 0
                 channels[ 'nodes.messages_ack' ] +=  float (format(channel. get (
                     'message_stats' ,{}). get ( 'ack_details' ,{}). get ( 'rate' ,0),  '.2f' ))
                 channels[ 'nodes.messages_deliver_get' ] +=  float (format(channel. get (
                     'message_stats' ,{}). get ( 'deliver_get_details' ,{}). get ( 'rate' ,0),  '.2f' ))
                 channels[ 'nodes.messages_redeliver' ] +=  float (format(channel. get (
                     'message_stats' ,{}). get ( 'redeliver_details' ,{}). get ( 'rate' ,0),  '.2f' ))
                 channels[ 'nodes.messages_publish' ] +=  float (format(channel. get (
                     'message_stats' ,{}). get ( 'publish_details' ,{}). get ( 'rate' ,0),  '.2f' ))
         return  channels
 
     def get_queues_details(self):
         queues = defaultdict( int )
         max_queue_message_ready = 0
         max_queue_message_ready_queue =  ''
         max_queue_message_unack = 0
         max_queue_message_unack_queue =  ''
         for  queue  in  self.call_api( 'queues' ):
             queues[ 'cluster.queues' ] += 1
             queues[ 'cluster.consumers' ] += queue[ 'consumers' ]
             vhost_name = queue[ 'vhost' ].replace( '.' '-' )
             if  vhost_name ==  '/' :
                 vhost_name =  'default'
             node_name = queue[ 'node' ].split( '@' )[1]
             queue_name = queue[ 'name' ].replace( '.' '-' )
             if  node_name == self.hostname.split( '.' )[0]:
                 queues[ 'nodes.consumers' ] += queue[ 'consumers' ]
                 queues[ 'nodes.queues' ] += 1
                 queues[ 'nodes.messages_ready' ] += \
                     queue. get ( 'messages_ready' , 0)
                 queues[ 'nodes.messages_unacknowledged' ] += \
                     queue. get ( 'messages_unacknowledged' ,0)
             queues[ 'queues_'  + vhost_name +  '_'  + queue_name +  '.messages_ready' ] = \
                 queue. get ( 'messages_ready' ,0)
             if  queue. get ( 'messages_ready' , 0) >= max_queue_message_ready:
                 max_queue_message_ready = queue. get ( 'messages_ready' ,0)
                 max_queue_message_ready_queue = queue_name
             queues[ 'queues_'  + vhost_name +  '_'  + queue_name +  '.messages_unacknowledged' ] = \
                 queue. get ( 'messages_unacknowledged' , 0)
             if  queue. get ( 'messages_unacknowledged' ,0) >= max_queue_message_unack:
                 max_queue_message_unack = queue. get ( 'messages_unacknowledged' , 0)
                 max_queue_message_unack_queue = queue_name
             queues[ 'queues_'  + vhost_name +  '_'  + queue_name +  '.messages_ack' ] =  float (format(queue. get (
                 'message_stats' ,{}). get ( 'ack_details' ,{}). get ( 'rate' ,0),  '.2f' ))
             queues[ 'queues_'  + vhost_name +  '_'  + queue_name +  '.messages_deliver_get' ] =  float (format(queue. get (
                 'message_stats' ,{}). get ( 'deliver_get_details' ,{}). get ( 'rate' ,0),  '.2f' ))
             queues[ 'queues_'  + vhost_name +  '_'  + queue_name +  '.messages_publish' ] =  float (format(queue. get (
                 'message_stats' ,{}). get ( 'publish_details' ,{}). get ( 'rate' ,0),  '.2f' ))
             queues[ 'queues_'  + vhost_name +  '_'  + queue_name +  '.messages_redeliver' ] =  float (format(queue. get (
                 'message_stats' ,{}). get ( 'redeliver_details' ,{}). get ( 'rate' ,0),  '.2f' ))
         queues[ 'queues_max-queue-message-ready' ] = max_queue_message_ready
         queues[ 'queues_max-queue-message-ready-queue' ] = max_queue_message_ready_queue
         queues[ 'queues_max-queue-message-unack' ] = max_queue_message_unack
         queues[ 'queues_max-queue-message-unack-queue' ] = max_queue_message_unack_queue
         return  queues
 
     def get_connections_details(self):
         connections = defaultdict( int )
         for  connection  in  self.call_api( 'connections' ):
             connections[ 'cluster.connections' ] += 1
             node_name = connection[ 'node' ].split( '@' )[1]
             if  node_name == self.hostname.split( '.' )[0]:
                 connections[ 'nodes.connections' ] += 1
                 key =  'nodes.connections_blocked'
                 if  key not  in  connections:
                     connections[key] = 0
                 if  'last_blocked_age'  in  connection and \
                         connection[ 'last_blocked_age' ] !=  'infinity'  and \
                         connection[ 'last_blocked_age' ] <= self.stat_interval:
                     connections[key] += 1
                 else :
                     connections[key] += 0
         return  connections
 
     def get_bindings_details(self):
         bindings = defaultdict( int )
         for  binding  in  self.call_api( 'bindings' ):
             bindings[ 'cluster.bindings' ] += 1
         return  bindings
 
     def get_stats(self):
         stats = {}
         stats.update(self.get_message_details())
         stats.update(self.get_nodes_details())
         stats.update(self.get_channels_details())
         stats.update(self.get_queues_details())
         stats.update(self.get_connections_details())
         stats.update(self.get_bindings_details())
         return  stats
 
if  __name__ ==  '__main__' :
     set  zabix server
     zabbix =  'zabbix.test.com'
     sender = ZabbixSender(zabbix)
     # monitor key
     host = sys.argv[1]
     port = sys.argv[2]
 
     # gethostname  if  ip
     ipr = re.compile(r '^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$' )
     if  ipr.match(host):
         result = socket.gethostbyaddr(host)
         host   = result[0]
         if  re.search( '.' , host):
             host = host.split( '.' )[0]
 
     api = RabbitMQAPI(username= 'zabbix' , password= 'zabbix' ,hostname=host, port=port)
     stats = api.get_stats()
 
     for  key  in  stats:
         sender.AddData(host, "rabbitmq_" +key, stats[key])
     sender.Send()
     print 1


rbl.check

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/usr/bin/env python
#fileencoding: utf-8
#Author: 
 
from  rblwatch import RBLSearch
import sys
 
ip = sys.argv[1]
 
# Do the lookup (for smtp.gmail.com)
searcher = RBLSearch(ip)
 
# Display a simply formatted report of the results
results = searcher.get_results()
if  results ==  "DNSBL Report" :
     print 0
else :
     print results
# Use the result data for something else
#result_data = searcher.listed







      本文转自Tenderrain 51CTO博客,原文链接:http://blog.51cto.com/tenderrain/1966611,如需转载请自行联系原作者






相关实践学习
容器服务Serverless版ACK Serverless 快速入门:在线魔方应用部署和监控
通过本实验,您将了解到容器服务Serverless版ACK Serverless 的基本产品能力,即可以实现快速部署一个在线魔方应用,并借助阿里云容器服务成熟的产品生态,实现在线应用的企业级监控,提升应用稳定性。
云原生实践公开课
课程大纲 开篇:如何学习并实践云原生技术 基础篇: 5 步上手 Kubernetes 进阶篇:生产环境下的 K8s 实践 相关的阿里云产品:容器服务&nbsp;ACK 容器服务&nbsp;Kubernetes&nbsp;版(简称&nbsp;ACK)提供高性能可伸缩的容器应用管理能力,支持企业级容器化应用的全生命周期管理。整合阿里云虚拟化、存储、网络和安全能力,打造云端最佳容器化应用运行环境。 了解产品详情:&nbsp;https://www.aliyun.com/product/kubernetes
相关文章
|
3月前
|
存储 SQL 监控
修改Zabbix源码实现监控数据双写,满足业务需求!
虽然对接Elasticsearch后有诸多好处,但是它不往数据库写历史数据了,同时还不再计算趋势数据了。有这么一个场景...
修改Zabbix源码实现监控数据双写,满足业务需求!
|
4月前
|
数据采集 监控 数据库
OceanBase社区版可以通过Zabbix监控
OceanBase社区版可以通过Zabbix监控
75 4
|
4月前
|
监控 关系型数据库 机器人
小白带你学习linux的监控平台zabbix
小白带你学习linux的监控平台zabbix
134 0
|
1月前
|
数据采集 监控 数据库
请问OceanBase社区版能否通过zabbix监控,然后将报错信息展现到grafana?
【2月更文挑战第25天】请问OceanBase社区版能否通过zabbix监控,然后将报错信息展现到grafana?
25 2
|
6月前
|
监控
zabbix如何添加自定义监控项
zabbix如何添加自定义监控项
256 0
|
2月前
|
监控 Cloud Native 关系型数据库
使用 Grafana 统一监控展示 - 对接 Zabbix
使用 Grafana 统一监控展示 - 对接 Zabbix
|
4月前
|
监控 Docker 容器
Zabbix【部署 03】zabbix-agent2安装配置使用(zabbix-agent2监控docker实例分享)
Zabbix【部署 03】zabbix-agent2安装配置使用(zabbix-agent2监控docker实例分享)
221 0
|
4月前
|
监控 Java
Zabbix【部署 02】Zabbix-Java-Gateway安装配置使用(使用Zabbix-Java-Gateway通过JMX监控Java应用程序实例分享)
Zabbix【部署 02】Zabbix-Java-Gateway安装配置使用(使用Zabbix-Java-Gateway通过JMX监控Java应用程序实例分享)
87 0
|
10天前
|
监控 关系型数据库 应用服务中间件
zabbix自定义监控、钉钉、邮箱报警
zabbix自定义监控、钉钉、邮箱报警,实验准备,安装,添加监控对象,添加自定义监控项,监控mariadb,监控NGINX,钉钉报警设置,邮件报警
129 0
|
4月前
|
存储 监控 前端开发
zabbix概述及简单的在centos7安装Zabbix5.0及添加监控对象
Zabbix是一种开源的企业级监控解决方案,用于实时监控网络、服务器、应用程序等各种设备和服务的性能和可用性,并提供通知和报警功能。它具有灵活可扩展、可定制化的特点,可以满足不同规模和需求的监控需求。
162 0

推荐镜像

更多