#!/usr/bin/python -O # # Dinko Korunic 'kreator', 2005. # wlan-stat.py # script for WLAN statistics from Cisco syslog output # - statistics per month and log message # # Copyright (C) 2005 Dinko Korunic, InfoMAR d.o.o. # # This program 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. # # This program 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 this program; if not, write to the Free Software Foundation, Inc., # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # $Id: wlan-stat.py 162 2005-07-19 22:25:21Z kreator $ import sys, re def main(): months = { 'Jan': 1, 'Feb': 2, 'Mar': 3, 'Apr': 4, 'May': 5, 'Jun': 6, 'Jul': 7, 'Aug': 8, 'Sep': 9, 'Oct': 10, 'Nov': 11, 'Dec': 12 } # helpful regexes time_regex = '^(\w{3}) +\d+ \d{2}:\d{2}:\d{2}' misc_regex = '.+' # standard Cisco log messages ap_logmsg = { 'assoc': '%DOT11-6-ASSOC:', 'disassoc': '%DOT11-6-DISASSOC:', 'maxret': '%DOT11-4-MAXRETRIES:', 'authfail': '%DOT11-7-AUTH_FAILED:', 'updownif': '%LINK-3-UPDOWN:', 'resetif': '%LINK-5-CHANGED:' } ap_stats = {} # generate prefix regexes for key, val in ap_logmsg.iteritems(): ap_logmsg[key] = re.compile(time_regex + misc_regex + val) ap_stats[key] = {} # match lines for line in sys.stdin: for msg_key, msg_val in ap_logmsg.iteritems(): result = msg_val.match(line) if result: msg_month_re = result.group(1) msg_month = months[msg_month_re] try: ap_stats[msg_key][msg_month] += 1 except KeyError: ap_stats[msg_key][msg_month] = 1 # DEBUG output for msg_key, msg_val in ap_stats.iteritems(): print msg_key, ':', msg_val if __name__ == '__main__': main()