Zabbix Monitoring Windows log Scripts
The script is used to monitor the logs on the Windows Server, view the log file at the end of n rows, and if n rows contain a field, output 0, otherwise output 1, and then zabbix the profile empty definition Kye, for monitoring.
Text file line break is "\ n"
Edit Script log.py
Import sysimport redef last_lines (filename, lines = 1): Lines = int (lines) block_size = 1024 block = ' nl_count = 0 start = 0 fsock = file (filename, ' RU ') try: # seek to end Fsock.seek (0, 2) # get seek position curpos = fsock.tell () while (curpos > 0): #while not EOF # seek ahead block_size+the length of last read block curpos -= (block_size + len (block)); if curpos < 0: curpos = 0 fsock.seek ( CurPos) # read to end block = fsock.read () nl_count = block.count (' \ n ') # if read enough (more) if nl_count >= lines: break # get the exact start position for n in range (nl_count - lines + 1): start = block.find (' \ n ', start) + 1 finally: fsock.close () return block[start:]list = last_lines (sys.argv[1], sys.argv[2]) If re.search (" AAA ", list): #查看是否包含" AAA "print 0else:print 1
Here's how it works: Python log.py log.txt #最后10行
This article from "Three O elder brother" blog, declined reprint!
Zabbix Monitoring Windows log Scripts