首页 > 数据库 >python监控MongoDB服务进程,故障钉钉告警

python监控MongoDB服务进程,故障钉钉告警

时间:2024-04-22 17:15:36浏览次数:17  
标签:mongo python MongoDB pd ip 告警 os port 2port

 

服务器1 xx.168.8x.77

#!/usr/bin/python
#! _*_ coding:utf-8 _*_

import os
import sys
import time

mongo_ip = '192.168.xx.77'
ports = ['x001','x002']
def port(ip,port):
   response = os.popen("tcping  %s %s|grep open|awk -F' ' '{print $4}'|cut -d'.' -f1" %(ip,port)).read().strip()
   if response == 'open':
      return response
   else:
      return 'port_fail'

def write_f(st):
   with open('mongo_pd.txt', 'a') as file:
    file.write(st)
    file.close()

pdlist = []
for p in ports:
   jg = port(mongo_ip,p)
   pdlist.append(mongo_ip+':'+p+'-->'+jg+'\n')
unique_list = list(set(pdlist))

if os.path.exists('mongo_pd.txt'):
   os.remove('mongo_pd.txt')
for din in unique_list:
   if 'port_fail' in din:
      write_f(din)
   else:
      write_f(din)

 

服务器2 x92.168.8x.83

#!/usr/bin/python
#! _*_ coding:utf-8 _*_

import os
import sys
import time
sshuser = 'root'
sshpassword = '12xxxxx'
ip = '1xx.168.x4.77'
pd_str = 'port_fail'



def dingding(ding_msg):
   os.system("/usr/bin/curl  https://oapi.dingtalk.com/robot/send?access_token=xb5ccxxxxxxxbbf1d7xxxx084xxxxxxe9b9ff968xxxxxxxxxx  -H \"Content-Type: application/json\" -d \"{'msgtype': 'text', 'at': {'atMobiles': ['13xxx20xxx'], 'isAtAll': false}, 'text': {'content': \'%s\'}}\" " %(ding_msg))

#pd_str = 'open'
mongo_8x77_2port_status = os.popen('sshpass -p %s  ssh  %s@%s -o StrictHostKeyChecking=no "cat /data/jk_mongodb/8483_jk_8477mongodb/mongo_pd.txt" |grep %s'%(sshpassword,sshuser,ip,pd_str)).read().strip()
#print(mongo_8x77_2port_status)
if 'port_fail' in mongo_8x77_2port_status:
    ding_msg = 'Yearning-pro_xx项目mongodb服务进程端口%s已经故障,请注意查看!!!'%(mongo_8x77_2port_status)
    dingding(ding_msg)

标签:mongo,python,MongoDB,pd,ip,告警,os,port,2port
From: https://www.cnblogs.com/hmysql/p/18150994

相关文章

  • 在Python中的for循环
    在Python中的for循环for循环:用于遍历序列(如列表、元组、字典、集合或字符串)或其他可迭代对象。pythonforiinrange(10):#这将循环10次,i的值从0到9print(i)while循环:当给定条件为真时,重复执行代码块。pythoni=0whilei<10:#这将循环10次print(i)i......
  • python 多并发
    多并发实现1#!/usr/bin/python2#-*-coding:utf-8-*-34"""5@File:.py6@Description:7@Time:2024/04/2210:00:008@Author:9@Version:1.010@Contact:[email protected]"""1213impor......
  • Python实现下载文件的三种方法
    下面来看看三种方法是如何来下载zip文件的:方法一: importurllibprint"downloadingwithurllib"url='http://www.jb51.net//test/demo.zip'urllib.urlretrieve(url,"demo.zip") 方法二: importurllib2print"downloadingwithurllib2"u......
  • 使用pyppeteer 下载chromium 报错 python pyppeteer 调用谷歌翻译api
    https://registry.npmmirror.com/binary.html?path=chromium-browser-snapshots/Win_x64/手动下载安装包 修改文件C:\Users\luyan\AppData\Local\Programs\Python\Python312\Lib\site-packages\pyppeteer\chromium_downloader.py #修改这段代码defdownload_chromium()-......
  • Python实现批量下载文件的示例代码
    前言下载文件是我们在日常工作中常常要做的一件事情。当我们需要从互联网上批量下载大量文件时,手动一个一个去下载显然不够高效。为了解决这个问题,我们可以使用Python编写一个批量下载文件的脚本,让它自动帮我们下载文件。同时,为了避免下载过程中被网站禁止访问,我们也可以运用代理......
  • Python数据容器
    1.容器定义:容纳多份数据的数据类型。Python的数据容器可以理解为C++中的数据结构,这些数据结构的方法多为“增删改查”。容器类型:列表、元组、字符串、2.列表list列表可理解为数组,下标从0开始。定义定义代码name_list=['zhangsan','lisi','wangwu']#字......
  • 接口自动化Python+requests踩坑记录
    问题描述同一个接口,传参相同,用postman,jmeter等接口工具都能正常访问,后台也能正常返回数据,但是用requests.post()调用就会返回400jmeter传参以及响应这是一个登录接口,如图所示的传参,是可以正常登录的  postman传参以及响应可以看到,两个工具的传参不一样,但是也是同样可以正......
  • ArcPy自动绘制大量地图并设置地图要素:Python
      本文介绍基于Python语言中ArcPy模块,实现ArcMap自动批量出图,并对地图要素进行自定义批量设置的方法。1任务需求  首先,我们来明确一下本文所需实现的需求。  现有通过Python基于Excel数据加以反距离加权空间插值并掩膜图层所绘制的北京市在2019年05月18日00时至23时(其中......
  • pyhon脚本监控远程服务器存活情况,异常发送钉钉告警
    #!/usr/bin/python#!_*_coding:utf-8_*_importosimporttimefromcollectionsimportCounterfromdatetimeimportdatetimehost='localhost'ips=['192.168.xx.70','192.168.xx.83','172.16.xx.107']defping(ip):  #respo......
  • 《最新出炉》系列初窥篇-Python+Playwright自动化测试-38-如何截图-下篇
    1.简介这个系列的文章也讲解和分享了差不多三分之一吧,突然有小伙伴或者童鞋们问道playwright有没有截图的方法。答案当然是:肯定有的。宏哥回过头来看看确实这个非常基础的知识点还没有讲解和分享。那么在这个契机下就把它插队分享和讲解一下。Playwright提供了一个截屏的API:page.......