使用python3调用wxpy模块监控linux日志并定时发送消息给群组或好友
作者:荣晓 发布时间:2022-05-12 03:35:29
标签:python,wxpy,模块,监控,linux
使用python3调用wxpy模块,监控linux日志并定时发送消息给群组或好友,具体代码如下所示:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from threading import Timer
from wxpy import *
import requests
import subprocess
import time
from PIL import Image, ImageDraw, ImageFont
from apscheduler.schedulers.blocking import BlockingScheduler
#cache_path=true 表示登陆一次之后,进行缓存,下次登陆只需要手机确认
bot = Bot(console_qr=2,cache_path=True)
#获取topic是否消费延迟
def get_Lag():
text=""
p = subprocess.Popen('kafka-consumer-offset-checker --zookeeper 192.168.1.116 --group t_sync --topic SYNC_DATABASE_UPDATE', shell=True, stdout=subprocess.PIPE,stderr=subprocess.PIPE,universal_newlines=True) #universal_newlines=True,表示输出为字符串,默认是byte
while True:
line =p.stdout.readline()
if not line:
break
else:
text+=line + '\n'
return text
def get_news():
text=[]
count=0
t=True
p = subprocess.Popen('tail -F /home/hadoop/da.txt', shell=True, stdout=subprocess.PIPE,stderr=subprocess.PIPE,universal_newlines=True)
while True:
line =str(p.stdout.readline())
if not line:
break
elif "send data" in line and t:
for item in line.split(','):
count +=1
if count <= 200:
text.append(item)
break
return text
def get_context():
result=""
word=get_news()
for i in range(len(word)):
if(i % 4 ==0):
result= result+word[i]+"\n"
else:
result= result+word[i]+" "
return result
def send_image():
try:
lags=get_Lag()
print(lags)
content=get_context()
#发送消费延迟的数据
lagImage= Image.new('RGB', (1000, 600),(255,255,255))
draw = ImageDraw.Draw(lagImage)
font = ImageFont.truetype("/usr/share/fonts/cjkuni-ukai/ukai.ttc", 18, encoding="unic")
draw.text((10, 10), lags, 'black', font)
lagImage.save('/home/hadoop/lags.jpg')
#发送日志消息
image= Image.new('RGB', (1000, 810),(255,255,255))
draw = ImageDraw.Draw(image)
font = ImageFont.truetype("/usr/share/fonts/cjkuni-ukai/ukai.ttc", 18, encoding="unic") #ukai.ttc 字体
draw.text((10, 10), content, 'black', font)
image.save('/home/hadoop/123.jpg')
#发送群组
group = bot.groups().search("大数据小组")[0]
group.send_image('/home/hadoop/123.jpg')
#发送好友
my_friend = bot.friends().search(u'涛')[0]
my_friend.send_image('/home/hadoop/lags.jpg')
my_friend.send_image('/home/hadoop/123.jpg')
# t = Timer(100, send_image)
#t.start()
except:
my_friend.send(u"今天消息发送失败了")
if __name__ == "__main__":
#send_image()
scheduler = BlockingScheduler()
scheduler.add_job(send_image, 'cron', hour='15', minute='01')
scheduler.add_job(send_image, 'cron', hour='14', minute='58')
scheduler.start()
总结
以上所述是小编给大家介绍的使用python3调用wxpy模块监控linux日志并定时发送消息给群组或好友,网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!
来源:https://blog.csdn.net/weixin_43015677/article/details/90411821
0
投稿
猜你喜欢
- 前言故事要从上面这张表情包开始讲起,看到这张表情包之后,我突发奇想,觉得可以将室友上班摸鱼的照片拼接起来,做成表情包叫他起床 激励他学习!!
- 本文实例讲述了PHP abstract 抽象类定义与用法。分享给大家供大家参考,具体如下:PHP抽象类应用要点:1.定义一些方法,子类必须完
- 本文为大家分享了threadpool线程池中所有的操作,供大家参考,具体内容如下首先介绍一下自己使用到的名词:工作线程(worker):创建
- 最近发现一个问题,是关于IDEA的一些骚操作的事儿~具体怎么回事,一起来看看。我们都知道使用git分布式版本控制工具,提、拉 代码都会有一个
- 编写程序的时候,经常要处理字符串,最基本就是字符串的查找,在php检测字符串中是否包含指定字符串可以使用正则,如果你对正则不了解,那么有几个
- 官方文档https://developers.weixin.qq.com/miniprogram/dev/devtools/download
- 没人愿意等待。所以,没有访问者真的能够忍受一个打开速度极慢的网站。但是,网页打开速度到底对用户行为有什么影响,恐怕没几个人能够说清楚吧。前几
- super()函数可以用于继承父类的方法,语法如下:super(type[, object-or-type])虽然super()函数的使用比
- Turtle图形库Turtle 库是 Python 内置的图形化模块,属于标准库之一,位于 Python 安装目录的 lib 文件夹下,常用
- 前面讲述了"专题一.函数的基础知识",而这篇文章讲述的Python的条件语句和循环语句的基础知识.主要内容包括:1.条件
- 1 什么是 NumpyNumPy,是 Numerical Python 的简称,用于高性能科学计算和数据分析的基础包,像数学科学工具(pan
- QMainWindow基本介绍QMainWindow主窗口为用户提供了一个应用程序框架,它有自己的布局,可以在布局中添加控件。窗口类型介绍P
- 本文实例讲述了Python判断Abundant Number的方法。分享给大家供大家参考。具体如下:Abundant Number,中文译成
- BLOG阅读:http://www.planabc.net/article.asp?id=118在使用CSS实现表现的时候,会经常接触到di
- 这里有一些很棒的自动化脚本,你可以在你的 Python 项目中使用它们。在做项目的时候,我们需要一些现成的代码来帮助我们解决日常生活中的问题
- 在flask中可以像go和angular那样使用页面模版(template),可以将HTML页面显示进行模版化,通过参数传递与页面进行数据交
- 一、图像的加法图像相加可以直接利用numpy模块进行相加,也可以采用opencv里面函数进行相加,注意事项:相加的图像类型、大小必须相同具体
- 注:本文的所有数据请移步—— 参考数据一、水平堆叠图堆叠图其实就是柱状图的一种特殊形式fr
- 对于部署在百度应用引擎BAE上的项目,使用百度云存储BCS(Baidu Cloud Storage)是不错的存储方案。百度云存储已有Pyth
- wxpython最为一款python GUI库,由于简单和轻便外加强大的功能而受到很多python爱好者的喜爱,pymysql作为pytho