📄 logengine.py
字号:
#!/usr/bin/env python# -*- coding: ISO-8859-1 -*-## Copyright 2003, 2004 Norwegian University of Science and Technology## This file is part of Network Administration Visualized (NAV)## NAV is free software; you can redistribute it and/or modify# it under the terms of the GNU General Public License as published by# the Free Software Foundation; either version 2 of the License, or# (at your option) any later version.## NAV is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.## You should have received a copy of the GNU General Public License# along with NAV; if not, write to the Free Software# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA### $Id: main.py 2774 2004-06-04 18:50:41Z gartmann $# Authors: Sigurd Gartmann <sigurd-nav@brogar.org>, 2004### The structure in this file is not good, but understandable. It is easy## to see that this file is converted from procedure oriented perl code.## go down to the main part first if you want to know what this is all## about.import reimport fcntlimport osimport navfrom mx import DateTimefrom nav import dbfrom ConfigParser import ConfigParserconfig = ConfigParser()config.read(os.path.join(nav.path.sysconfdir,'logger.conf'))logfile = config.get("paths","syslog")connection = db.getConnection('logger','logger')database = connection.cursor()def get_exception_dicts(config): options = config.options("priorityexceptions") exceptionorigin = {} exceptiontype = {} exceptiontypeorigin = {} exceptions = {} for option in options: newpriority = config.get("priorityexceptions", option) op = re.split("@",option) if len(op) == 1: exceptions[op[0]] = newpriority if len(op) == 2: any = re.compile("any",re.I) if not op[0] or any.search(op[0]): exceptionorigin[op[1]] = newpriority if not op[1] or any.search(op[1]): exceptiontype[op[0]] = newpriority #both fields if op[0] and op[1]: if not exceptiontypeorigin.has_key(op[0]): exceptiontypeorigin[op[0]] = {} exceptiontypeorigin[op[0]][op[1]] = newpriority #only one of the fields for exception, priority in exceptions.items(): typematch = re.search("^\w+\-\d+\-\S+$", exception) if typematch: exceptiontype[exception] = priority else: exceptionorigin[exception] = priority return (exceptionorigin,exceptiontype,exceptiontypeorigin)def createMessage(line): typicalmatch = re.search("^(\w+)\s+(\d+)\s+(\d+)\:(\d+):\d+\W+(\S+\.\w+)\W+(?:(\d{4})|.*)\s+\W*(\w+)\s+(\d+)\s+(\d+):(\d+):(\d+).*%(.*?):\s*(.*)$",line) if typicalmatch: servmonth = find_month(typicalmatch.group(1)) servyear = find_year(servmonth) servday = int(typicalmatch.group(2)) servhour = int(typicalmatch.group(3)) servmin = int(typicalmatch.group(4)) origin = typicalmatch.group(5) month = find_month(typicalmatch.group(7)) year = find_year(month) day = int(typicalmatch.group(8)) hour = int(typicalmatch.group(9)) min = int(typicalmatch.group(10)) type = typicalmatch.group(12) description = typicalmatch.group(13) # does no control of clocks, using servtime servtime = DateTime.DateTime(servyear,servmonth,servday,servhour,servmin) oritime = DateTime.DateTime(year,month,day,hour,min) #stoler p
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -