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,如需转载请自行联系原作者






相关实践学习
通过Ingress进行灰度发布
本场景您将运行一个简单的应用,部署一个新的应用用于新的发布,并通过Ingress能力实现灰度发布。
容器应用与集群管理
欢迎来到《容器应用与集群管理》课程,本课程是“云原生容器Clouder认证“系列中的第二阶段。课程将向您介绍与容器集群相关的概念和技术,这些概念和技术可以帮助您了解阿里云容器服务ACK/ACK Serverless的使用。同时,本课程也会向您介绍可以采取的工具、方法和可操作步骤,以帮助您了解如何基于容器服务ACK Serverless构建和管理企业级应用。 学习完本课程后,您将能够: 掌握容器集群、容器编排的基本概念 掌握Kubernetes的基础概念及核心思想 掌握阿里云容器服务ACK/ACK Serverless概念及使用方法 基于容器服务ACK Serverless搭建和管理企业级网站应用
相关文章
|
1月前
|
运维 监控 安全
【案例分享】中国通号卡斯柯公司:ZABBIX如何破解轨道交通监控难题
本文根据2023上海峰会上朱林贤的演讲整理,聚焦中国通号卡斯柯公司如何借助Zabbix实现轨道交通信号系统的智能化管理。作为中外合资企业,卡斯柯通过统一平台整合设备监控,大幅降低成本并提升灵活性,成功应用于国内外项目。文章探讨了传统监控系统的痛点、研发维护经验及国产化与开源技术挑战,为行业转型提供了宝贵启示。未来,开放协作将是推动轨道交通智能化发展的关键。
78 0
|
3月前
|
存储 缓存 监控
|
4月前
|
监控 Java 应用服务中间件
tomcat相关概念与部署tomcat多实例-zabbix监控(docker部署)
通过上述步骤,您可以在Ubuntu系统上成功编译并安装OpenCV 4.8。这种方法不仅使您能够定制OpenCV的功能,还可以优化性能以满足特定需求。确保按照每一步进行操作,以避免常见的编译问题。
84 23
|
4月前
|
监控 Java 应用服务中间件
tomcat相关概念与部署tomcat多实例-zabbix监控(docker部署)
通过上述步骤,您可以在Ubuntu系统上成功编译并安装OpenCV 4.8。这种方法不仅使您能够定制OpenCV的功能,还可以优化性能以满足特定需求。确保按照每一步进行操作,以避免常见的编译问题。
101 25
|
4月前
|
监控 Java 应用服务中间件
tomcat相关概念与部署tomcat多实例-zabbix监控(docker部署)
通过上述步骤,您可以在Ubuntu系统上成功编译并安装OpenCV 4.8。这种方法不仅使您能够定制OpenCV的功能,还可以优化性能以满足特定需求。确保按照每一步进行操作,以避免常见的编译问题。
96 22
|
5月前
|
监控 安全 前端开发
使用 Zabbix 监控堆外应用
使用 Zabbix 监控堆外应用
93 9
|
5月前
|
监控 数据可视化 Java
zabbix全面的监控能力
zabbix全面的监控能力
217 7
|
6月前
|
监控 Java Shell
监控堆外第三方监控工具Zabbix
监控堆外第三方监控工具Zabbix
116 5
|
6月前
|
SQL 监控 数据库
OceanBase社区版可以通过Zabbix监控
OceanBase社区版可以通过Zabbix监控
283 7
|
7月前
|
SQL 监控 数据库
OceanBase社区版可以通过Zabbix监控
【10月更文挑战第5天】随着OceanBase社区版的广泛应用,企业纷纷采用这一高性能、高可用的分布式数据库系统。为了确保系统的稳定运行,使用成熟的Zabbix监控工具进行全面监控至关重要。本文通过具体示例介绍了如何配置Zabbix监控OceanBase,包括安装配置、创建监控模板和监控项、编写脚本、设置触发器及图形展示等步骤,帮助读者快速上手,及时发现并解决问题,确保业务始终处于最佳状态。
178 2

热门文章

最新文章

推荐镜像

更多