def main(): ip = get_ip_address() disklist = f_detect_disk_readonly() for disk in disklist: # 如果某块磁盘频繁发生只读请联系技术支持! message = "%s %s文件系统只读" % (ip, disk) print sendsms(string.join(phone, "|"), message)
def login_codesend(): codeform = LoginSMSCodeForm() if codeform.validate_on_submit(): num = codeform.phonenumber.data user = UserPhone.query.filter_by(phone=num).first() if user is None: user = UserPhone(phone=num) db.session.add(user) db.session.commit() code = generate_code() decod_code = decoding_code(code) sendsms(decod_code, '+86' + str(num)) flash('Have send a validate code to your phone') return redirect(url_for('.login_codeverify', code=code, num=num)) return render_template('auth/logincodesend.html', form=codeform)
def main(): ip = get_ip_address() diskinfo = f_diskinfo() # df.1kblocks.total 1373990040 20641404 mount=/ fstype=ext4 # df.1kblocks.used 1373990040 10632160 mount=/ fstype=ext4 # df.1kblocks.free 1373990040 8960720 mount=/ fstype=ext4 for key in diskinfo: diskused = float(diskinfo[key].get("df.1kblocks.used")) disktotal = float(diskinfo[key].get("df.1kblocks.total")) utilization = (diskused / disktotal) if(utilization > watermark ): message = "%s 文件系统 [%s] 磁盘使用率超过 %.2f%%" % (ip, key, utilization * 100) print sendsms(string.join(phone, "|"), message)
def main(): ip = get_ip_address() diskinfo = f_diskinfo() # df.1kblocks.total 1373990040 20641404 mount=/ fstype=ext4 # df.1kblocks.used 1373990040 10632160 mount=/ fstype=ext4 # df.1kblocks.free 1373990040 8960720 mount=/ fstype=ext4 for key in diskinfo: diskused = float(diskinfo[key].get("df.1kblocks.used")) disktotal = float(diskinfo[key].get("df.1kblocks.total")) utilization = (diskused / disktotal) if (utilization > watermark): message = "%s 文件系统 [%s] 磁盘使用率超过 %.2f%%" % (ip, key, utilization * 100) print sendsms(string.join(phone, "|"), message)
def main(): ip = get_ip_address() meminfo = f_meminfo() # proc.meminfo.memfree 1373986088 4005464 # proc.meminfo.buffers 1373986088 381416 # proc.meminfo.cached 1373986088 9843132 # proc.meminfo.memtotal 1373986088 16268732 memtotal = float(meminfo.get("proc.meminfo.memtotal")); memused = memtotal - float(int(meminfo.get('proc.meminfo.memfree')) + int(meminfo.get('proc.meminfo.buffers')) + int(meminfo.get('proc.meminfo.cached'))); utilization = (memused / memtotal) if(utilization > watermark ): message = "%s 内存使用率超过 %.2f%%" % (ip, utilization * 100) sendsms(string.join(phone, "|") , message)
def check_server_status(server): ''' Function to check whether a server or host is available. If not, this function will call sendsms defined in sendsms.py to send a text message notification. The process will pause for 30 minutes and send another notification if the host is still unreachable. ''' server_status = check_ping(server) if server_status != True: sendsms() while server_status == False: time.sleep(1800) if server_status == True: break else: sendsms()
def main(): ip = get_ip_address() meminfo = f_meminfo() # proc.meminfo.memfree 1373986088 4005464 # proc.meminfo.buffers 1373986088 381416 # proc.meminfo.cached 1373986088 9843132 # proc.meminfo.memtotal 1373986088 16268732 memtotal = float(meminfo.get("proc.meminfo.memtotal")) memused = memtotal - float( int(meminfo.get('proc.meminfo.memfree')) + int(meminfo.get('proc.meminfo.buffers')) + int(meminfo.get('proc.meminfo.cached'))) utilization = (memused / memtotal) if (utilization > watermark): message = "%s 内存使用率超过 %.2f%%" % (ip, utilization * 100) sendsms(string.join(phone, "|"), message)
def motion_detection(gs_window, gs_sig, diff_thresh, min_area, mod): flag = 1 camera = cv2.VideoCapture(0) if (camera.isOpened()) == False: easygui.msgbox( "Please turn on your camera, and if you dont know how, please get out of my sight xD" ) size = (int(camera.get(cv2.CAP_PROP_FRAME_WIDTH)), int(camera.get(cv2.CAP_PROP_FRAME_HEIGHT))) print('size:' + repr(size)) es = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (5, 4)) kernel = np.ones((5, 5), np.uint8) background = None while True: text = "Undetected" grabbed, frame_lwpCV = camera.read() gray_lwpCV = cv2.cvtColor(frame_lwpCV, cv2.COLOR_BGR2GRAY) gray_lwpCV = cv2.GaussianBlur(gray_lwpCV, (gs_window, gs_window), gs_sig) # gray_lwpCV = cv2.blur(gray_lwpCV, (10, 50)) if background is None: background = gray_lwpCV continue diff = cv2.absdiff(background, gray_lwpCV) diff = cv2.threshold(diff, diff_thresh, 255, cv2.THRESH_BINARY)[1] diff = cv2.dilate(diff, es, iterations=2) image, contours, hierarchy = cv2.findContours(diff.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) for c in contours: if cv2.contourArea(c) < min_area: continue (x, y, w, h) = cv2.boundingRect(c) cv2.rectangle(frame_lwpCV, (x, y), (x + w, y + h), (0, 255, 0), 2) text = "Detected" if text == 'Undetected': cv2.putText(frame_lwpCV, "Motion: {}".format(text), (10, 20), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2) cv2.putText( frame_lwpCV, datetime.datetime.now().strftime("%A %d %B %Y %I:%M:%S%p"), (10, frame_lwpCV.shape[0] - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.35, (0, 255, 0), 1) if text == 'Detected': cv2.putText(frame_lwpCV, "Motion: {}".format(text), (10, 20), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 2) cv2.putText( frame_lwpCV, datetime.datetime.now().strftime("%A %d %B %Y %I:%M:%S%p"), (10, frame_lwpCV.shape[0] - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.35, (0, 0, 255), 1) if flag == 1 and mod == 1: sendsms.sendsms() cv2.imshow('contours', frame_lwpCV) cv2.imshow('dis', diff) key = cv2.waitKey(1) & 0xFF # 按'q'健退出循环 if key == ord('q'): break camera.release() cv2.destroyAllWindows()