闲着也是闲着,练练手,分析nginx日志http code码短信告知
#!/usr/bin/python
# -*- coding: UTF-8 -*-
'''
auth yufei
2016-4-3
分析nginx日志,计算200以及500等个数,并且短信通知
'''
import os
import fileinput
import re
import json
import urllib,urllib2
dir_log = r"/data/logs/access.log"
ipP = r"?P<ip>[\d.]*"
uidP = r"?P<uid>[\d.-]*"
timeP = r"?P<time>\[[^\[\]]*\]"
servernaemeP = r'?P<servernaeme>[\w.]*'
requestP = r'?P<request>\"[^\"]*\"'
statusP = r"?P<status>\d+"
bodyBytesSentP = r"?P<bodyBytesSent>\d+"
referP = r'?P<refer>\"[^\"]*\"'
userAgentP = r'?P<userAgent>\"[^\"]*\"'
phpP = r"?P<php>[\d.:]*"
qP = r"?P<q>[\d.]*"
hP = r"?P<h>[\d.]*"
nginxLogPattern = re.compile(r"(%s)\ -\ (%s)\ (%s)\ (