import osimport reimport shutilimport timeimport itchatfrom itchat.content import *# 说明:可以撤回的有文本文字、语音、视频、图片、位置、名片、分享、附件# {msg_id:(msg_from,msg_to,msg_time,msg_time_rec,msg_type,msg_content,msg_share_url)}msg_dict = {}# 文件存储临时目录rev_tmp_dir = os.path.join(os.getcwd(),"rollback_itchat/")# rec_tmp_dir = os.path.join(os.getcwd(), ‘tmp/‘)# print(rec_tmp_dir)if...
一、os.listdirimport os, time
path_to_watch = "."
before = dict ([(f, None) for f in os.listdir (path_to_watch)])
while 1:time.sleep (10)after = dict ([(f, None) for f in os.listdir (path_to_watch)])added = [f for f in after ifnot f in before]removed = [f for f in before ifnot f in after]if added: print"Added: ", ", ".join (added)if removed: print"Removed: ", ", ".join (removed)before = after二、F...
#!/usr/bin/python
#! --*-- coding:utf-8 --*--import requests
import time
import json
import sys
import commandsts = int(time.time())
#print ts
cmd = 'curl 172.31.0.92:9200/_cat/health'
(a, b) = commands.getstatusoutput(cmd)
#print b
status= b.split(' ')[157]
if status=='green':
healthy=3
elif status=='yellow':
healthy=2
elif status=='red':
healthy=1
else:
healthy=0#print healthypa...
一个简易的日志监控的脚本,功能如下:1.windows环境2.当匹配日志关键字时会发出声音,匹配的关键字不同,播放的声音不同3.能做到实时响应注意:是在win环境下哦直接上代码吧123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081#!/usr/bin/env python# encoding: utf-8 """MonitorLog.py Usage: MonitorLog.py ...M...
监控数据库是否可写,如果你的监控脚本逻辑是,写入数据库成功后显示成功,反之显示不成功然后报警。那么难题来了,数据库真的无法写入了,你的监控脚本的写入命令也会被mysql hang住,一直卡在那里,直到天荒地老,根本无法实现报警。那换个思路,如果设置个超时时间,是不是更好。#!/usr/bin/env python
# -*-coding:utf8-*-
import MySQLdb
import re
import smtplib
import json
from email.mime.text
import MIMEText
import...
#!/usr/bin/env python
#coding:utf8
import re
import os
import time
import smtplib
import socket
import fcntl
import struct
from email.mime.text import MIMEText
def get_ip_address(ifname):s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)return socket.inet_ntoa(fcntl.ioctl(s.fileno(),0x8915, # SIOCGIFADDRstruct.pack(256s, ifname[:15]))[20:24])def sendemail(subject,msg,fromemail,emailpasswd,toema...
一个简易的日志监控的脚本,功能如下:1.windows环境2.当匹配日志关键字时会发出声音,匹配的关键字不同,播放的声音不同3.能做到实时响应注意:是在win环境下哦直接上代码吧#!/usr/bin/env python
# encoding: utf-8"""
MonitorLog.pyUsage: MonitorLog.py ...
Monitor the log file-f log file
-h help infopython MonitorLog.py -f C:\monitor.log"""import sys
import os
import getopt
import subprocess
import time
impor...
#需求:
#1. 每分钟监控服务器日志,每分钟请求超过200次,加入黑名单# 编写思路
# 1. 读文件,获取每行的内容 open readlines
# 178.210.90.90 - - [04/Jun/2017:03:44:13 +0800]
#2. 找到IP地址,按照空格分割字符串,取第一个元素 split
#3. 把IP存到字典里面,每个IP出现一次,IP次数就加1
# {ip1:1,ip2:2,ip3:1}
# [178.210.90.90,178.210.90.90,178.210.90.90]
#4. 判断IP次数是否大于200,加入黑名单import time
point=0
wh...
这篇文章主要介绍了关于使用Python监控文件内容变化代码,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下在python中文件监控主要有两个库,一个是pyinotify,一个是watchdog。pyinotify依赖于Linux平台的inotify,今天我们就来探讨下pyinotify.利用seek监控文件内容,并打印出变化内容:#/usr/bin/env python
#-*- coding=utf-8 -*-pos = 0
while True:con = open("a.txt")if pos != 0:con.seek(pos,0)while True:...
这篇文章主要介绍了python监控linux内存并写入mongodb的相关资料,需要的朋友可以参考下(需要安装psutil 用来获取服务器资源,以及pymongo驱动)#pip install psutil#pip install pymongo
#vim memory_monitory.py文件内容如下#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import psutil
import socket
import time
from pymongo import MongoClient
mongodbIp = 192.168.200.112
mongodbPort = 27017
hostname = socket.gethos...
利用python来检查MySQL的主从复制,有一个注意点是,cur.execute("show slave status;") 不能用cur.execute("show slave status\G;")result = cur.fetchall() 返回的是个二元数组result[0] 返回时整个show slave status 状态信息。result[0][n] 返回具体的某一项。python代码如下:#!/usr/bin/env python#-*- coding: utf-8 -*-import MySQLdb, socket, paramiko,sys, os,datetimedef final_check_mysql (): status = True t...
crtrl.py监控Apache服务器进程的Python 脚本代码如下:!/usr/bin/env Python import os, sys, time
while True: time.sleep(4) try: ret = os.popen(ps -C apache -o pid,cmd).readlines() if len(ret) < 2: print "apache 进程异常退出, 4 秒后重新启动" time.sleep(3) os.system("service apache2 restart") except: print "Error", sys.exc_info()[1]
设置文件权限为执行属性(使用命令 chmod +x crtrl.py),然后加入到/etc/r...
本文实例讲述了python监控网站运行异常并发送邮件的方法。分享给大家供大家参考。具体如下:
这是一个简单的python开发的监控程序,当指定网页状态不正常是通过smtp发送通知邮件代码如下:#!/usr/bin/env python
# -*- coding: UTF-8 -*-
#author libertyspy
import socket
import smtplib
import urllib
mail_options = {server:smtp.qq.com,#使用了QQ的SMTP服务,需要在邮箱中设置开启SMTP服务port:25, #端口user:ha...
利用Python写了简单测试主机是否存活脚本,此脚本不适于线上使用,因为网络延迟、丢包现象会造成误报邮件,那么后续会更新判断三次ping不通后再发报警邮件,并启用多线程处理。#!/usr/bin/env python
# coding:UTF-8
import time
import pexpect
import smtplib
from email.mime.text import MIMEText
mail_host = "smtp.163.com" #定义smtp服务器
mail_to = "baojingtongzhi@163.com" #邮件收件人
mail_from = "monito...
代码如下:#!/usr/bin/env pythonimport sys,timefrom socket import socketdef read_interface(in_file): with file(in_file) as f: return f.readlines()[2:]def set_interface(inter_msg): dic={} for i in xrange(len(inter_msg)): dic[inter_msg[i].split(":")[0].strip()]={"in":inter_msg[i].split(":")[1].strip().split()[0],"out":inter_msg[i].split(":")[1].strip().split()[8]} return dicC...